From 6e80a34d09e8bb22bdac5feeff4cf30b571987ff Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 13 Sep 2024 09:31:23 +0200 Subject: [PATCH] Simplify table logic in effective_overflow() (#33431) On tables, we need to treat an overflow value of `scroll` or `auto` as `visible`. Both `scroll` or `auto` are scrollable, which implies that the other axis must also have a scrollable value. Therefore, when we make the value behave as the non-scrollable `visible`, we need to adjust the other axis too. The previous logic was checking `is_scrollable()` but that wasn't necessary, since computed values must have the same scrollability. Signed-off-by: Oriol Brufau --- components/layout_2020/style_ext.rs | 55 ++++++++++++----------------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/components/layout_2020/style_ext.rs b/components/layout_2020/style_ext.rs index f9aa9650c53..53bf9e6df33 100644 --- a/components/layout_2020/style_ext.rs +++ b/components/layout_2020/style_ext.rs @@ -622,49 +622,38 @@ impl ComputedValuesExt for ComputedValues { /// fn effective_overflow(&self) -> PhysicalVec { let style_box = self.get_box(); - let mut overflow_x = style_box.overflow_x; - let mut overflow_y = style_box.overflow_y; - // According to , - // overflow applies to table-wrapper boxes and not to table grid boxes. - // That's what Blink and WebKit do, however Firefox matches a CSSWG resolution that says - // the opposite: - // Due to the way that we implement table-wrapper boxes, it's easier to align with Firefox. - match style_box.display.inside() { - stylo::DisplayInside::Table - if matches!(self.pseudo(), Some(PseudoElement::ServoTableGrid)) => - { - // - // Tables ignore overflow values different than visible, clip and hidden. - // We also need to make sure that both axes have the same scrollability. - if matches!(overflow_x, Overflow::Auto | Overflow::Scroll) { - overflow_x = Overflow::Visible; - if overflow_y.is_scrollable() { - overflow_y = Overflow::Visible; - } - } - if matches!(overflow_y, Overflow::Auto | Overflow::Scroll) { - overflow_y = Overflow::Visible; - if overflow_x.is_scrollable() { - overflow_x = Overflow::Visible; - } - } + let overflow_x = style_box.overflow_x; + let overflow_y = style_box.overflow_y; + let ignores_overflow = match style_box.display.inside() { + stylo::DisplayInside::Table => { + // According to , + // - overflow applies to table-wrapper boxes and not to table grid boxes. + // That's what Blink and WebKit do, however Firefox matches a CSSWG resolution that says + // the opposite: + // Due to the way that we implement table-wrapper boxes, it's easier to align with Firefox. + // - Tables ignore overflow values different than visible, clip and hidden. + // This affects both axes, to ensure they have the same scrollability. + !matches!(self.pseudo(), Some(PseudoElement::ServoTableGrid)) || + matches!(overflow_x, Overflow::Auto | Overflow::Scroll) || + matches!(overflow_y, Overflow::Auto | Overflow::Scroll) }, stylo::DisplayInside::TableColumn | stylo::DisplayInside::TableColumnGroup | stylo::DisplayInside::TableRow | stylo::DisplayInside::TableRowGroup | stylo::DisplayInside::TableHeaderGroup | - stylo::DisplayInside::TableFooterGroup | - stylo::DisplayInside::Table => { + stylo::DisplayInside::TableFooterGroup => { // // Table-track and table-track-group boxes ignore overflow. - // We also ignore it on table-wrapper boxes (see above). - overflow_x = Overflow::Visible; - overflow_y = Overflow::Visible; + true }, - _ => {}, + _ => false, + }; + if ignores_overflow { + PhysicalVec::new(Overflow::Visible, Overflow::Visible) + } else { + PhysicalVec::new(overflow_x, overflow_y) } - PhysicalVec::new(overflow_x, overflow_y) } /// Return true if this style is a normal block and establishes