diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2018-02-10 07:46:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-10 07:46:38 -0500 |
commit | 2cc75a783d1a7e2a82ef1e6502ca5a4463a3fb4b (patch) | |
tree | e5782d3029b1a3b526015e7b073911409d32e303 /components | |
parent | 0098d519030f395f94f3f82fc04b93227fdff4ec (diff) | |
parent | 69c018c70d50bf8720578e95afdcd94c42058b13 (diff) | |
download | servo-2cc75a783d1a7e2a82ef1e6502ca5a4463a3fb4b.tar.gz servo-2cc75a783d1a7e2a82ef1e6502ca5a4463a3fb4b.zip |
Auto merge of #20010 - emilio:pres-hints-cascade, r=bholley
style: Cascade pres hints after normal user rules.
Per https://drafts.csswg.org/css-cascade/#preshint and
https://html.spec.whatwg.org/#presentational-hints.
This was causing failures in the link color reftests with the preferences sheet
as a User sheet.
Bug: 1436782
Reviewed-by: bholley
MozReview-Commit-ID: 9iwEqPBw4CF
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20010)
<!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r-- | components/style/rule_tree/mod.rs | 12 | ||||
-rw-r--r-- | components/style/stylist.rs | 64 |
2 files changed, 43 insertions, 33 deletions
diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index 9c710f07c5f..0ff2dbf28dc 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -472,22 +472,28 @@ impl RuleTree { /// where it likely did not result from a rigorous performance analysis.) const RULE_TREE_GC_INTERVAL: usize = 300; -/// The cascade level these rules are relevant at, as per[1]. +/// The cascade level these rules are relevant at, as per[1][2][3]. +/// +/// Presentational hints for SVG and HTML are in the "author-level +/// zero-specificity" level, that is, right after user rules, and before author +/// rules. /// /// The order of variants declared here is significant, and must be in /// _ascending_ order of precedence. /// /// [1]: https://drafts.csswg.org/css-cascade/#cascade-origin +/// [2]: https://drafts.csswg.org/css-cascade/#preshint +/// [3]: https://html.spec.whatwg.org/multipage/#presentational-hints #[repr(u8)] #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd)] #[cfg_attr(feature = "servo", derive(MallocSizeOf))] pub enum CascadeLevel { /// Normal User-Agent rules. UANormal = 0, - /// Presentational hints. - PresHints, /// User normal rules. UserNormal, + /// Presentational hints. + PresHints, /// Author normal rules. AuthorNormal, /// Style attribute normal rules. diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 2018468207f..18e5fb4c7d1 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -1157,7 +1157,10 @@ impl Stylist { /// Returns the applicable CSS declarations for the given element. /// - /// This corresponds to `ElementRuleCollector` in WebKit. + /// This corresponds to `ElementRuleCollector` in WebKit, and should push to + /// elements in the list in the order defined by: + /// + /// https://drafts.csswg.org/css-cascade/#cascade-origin pub fn push_applicable_declarations<E, F>( &self, element: E, @@ -1194,7 +1197,7 @@ impl Stylist { matches_user_rules && self.author_styles_enabled == AuthorStylesEnabled::Yes; - // Step 1: Normal user-agent rules. + // Normal user-agent rules. if let Some(map) = self.cascade_data.user_agent.cascade_data.normal_rules(pseudo_element) { map.get_all_matching_rules( element, @@ -1206,22 +1209,6 @@ impl Stylist { ); } - if pseudo_element.is_none() && !only_default_rules { - // Step 2: Presentational hints. - let length_before_preshints = applicable_declarations.len(); - element.synthesize_presentational_hints_for_legacy_attributes( - context.visited_handling(), - applicable_declarations - ); - if applicable_declarations.len() != length_before_preshints { - if cfg!(debug_assertions) { - for declaration in &applicable_declarations[length_before_preshints..] { - assert_eq!(declaration.level(), CascadeLevel::PresHints); - } - } - } - } - // NB: the following condition, although it may look somewhat // inaccurate, would be equivalent to something like: // @@ -1231,7 +1218,7 @@ impl Stylist { // // Which may be more what you would probably expect. if matches_user_rules { - // Step 3a: User normal rules. + // User normal rules. if let Some(map) = self.cascade_data.user.normal_rules(pseudo_element) { map.get_all_matching_rules( element, @@ -1244,7 +1231,26 @@ impl Stylist { } } - // Step 3b: XBL / Shadow DOM rules. + if pseudo_element.is_none() && !only_default_rules { + // Presentational hints. + // + // These go before author rules, but after user rules, see: + // https://drafts.csswg.org/css-cascade/#preshint + let length_before_preshints = applicable_declarations.len(); + element.synthesize_presentational_hints_for_legacy_attributes( + context.visited_handling(), + applicable_declarations + ); + if applicable_declarations.len() != length_before_preshints { + if cfg!(debug_assertions) { + for declaration in &applicable_declarations[length_before_preshints..] { + assert_eq!(declaration.level(), CascadeLevel::PresHints); + } + } + } + } + + // XBL / Shadow DOM rules, which are author rules too. // // TODO(emilio): Cascade order here is wrong for Shadow DOM. In // particular, normally document rules override ::slotted() rules, but @@ -1308,7 +1314,7 @@ impl Stylist { }); if matches_author_rules && !only_default_rules && !cut_off_inheritance { - // Step 3c: Author normal rules. + // Author normal rules. if let Some(map) = self.cascade_data.author.normal_rules(pseudo_element) { map.get_all_matching_rules( element, @@ -1322,7 +1328,7 @@ impl Stylist { } if !only_default_rules { - // Step 4: Normal style attributes. + // Style attribute ("Normal override declarations"). if let Some(sa) = style_attribute { applicable_declarations.push( ApplicableDeclarationBlock::from_declarations( @@ -1332,7 +1338,6 @@ impl Stylist { ); } - // Step 5: SMIL override. // Declarations from SVG SMIL animation elements. if let Some(so) = smil_override { applicable_declarations.push( @@ -1343,9 +1348,9 @@ impl Stylist { ); } - // Step 6: Animations. - // The animations sheet (CSS animations, script-generated animations, - // and CSS transitions that are no longer tied to CSS markup) + // The animations sheet (CSS animations, script-generated + // animations, and CSS transitions that are no longer tied to CSS + // markup). if let Some(anim) = animation_rules.0 { applicable_declarations.push( ApplicableDeclarationBlock::from_declarations( @@ -1357,13 +1362,12 @@ impl Stylist { } // - // Steps 7-10 correspond to !important rules, and are handled during - // rule tree insertion. + // !important rules are handled during rule tree insertion. // if !only_default_rules { - // Step 11: Transitions. - // The transitions sheet (CSS transitions that are tied to CSS markup) + // The transitions sheet (CSS transitions that are tied to CSS + // markup). if let Some(anim) = animation_rules.1 { applicable_declarations.push( ApplicableDeclarationBlock::from_declarations( |