style: Rename DeclarationSource to DeclarationPushMode.

Bug: 1461285
Reviewed-by: emilio
MozReview-Commit-ID: Iyv9JrXrpzl
This commit is contained in:
Xidorn Quan 2018-07-09 16:03:32 +10:00 committed by Emilio Cobos Álvarez
parent f526af7f01
commit 36038869aa
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 22 additions and 24 deletions

View file

@ -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)] #[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
pub enum DeclarationSource { pub enum DeclarationPushMode {
/// The declaration was obtained from CSS parsing of sheets and such. /// 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, Parsing,
/// The declaration was obtained from CSSOM. /// In this mode, the new declaration is always pushed to the end of the
CssOm, /// declaration block. This is for CSSOM.
Append,
} }
/// A declaration [importance][importance]. /// A declaration [importance][importance].
@ -418,10 +422,10 @@ impl PropertyDeclarationBlock {
&mut self, &mut self,
mut drain: SourcePropertyDeclarationDrain, mut drain: SourcePropertyDeclarationDrain,
importance: Importance, importance: Importance,
source: DeclarationSource, mode: DeclarationPushMode,
) -> bool { ) -> bool {
match source { match mode {
DeclarationSource::Parsing => { DeclarationPushMode::Parsing => {
let all_shorthand_len = match drain.all_shorthand { let all_shorthand_len = match drain.all_shorthand {
AllShorthand::NotSet => 0, AllShorthand::NotSet => 0,
AllShorthand::CSSWideKeyword(_) | AllShorthand::CSSWideKeyword(_) |
@ -433,7 +437,7 @@ impl PropertyDeclarationBlock {
// With deduplication the actual length increase may be less than this. // With deduplication the actual length increase may be less than this.
self.declarations.reserve(push_calls_count); self.declarations.reserve(push_calls_count);
} }
DeclarationSource::CssOm => { _ => {
// Don't bother reserving space, since it's usually the case // Don't bother reserving space, since it's usually the case
// that CSSOM just overrides properties and we don't need to use // that CSSOM just overrides properties and we don't need to use
// more memory. See bug 1424346 for an example where this // more memory. See bug 1424346 for an example where this
@ -448,7 +452,7 @@ impl PropertyDeclarationBlock {
changed |= self.push( changed |= self.push(
decl, decl,
importance, importance,
source, mode,
); );
} }
match drain.all_shorthand { match drain.all_shorthand {
@ -461,7 +465,7 @@ impl PropertyDeclarationBlock {
changed |= self.push( changed |= self.push(
decl, decl,
importance, importance,
source, mode,
); );
} }
} }
@ -473,7 +477,7 @@ impl PropertyDeclarationBlock {
changed |= self.push( changed |= self.push(
decl, decl,
importance, importance,
source, mode,
); );
} }
} }
@ -483,22 +487,16 @@ impl PropertyDeclarationBlock {
/// Adds or overrides the declaration for a given property in this block. /// 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 /// presence of another declaration with the same ID in the declaration
/// block. /// 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. /// Returns whether the declaration has changed.
pub fn push( pub fn push(
&mut self, &mut self,
declaration: PropertyDeclaration, declaration: PropertyDeclaration,
importance: Importance, importance: Importance,
source: DeclarationSource, mode: DeclarationPushMode,
) -> bool { ) -> bool {
let longhand_id = match declaration.id() { let longhand_id = match declaration.id() {
PropertyDeclarationId::Longhand(id) => Some(id), PropertyDeclarationId::Longhand(id) => Some(id),
@ -516,7 +514,7 @@ impl PropertyDeclarationBlock {
continue; continue;
} }
if matches!(source, DeclarationSource::Parsing) { if matches!(mode, DeclarationPushMode::Parsing) {
let important = self.declarations_importance[i]; let important = self.declarations_importance[i];
// For declarations from parsing, non-important declarations // For declarations from parsing, non-important declarations
@ -1209,7 +1207,7 @@ pub fn parse_property_declaration_list(
block.extend( block.extend(
iter.parser.declarations.drain(), iter.parser.declarations.drain(),
importance, importance,
DeclarationSource::Parsing, DeclarationPushMode::Parsing,
); );
} }
Err((error, slice)) => { Err((error, slice)) => {

View file

@ -8,7 +8,7 @@ use cssparser::{AtRuleParser, CowRcStr, Parser, ParserInput, QualifiedRuleParser
use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token}; use cssparser::{parse_one_rule, DeclarationListParser, DeclarationParser, SourceLocation, Token};
use error_reporting::ContextualParseError; use error_reporting::ContextualParseError;
use parser::ParserContext; use parser::ParserContext;
use properties::{DeclarationSource, Importance, PropertyDeclaration}; use properties::{DeclarationPushMode, Importance, PropertyDeclaration};
use properties::{LonghandId, PropertyDeclarationBlock, PropertyId}; use properties::{LonghandId, PropertyDeclarationBlock, PropertyId};
use properties::{PropertyDeclarationId, SourcePropertyDeclaration}; use properties::{PropertyDeclarationId, SourcePropertyDeclaration};
use properties::LonghandIdSet; use properties::LonghandIdSet;
@ -554,7 +554,7 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
block.extend( block.extend(
iter.parser.declarations.drain(), iter.parser.declarations.drain(),
Importance::Normal, Importance::Normal,
DeclarationSource::Parsing, DeclarationPushMode::Parsing,
); );
}, },
Err((error, slice)) => { Err((error, slice)) => {