mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use a single RestyleHint representation.
Differential Revision: https://phabricator.services.mozilla.com/D22828
This commit is contained in:
parent
8dbf9b1da9
commit
95ee1a5adf
3 changed files with 11 additions and 77 deletions
|
@ -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();
|
||||
"""
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue