diff --git a/components/style/gecko_bindings/sugar/mod.rs b/components/style/gecko_bindings/sugar/mod.rs index 159beb6a332..1d4208f5421 100644 --- a/components/style/gecko_bindings/sugar/mod.rs +++ b/components/style/gecko_bindings/sugar/mod.rs @@ -13,6 +13,7 @@ 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; diff --git a/components/style/gecko_bindings/sugar/origin_flags.rs b/components/style/gecko_bindings/sugar/origin_flags.rs new file mode 100644 index 00000000000..1a121ee98ad --- /dev/null +++ b/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 { + 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); + } + } + } +} diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index d20fce6fb13..f4a767024ac 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -74,6 +74,7 @@ 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; @@ -954,11 +955,14 @@ pub extern "C" fn Servo_StyleSet_FlushStyleSheets( 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]