mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Flush shadow roots stylesheets only if they changed
This commit is contained in:
parent
a841c713d6
commit
2674a3e717
4 changed files with 54 additions and 7 deletions
|
@ -437,6 +437,23 @@ impl<'ld> ServoLayoutDocument<'ld> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn flush_shadow_roots_stylesheets(
|
||||||
|
&self,
|
||||||
|
device: &Device,
|
||||||
|
quirks_mode: QuirksMode,
|
||||||
|
guard: &SharedRwLockReadGuard,
|
||||||
|
) {
|
||||||
|
unsafe {
|
||||||
|
if !self.document.shadow_roots_styles_changed() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.document.flush_shadow_roots_stylesheets();
|
||||||
|
for shadow_root in self.shadow_roots() {
|
||||||
|
shadow_root.flush_stylesheets(device, quirks_mode, guard);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_layout_js(doc: LayoutDom<Document>) -> ServoLayoutDocument<'ld> {
|
pub fn from_layout_js(doc: LayoutDom<Document>) -> ServoLayoutDocument<'ld> {
|
||||||
ServoLayoutDocument {
|
ServoLayoutDocument {
|
||||||
document: doc,
|
document: doc,
|
||||||
|
|
|
@ -1352,13 +1352,11 @@ impl LayoutThread {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Flush shadow roots stylesheets if dirty.
|
// Flush shadow roots stylesheets if dirty.
|
||||||
for shadow_root in document.shadow_roots() {
|
document.flush_shadow_roots_stylesheets(
|
||||||
shadow_root.flush_stylesheets(
|
|
||||||
&self.stylist.device(),
|
&self.stylist.device(),
|
||||||
document.quirks_mode(),
|
document.quirks_mode(),
|
||||||
guards.author.clone(),
|
guards.author.clone(),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
let restyles = document.drain_pending_restyles();
|
let restyles = document.drain_pending_restyles();
|
||||||
debug!("Draining restyles: {}", restyles.len());
|
debug!("Draining restyles: {}", restyles.len());
|
||||||
|
|
|
@ -379,6 +379,8 @@ pub struct Document {
|
||||||
completely_loaded: Cell<bool>,
|
completely_loaded: Cell<bool>,
|
||||||
/// List of shadow roots bound to the document tree.
|
/// List of shadow roots bound to the document tree.
|
||||||
shadow_roots: DomRefCell<Vec<Dom<ShadowRoot>>>,
|
shadow_roots: DomRefCell<Vec<Dom<ShadowRoot>>>,
|
||||||
|
/// Whether any of the shadow roots need the stylesheets flushed.
|
||||||
|
shadow_roots_styles_changed: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
|
@ -2431,6 +2433,8 @@ pub trait LayoutDocumentHelpers {
|
||||||
unsafe fn quirks_mode(&self) -> QuirksMode;
|
unsafe fn quirks_mode(&self) -> QuirksMode;
|
||||||
unsafe fn style_shared_lock(&self) -> &StyleSharedRwLock;
|
unsafe fn style_shared_lock(&self) -> &StyleSharedRwLock;
|
||||||
unsafe fn shadow_roots(&self) -> Vec<LayoutDom<ShadowRoot>>;
|
unsafe fn shadow_roots(&self) -> Vec<LayoutDom<ShadowRoot>>;
|
||||||
|
unsafe fn shadow_roots_styles_changed(&self) -> bool;
|
||||||
|
unsafe fn flush_shadow_roots_stylesheets(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -2485,6 +2489,16 @@ impl LayoutDocumentHelpers for LayoutDom<Document> {
|
||||||
.map(|sr| sr.to_layout())
|
.map(|sr| sr.to_layout())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn shadow_roots_styles_changed(&self) -> bool {
|
||||||
|
(*self.unsafe_get()).shadow_roots_styles_changed()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn flush_shadow_roots_stylesheets(&self) {
|
||||||
|
(*self.unsafe_get()).flush_shadow_roots_stylesheets()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#is-a-registrable-domain-suffix-of-or-is-equal-to
|
// https://html.spec.whatwg.org/multipage/#is-a-registrable-domain-suffix-of-or-is-equal-to
|
||||||
|
@ -2694,6 +2708,7 @@ impl Document {
|
||||||
script_and_layout_blockers: Cell::new(0),
|
script_and_layout_blockers: Cell::new(0),
|
||||||
delayed_tasks: Default::default(),
|
delayed_tasks: Default::default(),
|
||||||
shadow_roots: DomRefCell::new(Vec::new()),
|
shadow_roots: DomRefCell::new(Vec::new()),
|
||||||
|
shadow_roots_styles_changed: Cell::new(false),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3151,6 +3166,7 @@ impl Document {
|
||||||
self.shadow_roots
|
self.shadow_roots
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.push(Dom::from_ref(shadow_root));
|
.push(Dom::from_ref(shadow_root));
|
||||||
|
self.invalidate_shadow_roots_stylesheets();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) {
|
pub fn unregister_shadow_root(&self, shadow_root: &ShadowRoot) {
|
||||||
|
@ -3160,6 +3176,21 @@ impl Document {
|
||||||
shadow_roots.remove(index);
|
shadow_roots.remove(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn invalidate_shadow_roots_stylesheets(&self) {
|
||||||
|
self.shadow_roots_styles_changed.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn shadow_roots_styles_changed(&self) -> bool {
|
||||||
|
self.shadow_roots_styles_changed.get()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn flush_shadow_roots_stylesheets(&self) {
|
||||||
|
if !self.shadow_roots_styles_changed.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.shadow_roots_styles_changed.set(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
|
|
|
@ -75,6 +75,7 @@ impl ShadowRoot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invalidate_stylesheets(&self) {
|
pub fn invalidate_stylesheets(&self) {
|
||||||
|
self.document.invalidate_shadow_roots_stylesheets();
|
||||||
self.author_styles.borrow_mut().stylesheets.force_dirty();
|
self.author_styles.borrow_mut().stylesheets.force_dirty();
|
||||||
// Mark the host element dirty so a reflow will be performed.
|
// Mark the host element dirty so a reflow will be performed.
|
||||||
self.host
|
self.host
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue