script: Remove layout helper traits (#44092)

Servo has lots of `LayoutXYZHelper` traits that are used to define
additional methods on `LayoutDom<XYZ>`. We can replace them with `impl
LayoutDom<XYZ>` blocks, reducing the number of LoC and making it easier
to add or modify methods.

Testing: These should be covered by existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
Simon Wülker
2026-04-10 20:31:10 +02:00
committed by GitHub
parent a670c7a52b
commit 0fef52f10c
26 changed files with 229 additions and 460 deletions

View File

@@ -17,9 +17,7 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{DomRoot, LayoutDom};
use crate::dom::bindings::str::DOMString;
use crate::dom::document::Document;
use crate::dom::element::{
CustomElementCreationMode, Element, ElementCreator, LayoutElementHelpers,
};
use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
use crate::dom::html::htmlcollection::HTMLCollection;
use crate::dom::html::htmlelement::HTMLElement;
use crate::dom::html::htmltablerowelement::HTMLTableRowElement;
@@ -107,20 +105,15 @@ impl HTMLTableSectionElementMethods<crate::DomTypeHolder> for HTMLTableSectionEl
}
}
pub(crate) trait HTMLTableSectionElementLayoutHelpers {
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_height(self) -> LengthOrPercentageOrAuto;
}
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
fn get_background_color(self) -> Option<AbsoluteColor> {
impl LayoutDom<'_, HTMLTableSectionElement> {
pub(crate) fn get_background_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
.and_then(AttrValue::as_color)
.cloned()
}
fn get_height(self) -> LengthOrPercentageOrAuto {
pub(crate) fn get_height(self) -> LengthOrPercentageOrAuto {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("height"))
.map(AttrValue::as_dimension)