Add width and height presentational hints for table-related elements (#33405)

We were only parsing the `width` attribute as a presentation hint for
`<table>`, `<td>` and `<th>`. This patch also handles `<colgroup>` and
`<col>`.

Also, we weren't parsing `height` at all, now we do it for `<table>`,
`<td>`, `<th>`, `<tr>`, `<tbody>`, `<thead>` and `<tfoot>`.

One test is now crashing, but this was an existing issue: #33423

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Oriol Brufau 2024-09-12 15:34:20 +02:00 committed by GitHub
parent 37ab4b9825
commit 4839cdf176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 65 additions and 228 deletions

View file

@ -850,6 +850,8 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
this.get_width()
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
this.get_width()
} else if let Some(this) = self.downcast::<HTMLTableColElement>() {
this.get_width()
} else if let Some(this) = self.downcast::<HTMLHRElement>() {
// https://html.spec.whatwg.org/multipage/#the-hr-element-2:attr-hr-width
this.get_width()
@ -886,6 +888,14 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
this.get_height()
} else if let Some(this) = self.downcast::<HTMLImageElement>() {
this.get_height()
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
this.get_height()
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
this.get_height()
} else if let Some(this) = self.downcast::<HTMLTableRowElement>() {
this.get_height()
} else if let Some(this) = self.downcast::<HTMLTableSectionElement>() {
this.get_height()
} else {
LengthOrPercentageOrAuto::Auto
};

View file

@ -111,6 +111,7 @@ pub trait HTMLTableCellElementLayoutHelpers<'dom> {
fn get_rowspan(self) -> Option<u32>;
fn get_table(self) -> Option<LayoutDom<'dom, HTMLTableElement>>;
fn get_width(self) -> LengthOrPercentageOrAuto;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
impl<'dom> HTMLTableCellElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableCellElement> {
@ -151,6 +152,14 @@ impl<'dom> HTMLTableCellElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTable
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
fn get_height(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
impl VirtualMethods for HTMLTableCellElement {
@ -185,6 +194,7 @@ impl VirtualMethods for HTMLTableCellElement {
},
local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()),
local_name!("width") => AttrValue::from_nonzero_dimension(value.into()),
local_name!("height") => AttrValue::from_nonzero_dimension(value.into()),
_ => self
.super_type()
.unwrap()

View file

@ -5,7 +5,7 @@
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use super::bindings::root::LayoutDom;
use super::element::Element;
@ -66,6 +66,7 @@ impl HTMLTableColElementMethods for HTMLTableColElement {
pub trait HTMLTableColElementLayoutHelpers<'dom> {
fn get_span(self) -> Option<u32>;
fn get_width(self) -> LengthOrPercentageOrAuto;
}
impl<'dom> HTMLTableColElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableColElement> {
@ -74,6 +75,14 @@ impl<'dom> HTMLTableColElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableC
.get_attr_for_layout(&ns!(), &local_name!("span"))
.map(AttrValue::as_uint)
}
fn get_width(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("width"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
impl VirtualMethods for HTMLTableColElement {
@ -92,6 +101,7 @@ impl VirtualMethods for HTMLTableColElement {
}
attr
},
local_name!("width") => AttrValue::from_nonzero_dimension(value.into()),
_ => self
.super_type()
.unwrap()

View file

@ -443,6 +443,7 @@ pub trait HTMLTableElementLayoutHelpers {
fn get_cellpadding(self) -> Option<u32>;
fn get_cellspacing(self) -> Option<u32>;
fn get_width(self) -> LengthOrPercentageOrAuto;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
@ -472,6 +473,14 @@ impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
fn get_height(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
impl VirtualMethods for HTMLTableElement {
@ -512,6 +521,7 @@ impl VirtualMethods for HTMLTableElement {
match *local_name {
local_name!("border") => AttrValue::from_u32(value.into(), 1),
local_name!("width") => AttrValue::from_nonzero_dimension(value.into()),
local_name!("height") => AttrValue::from_nonzero_dimension(value.into()),
local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()),
_ => self
.super_type()

View file

@ -5,7 +5,7 @@
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::color::AbsoluteColor;
use crate::dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
@ -154,6 +154,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
pub trait HTMLTableRowElementLayoutHelpers {
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
@ -163,6 +164,14 @@ impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
.and_then(AttrValue::as_color)
.cloned()
}
fn get_height(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
impl VirtualMethods for HTMLTableRowElement {
@ -173,6 +182,7 @@ impl VirtualMethods for HTMLTableRowElement {
fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue {
match *local_name {
local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()),
local_name!("height") => AttrValue::from_nonzero_dimension(value.into()),
_ => self
.super_type()
.unwrap()

View file

@ -5,7 +5,7 @@
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::color::AbsoluteColor;
use crate::dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::HTMLTableSectionElementMethods;
@ -92,6 +92,7 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
pub trait HTMLTableSectionElementLayoutHelpers {
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
@ -101,6 +102,14 @@ impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElem
.and_then(AttrValue::as_color)
.cloned()
}
fn get_height(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)
.cloned()
.unwrap_or(LengthOrPercentageOrAuto::Auto)
}
}
impl VirtualMethods for HTMLTableSectionElement {
@ -111,6 +120,7 @@ impl VirtualMethods for HTMLTableSectionElement {
fn parse_plain_attribute(&self, local_name: &LocalName, value: DOMString) -> AttrValue {
match *local_name {
local_name!("bgcolor") => AttrValue::from_legacy_color(value.into()),
local_name!("height") => AttrValue::from_nonzero_dimension(value.into()),
_ => self
.super_type()
.unwrap()

View file

@ -1,2 +0,0 @@
[floats-wrap-bfc-005.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[inline-block-valign-001.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[border-image-repeat-002.htm]
expected: FAIL

View file

@ -1,2 +0,0 @@
[border-image-repeat-004.htm]
expected: FAIL

View file

@ -1,2 +0,0 @@
[css3-border-image-repeat-repeat.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[large-col-widths.html]
expected: CRASH

View file

@ -1,10 +1,4 @@
[colgroup-col.html]
[table 1]
expected: FAIL
[table 2]
expected: FAIL
[table 3]
expected: FAIL

View file

@ -569,198 +569,6 @@
[<embed height="0px"> mapping to <embed> height property]
expected: FAIL
[<td height="200"> mapping to <td> height property]
expected: FAIL
[<td height="1007"> mapping to <td> height property]
expected: FAIL
[<td height=" 00523 "> mapping to <td> height property]
expected: FAIL
[<td height="200.25"> mapping to <td> height property]
expected: FAIL
[<td height="200.7"> mapping to <td> height property]
expected: FAIL
[<td height="200."> mapping to <td> height property]
expected: FAIL
[<td height="200in"> mapping to <td> height property]
expected: FAIL
[<td height="200.25in"> mapping to <td> height property]
expected: FAIL
[<td height="200 %"> mapping to <td> height property]
expected: FAIL
[<td height="200 abc"> mapping to <td> height property]
expected: FAIL
[<td height="200%"> mapping to <td> height property]
expected: FAIL
[<td height="200%abc"> mapping to <td> height property]
expected: FAIL
[<td height="200.25%"> mapping to <td> height property]
expected: FAIL
[<td height="200.%"> mapping to <td> height property]
expected: FAIL
[<td height="20.25e2"> mapping to <td> height property]
expected: FAIL
[<td height="20.25E2"> mapping to <td> height property]
expected: FAIL
[<table height="200"> mapping to <table> height property]
expected: FAIL
[<table height="1007"> mapping to <table> height property]
expected: FAIL
[<table height=" 00523 "> mapping to <table> height property]
expected: FAIL
[<table height="200.25"> mapping to <table> height property]
expected: FAIL
[<table height="200.7"> mapping to <table> height property]
expected: FAIL
[<table height="200."> mapping to <table> height property]
expected: FAIL
[<table height="200in"> mapping to <table> height property]
expected: FAIL
[<table height="200.25in"> mapping to <table> height property]
expected: FAIL
[<table height="200 %"> mapping to <table> height property]
expected: FAIL
[<table height="200 abc"> mapping to <table> height property]
expected: FAIL
[<table height="200%"> mapping to <table> height property]
expected: FAIL
[<table height="200%abc"> mapping to <table> height property]
expected: FAIL
[<table height="200.25%"> mapping to <table> height property]
expected: FAIL
[<table height="200.%"> mapping to <table> height property]
expected: FAIL
[<table height="20.25e2"> mapping to <table> height property]
expected: FAIL
[<table height="20.25E2"> mapping to <table> height property]
expected: FAIL
[<tr height="200"> mapping to <tr> height property]
expected: FAIL
[<tr height="1007"> mapping to <tr> height property]
expected: FAIL
[<tr height=" 00523 "> mapping to <tr> height property]
expected: FAIL
[<tr height="200.25"> mapping to <tr> height property]
expected: FAIL
[<tr height="200.7"> mapping to <tr> height property]
expected: FAIL
[<tr height="200."> mapping to <tr> height property]
expected: FAIL
[<tr height="200in"> mapping to <tr> height property]
expected: FAIL
[<tr height="200.25in"> mapping to <tr> height property]
expected: FAIL
[<tr height="200 %"> mapping to <tr> height property]
expected: FAIL
[<tr height="200 abc"> mapping to <tr> height property]
expected: FAIL
[<tr height="200%"> mapping to <tr> height property]
expected: FAIL
[<tr height="200%abc"> mapping to <tr> height property]
expected: FAIL
[<tr height="200.25%"> mapping to <tr> height property]
expected: FAIL
[<tr height="200.%"> mapping to <tr> height property]
expected: FAIL
[<tr height="20.25e2"> mapping to <tr> height property]
expected: FAIL
[<tr height="20.25E2"> mapping to <tr> height property]
expected: FAIL
[<col width="200"> mapping to <col> width property]
expected: FAIL
[<col width="1007"> mapping to <col> width property]
expected: FAIL
[<col width=" 00523 "> mapping to <col> width property]
expected: FAIL
[<col width="200.25"> mapping to <col> width property]
expected: FAIL
[<col width="200.7"> mapping to <col> width property]
expected: FAIL
[<col width="200."> mapping to <col> width property]
expected: FAIL
[<col width="200in"> mapping to <col> width property]
expected: FAIL
[<col width="200.25in"> mapping to <col> width property]
expected: FAIL
[<col width="200 %"> mapping to <col> width property]
expected: FAIL
[<col width="200 abc"> mapping to <col> width property]
expected: FAIL
[<col width="200%"> mapping to <col> width property]
expected: FAIL
[<col width="200%abc"> mapping to <col> width property]
expected: FAIL
[<col width="200.25%"> mapping to <col> width property]
expected: FAIL
[<col width="200.%"> mapping to <col> width property]
expected: FAIL
[<col width="20.25e2"> mapping to <col> width property]
expected: FAIL
[<col width="20.25E2"> mapping to <col> width property]
expected: FAIL
[<embed hspace="200"> mapping to <embed> marginLeft property]
expected: FAIL

View file

@ -128,30 +128,18 @@
[table th align attribute justify is correct]
expected: FAIL
[tr height attribute pixel is correct]
expected: FAIL
[td height attribute pixel is correct]
expected: FAIL
[th height attribute pixel is correct]
expected: FAIL
[table_tr height attribute percentage is correct]
expected: FAIL
[table_td height attribute percentage is correct]
expected: FAIL
[table_th height attribute percentage is correct]
expected: FAIL
[table height attribute pixel is correct]
expected: FAIL
[table height attribute 90% is correct]
expected: FAIL
[table height attribute 110% is correct]
expected: FAIL
@ -160,6 +148,3 @@
[th default align attribute is center]
expected: FAIL
[table col width attribute is correct]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-row-group-height.html]
expected: FAIL