From e9f0e76d3c53888683fca4c9330f4b5884238f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 11 Feb 2019 10:20:42 +0100 Subject: [PATCH] Implement TShadowRoot::style_data --- components/layout_thread/dom_wrapper.rs | 7 ++++++- components/script/dom/documentorshadowroot.rs | 7 +++++++ components/script/dom/shadowroot.rs | 21 +++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 580965b91d0..8dc06aad9cb 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -200,7 +200,12 @@ impl<'sr> TShadowRoot for ServoShadowRoot<'sr> { where Self: 'a, { - None + Some(unsafe { + &self + .shadow_root + .get_style_data_for_layout::() + .data + }) } } diff --git a/components/script/dom/documentorshadowroot.rs b/components/script/dom/documentorshadowroot.rs index 577df4bfd51..80b0e0022ba 100644 --- a/components/script/dom/documentorshadowroot.rs +++ b/components/script/dom/documentorshadowroot.rs @@ -18,6 +18,7 @@ use script_traits::UntrustedNodeAddress; use servo_arc::Arc; 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::stylesheet_set::StylesheetSet; @@ -43,6 +44,12 @@ impl PartialEq for StyleSheetInDocument { } } +impl ToMediaListKey for StyleSheetInDocument { + fn to_media_list_key(&self) -> MediaListKey { + self.sheet.to_media_list_key() + } +} + impl ::style::stylesheets::StylesheetInDocument for StyleSheetInDocument { fn origin(&self, guard: &SharedRwLockReadGuard) -> Origin { self.sheet.origin(guard) diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index 7790423fb0a..d99f0c86493 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -20,6 +20,7 @@ use crate::dom::window::Window; use dom_struct::dom_struct; use servo_arc::Arc; use style::author_styles::AuthorStyles; +use style::dom::TElement; use style::stylesheets::Stylesheet; // https://dom.spec.whatwg.org/#interface-shadowroot @@ -29,8 +30,7 @@ pub struct ShadowRoot { document_or_shadow_root: DocumentOrShadowRoot, document: Dom, host: Dom, - /// List of stylesheets associated with nodes in this shadow tree. - /// |None| if the list needs to be refreshed. + /// List of author styles associated with nodes in this shadow tree. author_styles: DomRefCell>, stylesheet_list: MutNullableDom, window: Dom, @@ -119,6 +119,9 @@ impl ShadowRootMethods for ShadowRoot { #[allow(unsafe_code)] pub trait LayoutShadowRootHelpers { unsafe fn get_host_for_layout(&self) -> LayoutDom; + unsafe fn get_style_data_for_layout<'a, E: TElement>( + &self, + ) -> &'a AuthorStyles; } impl LayoutShadowRootHelpers for LayoutDom { @@ -127,6 +130,20 @@ impl LayoutShadowRootHelpers for LayoutDom { unsafe fn get_host_for_layout(&self) -> LayoutDom { (*self.unsafe_get()).host.to_layout() } + + #[inline] + #[allow(unsafe_code)] + unsafe fn get_style_data_for_layout<'a, E: TElement>( + &self, + ) -> &'a AuthorStyles { + { + let mut author_styles = (*self.unsafe_get()).author_styles.borrow_mut_for_layout(); + // let document = &(*self.unsafe_get()).document; + // let guard = document.style_shared_lock().read(); + // author_styles.flush::(&document.device(), document.quirks_mode(), &guard); + } + (*self.unsafe_get()).author_styles.borrow_for_layout() + } } impl StyleSheetListOwner for Dom {