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,7 +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::{AttributeMutation, Element, LayoutElementHelpers};
use crate::dom::element::{AttributeMutation, Element};
use crate::dom::eventtarget::EventTarget;
use crate::dom::html::htmlelement::HTMLElement;
use crate::dom::node::{BindContext, Node, NodeTraits};
@@ -84,20 +84,15 @@ impl HTMLBodyElementMethods<crate::DomTypeHolder> for HTMLBodyElement {
window_event_handlers!(ForwardToWindow);
}
pub(crate) trait HTMLBodyElementLayoutHelpers {
fn get_background_color(self) -> Option<AbsoluteColor>;
fn get_color(self) -> Option<AbsoluteColor>;
}
impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> {
fn get_background_color(self) -> Option<AbsoluteColor> {
impl LayoutDom<'_, HTMLBodyElement> {
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_color(self) -> Option<AbsoluteColor> {
pub(crate) fn get_color(self) -> Option<AbsoluteColor> {
self.upcast::<Element>()
.get_attr_for_layout(&ns!(), &local_name!("text"))
.and_then(AttrValue::as_color)