mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -23,6 +23,7 @@ use net_traits::{
|
|||
FetchMetadata, FetchResponseListener, NetworkError, ReferrerPolicy, ResourceFetchTiming,
|
||||
ResourceTimingType,
|
||||
};
|
||||
use script_bindings::root::Dom;
|
||||
use servo_arc::Arc;
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use style::attr::AttrValue;
|
||||
|
@ -41,6 +42,7 @@ use crate::dom::bindings::str::{DOMString, USVString};
|
|||
use crate::dom::csp::{GlobalCspReporting, Violation};
|
||||
use crate::dom::cssstylesheet::CSSStyleSheet;
|
||||
use crate::dom::document::Document;
|
||||
use crate::dom::documentorshadowroot::StylesheetSource;
|
||||
use crate::dom::domtokenlist::DOMTokenList;
|
||||
use crate::dom::element::{
|
||||
AttributeMutation, Element, ElementCreator, cors_setting_for_element,
|
||||
|
@ -178,11 +180,13 @@ impl HTMLLinkElement {
|
|||
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>> {
|
||||
|
@ -416,7 +420,7 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
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