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

@ -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()