From 36038869aa10485042d791792fdb7de17d5fce01 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 9 Jul 2018 16:03:32 +1000 Subject: [PATCH] style: Rename DeclarationSource to DeclarationPushMode. Bug: 1461285 Reviewed-by: emilio MozReview-Commit-ID: Iyv9JrXrpzl --- .../style/properties/declaration_block.rs | 42 +++++++++---------- .../style/stylesheets/keyframes_rule.rs | 4 +- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 8727ba4cc41..92fa0bc4134 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -39,13 +39,17 @@ impl AnimationRules { } } -/// Whether a given declaration comes from CSS parsing, or from CSSOM. +/// Enum for how a given declaration should be pushed into a declaration block. #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] -pub enum DeclarationSource { - /// The declaration was obtained from CSS parsing of sheets and such. +pub enum DeclarationPushMode { + /// Mode used when declarations were obtained from CSS parsing. + /// If there is an existing declaration of the same property with a higher + /// importance, the new declaration will be discarded. Otherwise, it will + /// be appended to the end of the declaration block. Parsing, - /// The declaration was obtained from CSSOM. - CssOm, + /// In this mode, the new declaration is always pushed to the end of the + /// declaration block. This is for CSSOM. + Append, } /// A declaration [importance][importance]. @@ -418,10 +422,10 @@ impl PropertyDeclarationBlock { &mut self, mut drain: SourcePropertyDeclarationDrain, importance: Importance, - source: DeclarationSource, + mode: DeclarationPushMode, ) -> bool { - match source { - DeclarationSource::Parsing => { + match mode { + DeclarationPushMode::Parsing => { let all_shorthand_len = match drain.all_shorthand { AllShorthand::NotSet => 0, AllShorthand::CSSWideKeyword(_) | @@ -433,7 +437,7 @@ impl PropertyDeclarationBlock { // With deduplication the actual length increase may be less than this. self.declarations.reserve(push_calls_count); } - DeclarationSource::CssOm => { + _ => { // Don't bother reserving space, since it's usually the case // that CSSOM just overrides properties and we don't need to use // more memory. See bug 1424346 for an example where this @@ -448,7 +452,7 @@ impl PropertyDeclarationBlock { changed |= self.push( decl, importance, - source, + mode, ); } match drain.all_shorthand { @@ -461,7 +465,7 @@ impl PropertyDeclarationBlock { changed |= self.push( decl, importance, - source, + mode, ); } } @@ -473,7 +477,7 @@ impl PropertyDeclarationBlock { changed |= self.push( decl, importance, - source, + mode, ); } } @@ -483,22 +487,16 @@ impl PropertyDeclarationBlock { /// Adds or overrides the declaration for a given property in this block. /// - /// Depending on the value of `source`, this has a different behavior in the + /// Depending on the value of `mode`, this has a different behavior in the /// presence of another declaration with the same ID in the declaration /// block. /// - /// * For `DeclarationSource::Parsing`, this will not override a - /// declaration with more importance, and will ensure that, if inserted, - /// it's inserted at the end of the declaration block. - /// - /// * For `DeclarationSource::CssOm`, this will override importance. - /// /// Returns whether the declaration has changed. pub fn push( &mut self, declaration: PropertyDeclaration, importance: Importance, - source: DeclarationSource, + mode: DeclarationPushMode, ) -> bool { let longhand_id = match declaration.id() { PropertyDeclarationId::Longhand(id) => Some(id), @@ -516,7 +514,7 @@ impl PropertyDeclarationBlock { continue; } - if matches!(source, DeclarationSource::Parsing) { + if matches!(mode, DeclarationPushMode::Parsing) { let important = self.declarations_importance[i]; // For declarations from parsing, non-important declarations @@ -1209,7 +1207,7 @@ pub fn parse_property_declaration_list( block.extend( iter.parser.declarations.drain(), importance, - DeclarationSource::Parsing, + DeclarationPushMode::Parsing, ); } Err((error, slice)) => { diff --git a/components/style/stylesheets/keyframes_rule.rs b/components/style/stylesheets/keyframes_rule.rs index 85dc00bb9af..82476652b9c 100644 --- a/components/style/stylesheets/keyframes_rule.rs +++ b/components/style/stylesheets/keyframes_rule.rs @@ -8,7 +8,7 @@ use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token}; use error_reporting::ContextualParseError; use parser::ParserContext; -use properties::{DeclarationSource, Importance, PropertyDeclaration}; +use properties::{DeclarationPushMode, Importance, PropertyDeclaration}; use properties::{LonghandId, PropertyDeclarationBlock, PropertyId}; use properties::{PropertyDeclarationId, SourcePropertyDeclaration}; use properties::LonghandIdSet; @@ -554,7 +554,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> { block.extend( iter.parser.declarations.drain(), Importance::Normal, - DeclarationSource::Parsing, + DeclarationPushMode::Parsing, ); }, Err((error, slice)) => {