style: Make Servo_StyleSet_NoteStyleSheetsChanged take a set of origins to dirty. draft
authorCameron McCormack <cam@mcc.id.au>
Sat, 12 Aug 2017 18:18:52 +0800
changeset 645509 7521a53080194e3c598638cd2cb68b8f00321b99
parent 645508 5d96bbf58c53e389b93bbe90e4ccdc87db55b8e7
child 645510 ccedec7a6cbf8829832d328955ecee949fdd79cb
push id73769
push userbmo:cam@mcc.id.au
push dateSun, 13 Aug 2017 04:04:30 +0000
milestone57.0a1
style: Make Servo_StyleSet_NoteStyleSheetsChanged take a set of origins to dirty. MozReview-Commit-ID: 6Y4MRB5bWto
servo/components/style/gecko_bindings/sugar/mod.rs
servo/components/style/gecko_bindings/sugar/origin_flags.rs
servo/ports/geckolib/glue.rs
--- a/servo/components/style/gecko_bindings/sugar/mod.rs
+++ b/servo/components/style/gecko_bindings/sugar/mod.rs
@@ -8,11 +8,12 @@ mod ns_com_ptr;
 mod ns_compatibility;
 mod ns_css_shadow_array;
 mod ns_css_shadow_item;
 pub mod ns_css_value;
 mod ns_style_auto_array;
 pub mod ns_style_coord;
 mod ns_t_array;
 mod ns_timing_function;
+mod origin_flags;
 pub mod ownership;
 pub mod refptr;
 mod style_complex_color;
new file mode 100644
--- /dev/null
+++ b/servo/components/style/gecko_bindings/sugar/origin_flags.rs
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+//! Helper to iterate over `OriginFlags` bits.
+
+use gecko_bindings::structs::OriginFlags;
+use gecko_bindings::structs::OriginFlags_Author;
+use gecko_bindings::structs::OriginFlags_User;
+use gecko_bindings::structs::OriginFlags_UserAgent;
+use stylesheets::Origin;
+
+impl OriginFlags {
+    /// Returns an iterator over the origins present in the `OriginFlags`,
+    /// in order from highest priority (author) to lower (user agent).
+    pub fn iter(self) -> OriginFlagsIter {
+        OriginFlagsIter {
+            origin_flags: self,
+            cur: 0,
+        }
+    }
+}
+
+/// Iterates over the origins present in an `OriginFlags`, in order from
+/// highest priority (author) to lower (user agent).
+pub struct OriginFlagsIter {
+    origin_flags: OriginFlags,
+    cur: usize,
+}
+
+impl Iterator for OriginFlagsIter {
+    type Item = Origin;
+
+    fn next(&mut self) -> Option<Origin> {
+        loop {
+            let (bit, origin) = match self.cur {
+                0 => (OriginFlags_Author, Origin::Author),
+                1 => (OriginFlags_User, Origin::User),
+                2 => (OriginFlags_UserAgent, Origin::UserAgent),
+                _ => return None,
+            };
+
+            self.cur += 1;
+
+            if (self.origin_flags & bit).0 != 0 {
+                return Some(origin);
+            }
+        }
+    }
+}
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -69,16 +69,17 @@ use style::gecko_bindings::bindings::nsT
 use style::gecko_bindings::structs;
 use style::gecko_bindings::structs::{CSSPseudoElementType, CompositeOperation, Loader};
 use style::gecko_bindings::structs::{RawServoStyleRule, ServoStyleContextStrong};
 use style::gecko_bindings::structs::{ServoStyleSheet, SheetParsingMode, nsIAtom, nsCSSPropertyID};
 use style::gecko_bindings::structs::{nsCSSFontFaceRule, nsCSSCounterStyleRule};
 use style::gecko_bindings::structs::{nsRestyleHint, nsChangeHint, PropertyValuePair};
 use style::gecko_bindings::structs::IterationCompositeOperation;
 use style::gecko_bindings::structs::MallocSizeOf;
+use style::gecko_bindings::structs::OriginFlags;
 use style::gecko_bindings::structs::RawGeckoGfxMatrix4x4;
 use style::gecko_bindings::structs::RawGeckoPresContextOwned;
 use style::gecko_bindings::structs::SeenPtrs;
 use style::gecko_bindings::structs::ServoElementSnapshotTable;
 use style::gecko_bindings::structs::ServoTraversalFlags;
 use style::gecko_bindings::structs::StyleRuleInclusion;
 use style::gecko_bindings::structs::URLExtraData;
 use style::gecko_bindings::structs::nsCSSValueSharedList;
@@ -949,21 +950,24 @@ pub extern "C" fn Servo_StyleSet_FlushSt
     let doc_element = doc_element.map(GeckoElement);
     data.flush_stylesheets(&guard, doc_element);
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged(
     raw_data: RawServoStyleSetBorrowed,
     author_style_disabled: bool,
+    changed_origins: OriginFlags,
 ) {
     let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
-    data.stylesheets.force_dirty();
+    for origin in changed_origins.iter() {
+        data.stylesheets.force_dirty_origin(&origin);
+        data.clear_stylist_origin(&origin);
+    }
     data.stylesheets.set_author_style_disabled(author_style_disabled);
-    data.clear_stylist();
 }
 
 #[no_mangle]
 pub extern "C" fn Servo_StyleSheet_HasRules(
     raw_contents: RawServoStyleSheetContentsBorrowed
 ) -> bool {
     let global_style_data = &*GLOBAL_STYLE_DATA;
     let guard = global_style_data.shared_lock.read();