diff options
-rw-r--r-- | components/script/dom/cssstyledeclaration.rs | 5 | ||||
-rw-r--r-- | components/style/keyframes.rs | 2 | ||||
-rw-r--r-- | components/style/properties/declaration_block.rs | 19 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 70 | ||||
-rw-r--r-- | ports/geckolib/glue.rs | 10 |
5 files changed, 70 insertions, 36 deletions
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs index d5d248f7880..384dfd4d412 100644 --- a/components/script/dom/cssstyledeclaration.rs +++ b/components/script/dom/cssstyledeclaration.rs @@ -272,10 +272,7 @@ impl CSSStyleDeclaration { // Step 8 // Step 9 - *changed = false; - parsed.expand(|declaration| { - *changed |= pdb.set_parsed_declaration(declaration, importance); - }); + *changed = parsed.expand_set_into(pdb, importance); Ok(()) }) diff --git a/components/style/keyframes.rs b/components/style/keyframes.rs index 67f0c848f8d..3b0754a2dcd 100644 --- a/components/style/keyframes.rs +++ b/components/style/keyframes.rs @@ -374,7 +374,7 @@ impl<'a> QualifiedRuleParser for KeyframeListParser<'a> { let mut block = PropertyDeclarationBlock::new(); while let Some(declaration) = iter.next() { match declaration { - Ok(parsed) => parsed.expand(|d| block.push(d, Importance::Normal)), + Ok(parsed) => parsed.expand_push_into(&mut block, Importance::Normal), Err(range) => { let pos = range.start; let message = format!("Unsupported keyframe property declaration: '{}'", diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 4d3da86906c..003be974adc 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -88,7 +88,7 @@ impl PropertyDeclarationBlock { &self.declarations } - /// Returns wheather this block contains any declaration with `!important`. + /// Returns whether this block contains any declaration with `!important`. /// /// This is based on the `important_count` counter, /// which should be maintained whenever `declarations` is changed. @@ -97,7 +97,7 @@ impl PropertyDeclarationBlock { self.important_count > 0 } - /// Returns wheather this block contains any declaration without `!important`. + /// Returns whether this block contains any declaration without `!important`. /// /// This is based on the `important_count` counter, /// which should be maintained whenever `declarations` is changed. @@ -202,16 +202,9 @@ impl PropertyDeclarationBlock { self.push_common(declaration, importance, false); } - /// Adds or overrides the declaration for a given property in this block, - /// Returns whether the declaration block is actually changed. - pub fn set_parsed_declaration(&mut self, - declaration: PropertyDeclaration, - importance: Importance) -> bool { - self.push_common(declaration, importance, true) - } - - fn push_common(&mut self, declaration: PropertyDeclaration, importance: Importance, - overwrite_more_important: bool) -> bool { + /// Implementation detail of push and ParsedDeclaration::expand* + pub fn push_common(&mut self, declaration: PropertyDeclaration, importance: Importance, + overwrite_more_important: bool) -> bool { let definitely_new = if let PropertyDeclarationId::Longhand(id) = declaration.id() { !self.longhands.contains(id) } else { @@ -697,7 +690,7 @@ pub fn parse_property_declaration_list(context: &ParserContext, let mut iter = DeclarationListParser::new(input, parser); while let Some(declaration) = iter.next() { match declaration { - Ok((parsed, importance)) => parsed.expand(|d| block.push(d, importance)), + Ok((parsed, importance)) => parsed.expand_push_into(&mut block, importance), Err(range) => { let pos = range.start; let message = format!("Unsupported property declaration: '{}'", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index af392618f5e..9bb2b94749d 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -888,7 +888,29 @@ pub enum ParsedDeclaration { impl ParsedDeclaration { /// Transform this ParsedDeclaration into a sequence of PropertyDeclaration /// by expanding shorthand declarations into their corresponding longhands - pub fn expand<F>(self, mut push: F) where F: FnMut(PropertyDeclaration) { + /// + /// Adds or overrides exsting declarations in the given block, + /// except if existing declarations are more important. + #[inline] + pub fn expand_push_into(self, block: &mut PropertyDeclarationBlock, + importance: Importance) { + self.expand_into(block, importance, false); + } + + /// Transform this ParsedDeclaration into a sequence of PropertyDeclaration + /// by expanding shorthand declarations into their corresponding longhands + /// + /// Add or override existing declarations in the given block. + /// Return whether anything changed. + #[inline] + pub fn expand_set_into(self, block: &mut PropertyDeclarationBlock, + importance: Importance) -> bool { + self.expand_into(block, importance, true) + } + + fn expand_into(self, block: &mut PropertyDeclarationBlock, + importance: Importance, + overwrite_more_important: bool) -> bool { match self { % for shorthand in data.shorthands: ParsedDeclaration::${shorthand.camel_case}( @@ -898,32 +920,58 @@ impl ParsedDeclaration { % endfor } ) => { + let mut changed = false; % for sub_property in shorthand.sub_properties: - push(PropertyDeclaration::${sub_property.camel_case}( - % if sub_property.boxed: - Box::new(${sub_property.ident}) - % else: - ${sub_property.ident} - % endif - )); + changed |= block.push_common( + PropertyDeclaration::${sub_property.camel_case}( + % if sub_property.boxed: + Box::new(${sub_property.ident}) + % else: + ${sub_property.ident} + % endif + ), + importance, + overwrite_more_important, + ); % endfor + changed }, ParsedDeclaration::${shorthand.camel_case}CSSWideKeyword(keyword) => { + let mut changed = false; % for sub_property in shorthand.sub_properties: - push(PropertyDeclaration::CSSWideKeyword(LonghandId::${sub_property.camel_case}, keyword)); + changed |= block.push_common( + PropertyDeclaration::CSSWideKeyword( + LonghandId::${sub_property.camel_case}, + keyword, + ), + importance, + overwrite_more_important, + ); % endfor + changed }, ParsedDeclaration::${shorthand.camel_case}WithVariables(value) => { debug_assert_eq!( value.from_shorthand, Some(ShorthandId::${shorthand.camel_case}) ); + let mut changed = false; % for sub_property in shorthand.sub_properties: - push(PropertyDeclaration::WithVariables(LonghandId::${sub_property.camel_case}, value.clone())); + changed |= block.push_common( + PropertyDeclaration::WithVariables( + LonghandId::${sub_property.camel_case}, + value.clone() + ), + importance, + overwrite_more_important, + ); % endfor + changed } % endfor - ParsedDeclaration::LonghandOrCustom(declaration) => push(declaration), + ParsedDeclaration::LonghandOrCustom(declaration) => { + block.push_common(declaration, importance, overwrite_more_important) + } } } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 06cf42f34f2..8f16fe47c6d 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -800,7 +800,7 @@ pub extern "C" fn Servo_ParseProperty(property: *const nsACString, value: *const Ok(parsed) => { let global_style_data = &*GLOBAL_STYLE_DATA; let mut block = PropertyDeclarationBlock::new(); - parsed.expand(|d| block.push(d, Importance::Normal)); + parsed.expand_push_into(&mut block, Importance::Normal); Arc::new(global_style_data.shared_lock.wrap(block)).into_strong() } Err(_) => RawServoDeclarationBlockStrong::null() @@ -958,13 +958,9 @@ fn set_property(declarations: RawServoDeclarationBlockBorrowed, property_id: Pro if let Ok(parsed) = parse_one_declaration(property_id, value, &base_url, &StdoutErrorReporter, extra_data) { let importance = if is_important { Importance::Important } else { Importance::Normal }; - let mut changed = false; write_locked_arc(declarations, |decls: &mut PropertyDeclarationBlock| { - parsed.expand(|decl| { - changed |= decls.set_parsed_declaration(decl, importance); - }); - }); - changed + parsed.expand_set_into(decls, importance) + }) } else { false } |