mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add support for cellpadding attribute (#31201)
This commit is contained in:
parent
091653417a
commit
7d1b19c865
17 changed files with 58 additions and 68 deletions
|
@ -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 {
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue