Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout: Set padding to zero on tables in collapsed-borders mode #34908

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/layout_2020/geom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<T: Copy> LogicalSides<T> {
}
}

impl LogicalSides<&'_ LengthPercentage> {
impl LogicalSides<LengthPercentage> {
pub fn percentages_relative_to(&self, basis: Au) -> LogicalSides<Au> {
self.map(|value| value.to_used_value(basis))
}
Expand Down
26 changes: 16 additions & 10 deletions components/layout_2020/style_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use app_units::Au;
use style::computed_values::border_collapse::T as BorderCollapse;
use style::computed_values::direction::T as Direction;
use style::computed_values::mix_blend_mode::T as ComputedMixBlendMode;
use style::computed_values::position::T as ComputedPosition;
Expand Down Expand Up @@ -276,10 +277,8 @@ pub(crate) trait ComputedValuesExt {
writing_mode: WritingMode,
containing_block_inline_size: Au,
) -> PaddingBorderMargin;
fn padding(
&self,
containing_block_writing_mode: WritingMode,
) -> LogicalSides<&LengthPercentage>;
fn padding(&self, containing_block_writing_mode: WritingMode)
-> LogicalSides<LengthPercentage>;
fn border_style(&self, containing_block_writing_mode: WritingMode)
-> LogicalSides<BorderStyle>;
fn border_width(&self, containing_block_writing_mode: WritingMode) -> LogicalSides<Au>;
Expand Down Expand Up @@ -579,14 +578,21 @@ impl ComputedValuesExt for ComputedValues {
fn padding(
&self,
containing_block_writing_mode: WritingMode,
) -> LogicalSides<&LengthPercentage> {
let padding = self.get_padding();
) -> LogicalSides<LengthPercentage> {
if self.get_box().display.inside() == stylo::DisplayInside::Table &&
self.get_inherited_table().border_collapse == BorderCollapse::Collapse
{
// https://drafts.csswg.org/css-tables/#collapsed-style-overrides
// > The padding of the table-root is ignored (as if it was set to 0px).
return LogicalSides::zero();
}
let padding = self.get_padding().clone();
Comment on lines +582 to +589
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit more magical than I would like. But I guess this needs to be accessed by every parent context. So I can't really think of a better way.

LogicalSides::from_physical(
&PhysicalSides::new(
&padding.padding_top.0,
&padding.padding_right.0,
&padding.padding_bottom.0,
&padding.padding_left.0,
padding.padding_top.0,
padding.padding_right.0,
padding.padding_bottom.0,
padding.padding_left.0,
),
containing_block_writing_mode,
)
Expand Down
52 changes: 52 additions & 0 deletions tests/wpt/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -105991,6 +105991,58 @@
{}
]
],
"collapsing-border-model-011.html": [
"9c03ddeda9051c6e823ca1f31729eed0d8a8ac7b",
[
null,
[
[
"/css/reference/ref-filled-green-100px-square-only.html",
"=="
]
],
{}
]
],
"collapsing-border-model-012.html": [
"39b176ce375994ece4ca6c05b7484ef59fcd1c79",
[
null,
[
[
"/css/reference/ref-filled-green-100px-square-only.html",
"=="
]
],
{}
]
],
"collapsing-border-model-013.html": [
"5e5f57694c9015c5a74082a9525bb2ce44d39bfc",
[
null,
[
[
"/css/reference/ref-filled-green-100px-square-only.html",
"=="
]
],
{}
]
],
"collapsing-border-model-014.html": [
"18177526b824cfebbc95467031c30d04b7b3ff79",
[
null,
[
[
"/css/reference/ref-filled-green-100px-square-only.html",
"=="
]
],
{}
]
],
"column-visibility-004.xht": [
"60d233fa9402f0b57a45f299405dacca5abc8ee6",
[
Expand Down
17 changes: 17 additions & 0 deletions tests/wpt/tests/css/CSS2/tables/collapsing-border-model-011.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>CSS Test: Tables under the collapsing borders model don't have padding</title>
<link rel="author" title="Oriol Brufau" href="obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/CSS21/tables.html#collapsing-borders">
<link rel="match" href="../../reference/ref-filled-green-100px-square-only.html">
<style>
table {
border-collapse: collapse;
box-sizing: content-box;
width: 100px;
height: 100px;
padding: 100px;
background: green;
}
</style>
<p>Test passes if there is a filled green square.</p>
<table></table>
17 changes: 17 additions & 0 deletions tests/wpt/tests/css/CSS2/tables/collapsing-border-model-012.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<title>CSS Test: Tables under the collapsing borders model don't have padding</title>
<link rel="author" title="Oriol Brufau" href="obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/CSS21/tables.html#collapsing-borders">
<link rel="match" href="../../reference/ref-filled-green-100px-square-only.html">
<style>
table {
border-collapse: collapse;
box-sizing: border-box;
width: 100px;
height: 100px;
padding: 100px;
background: green;
}
</style>
<p>Test passes if there is a filled green square.</p>
<table></table>
22 changes: 22 additions & 0 deletions tests/wpt/tests/css/CSS2/tables/collapsing-border-model-013.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<title>CSS Test: Tables under the collapsing borders model don't have padding</title>
<link rel="author" title="Oriol Brufau" href="obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/CSS21/tables.html#collapsing-borders">
<link rel="match" href="../../reference/ref-filled-green-100px-square-only.html">
<style>
div {
float: left;
background: green;
}
table {
border-collapse: collapse;
box-sizing: content-box;
width: 100px;
height: 100px;
padding: 100px;
}
</style>
<p>Test passes if there is a filled green square.</p>
<div>
<table></table>
</div>
22 changes: 22 additions & 0 deletions tests/wpt/tests/css/CSS2/tables/collapsing-border-model-014.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<title>CSS Test: Tables under the collapsing borders model don't have padding</title>
<link rel="author" title="Oriol Brufau" href="obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/CSS21/tables.html#collapsing-borders">
<link rel="match" href="../../reference/ref-filled-green-100px-square-only.html">
<style>
div {
float: left;
background: green;
}
table {
border-collapse: collapse;
box-sizing: border-box;
width: 100px;
height: 100px;
padding: 100px;
}
</style>
<p>Test passes if there is a filled green square.</p>
<div>
<table></table>
</div>
Loading