diff --git a/components/style/gecko/restyle_damage.rs b/components/style/gecko/restyle_damage.rs index f8a43e8b7ea..cd79f644a9a 100644 --- a/components/style/gecko/restyle_damage.rs +++ b/components/style/gecko/restyle_damage.rs @@ -72,7 +72,8 @@ impl GeckoRestyleDamage { } else { StyleChange::Unchanged }; - StyleDifference::new(GeckoRestyleDamage(nsChangeHint(hint)), change) + let damage = GeckoRestyleDamage(nsChangeHint(hint)); + StyleDifference { damage, change } } /// Returns true if this restyle damage contains all the damage of |other|. diff --git a/components/style/matching.rs b/components/style/matching.rs index 103cf24da25..a38b93c3464 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -31,16 +31,6 @@ pub struct StyleDifference { pub change: StyleChange, } -impl StyleDifference { - /// Creates a new `StyleDifference`. - pub fn new(damage: RestyleDamage, change: StyleChange) -> Self { - StyleDifference { - change: change, - damage: damage, - } - } -} - /// Represents whether or not the style of an element has changed. #[derive(Clone, Copy, Debug)] pub enum StyleChange { @@ -352,78 +342,80 @@ trait PrivateMatchMethods: TElement { } match difference.change { - StyleChange::Unchanged => ChildCascadeRequirement::CanSkipCascade, + StyleChange::Unchanged => { + return ChildCascadeRequirement::CanSkipCascade + }, StyleChange::Changed { reset_only } => { // If inherited properties changed, the best we can do is // cascade the children. if !reset_only { return ChildCascadeRequirement::MustCascadeChildren } - - let old_display = old_values.get_box().clone_display(); - let new_display = new_values.get_box().clone_display(); - - // If we used to be a display: none element, and no longer are, - // our children need to be restyled because they're unstyled. - // - // NOTE(emilio): Gecko has the special-case of -moz-binding, but - // that gets handled on the frame constructor when processing - // the reframe, so no need to handle that here. - if old_display == display::T::none && old_display != new_display { - return ChildCascadeRequirement::MustCascadeChildren - } - - // Blockification of children may depend on our display value, - // so we need to actually do the recascade. We could potentially - // do better, but it doesn't seem worth it. - if old_display.is_item_container() != new_display.is_item_container() { - return ChildCascadeRequirement::MustCascadeChildren - } - - // Line break suppression may also be affected if the display - // type changes from ruby to non-ruby. - #[cfg(feature = "gecko")] - { - if old_display.is_ruby_type() != new_display.is_ruby_type() { - return ChildCascadeRequirement::MustCascadeChildren - } - } - - // Children with justify-items: auto may depend on our - // justify-items property value. - // - // Similarly, we could potentially do better, but this really - // seems not common enough to care about. - #[cfg(feature = "gecko")] - { - use values::specified::align::AlignFlags; - - let old_justify_items = - old_values.get_position().clone_justify_items(); - let new_justify_items = - new_values.get_position().clone_justify_items(); - - let was_legacy_justify_items = - old_justify_items.computed.0.contains(AlignFlags::LEGACY); - - let is_legacy_justify_items = - new_justify_items.computed.0.contains(AlignFlags::LEGACY); - - if is_legacy_justify_items != was_legacy_justify_items { - return ChildCascadeRequirement::MustCascadeChildren; - } - - if was_legacy_justify_items && - old_justify_items.computed != new_justify_items.computed { - return ChildCascadeRequirement::MustCascadeChildren; - } - } - - // We could prove that, if our children don't inherit reset - // properties, we can stop the cascade. - ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle } } + + let old_display = old_values.get_box().clone_display(); + let new_display = new_values.get_box().clone_display(); + + // If we used to be a display: none element, and no longer are, + // our children need to be restyled because they're unstyled. + // + // NOTE(emilio): Gecko has the special-case of -moz-binding, but + // that gets handled on the frame constructor when processing + // the reframe, so no need to handle that here. + if old_display == display::T::none && old_display != new_display { + return ChildCascadeRequirement::MustCascadeChildren + } + + // Blockification of children may depend on our display value, + // so we need to actually do the recascade. We could potentially + // do better, but it doesn't seem worth it. + if old_display.is_item_container() != new_display.is_item_container() { + return ChildCascadeRequirement::MustCascadeChildren + } + + // Line break suppression may also be affected if the display + // type changes from ruby to non-ruby. + #[cfg(feature = "gecko")] + { + if old_display.is_ruby_type() != new_display.is_ruby_type() { + return ChildCascadeRequirement::MustCascadeChildren + } + } + + // Children with justify-items: auto may depend on our + // justify-items property value. + // + // Similarly, we could potentially do better, but this really + // seems not common enough to care about. + #[cfg(feature = "gecko")] + { + use values::specified::align::AlignFlags; + + let old_justify_items = + old_values.get_position().clone_justify_items(); + let new_justify_items = + new_values.get_position().clone_justify_items(); + + let was_legacy_justify_items = + old_justify_items.computed.0.contains(AlignFlags::LEGACY); + + let is_legacy_justify_items = + new_justify_items.computed.0.contains(AlignFlags::LEGACY); + + if is_legacy_justify_items != was_legacy_justify_items { + return ChildCascadeRequirement::MustCascadeChildren; + } + + if was_legacy_justify_items && + old_justify_items.computed != new_justify_items.computed { + return ChildCascadeRequirement::MustCascadeChildren; + } + } + + // We could prove that, if our children don't inherit reset + // properties, we can stop the cascade. + ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle } #[cfg(feature = "servo")] diff --git a/components/style/parser.rs b/components/style/parser.rs index eb0d8a4eb96..1b1d4151600 100644 --- a/components/style/parser.rs +++ b/components/style/parser.rs @@ -61,6 +61,7 @@ pub struct ParserContext<'a> { impl<'a> ParserContext<'a> { /// Create a parser context. + #[inline] pub fn new( stylesheet_origin: Origin, url_data: &'a UrlExtraData, @@ -79,6 +80,7 @@ impl<'a> ParserContext<'a> { } /// Create a parser context for on-the-fly parsing in CSSOM + #[inline] pub fn new_for_cssom( url_data: &'a UrlExtraData, rule_type: Option, @@ -95,6 +97,7 @@ impl<'a> ParserContext<'a> { } /// Create a parser context based on a previous context, but with a modified rule type. + #[inline] pub fn new_with_rule_type( context: &'a ParserContext, rule_type: CssRuleType, diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 213d1df5431..d26557d5c1b 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1016,18 +1016,23 @@ pub fn append_serialization<'a, W, I, N>(dest: &mut W, /// A helper to parse the style attribute of an element, in order for this to be /// shared between Servo and Gecko. -pub fn parse_style_attribute(input: &str, - url_data: &UrlExtraData, - error_reporter: &R, - quirks_mode: QuirksMode) - -> PropertyDeclarationBlock - where R: ParseErrorReporter +pub fn parse_style_attribute( + input: &str, + url_data: &UrlExtraData, + error_reporter: &R, + quirks_mode: QuirksMode, +) -> PropertyDeclarationBlock +where + R: ParseErrorReporter { - let context = ParserContext::new(Origin::Author, - url_data, - Some(CssRuleType::Style), - ParsingMode::DEFAULT, - quirks_mode); + let context = ParserContext::new( + Origin::Author, + url_data, + Some(CssRuleType::Style), + ParsingMode::DEFAULT, + quirks_mode, + ); + let error_context = ParserErrorContext { error_reporter: error_reporter }; let mut input = ParserInput::new(input); parse_property_declaration_list(&context, &error_context, &mut Parser::new(&mut input)) @@ -1049,11 +1054,14 @@ pub fn parse_one_declaration_into( where R: ParseErrorReporter { - let context = ParserContext::new(Origin::Author, - url_data, - Some(CssRuleType::Style), - parsing_mode, - quirks_mode); + let context = ParserContext::new( + Origin::Author, + url_data, + Some(CssRuleType::Style), + parsing_mode, + quirks_mode, + ); + let mut input = ParserInput::new(input); let mut parser = Parser::new(&mut input); let start_position = parser.position(); diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index f1ddcd53b2b..4ad15abecbe 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -954,7 +954,8 @@ impl UnparsedValue { ::custom_properties::substitute(&self.css, self.first_token_type, custom_properties) .ok() .and_then(|css| { - // As of this writing, only the base URL is used for property values: + // As of this writing, only the base URL is used for property + // values. let context = ParserContext::new( Origin::Author, &self.url_data, @@ -962,6 +963,7 @@ impl UnparsedValue { ParsingMode::DEFAULT, quirks_mode, ); + let mut input = ParserInput::new(&css); Parser::new(&mut input).parse_entirely(|input| { match self.from_shorthand { diff --git a/components/style/servo/restyle_damage.rs b/components/style/servo/restyle_damage.rs index def2a331cc7..52e1d402ef2 100644 --- a/components/style/servo/restyle_damage.rs +++ b/components/style/servo/restyle_damage.rs @@ -5,49 +5,53 @@ //! The restyle damage is a hint that tells layout which kind of operations may //! be needed in presence of incremental style changes. -#![deny(missing_docs)] - use computed_values::display; use matching::{StyleChange, StyleDifference}; use properties::ComputedValues; use std::fmt; bitflags! { - #[doc = "Individual layout actions that may be necessary after restyling."] + /// Individual layout actions that may be necessary after restyling. pub struct ServoRestyleDamage: u8 { - #[doc = "Repaint the node itself."] - #[doc = "Currently unused; need to decide how this propagates."] + /// Repaint the node itself. + /// + /// Currently unused; need to decide how this propagates. const REPAINT = 0x01; - #[doc = "The stacking-context-relative position of this node or its descendants has \ - changed."] - #[doc = "Propagates both up and down the flow tree."] + /// The stacking-context-relative position of this node or its + /// descendants has changed. + /// + /// Propagates both up and down the flow tree. const REPOSITION = 0x02; - #[doc = "Recompute the overflow regions (bounding box of object and all descendants)."] - #[doc = "Propagates down the flow tree because the computation is bottom-up."] + /// Recompute the overflow regions (bounding box of object and all descendants). + /// + /// Propagates down the flow tree because the computation is bottom-up. const STORE_OVERFLOW = 0x04; - #[doc = "Recompute intrinsic inline_sizes (minimum and preferred)."] - #[doc = "Propagates down the flow tree because the computation is"] - #[doc = "bottom-up."] + /// Recompute intrinsic inline_sizes (minimum and preferred). + /// + /// Propagates down the flow tree because the computation is. + /// bottom-up. const BUBBLE_ISIZES = 0x08; - #[doc = "Recompute actual inline-sizes and block-sizes, only taking out-of-flow children \ - into account. \ - Propagates up the flow tree because the computation is top-down."] + /// Recompute actual inline-sizes and block-sizes, only taking + /// out-of-flow children into account. + /// + /// Propagates up the flow tree because the computation is top-down. const REFLOW_OUT_OF_FLOW = 0x10; - #[doc = "Recompute actual inline_sizes and block_sizes."] - #[doc = "Propagates up the flow tree because the computation is"] - #[doc = "top-down."] + /// Recompute actual inline_sizes and block_sizes. + /// + /// Propagates up the flow tree because the computation is top-down. const REFLOW = 0x20; - #[doc = "Re-resolve generated content. \ - Propagates up the flow tree because the computation is inorder."] + /// Re-resolve generated content. + /// + /// Propagates up the flow tree because the computation is inorder. const RESOLVE_GENERATED_CONTENT = 0x40; - #[doc = "The entire flow needs to be reconstructed."] + /// The entire flow needs to be reconstructed. const RECONSTRUCT_FLOW = 0x80; } } @@ -70,7 +74,7 @@ impl ServoRestyleDamage { // optimization to skip the cascade in those cases applies. StyleChange::Changed { reset_only: false } }; - StyleDifference::new(damage, change) + StyleDifference { damage, change } } /// Returns a bitmask that represents a flow that needs to be rebuilt and diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index c33d1063fcb..f046f5d3415 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -313,8 +313,11 @@ impl<'a, 'b, R: ParseErrorReporter> NestedRuleParser<'a, 'b, R> { input: &mut Parser, rule_type: CssRuleType ) -> Arc> { - let context = - ParserContext::new_with_rule_type(self.context, rule_type, self.namespaces); + let context = ParserContext::new_with_rule_type( + self.context, + rule_type, + self.namespaces, + ); let nested_parser = NestedRuleParser { stylesheet_origin: self.stylesheet_origin, @@ -439,33 +442,32 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a ) -> Result> { match prelude { AtRuleBlockPrelude::FontFace(location) => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::FontFace, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::FontFace, + self.namespaces, + ); Ok(CssRule::FontFace(Arc::new(self.shared_lock.wrap( parse_font_face_block(&context, self.error_context, input, location).into())))) } AtRuleBlockPrelude::FontFeatureValues(family_names, location) => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::FontFeatureValues, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::FontFeatureValues, + self.namespaces, + ); + Ok(CssRule::FontFeatureValues(Arc::new(self.shared_lock.wrap( FontFeatureValuesRule::parse(&context, self.error_context, input, family_names, location))))) } AtRuleBlockPrelude::CounterStyle(name) => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::CounterStyle, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::CounterStyle, + self.namespaces, + ); + Ok(CssRule::CounterStyle(Arc::new(self.shared_lock.wrap( parse_counter_style_body(name, &context, self.error_context, input)?.into())))) } @@ -477,12 +479,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a })))) } AtRuleBlockPrelude::Supports(cond, location) => { - let eval_context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::Style, - self.namespaces, - ); + let eval_context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::Style, + self.namespaces, + ); + let enabled = cond.eval(&eval_context); Ok(CssRule::Supports(Arc::new(self.shared_lock.wrap(SupportsRule { condition: cond, @@ -492,22 +494,21 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a })))) } AtRuleBlockPrelude::Viewport => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::Viewport, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::Viewport, + self.namespaces, + ); + Ok(CssRule::Viewport(Arc::new(self.shared_lock.wrap( ViewportRule::parse(&context, self.error_context, input)?)))) } AtRuleBlockPrelude::Keyframes(name, prefix, location) => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::Keyframes, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::Keyframes, + self.namespaces, + ); Ok(CssRule::Keyframes(Arc::new(self.shared_lock.wrap(KeyframesRule { name: name, @@ -517,12 +518,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> AtRuleParser<'i> for NestedRuleParser<'a })))) } AtRuleBlockPrelude::Page(location) => { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::Page, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::Page, + self.namespaces, + ); + let declarations = parse_property_declaration_list(&context, self.error_context, input); Ok(CssRule::Page(Arc::new(self.shared_lock.wrap(PageRule { block: Arc::new(self.shared_lock.wrap(declarations)), @@ -573,12 +574,12 @@ impl<'a, 'b, 'i, R: ParseErrorReporter> QualifiedRuleParser<'i> for NestedRulePa prelude: QualifiedRuleParserPrelude, input: &mut Parser<'i, 't> ) -> Result> { - let context = - ParserContext::new_with_rule_type( - self.context, - CssRuleType::Style, - self.namespaces, - ); + let context = ParserContext::new_with_rule_type( + self.context, + CssRuleType::Style, + self.namespaces, + ); + let declarations = parse_property_declaration_list(&context, self.error_context, input); Ok(CssRule::Style(Arc::new(self.shared_lock.wrap(StyleRule { selectors: prelude.selectors, diff --git a/components/style/stylesheets/stylesheet.rs b/components/style/stylesheets/stylesheet.rs index 02d87f1ceea..038df8a2279 100644 --- a/components/style/stylesheets/stylesheet.rs +++ b/components/style/stylesheets/stylesheet.rs @@ -309,13 +309,16 @@ impl StylesheetInDocument for DocumentStyleSheet { impl Stylesheet { /// Updates an empty stylesheet from a given string of text. - pub fn update_from_str(existing: &Stylesheet, - css: &str, - url_data: UrlExtraData, - stylesheet_loader: Option<&StylesheetLoader>, - error_reporter: &R, - line_number_offset: u32) - where R: ParseErrorReporter + pub fn update_from_str( + existing: &Stylesheet, + css: &str, + url_data: UrlExtraData, + stylesheet_loader: Option<&StylesheetLoader>, + error_reporter: &R, + line_number_offset: u32, + ) + where + R: ParseErrorReporter, { let namespaces = RwLock::new(Namespaces::default()); let (rules, source_map_url, source_url) = @@ -359,14 +362,14 @@ impl Stylesheet { let mut input = ParserInput::new_with_line_number_offset(css, line_number_offset); let mut input = Parser::new(&mut input); - let context = - ParserContext::new( - origin, - url_data, - None, - ParsingMode::DEFAULT, - quirks_mode - ); + let context = ParserContext::new( + origin, + url_data, + None, + ParsingMode::DEFAULT, + quirks_mode + ); + let error_context = ParserErrorContext { error_reporter }; let rule_parser = TopLevelRuleParser { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index c0b60adaad5..9c02b3d7f14 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -2492,11 +2492,13 @@ pub extern "C" fn Servo_ParseEasing( // FIXME Dummy URL data would work fine here. let url_data = unsafe { RefPtr::from_ptr_ref(&data) }; - let context = ParserContext::new(Origin::Author, - url_data, - Some(CssRuleType::Style), - ParsingMode::DEFAULT, - QuirksMode::NoQuirks); + let context = ParserContext::new( + Origin::Author, + url_data, + Some(CssRuleType::Style), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); let easing = unsafe { (*easing).to_string() }; let mut input = ParserInput::new(&easing); let mut parser = Parser::new(&mut input); @@ -2961,9 +2963,12 @@ pub extern "C" fn Servo_MediaList_AppendMedium( ) { let new_medium = unsafe { new_medium.as_ref().unwrap().as_str_unchecked() }; let url_data = unsafe { dummy_url_data() }; - let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media), - ParsingMode::DEFAULT, - QuirksMode::NoQuirks); + let context = ParserContext::new_for_cssom( + url_data, + Some(CssRuleType::Media), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); write_locked_arc(list, |list: &mut MediaList| { list.append_medium(&context, new_medium); }) @@ -2976,9 +2981,12 @@ pub extern "C" fn Servo_MediaList_DeleteMedium( ) -> bool { let old_medium = unsafe { old_medium.as_ref().unwrap().as_str_unchecked() }; let url_data = unsafe { dummy_url_data() }; - let context = ParserContext::new_for_cssom(url_data, Some(CssRuleType::Media), - ParsingMode::DEFAULT, - QuirksMode::NoQuirks); + let context = ParserContext::new_for_cssom( + url_data, + Some(CssRuleType::Media), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); write_locked_arc(list, |list: &mut MediaList| list.delete_medium(&context, old_medium)) } @@ -3362,9 +3370,13 @@ pub extern "C" fn Servo_DeclarationBlock_SetBackgroundImage( let url_data = unsafe { RefPtr::from_ptr_ref(&raw_extra_data) }; let string = unsafe { (*value).to_string() }; - let context = ParserContext::new(Origin::Author, url_data, - Some(CssRuleType::Style), ParsingMode::DEFAULT, - QuirksMode::NoQuirks); + let context = ParserContext::new( + Origin::Author, + url_data, + Some(CssRuleType::Style), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); if let Ok(mut url) = SpecifiedUrl::parse_from_string(string.into(), &context) { url.build_image_value(); let decl = PropertyDeclaration::BackgroundImage(BackgroundImage( @@ -3420,13 +3432,13 @@ pub extern "C" fn Servo_CSSSupports(cond: *const nsACString) -> bool { let url_data = unsafe { dummy_url_data() }; // NOTE(emilio): The supports API is not associated to any stylesheet, // so the fact that there are no namespace map here is fine. - let context = - ParserContext::new_for_cssom( - url_data, - Some(CssRuleType::Style), - ParsingMode::DEFAULT, - QuirksMode::NoQuirks, - ); + let context = ParserContext::new_for_cssom( + url_data, + Some(CssRuleType::Style), + ParsingMode::DEFAULT, + QuirksMode::NoQuirks, + ); + cond.eval(&context) } else { false