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 <obrufau@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-13 09:31:23 +02:00 committed by GitHub
parent 497df024b1
commit 6e80a34d09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -622,49 +622,38 @@ impl ComputedValuesExt for ComputedValues {
/// <https://www.w3.org/TR/css-overflow-3/#overflow-control>
fn effective_overflow(&self) -> PhysicalVec<Overflow> {
let style_box = self.get_box();
let mut overflow_x = style_box.overflow_x;
let mut overflow_y = style_box.overflow_y;
// According to <https://drafts.csswg.org/css-tables/#global-style-overrides>,
// 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: <https://lists.w3.org/Archives/Public/www-style/2012Aug/0298.html>
// 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)) =>
{
// <https://drafts.csswg.org/css-tables/#global-style-overrides>
// 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 <https://drafts.csswg.org/css-tables/#global-style-overrides>,
// - 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: <https://lists.w3.org/Archives/Public/www-style/2012Aug/0298.html>
// 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 => {
// <https://drafts.csswg.org/css-tables/#global-style-overrides>
// 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