From 95ee1a5adf64d9c87a7e03f2fb7fdd8017ea2f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 14 Mar 2019 11:47:50 +0000 Subject: [PATCH] style: Use a single RestyleHint representation. Differential Revision: https://phabricator.services.mozilla.com/D22828 --- components/style/cbindgen.toml | 7 ++ components/style/gecko/wrapper.rs | 8 +- .../invalidation/element/restyle_hints.rs | 73 +------------------ 3 files changed, 11 insertions(+), 77 deletions(-) diff --git a/components/style/cbindgen.toml b/components/style/cbindgen.toml index 0a0db7d1615..f36fd09a243 100644 --- a/components/style/cbindgen.toml +++ b/components/style/cbindgen.toml @@ -104,6 +104,7 @@ include = [ "TransformOrigin", "WordBreak", "Contain", + "RestyleHint", ] item_types = ["enums", "structs", "typedefs"] @@ -197,3 +198,9 @@ item_types = ["enums", "structs", "typedefs"] "GenericBorderRadius" = """ inline const StyleLengthPercentage& Get(mozilla::HalfCorner) const; """ + +"RestyleHint" = """ + static inline StyleRestyleHint RestyleSubtree(); + static inline StyleRestyleHint RecascadeSubtree(); + static inline StyleRestyleHint ForAnimations(); +""" diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index f5058fc63c4..558ee60f4e2 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -44,7 +44,6 @@ use crate::gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentLWThe use crate::gecko_bindings::bindings::{Gecko_SetNodeFlags, Gecko_UnsetNodeFlags}; use crate::gecko_bindings::structs; use crate::gecko_bindings::structs::nsChangeHint; -use crate::gecko_bindings::structs::nsRestyleHint; use crate::gecko_bindings::structs::Document_DocumentTheme as DocumentTheme; use crate::gecko_bindings::structs::EffectCompositor_CascadeLevel as CascadeLevel; use crate::gecko_bindings::structs::ELEMENT_HANDLED_SNAPSHOT; @@ -58,6 +57,7 @@ use crate::gecko_bindings::structs::{RawGeckoElement, RawGeckoNode, RawGeckoXBLB use crate::gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI}; use crate::global_style_data::GLOBAL_STYLE_DATA; use crate::hash::FxHashMap; +use crate::invalidation::element::restyle_hints::RestyleHint; use crate::logical_geometry::WritingMode; use crate::media_queries::Device; use crate::properties::animated_properties::{AnimationValue, AnimationValueMap}; @@ -802,11 +802,10 @@ impl<'le> GeckoElement<'le> { /// Also this function schedules style flush. pub unsafe fn note_explicit_hints( &self, - restyle_hint: nsRestyleHint, + restyle_hint: RestyleHint, change_hint: nsChangeHint, ) { use crate::gecko::restyle_damage::GeckoRestyleDamage; - use crate::invalidation::element::restyle_hints::RestyleHint; let damage = GeckoRestyleDamage::new(change_hint); debug!( @@ -814,7 +813,6 @@ impl<'le> GeckoElement<'le> { self, restyle_hint, change_hint ); - let restyle_hint: RestyleHint = restyle_hint.into(); debug_assert!( !(restyle_hint.has_animation_hint() && restyle_hint.has_non_animation_hint()), "Animation restyle hints should not appear with non-animation restyle hints" @@ -1516,7 +1514,7 @@ impl<'le> TElement for GeckoElement<'le> { ); unsafe { self.note_explicit_hints( - nsRestyleHint::eRestyle_Subtree, + RestyleHint::restyle_subtree(), nsChangeHint::nsChangeHint_Empty, ); } diff --git a/components/style/invalidation/element/restyle_hints.rs b/components/style/invalidation/element/restyle_hints.rs index de84fe56c85..9dbd12bab59 100644 --- a/components/style/invalidation/element/restyle_hints.rs +++ b/components/style/invalidation/element/restyle_hints.rs @@ -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 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, - } -}