aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlbodyelement.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-01-03 19:55:01 +0100
committerGitHub <noreply@github.com>2025-01-03 18:55:01 +0000
commite8f75c9aea37d49d988f209281169af1fed05d8e (patch)
treefeb84b30238157c296b83c8a04394c853d5052f6 /components/script/dom/htmlbodyelement.rs
parent621ddd749c7655a93547f52a438f2e2941d7df15 (diff)
downloadservo-e8f75c9aea37d49d988f209281169af1fed05d8e.tar.gz
servo-e8f75c9aea37d49d988f209281169af1fed05d8e.zip
script: Expose node helpers as `NodeTraits` and give more descriptive names (#34832)
This puts a few commonly used `Node` helpers into a trait (`NodeTraits`) and gives them more descriptive names and documentation. The renames: - `document_from_node` -> `NodeTraits::owner_document` - `window_from_node` -> `NodeTraits::owner_window` - `stylesheets_owner_from_node<T:` -> `NodeTraits::stylesheet_list_owner` - `containing_shadow_root` -> `NodeTraits::containing_shadow_root` Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/script/dom/htmlbodyelement.rs')
-rw-r--r--components/script/dom/htmlbodyelement.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 0b749b779a5..01ff408ae5e 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -20,7 +20,7 @@ use crate::dom::document::Document;
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
use crate::dom::eventtarget::EventTarget;
use crate::dom::htmlelement::HTMLElement;
-use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
+use crate::dom::node::{BindContext, Node, NodeTraits};
use crate::dom::virtualmethods::VirtualMethods;
use crate::script_runtime::CanGc;
@@ -86,10 +86,8 @@ impl HTMLBodyElementMethods<crate::DomTypeHolder> for HTMLBodyElement {
// https://html.spec.whatwg.org/multipage/#dom-body-background
fn SetBackground(&self, input: DOMString, can_gc: CanGc) {
- let value = AttrValue::from_resolved_url(
- &document_from_node(self).base_url().get_arc(),
- input.into(),
- );
+ let value =
+ AttrValue::from_resolved_url(&self.owner_document().base_url().get_arc(), input.into());
self.upcast::<Element>()
.set_attribute(&local_name!("background"), value, can_gc);
}
@@ -152,7 +150,7 @@ impl VirtualMethods for HTMLBodyElement {
return;
}
- let window = window_from_node(self);
+ let window = self.owner_window();
window.prevent_layout_until_load_event();
if window.is_top_level() {
window.send_to_embedder(EmbedderMsg::HeadParsed);
@@ -165,7 +163,7 @@ impl VirtualMethods for HTMLBodyElement {
AttrValue::from_legacy_color(value.into())
},
local_name!("background") => AttrValue::from_resolved_url(
- &document_from_node(self).base_url().get_arc(),
+ &self.owner_document().base_url().get_arc(),
value.into(),
),
_ => self
@@ -178,7 +176,7 @@ impl VirtualMethods for HTMLBodyElement {
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
let do_super_mutate = match (attr.local_name(), mutation) {
(name, AttributeMutation::Set(_)) if name.starts_with("on") => {
- let window = window_from_node(self);
+ let window = self.owner_window();
// https://html.spec.whatwg.org/multipage/
// #event-handlers-on-elements,-document-objects,-and-window-objects:event-handlers-3
match name {