style: Reindent some code.

MozReview-Commit-ID: H2qucldbBkc
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-09-04 22:13:05 +02:00
parent 05371b56eb
commit deefacc9de
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 108 additions and 79 deletions

View file

@ -394,51 +394,55 @@ trait PrivateMatchMethods: TElement {
match difference.change { match difference.change {
StyleChange::Unchanged => ChildCascadeRequirement::CanSkipCascade, StyleChange::Unchanged => ChildCascadeRequirement::CanSkipCascade,
StyleChange::Changed { reset_only } => { StyleChange::Changed { reset_only } => {
if reset_only { // If inherited properties changed, the best we can do is
let old_display = old_values.get_box().clone_display(); // cascade the children.
let new_display = new_values.get_box().clone_display(); if !reset_only {
return ChildCascadeRequirement::MustCascadeChildren
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
} }
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
} }
} }
} }

View file

@ -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. /// 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 /// https://drafts.csswg.org/css2/visuren.html#dis-pos-flo
fn blockify_if_necessary(&mut self, fn blockify_if_necessary(
layout_parent_style: &ComputedValues, &mut self,
flags: CascadeFlags) { layout_parent_style: &ComputedValues,
flags: CascadeFlags,
) {
let mut blockify = false; let mut blockify = false;
macro_rules! blockify_if { macro_rules! blockify_if {
($if_what:expr) => { ($if_what:expr) => {
@ -80,8 +82,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
let blockified_display = let blockified_display =
display.equivalent_block_display(flags.contains(IS_ROOT_ELEMENT)); display.equivalent_block_display(flags.contains(IS_ROOT_ELEMENT));
if display != blockified_display { if display != blockified_display {
self.style.mutate_box().set_adjusted_display(blockified_display, self.style.mutate_box().set_adjusted_display(
is_item_or_root); 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://lists.w3.org/Archives/Public/www-style/2017Mar/0045.html
/// https://github.com/servo/servo/issues/15754 /// https://github.com/servo/servo/issues/15754
fn adjust_for_writing_mode(&mut self, fn adjust_for_writing_mode(
layout_parent_style: &ComputedValues) { &mut self,
let our_writing_mode = self.style.get_inheritedbox().clone_writing_mode(); layout_parent_style: &ComputedValues,
let parent_writing_mode = layout_parent_style.get_inheritedbox().clone_writing_mode(); ) {
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 && if our_writing_mode != parent_writing_mode &&
self.style.get_box().clone_display() == display::inline { self.style.get_box().clone_display() == display::inline {
@ -324,9 +332,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// If a <fieldset> has grid/flex display type, we need to inherit /// If a <fieldset> has grid/flex display type, we need to inherit
/// this type into its ::-moz-fieldset-content anonymous box. /// this type into its ::-moz-fieldset-content anonymous box.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn adjust_for_fieldset_content(&mut self, fn adjust_for_fieldset_content(
layout_parent_style: &ComputedValues, &mut self,
flags: CascadeFlags) { layout_parent_style: &ComputedValues,
flags: CascadeFlags,
) {
use properties::IS_FIELDSET_CONTENT; use properties::IS_FIELDSET_CONTENT;
if !flags.contains(IS_FIELDSET_CONTENT) { if !flags.contains(IS_FIELDSET_CONTENT) {
return; return;
@ -337,8 +347,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
// when <fieldset> has "display: contents". // when <fieldset> has "display: contents".
let parent_display = layout_parent_style.get_box().clone_display(); let parent_display = layout_parent_style.get_box().clone_display();
let new_display = match parent_display { let new_display = match parent_display {
display::flex | display::inline_flex => Some(display::flex), display::flex |
display::grid | display::inline_grid => Some(display::grid), display::inline_flex => Some(display::flex),
display::grid |
display::inline_grid => Some(display::grid),
_ => None, _ => None,
}; };
if let Some(new_display) = new_display { if let Some(new_display) = new_display {
@ -355,22 +367,25 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn adjust_for_table_text_align(&mut self) { fn adjust_for_table_text_align(&mut self) {
use properties::longhands::text_align::computed_value::T as text_align; use properties::longhands::text_align::computed_value::T as text_align;
if self.style.get_box().clone_display() != display::table { if self.style.get_box().clone_display() != display::table {
return; return;
} }
match self.style.get_inheritedtext().clone_text_align() { match self.style.get_inheritedtext().clone_text_align() {
text_align::_moz_left | text_align::_moz_left |
text_align::_moz_center | text_align::_moz_center |
text_align::_moz_right => {} text_align::_moz_right => {},
_ => return, _ => 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. /// 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; use properties::computed_value_flags::HAS_TEXT_DECORATION_LINES;
if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) || if layout_parent_style.flags.contains(HAS_TEXT_DECORATION_LINES) ||
!self.style.get_text().clone_text_decoration_line().is_empty() { !self.style.get_text().clone_text_decoration_line().is_empty() {
@ -379,7 +394,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
} }
#[cfg(feature = "gecko")] #[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; use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
// Line break suppression should only be propagated to in-flow children. // Line break suppression should only be propagated to in-flow children.
if self.style.floated() || self.style.out_of_flow_positioned() { 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() { match self.style.get_box().clone_display() {
// Ruby base and text are always non-breakable. // 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. // Ruby base container and text container are breakable.
// Note that, when certain HTML tags, e.g. form controls, have ruby // Note that, when certain HTML tags, e.g. form controls, have ruby
// level container display type, they could also escape from the // level container display type, they could also escape from the
// line break suppression flag while they shouldn't. However, it is // line break suppression flag while they shouldn't. However, it is
// generally fine since they themselves are non-breakable. // 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 // 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 // has a ruby display type, because any of the ruby boxes can be
// anonymous. // anonymous.
@ -415,9 +435,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// * suppress border and padding for ruby level containers, /// * suppress border and padding for ruby level containers,
/// * correct unicode-bidi. /// * correct unicode-bidi.
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
fn adjust_for_ruby(&mut self, fn adjust_for_ruby(
layout_parent_style: &ComputedValues, &mut self,
flags: CascadeFlags) { layout_parent_style: &ComputedValues,
flags: CascadeFlags,
) {
use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP; use properties::SKIP_ROOT_AND_ITEM_BASED_DISPLAY_FIXUP;
use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK; use properties::computed_value_flags::SHOULD_SUPPRESS_LINEBREAK;
use properties::longhands::unicode_bidi::computed_value::T as unicode_bidi; 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 // per spec https://drafts.csswg.org/css-ruby-1/#bidi
if self_display.is_ruby_type() { if self_display.is_ruby_type() {
let new_value = match self.style.get_text().clone_unicode_bidi() { 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), unicode_bidi::bidi_override => Some(unicode_bidi::isolate_override),
_ => None, _ => None,
}; };
@ -521,9 +544,11 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> {
/// When comparing to Gecko, this is similar to the work done by /// When comparing to Gecko, this is similar to the work done by
/// `nsStyleContext::ApplyStyleFixups`, plus some parts of /// `nsStyleContext::ApplyStyleFixups`, plus some parts of
/// `nsStyleSet::GetContext`. /// `nsStyleSet::GetContext`.
pub fn adjust(&mut self, pub fn adjust(
layout_parent_style: &ComputedValues, &mut self,
flags: CascadeFlags) { layout_parent_style: &ComputedValues,
flags: CascadeFlags,
) {
self.adjust_for_visited(flags); self.adjust_for_visited(flags);
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {