Add support for cellpadding attribute (#31201)

This commit is contained in:
Oriol Brufau 2024-01-29 12:51:30 +01:00 committed by GitHub
parent 091653417a
commit 7d1b19c865
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 58 additions and 68 deletions

View file

@ -989,6 +989,32 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
PropertyDeclaration::BorderRightWidth(width_value),
));
}
if let Some(cellpadding) = self
.downcast::<HTMLTableCellElement>()
.and_then(|this| this.get_table())
.and_then(|table| table.get_cellpadding())
{
let cellpadding = NonNegative(specified::LengthPercentage::Length(
specified::NoCalcLength::from_px(cellpadding as f32),
));
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::PaddingTop(cellpadding.clone()),
));
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::PaddingLeft(cellpadding.clone()),
));
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::PaddingBottom(cellpadding.clone()),
));
hints.push(from_declaration(
shared_lock,
PropertyDeclaration::PaddingRight(cellpadding),
));
}
}
fn get_colspan(self) -> u32 {

View file

@ -17,8 +17,10 @@ use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::{Element, LayoutElementHelpers};
use crate::dom::htmlelement::HTMLElement;
use crate::dom::htmltableelement::HTMLTableElement;
use crate::dom::htmltablerowelement::HTMLTableRowElement;
use crate::dom::node::Node;
use crate::dom::htmltablesectionelement::HTMLTableSectionElement;
use crate::dom::node::{LayoutNodeHelpers, Node};
use crate::dom::virtualmethods::VirtualMethods;
const DEFAULT_COLSPAN: u32 = 1;
@ -103,14 +105,15 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
}
}
pub trait HTMLTableCellElementLayoutHelpers {
pub trait HTMLTableCellElementLayoutHelpers<'dom> {
fn get_background_color(self) -> Option<RGBA>;
fn get_colspan(self) -> Option<u32>;
fn get_rowspan(self) -> Option<u32>;
fn get_table(self) -> Option<LayoutDom<'dom, HTMLTableElement>>;
fn get_width(self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> {
impl<'dom> HTMLTableCellElementLayoutHelpers<'dom> for LayoutDom<'dom, HTMLTableCellElement> {
fn get_background_color(self) -> Option<RGBA> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
@ -130,6 +133,17 @@ impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> {
.map(AttrValue::as_uint)
}
fn get_table(self) -> Option<LayoutDom<'dom, HTMLTableElement>> {
let row = self.upcast::<Node>().composed_parent_node_ref()?;
row.downcast::<HTMLTableRowElement>()?;
let section = row.composed_parent_node_ref()?;
section.downcast::<HTMLTableElement>().or_else(|| {
section.downcast::<HTMLTableSectionElement>()?;
let table = section.composed_parent_node_ref()?;
table.downcast::<HTMLTableElement>()
})
}
fn get_width(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("width"))

View file

@ -33,6 +33,7 @@ use crate::dom::virtualmethods::VirtualMethods;
pub struct HTMLTableElement {
htmlelement: HTMLElement,
border: Cell<Option<u32>>,
cellpadding: Cell<Option<u32>>,
cellspacing: Cell<Option<u32>>,
tbodies: MutNullableDom<HTMLCollection>,
}
@ -62,6 +63,7 @@ impl HTMLTableElement {
HTMLTableElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
border: Cell::new(None),
cellpadding: Cell::new(None),
cellspacing: Cell::new(None),
tbodies: Default::default(),
}
@ -425,6 +427,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
pub trait HTMLTableElementLayoutHelpers {
fn get_background_color(self) -> Option<RGBA>;
fn get_border(self) -> Option<u32>;
fn get_cellpadding(self) -> Option<u32>;
fn get_cellspacing(self) -> Option<u32>;
fn get_width(self) -> LengthOrPercentageOrAuto;
}
@ -442,6 +445,11 @@ impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
unsafe { (*self.unsafe_get()).border.get() }
}
#[allow(unsafe_code)]
fn get_cellpadding(self) -> Option<u32> {
unsafe { (*self.unsafe_get()).cellpadding.get() }
}
#[allow(unsafe_code)]
fn get_cellspacing(self) -> Option<u32> {
unsafe { (*self.unsafe_get()).cellspacing.get() }
@ -472,6 +480,13 @@ impl VirtualMethods for HTMLTableElement {
.map(|value| parse_unsigned_integer(value.chars()).unwrap_or(1)),
);
},
local_name!("cellpadding") => {
self.cellpadding.set(
mutation
.new_value(attr)
.and_then(|value| parse_unsigned_integer(value.chars()).ok()),
);
},
local_name!("cellspacing") => {
self.cellspacing.set(
mutation

View file

@ -4,12 +4,3 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -4,12 +4,3 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -4,12 +4,3 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -1,9 +1,3 @@
[computing-column-measure-0.html]
[Checking intermediate min-content width for span 1 (2)]
expected: FAIL
[Checking intermediate min-content width for span 1 (3)]
expected: FAIL
[Checking intermediate min-content width for span 1 (4)]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-overflow-024.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-overflow-025.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[item-with-table-with-infinite-max-intrinsic-width.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table-with-infinite-max-intrinsic-width.html]
expected: FAIL

View file

@ -5,11 +5,5 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -5,11 +5,5 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -5,11 +5,5 @@
[td 2]
expected: FAIL
[td 3]
expected: FAIL
[td 4]
expected: FAIL
[td 5]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-overflow-024.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table_colspan_fixed_a.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[table_colspan_simple_a.html]
expected: FAIL