From 5f5f2abc0f72717e8c3a33032d913cb3c4f9da89 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Sat, 27 Sep 2025 15:04:46 +0200 Subject: [PATCH] script: Rename `StylesheetLoader` to `ElementStylesheetLoader` (#39537) `StylesheetLoader` implements the `StylesheetLoader` trait from Stylo. This is pretty confusing as the names are the same. This change renames the Servo version to `ElementStyleSheet` loader so that it's clearer from reading the code what each of these things are. Testing: This change just makes a few renames so shouldn't change test results. Signed-off-by: Martin Robinson --- components/script/dom/cssrulelist.rs | 4 +- components/script/dom/html/htmllinkelement.rs | 4 +- .../script/dom/html/htmlstyleelement.rs | 4 +- components/script/stylesheet_loader.rs | 41 ++++++++++--------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/components/script/dom/cssrulelist.rs b/components/script/dom/cssrulelist.rs index 09976f32a98..460ed1ba940 100644 --- a/components/script/dom/cssrulelist.rs +++ b/components/script/dom/cssrulelist.rs @@ -29,7 +29,7 @@ use crate::dom::cssstylesheet::CSSStyleSheet; use crate::dom::html::htmlelement::HTMLElement; use crate::dom::window::Window; use crate::script_runtime::CanGc; -use crate::stylesheet_loader::StylesheetLoader; +use crate::stylesheet_loader::ElementStylesheetLoader; unsafe_no_jsmanaged_fields!(RulesSource); @@ -130,7 +130,7 @@ impl CSSRuleList { .and_then(DomRoot::downcast::); let loader = owner .as_ref() - .map(|element| StylesheetLoader::for_element(element)); + .map(|element| ElementStylesheetLoader::new(element)); let allow_import_rules = if self.parent_stylesheet.is_constructed() { AllowImportRules::No } else { diff --git a/components/script/dom/html/htmllinkelement.rs b/components/script/dom/html/htmllinkelement.rs index 18bfb43dbc6..b023442c876 100644 --- a/components/script/dom/html/htmllinkelement.rs +++ b/components/script/dom/html/htmllinkelement.rs @@ -60,7 +60,7 @@ use crate::dom::virtualmethods::VirtualMethods; use crate::links::LinkRelations; use crate::network_listener::{PreInvoke, ResourceTimingListener, submit_timing}; use crate::script_runtime::CanGc; -use crate::stylesheet_loader::{StylesheetContextSource, StylesheetLoader, StylesheetOwner}; +use crate::stylesheet_loader::{ElementStylesheetLoader, StylesheetContextSource, StylesheetOwner}; #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] pub(crate) struct RequestGenerationId(u32); @@ -589,7 +589,7 @@ impl HTMLLinkElement { self.request_generation_id .set(self.request_generation_id.get().increment()); - let loader = StylesheetLoader::for_element(self.upcast()); + let loader = ElementStylesheetLoader::new(self.upcast()); loader.load( StylesheetContextSource::LinkElement { media: Some(media) }, link_url, diff --git a/components/script/dom/html/htmlstyleelement.rs b/components/script/dom/html/htmlstyleelement.rs index 6420396cdff..d2e8db54445 100644 --- a/components/script/dom/html/htmlstyleelement.rs +++ b/components/script/dom/html/htmlstyleelement.rs @@ -34,7 +34,7 @@ use crate::dom::stylesheet::StyleSheet as DOMStyleSheet; use crate::dom::stylesheetcontentscache::{StylesheetContentsCache, StylesheetContentsCacheKey}; use crate::dom::virtualmethods::VirtualMethods; use crate::script_runtime::CanGc; -use crate::stylesheet_loader::{StylesheetLoader, StylesheetOwner}; +use crate::stylesheet_loader::{ElementStylesheetLoader, StylesheetOwner}; #[dom_struct] pub(crate) struct HTMLStyleElement { @@ -133,7 +133,7 @@ impl HTMLStyleElement { .expect("Element.textContent must be a string"); let shared_lock = node.owner_doc().style_shared_lock().clone(); let mq = Arc::new(shared_lock.wrap(self.create_media_list(self.Media().str()))); - let loader = StylesheetLoader::for_element(self.upcast()); + let loader = ElementStylesheetLoader::new(self.upcast()); let stylesheetcontents_create_callback = || { #[cfg(feature = "tracing")] diff --git a/components/script/stylesheet_loader.rs b/components/script/stylesheet_loader.rs index 68f8a2810a2..7744d0790f3 100644 --- a/components/script/stylesheet_loader.rs +++ b/components/script/stylesheet_loader.rs @@ -154,7 +154,7 @@ impl FetchResponseListener for StylesheetContext { _: RequestId, status: Result, ) { - let elem = self.elem.root(); + let element = self.elem.root(); let document = self.document.root(); let mut successful = false; @@ -201,12 +201,12 @@ impl FetchResponseListener for StylesheetContext { let protocol_encoding_label = metadata.charset.as_deref(); let final_url = metadata.final_url; - let win = elem.owner_window(); + let win = element.owner_window(); - let loader = StylesheetLoader::for_element(&elem); + let loader = ElementStylesheetLoader::new(&element); match self.source { StylesheetContextSource::LinkElement { ref mut media } => { - let link = elem.downcast::().unwrap(); + let link = element.downcast::().unwrap(); // We must first check whether the generations of the context and the element match up, // else we risk applying the wrong stylesheet when responses come out-of-order. let is_stylesheet_load_applicable = self @@ -268,7 +268,7 @@ impl FetchResponseListener for StylesheetContext { successful = metadata.status == http::StatusCode::OK; } - let owner = elem + let owner = element .upcast::() .as_stylesheet_owner() .expect("Stylesheet not loaded by