style: Make Servo_StyleSet_NoteStyleSheetsChanged take a set of origins to dirty.

This commit is contained in:
Cameron McCormack 2017-08-12 18:18:52 +08:00
parent d90ff1801a
commit 0cf487b0ac
3 changed files with 57 additions and 2 deletions

View file

@ -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;

View file

@ -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);
}
}
}
}