From 60e206143c7346b2255c9c1a6af745d4b0c77985 Mon Sep 17 00:00:00 2001 From: Oriol Brufau Date: Fri, 12 May 2023 19:35:00 +0200 Subject: [PATCH] Further changes required by Servo --- components/layout_thread/lib.rs | 8 ++------ components/layout_thread_2020/lib.rs | 8 ++------ components/script/dom/documentorshadowroot.rs | 17 ++++------------- components/script/dom/shadowroot.rs | 12 ++++-------- components/script/layout_dom/document.rs | 7 +++---- components/script/layout_dom/shadow_root.rs | 9 +++------ components/style/stylesheets/import_rule.rs | 5 ++--- components/style/stylist.rs | 1 + 8 files changed, 21 insertions(+), 46 deletions(-) diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index bf4ff1b85bc..1e8bd2848be 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -96,7 +96,7 @@ use std::time::Duration; use style::animation::{AnimationSetKey, DocumentAnimationSet, ElementAnimationSet}; use style::context::SharedStyleContext; use style::context::{QuirksMode, RegisteredSpeculativePainter, RegisteredSpeculativePainters}; -use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TDocument, TElement, TNode}; +use style::dom::{ShowSubtree, ShowSubtreeDataAndPrimaryValues, TElement, TNode}; use style::driver; use style::error_reporting::RustLogReporter; use style::global_style_data::{GLOBAL_STYLE_DATA, STYLE_THREAD_POOL}; @@ -1285,11 +1285,7 @@ impl LayoutThread { ); // Flush shadow roots stylesheets if dirty. - document.flush_shadow_roots_stylesheets( - &self.stylist.device(), - document.quirks_mode(), - guards.author.clone(), - ); + document.flush_shadow_roots_stylesheets(&mut self.stylist, guards.author.clone()); let restyles = std::mem::take(&mut data.pending_restyles); debug!("Draining restyles: {}", restyles.len()); diff --git a/components/layout_thread_2020/lib.rs b/components/layout_thread_2020/lib.rs index 90c6f4da952..13bef27f3be 100644 --- a/components/layout_thread_2020/lib.rs +++ b/components/layout_thread_2020/lib.rs @@ -82,7 +82,7 @@ use style::animation::DocumentAnimationSet; use style::context::{ QuirksMode, RegisteredSpeculativePainter, RegisteredSpeculativePainters, SharedStyleContext, }; -use style::dom::{TDocument, TElement, TNode}; +use style::dom::{TElement, TNode}; use style::driver; use style::error_reporting::RustLogReporter; use style::global_style_data::{GLOBAL_STYLE_DATA, STYLE_THREAD_POOL}; @@ -943,11 +943,7 @@ impl LayoutThread { } // Flush shadow roots stylesheets if dirty. - document.flush_shadow_roots_stylesheets( - &self.stylist.device(), - document.quirks_mode(), - guards.author.clone(), - ); + document.flush_shadow_roots_stylesheets(&mut self.stylist, guards.author.clone()); let restyles = std::mem::take(&mut data.pending_restyles); debug!("Draining restyles: {}", restyles.len()); diff --git a/components/script/dom/documentorshadowroot.rs b/components/script/dom/documentorshadowroot.rs index 43d345e5e01..51bce1c7b2d 100644 --- a/components/script/dom/documentorshadowroot.rs +++ b/components/script/dom/documentorshadowroot.rs @@ -20,11 +20,10 @@ use servo_arc::Arc; use servo_atoms::Atom; use std::collections::HashMap; use std::fmt; -use style::context::QuirksMode; use style::invalidation::media_queries::{MediaListKey, ToMediaListKey}; use style::media_queries::MediaList; use style::shared_lock::{SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard}; -use style::stylesheets::{CssRule, Origin, Stylesheet}; +use style::stylesheets::{Stylesheet, StylesheetContents}; #[derive(Clone, JSTraceable, MallocSizeOf)] #[unrooted_must_root_lint::must_root] @@ -48,19 +47,11 @@ impl PartialEq for StyleSheetInDocument { impl ToMediaListKey for StyleSheetInDocument { fn to_media_list_key(&self) -> MediaListKey { - self.sheet.to_media_list_key() + self.sheet.contents.to_media_list_key() } } impl ::style::stylesheets::StylesheetInDocument for StyleSheetInDocument { - fn origin(&self, guard: &SharedRwLockReadGuard) -> Origin { - self.sheet.origin(guard) - } - - fn quirks_mode(&self, guard: &SharedRwLockReadGuard) -> QuirksMode { - self.sheet.quirks_mode(guard) - } - fn enabled(&self) -> bool { self.sheet.enabled() } @@ -69,8 +60,8 @@ impl ::style::stylesheets::StylesheetInDocument for StyleSheetInDocument { self.sheet.media(guard) } - fn rules<'a, 'b: 'a>(&'a self, guard: &'b SharedRwLockReadGuard) -> &'a [CssRule] { - self.sheet.rules(guard) + fn contents(&self) -> &StylesheetContents { + self.sheet.contents() } } diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index c70c13d8cef..1fa9faae287 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -19,15 +19,13 @@ use crate::dom::stylesheetlist::{StyleSheetList, StyleSheetListOwner}; use crate::dom::window::Window; use crate::stylesheet_set::StylesheetSetRef; use dom_struct::dom_struct; -use selectors::context::QuirksMode; use servo_arc::Arc; use servo_atoms::Atom; use style::author_styles::AuthorStyles; use style::dom::TElement; -use style::media_queries::Device; use style::shared_lock::SharedRwLockReadGuard; use style::stylesheets::Stylesheet; -use style::stylist::CascadeData; +use style::stylist::{CascadeData, Stylist}; /// Whether a shadow root hosts an User Agent widget. #[derive(JSTraceable, MallocSizeOf, PartialEq)] @@ -245,8 +243,7 @@ pub trait LayoutShadowRootHelpers<'dom> { fn get_style_data_for_layout(self) -> &'dom CascadeData; unsafe fn flush_stylesheets( self, - device: &Device, - quirks_mode: QuirksMode, + stylist: &mut Stylist, guard: &SharedRwLockReadGuard, ); } @@ -277,13 +274,12 @@ impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> { #[allow(unsafe_code)] unsafe fn flush_stylesheets( self, - device: &Device, - quirks_mode: QuirksMode, + stylist: &mut Stylist, guard: &SharedRwLockReadGuard, ) { let author_styles = self.unsafe_get().author_styles.borrow_mut_for_layout(); if author_styles.stylesheets.dirty() { - author_styles.flush::(device, quirks_mode, guard); + author_styles.flush::(stylist, guard); } } } diff --git a/components/script/layout_dom/document.rs b/components/script/layout_dom/document.rs index e723f731cab..392c1686f97 100644 --- a/components/script/layout_dom/document.rs +++ b/components/script/layout_dom/document.rs @@ -12,10 +12,10 @@ use script_layout_interface::wrapper_traits::LayoutDataTrait; use selectors::matching::QuirksMode; use std::marker::PhantomData; use style::dom::{TDocument, TNode}; -use style::media_queries::Device; use style::shared_lock::{ SharedRwLock as StyleSharedRwLock, SharedRwLockReadGuard as StyleSharedRwLockReadGuard, }; +use style::stylist::Stylist; // A wrapper around documents that ensures ayout can only ever access safe properties. pub struct ServoLayoutDocument<'dom, LayoutDataType: LayoutDataTrait> { @@ -90,8 +90,7 @@ impl<'ld, LayoutDataType: LayoutDataTrait> ServoLayoutDocument<'ld, LayoutDataTy pub fn flush_shadow_roots_stylesheets( &self, - device: &Device, - quirks_mode: QuirksMode, + stylist: &mut Stylist, guard: &StyleSharedRwLockReadGuard, ) { unsafe { @@ -100,7 +99,7 @@ impl<'ld, LayoutDataType: LayoutDataTrait> ServoLayoutDocument<'ld, LayoutDataTy } self.document.flush_shadow_roots_stylesheets(); for shadow_root in self.shadow_roots() { - shadow_root.flush_stylesheets(device, quirks_mode, guard); + shadow_root.flush_stylesheets(stylist, guard); } } } diff --git a/components/script/layout_dom/shadow_root.rs b/components/script/layout_dom/shadow_root.rs index 2fd1511ccfa..19336befe74 100644 --- a/components/script/layout_dom/shadow_root.rs +++ b/components/script/layout_dom/shadow_root.rs @@ -7,13 +7,11 @@ use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot}; use crate::layout_dom::ServoLayoutElement; use crate::layout_dom::ServoLayoutNode; use script_layout_interface::wrapper_traits::LayoutDataTrait; -use selectors::matching::QuirksMode; use std::fmt; use std::marker::PhantomData; use style::dom::TShadowRoot; -use style::media_queries::Device; use style::shared_lock::SharedRwLockReadGuard as StyleSharedRwLockReadGuard; -use style::stylist::CascadeData; +use style::stylist::{CascadeData, Stylist}; pub struct ServoShadowRoot<'dom, LayoutDataType: LayoutDataTrait> { /// The wrapped private DOM ShadowRoot. @@ -74,11 +72,10 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ServoShadowRoot<'dom, LayoutDataType pub unsafe fn flush_stylesheets( &self, - device: &Device, - quirks_mode: QuirksMode, + stylist: &mut Stylist, guard: &StyleSharedRwLockReadGuard, ) { self.shadow_root - .flush_stylesheets::>(device, quirks_mode, guard) + .flush_stylesheets::>(stylist, guard) } } diff --git a/components/style/stylesheets/import_rule.rs b/components/style/stylesheets/import_rule.rs index 201513760b3..396be242024 100644 --- a/components/style/stylesheets/import_rule.rs +++ b/components/style/stylesheets/import_rule.rs @@ -6,12 +6,11 @@ //! //! [import]: https://drafts.csswg.org/css-cascade-3/#at-import -use crate::context::QuirksMode; use crate::media_queries::MediaList; use crate::shared_lock::{DeepCloneParams, DeepCloneWithLock}; use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard}; use crate::str::CssStringWriter; -use crate::stylesheets::{CssRule, Origin, StylesheetInDocument}; +use crate::stylesheets::{CssRule, StylesheetInDocument}; use crate::values::CssUrl; use cssparser::SourceLocation; use std::fmt::{self, Write}; @@ -112,7 +111,7 @@ impl ImportSheet { /// Returns the rules for this import rule. pub fn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a [CssRule] { - self.0.rules() + self.0.rules(guard) } } diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 15783b54db0..c4eebefeab9 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -453,6 +453,7 @@ pub struct Stylist { stylesheets: StylistStylesheetSet, /// A cache of CascadeDatas for AuthorStylesheetSets (i.e., shadow DOM). + #[cfg_attr(feature = "servo", ignore_malloc_size_of = "XXX: how to handle this?")] author_data_cache: CascadeDataCache, /// If true, the quirks-mode stylesheet is applied.