style: Use a single RestyleHint representation.

Differential Revision: https://phabricator.services.mozilla.com/D22828
This commit is contained in:
Emilio Cobos Álvarez 2019-03-14 11:47:50 +00:00
parent 8dbf9b1da9
commit 95ee1a5adf
3 changed files with 11 additions and 77 deletions

View file

@ -4,12 +4,11 @@
//! Restyle hints: an optimization to avoid unnecessarily matching selectors.
#[cfg(feature = "gecko")]
use crate::gecko_bindings::structs::nsRestyleHint;
use crate::traversal_flags::TraversalFlags;
bitflags! {
/// The kind of restyle we need to do for a given element.
#[repr(C)]
pub struct RestyleHint: u8 {
/// Do a selector match of the element.
const RESTYLE_SELF = 1 << 0;
@ -190,75 +189,5 @@ impl Default for RestyleHint {
}
}
#[cfg(feature = "gecko")]
impl From<nsRestyleHint> for RestyleHint {
fn from(mut raw: nsRestyleHint) -> Self {
let mut hint = RestyleHint::empty();
debug_assert!(
raw.0 & nsRestyleHint::eRestyle_LaterSiblings.0 == 0,
"Handle later siblings manually if necessary plz."
);
if (raw.0 & (nsRestyleHint::eRestyle_Self.0 | nsRestyleHint::eRestyle_Subtree.0)) != 0 {
raw.0 &= !nsRestyleHint::eRestyle_Self.0;
hint.insert(RestyleHint::RESTYLE_SELF);
}
if (raw.0 & (nsRestyleHint::eRestyle_Subtree.0 | nsRestyleHint::eRestyle_SomeDescendants.0)) !=
0
{
raw.0 &= !nsRestyleHint::eRestyle_Subtree.0;
raw.0 &= !nsRestyleHint::eRestyle_SomeDescendants.0;
hint.insert(RestyleHint::RESTYLE_DESCENDANTS);
}
if (raw.0 & (nsRestyleHint::eRestyle_ForceDescendants.0 | nsRestyleHint::eRestyle_Force.0)) !=
0
{
raw.0 &= !nsRestyleHint::eRestyle_Force.0;
hint.insert(RestyleHint::RECASCADE_SELF);
}
if (raw.0 & nsRestyleHint::eRestyle_ForceDescendants.0) != 0 {
raw.0 &= !nsRestyleHint::eRestyle_ForceDescendants.0;
hint.insert(RestyleHint::RECASCADE_DESCENDANTS);
}
hint.insert(RestyleHint::from_bits_truncate(raw.0 as u8));
hint
}
}
#[cfg(feature = "servo")]
malloc_size_of_is_0!(RestyleHint);
/// Asserts that all replacement hints have a matching nsRestyleHint value.
#[cfg(feature = "gecko")]
#[inline]
pub fn assert_restyle_hints_match() {
use crate::gecko_bindings::structs;
macro_rules! check_restyle_hints {
( $( $a:ident => $b:path),*, ) => {
if cfg!(debug_assertions) {
let mut replacements = RestyleHint::replacements();
$(
assert_eq!(structs::nsRestyleHint::$a.0 as usize, $b.bits() as usize, stringify!($b));
replacements.remove($b);
)*
assert_eq!(replacements, RestyleHint::empty(),
"all RestyleHint replacement bits should have an \
assertion");
}
}
}
check_restyle_hints! {
eRestyle_CSSTransitions => RestyleHint::RESTYLE_CSS_TRANSITIONS,
eRestyle_CSSAnimations => RestyleHint::RESTYLE_CSS_ANIMATIONS,
eRestyle_StyleAttribute => RestyleHint::RESTYLE_STYLE_ATTRIBUTE,
eRestyle_StyleAttribute_Animations => RestyleHint::RESTYLE_SMIL,
}
}