From deefacc9de41b0f7ca320a7cc31f57970caf8988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 4 Sep 2017 22:13:05 +0200 Subject: [PATCH] style: Reindent some code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MozReview-Commit-ID: H2qucldbBkc Signed-off-by: Emilio Cobos Álvarez --- components/style/matching.rs | 92 +++++++++++++++-------------- components/style/style_adjuster.rs | 95 +++++++++++++++++++----------- 2 files changed, 108 insertions(+), 79 deletions(-) diff --git a/components/style/matching.rs b/components/style/matching.rs index cb9295c47af..c3c5e37c165 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -394,51 +394,55 @@ trait PrivateMatchMethods: TElement { match difference.change { StyleChange::Unchanged => ChildCascadeRequirement::CanSkipCascade, StyleChange::Changed { reset_only } => { - if reset_only { - let old_display = old_values.get_box().clone_display(); - let new_display = new_values.get_box().clone_display(); - - if old_display.is_item_container() != new_display.is_item_container() { - // Blockification of children may depend on our display - // value, so we need to actually do the recascade. - return ChildCascadeRequirement::MustCascadeChildren - } - - #[cfg(feature = "gecko")] - { - use values::specified::align; - - // Children with justify-items: legacy may depend on our - // property value. - // - // TODO(emilio): We could special-case this even more - // creating a new `ChildCascadeRequirement` variant, but - // it's unclear it matters. - 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(align::ALIGN_LEGACY); - - let is_legacy_justify_items = - new_justify_items.computed.0.contains(align::ALIGN_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; - } - } - - ChildCascadeRequirement::MustCascadeChildrenIfInheritResetStyle - } else { - ChildCascadeRequirement::MustCascadeChildren + // 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(); + + // 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 + } + + // 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; + + 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(align::ALIGN_LEGACY); + + let is_legacy_justify_items = + new_justify_items.computed.0.contains(align::ALIGN_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 } } } diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index 9e0a0e9b409..c2044c143b5 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -50,9 +50,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// Apply the blockification rules based on the table in CSS 2.2 section 9.7. /// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo - fn blockify_if_necessary(&mut self, - layout_parent_style: &ComputedValues, - flags: CascadeFlags) { + fn blockify_if_necessary( + &mut self, + layout_parent_style: &ComputedValues, + flags: CascadeFlags, + ) { let mut blockify = false; macro_rules! blockify_if { ($if_what:expr) => { @@ -80,8 +82,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { let blockified_display = display.equivalent_block_display(flags.contains(IS_ROOT_ELEMENT)); if display != blockified_display { - self.style.mutate_box().set_adjusted_display(blockified_display, - is_item_or_root); + self.style.mutate_box().set_adjusted_display( + blockified_display, + is_item_or_root, + ); } } @@ -165,10 +169,14 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// /// https://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html /// https://github.com/servo/servo/issues/15754 - fn adjust_for_writing_mode(&mut self, - layout_parent_style: &ComputedValues) { - let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode(); - let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode(); + fn adjust_for_writing_mode( + &mut self, + layout_parent_style: &ComputedValues, + ) { + let our_writing_mode = + self.style.get_inheritedbox().clone_writing_mode(); + let parent_writing_mode = + layout_parent_style.get_inheritedbox().clone_writing_mode(); if our_writing_mode != parent_writing_mode && self.style.get_box().clone_display() == display::inline { @@ -324,9 +332,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// If a
has grid/flex display type, we need to inherit /// this type into its ::-moz-fieldset-content anonymous box. #[cfg(feature = "gecko")] - fn adjust_for_fieldset_content(&mut self, - layout_parent_style: &ComputedValues, - flags: CascadeFlags) { + fn adjust_for_fieldset_content( + &mut self, + layout_parent_style: &ComputedValues, + flags: CascadeFlags, + ) { use properties::IS_FIELDSET_CONTENT; if !flags.contains(IS_FIELDSET_CONTENT) { return; @@ -337,8 +347,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { // when
has "display: contents". let parent_display = layout_parent_style.get_box().clone_display(); let new_display = match parent_display { - display::flex | display::inline_flex => Some(display::flex), - display::grid | display::inline_grid => Some(display::grid), + display::flex | + display::inline_flex => Some(display::flex), + display::grid | + display::inline_grid => Some(display::grid), _ => None, }; if let Some(new_display) = new_display { @@ -355,22 +367,25 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { #[cfg(feature = "gecko")] fn adjust_for_table_text_align(&mut self) { use properties::longhands::text_align::computed_value::T as text_align; - if self.style.get_box().clone_display() != display::table { - return; - } + if self.style.get_box().clone_display() != display::table { + return; + } - match self.style.get_inheritedtext().clone_text_align() { - text_align::_moz_left | - text_align::_moz_center | - text_align::_moz_right => {} - _ => return, - } + match self.style.get_inheritedtext().clone_text_align() { + text_align::_moz_left | + text_align::_moz_center | + text_align::_moz_right => {}, + _ => return, + } - self.style.mutate_inheritedtext().set_text_align(text_align::start); + self.style.mutate_inheritedtext().set_text_align(text_align::start) } /// Set the HAS_TEXT_DECORATION_LINES flag based on parent style. - fn adjust_for_text_decoration_lines(&mut self, layout_parent_style: &ComputedValues) { + fn adjust_for_text_decoration_lines( + &mut self, + layout_parent_style: &ComputedValues, + ) { use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES; if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) || !self.style.get_text().clone_text_decoration_line().is_empty() { @@ -379,7 +394,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } #[cfg(feature = "gecko")] - fn should_suppress_linebreak(&self, layout_parent_style: &ComputedValues) -> bool { + fn should_suppress_linebreak( + &self, + layout_parent_style: &ComputedValues, + ) -> bool { use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; // Line break suppression should only be propagated to in-flow children. if self.style.floated() || self.style.out_of_flow_positioned() { @@ -395,13 +413,15 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } match self.style.get_box().clone_display() { // Ruby base and text are always non-breakable. - display::ruby_base | display::ruby_text => true, + display::ruby_base | + display::ruby_text => true, // Ruby base container and text container are breakable. // Note that, when certain HTML tags, e.g. form controls, have ruby // level container display type, they could also escape from the // line break suppression flag while they shouldn't. However, it is // generally fine since they themselves are non-breakable. - display::ruby_base_container | display::ruby_text_container => false, + display::ruby_base_container | + display::ruby_text_container => false, // Anything else is non-breakable if and only if its layout parent // has a ruby display type, because any of the ruby boxes can be // anonymous. @@ -415,9 +435,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// * suppress border and padding for ruby level containers, /// * correct unicode-bidi. #[cfg(feature = "gecko")] - fn adjust_for_ruby(&mut self, - layout_parent_style: &ComputedValues, - flags: CascadeFlags) { + fn adjust_for_ruby( + &mut self, + layout_parent_style: &ComputedValues, + flags: CascadeFlags, + ) { use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; use properties::longhands::unicode_bidi::computed_value::T as unicode_bidi; @@ -447,7 +469,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { // per spec https://drafts.csswg.org/css-ruby-1/#bidi if self_display.is_ruby_type() { let new_value = match self.style.get_text().clone_unicode_bidi() { - unicode_bidi::normal | unicode_bidi::embed => Some(unicode_bidi::isolate), + unicode_bidi::normal | + unicode_bidi::embed => Some(unicode_bidi::isolate), unicode_bidi::bidi_override => Some(unicode_bidi::isolate_override), _ => None, }; @@ -521,9 +544,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { /// When comparing to Gecko, this is similar to the work done by /// `nsStyleContext::ApplyStyleFixups`, plus some parts of /// `nsStyleSet::GetContext`. - pub fn adjust(&mut self, - layout_parent_style: &ComputedValues, - flags: CascadeFlags) { + pub fn adjust( + &mut self, + layout_parent_style: &ComputedValues, + flags: CascadeFlags, + ) { self.adjust_for_visited(flags); #[cfg(feature = "gecko")] {