Skip to content

Commit

Permalink
geckolib: Return @font-face rules to Gecko in the expected cascade or…
Browse files Browse the repository at this point in the history
…der.
  • Loading branch information
heycam committed Aug 14, 2017
1 parent 0eabba3 commit f26a7e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions components/style/stylesheets/origin.rs
Expand Up @@ -64,6 +64,17 @@ impl<T> PerOrigin<T> {
PerOriginIter {
data: &self,
cur: 0,
rev: false,
}
}

/// Iterates over references to per-origin extra style data, from lowest
/// level (user agent) to highest (author).
pub fn iter_origins_rev(&self) -> PerOriginIter<T> {
PerOriginIter {
data: &self,
cur: 2,
rev: true,
}
}

Expand Down Expand Up @@ -99,7 +110,8 @@ impl<T> PerOriginClear for PerOrigin<T> where T: PerOriginClear {
/// @counter-style and @keyframes rules.
pub struct PerOriginIter<'a, T: 'a> {
data: &'a PerOrigin<T>,
cur: usize,
cur: i8,
rev: bool,
}

impl<'a, T> Iterator for PerOriginIter<'a, T> where T: 'a {
Expand All @@ -112,7 +124,7 @@ impl<'a, T> Iterator for PerOriginIter<'a, T> where T: 'a {
2 => (&self.data.user_agent, Origin::UserAgent),
_ => return None,
};
self.cur += 1;
self.cur += if self.rev { -1 } else { 1 };
Some(result)
}
}
Expand All @@ -125,7 +137,7 @@ impl<'a, T> Iterator for PerOriginIter<'a, T> where T: 'a {
/// each time from `next()`.
pub struct PerOriginIterMut<'a, T: 'a> {
data: *mut PerOrigin<T>,
cur: usize,
cur: i8,
_marker: PhantomData<&'a mut PerOrigin<T>>,
}

Expand Down
4 changes: 3 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -3449,8 +3449,10 @@ pub extern "C" fn Servo_StyleSet_GetFontFaceRules(raw_data: RawServoStyleSetBorr
.map(|(d, _)| d.font_faces.len() as u32)
.sum();

// Reversed iterator because Gecko expects rules to appear sorted
// UserAgent first, Author last.
let font_face_iter = data.extra_style_data
.iter_origins()
.iter_origins_rev()
.flat_map(|(d, o)| d.font_faces.iter().zip(iter::repeat(o)));

unsafe { rules.set_len(len) };
Expand Down

0 comments on commit f26a7e9

Please sign in to comment.