mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Remove DeclarationPushMode.
Bug: 1473180 Reviewed-by: emilio MozReview-Commit-ID: LFgYeKE1SNk
This commit is contained in:
parent
a0edeb1a92
commit
1a91beaf57
2 changed files with 31 additions and 68 deletions
|
@ -64,19 +64,6 @@ pub struct SourcePropertyDeclarationUpdate {
|
||||||
any_removal: bool,
|
any_removal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enum for how a given declaration should be pushed into a declaration block.
|
|
||||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)]
|
|
||||||
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,
|
|
||||||
/// In this mode, the new declaration is always pushed to the end of the
|
|
||||||
/// declaration block. This is another possible behavior of CSSOM.
|
|
||||||
Append,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A declaration [importance][importance].
|
/// A declaration [importance][importance].
|
||||||
///
|
///
|
||||||
/// [importance]: https://drafts.csswg.org/css-cascade/#importance
|
/// [importance]: https://drafts.csswg.org/css-cascade/#importance
|
||||||
|
@ -472,10 +459,7 @@ impl PropertyDeclarationBlock {
|
||||||
&mut self,
|
&mut self,
|
||||||
mut drain: SourcePropertyDeclarationDrain,
|
mut drain: SourcePropertyDeclarationDrain,
|
||||||
importance: Importance,
|
importance: Importance,
|
||||||
mode: DeclarationPushMode,
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match mode {
|
|
||||||
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(_) |
|
||||||
|
@ -486,42 +470,25 @@ 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);
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// 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
|
|
||||||
// matters.
|
|
||||||
//
|
|
||||||
// TODO: Would it be worth to call reserve() just if it's empty?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut changed = false;
|
let mut changed = false;
|
||||||
for decl in &mut drain.declarations {
|
for decl in &mut drain.declarations {
|
||||||
changed |= self.push(
|
changed |= self.push(decl, importance);
|
||||||
decl,
|
|
||||||
importance,
|
|
||||||
mode,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
drain.all_shorthand.declarations().fold(changed, |changed, decl| {
|
drain.all_shorthand.declarations().fold(changed, |changed, decl| {
|
||||||
changed | self.push(decl, importance, mode)
|
changed | self.push(decl, importance)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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 `mode`, this has a different behavior in the
|
|
||||||
/// presence of another declaration with the same ID in the declaration
|
|
||||||
/// block.
|
|
||||||
///
|
|
||||||
/// Returns whether the declaration has changed.
|
/// Returns whether the declaration has changed.
|
||||||
|
///
|
||||||
|
/// This is only used for parsing and internal use.
|
||||||
pub fn push(
|
pub fn push(
|
||||||
&mut self,
|
&mut self,
|
||||||
declaration: PropertyDeclaration,
|
declaration: PropertyDeclaration,
|
||||||
importance: Importance,
|
importance: Importance,
|
||||||
mode: DeclarationPushMode,
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if !self.is_definitely_new(&declaration) {
|
if !self.is_definitely_new(&declaration) {
|
||||||
let mut index_to_remove = None;
|
let mut index_to_remove = None;
|
||||||
|
@ -530,7 +497,6 @@ impl PropertyDeclarationBlock {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -554,7 +520,6 @@ impl PropertyDeclarationBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
index_to_remove = Some(i);
|
index_to_remove = Some(i);
|
||||||
break;
|
break;
|
||||||
|
@ -1400,7 +1365,6 @@ pub fn parse_property_declaration_list(
|
||||||
block.extend(
|
block.extend(
|
||||||
iter.parser.declarations.drain(),
|
iter.parser.declarations.drain(),
|
||||||
importance,
|
importance,
|
||||||
DeclarationPushMode::Parsing,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err((error, slice)) => {
|
Err((error, slice)) => {
|
||||||
|
|
|
@ -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::{DeclarationPushMode, Importance, PropertyDeclaration};
|
use properties::{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,6 @@ impl<'a, 'i> QualifiedRuleParser<'i> for KeyframeListParser<'a> {
|
||||||
block.extend(
|
block.extend(
|
||||||
iter.parser.declarations.drain(),
|
iter.parser.declarations.drain(),
|
||||||
Importance::Normal,
|
Importance::Normal,
|
||||||
DeclarationPushMode::Parsing,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
Err((error, slice)) => {
|
Err((error, slice)) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue