mirror of
https://github.com/servo/servo.git
synced 2025-07-19 05:13:55 +01:00
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:
parent
d671f58078
commit
bbed6cddcd
6 changed files with 112 additions and 57 deletions
|
@ -8,6 +8,7 @@ use dom_struct::dom_struct;
|
|||
use html5ever::{LocalName, Prefix};
|
||||
use js::rust::HandleObject;
|
||||
use net_traits::ReferrerPolicy;
|
||||
use script_bindings::root::Dom;
|
||||
use servo_arc::Arc;
|
||||
use style::media_queries::MediaList as StyleMediaList;
|
||||
use style::stylesheets::{AllowImportRules, Origin, Stylesheet, UrlExtraData};
|
||||
|
@ -22,6 +23,7 @@ use crate::dom::bindings::str::DOMString;
|
|||
use crate::dom::csp::{CspReporting, InlineCheckType};
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::documentorshadowroot::StylesheetSource;
|
||||
use crate::dom::element::{AttributeMutation, Element, ElementCreator};
|
||||
use crate::dom::htmlelement::HTMLElement;
|
||||
use crate::dom::medialist::MediaList;
|
||||
|
@ -153,11 +155,13 @@ impl HTMLStyleElement {
|
|||
pub(crate) fn set_stylesheet(&self, s: Arc<Stylesheet>) {
|
||||
let stylesheets_owner = self.stylesheet_list_owner();
|
||||
if let Some(ref s) = *self.stylesheet.borrow() {
|
||||
stylesheets_owner.remove_stylesheet(self.upcast(), s)
|
||||
stylesheets_owner
|
||||
.remove_stylesheet(StylesheetSource::Element(Dom::from_ref(self.upcast())), s)
|
||||
}
|
||||
*self.stylesheet.borrow_mut() = Some(s.clone());
|
||||
self.clean_stylesheet_ownership();
|
||||
stylesheets_owner.add_stylesheet(self.upcast(), s);
|
||||
stylesheets_owner
|
||||
.add_stylesheet(StylesheetSource::Element(Dom::from_ref(self.upcast())), s);
|
||||
}
|
||||
|
||||
pub(crate) fn get_stylesheet(&self) -> Option<Arc<Stylesheet>> {
|
||||
|
@ -192,7 +196,7 @@ impl HTMLStyleElement {
|
|||
if let Some(s) = self.stylesheet.borrow_mut().take() {
|
||||
self.clean_stylesheet_ownership();
|
||||
self.stylesheet_list_owner()
|
||||
.remove_stylesheet(self.upcast(), &s)
|
||||
.remove_stylesheet(StylesheetSource::Element(Dom::from_ref(self.upcast())), &s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue