css: Refactor StyleSheetInDocument owner (#38136)

Refactor `documentotshadowroot::StyleSheetInDocument`, renaming it into
`ServoStylesheetInDocument` to avoid confusion with Stylo's
`StylesheetInDocument` trait.

To support constructed stylesheet. The `ServoStylesheetInDocument.owner`
would contains enum of:
- `Dom<Element>` - for stylesheet parsed from an element.
- `Dom<CSSStylesheet>` - for constructed stylesheet.

Testing: No WPT regression.
Fixes: #38133

---------

Signed-off-by: Jo Steven Novaryo <jo.steven.novaryo@huawei.com>
This commit is contained in:
Jo Steven Novaryo 2025-07-18 13:39:09 +08:00 committed by GitHub
parent d671f58078
commit bbed6cddcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 112 additions and 57 deletions

View file

@ -11,7 +11,7 @@ use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::cssstylesheet::CSSStyleSheet;
use crate::dom::document::Document;
use crate::dom::element::Element;
use crate::dom::documentorshadowroot::StylesheetSource;
use crate::dom::shadowroot::ShadowRoot;
use crate::dom::stylesheet::StyleSheet;
use crate::dom::window::Window;
@ -39,7 +39,8 @@ impl StyleSheetListOwner {
}
}
pub(crate) fn add_stylesheet(&self, owner: &Element, sheet: Arc<Stylesheet>) {
#[cfg_attr(crown, allow(crown::unrooted_must_root))] // Owner needs to be rooted already necessarily.
pub(crate) fn add_stylesheet(&self, owner: StylesheetSource, sheet: Arc<Stylesheet>) {
match *self {
StyleSheetListOwner::Document(ref doc) => doc.add_stylesheet(owner, sheet),
StyleSheetListOwner::ShadowRoot(ref shadow_root) => {
@ -48,7 +49,8 @@ impl StyleSheetListOwner {
}
}
pub(crate) fn remove_stylesheet(&self, owner: &Element, s: &Arc<Stylesheet>) {
#[cfg_attr(crown, allow(crown::unrooted_must_root))] // Owner needs to be rooted already necessarily.
pub(crate) fn remove_stylesheet(&self, owner: StylesheetSource, s: &Arc<Stylesheet>) {
match *self {
StyleSheetListOwner::Document(ref doc) => doc.remove_stylesheet(owner, s),
StyleSheetListOwner::ShadowRoot(ref shadow_root) => {