diff options
Diffstat (limited to 'components/style/matching.rs')
-rw-r--r-- | components/style/matching.rs | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/components/style/matching.rs b/components/style/matching.rs index e10c19baaca..320546147bf 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -17,7 +17,7 @@ use invalidation::element::restyle_hints::{RESTYLE_CSS_ANIMATIONS, RESTYLE_CSS_T use invalidation::element::restyle_hints::{RESTYLE_SMIL, RESTYLE_STYLE_ATTRIBUTE}; use invalidation::element::restyle_hints::RestyleHint; use log::LogLevel::Trace; -use properties::{ALLOW_SET_ROOT_FONT_SIZE, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP}; +use properties::{ALLOW_SET_ROOT_FONT_SIZE, PROHIBIT_DISPLAY_CONTENTS, SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP}; use properties::{AnimationRules, CascadeFlags, ComputedValues}; use properties::{VISITED_DEPENDENT_ONLY, cascade}; use properties::longhands::display::computed_value as display; @@ -29,15 +29,23 @@ use sharing::StyleSharingBehavior; use stylearc::Arc; use stylist::RuleInclusion; -/// The way a style should be inherited. -enum InheritMode { +/// Whether we are cascading for an eager pseudo-element or something else. +/// +/// Controls where we inherit styles from, and whether display:contents is +/// prohibited. +#[derive(PartialEq, Copy, Clone)] +enum CascadeTarget { /// Inherit from the parent element, as normal CSS dictates, _or_ from the /// closest non-Native Anonymous element in case this is Native Anonymous - /// Content. + /// Content. display:contents is allowed. Normal, /// Inherit from the primary style, this is used while computing eager /// pseudos, like ::before and ::after when we're traversing the parent. - FromPrimaryStyle, + /// Also prohibits display:contents from having an effect. + /// + /// TODO(emilio) display:contents really should apply to ::before/::after. + /// https://github.com/w3c/csswg-drafts/issues/1345 + EagerPseudo, } /// Represents the result of comparing an element's old and new style. @@ -251,7 +259,7 @@ trait PrivateMatchMethods: TElement { font_metrics_provider: &FontMetricsProvider, rule_node: &StrongRuleNode, primary_style: &ComputedStyle, - inherit_mode: InheritMode, + cascade_target: CascadeTarget, cascade_visited: CascadeVisitedMode, visited_values_to_insert: Option<Arc<ComputedValues>>) -> Arc<ComputedValues> { @@ -263,15 +271,17 @@ trait PrivateMatchMethods: TElement { if cascade_visited.visited_dependent_only() { cascade_flags.insert(VISITED_DEPENDENT_ONLY); } - if !self.is_native_anonymous() { + if self.is_native_anonymous() || cascade_target == CascadeTarget::EagerPseudo { + cascade_flags.insert(PROHIBIT_DISPLAY_CONTENTS); + } else { cascade_flags.insert(ALLOW_SET_ROOT_FONT_SIZE); } // Grab the inherited values. let parent_el; let parent_data; - let style_to_inherit_from = match inherit_mode { - InheritMode::Normal => { + let style_to_inherit_from = match cascade_target { + CascadeTarget::Normal => { parent_el = self.inheritance_parent(); parent_data = parent_el.as_ref().and_then(|e| e.borrow_data()); let parent_style = parent_data.as_ref().map(|d| { @@ -287,7 +297,7 @@ trait PrivateMatchMethods: TElement { }); parent_style.map(|s| cascade_visited.values(s)) } - InheritMode::FromPrimaryStyle => { + CascadeTarget::EagerPseudo => { parent_el = Some(self.clone()); Some(cascade_visited.values(primary_style)) } @@ -390,17 +400,17 @@ trait PrivateMatchMethods: TElement { // Grab the rule node. let style = eager_pseudo_style.unwrap_or(primary_style); let rule_node = cascade_visited.rules(style); - let inherit_mode = if eager_pseudo_style.is_some() { - InheritMode::FromPrimaryStyle + let cascade_target = if eager_pseudo_style.is_some() { + CascadeTarget::EagerPseudo } else { - InheritMode::Normal + CascadeTarget::Normal }; self.cascade_with_rules(context.shared, &context.thread_local.font_metrics_provider, rule_node, primary_style, - inherit_mode, + cascade_target, cascade_visited, visited_values_to_insert) } @@ -536,7 +546,7 @@ trait PrivateMatchMethods: TElement { &context.thread_local.font_metrics_provider, &without_transition_rules, primary_style, - InheritMode::Normal, + CascadeTarget::Normal, CascadeVisitedMode::Unvisited, None)) } @@ -1480,7 +1490,7 @@ pub trait MatchMethods : TElement { font_metrics_provider, &without_animation_rules, primary_style, - InheritMode::Normal, + CascadeTarget::Normal, CascadeVisitedMode::Unvisited, None) } |