diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-29 14:19:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 14:19:16 -0500 |
commit | 939716a7bc2ba2fbd8dcfe8b64d2f61edfa99c95 (patch) | |
tree | 841ba5c30c253ea1209020a7bc9072dc57c1669b /components/style/stylesheet_set.rs | |
parent | 63533ce72ae13631b872d4abc89a8b8a3fd211f6 (diff) | |
parent | 9c77dd8de6844625f7b150c1518077ee0804a8d2 (diff) | |
download | servo-939716a7bc2ba2fbd8dcfe8b64d2f61edfa99c95.tar.gz servo-939716a7bc2ba2fbd8dcfe8b64d2f61edfa99c95.zip |
Auto merge of #17078 - emilio:stylesheet-invalidation-scopes, r=heycam
stylo: Avoid restyling the whole document when adding stylesheets.
This is for bug 1357583.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17078)
<!-- Reviewable:end -->
Diffstat (limited to 'components/style/stylesheet_set.rs')
-rw-r--r-- | components/style/stylesheet_set.rs | 70 |
1 files changed, 61 insertions, 9 deletions
diff --git a/components/style/stylesheet_set.rs b/components/style/stylesheet_set.rs index c21084892a7..2908d81bef4 100644 --- a/components/style/stylesheet_set.rs +++ b/components/style/stylesheet_set.rs @@ -4,9 +4,13 @@ //! A centralized set of stylesheets for a document. +use dom::TElement; +use invalidation::StylesheetInvalidationSet; +use shared_lock::SharedRwLockReadGuard; use std::slice; use stylearc::Arc; use stylesheets::Stylesheet; +use stylist::Stylist; /// Entry for a StylesheetSet. We don't bother creating a constructor, because /// there's no sensible defaults for the member variables. @@ -40,6 +44,9 @@ pub struct StylesheetSet { /// Has author style been disabled? author_style_disabled: bool, + + /// The style invalidations that we still haven't processed. + invalidations: StylesheetInvalidationSet, } impl StylesheetSet { @@ -49,6 +56,7 @@ impl StylesheetSet { entries: vec![], dirty: false, author_style_disabled: false, + invalidations: StylesheetInvalidationSet::new(), } } @@ -63,32 +71,57 @@ impl StylesheetSet { } /// Appends a new stylesheet to the current set. - pub fn append_stylesheet(&mut self, sheet: &Arc<Stylesheet>, - unique_id: u64) { + pub fn append_stylesheet( + &mut self, + stylist: &Stylist, + sheet: &Arc<Stylesheet>, + unique_id: u64, + guard: &SharedRwLockReadGuard) + { + debug!("StylesheetSet::append_stylesheet"); self.remove_stylesheet_if_present(unique_id); self.entries.push(StylesheetSetEntry { unique_id: unique_id, sheet: sheet.clone(), }); self.dirty = true; + self.invalidations.collect_invalidations_for( + stylist, + sheet, + guard) } /// Prepend a new stylesheet to the current set. - pub fn prepend_stylesheet(&mut self, sheet: &Arc<Stylesheet>, - unique_id: u64) { + pub fn prepend_stylesheet( + &mut self, + stylist: &Stylist, + sheet: &Arc<Stylesheet>, + unique_id: u64, + guard: &SharedRwLockReadGuard) + { + debug!("StylesheetSet::prepend_stylesheet"); self.remove_stylesheet_if_present(unique_id); self.entries.insert(0, StylesheetSetEntry { unique_id: unique_id, sheet: sheet.clone(), }); self.dirty = true; + self.invalidations.collect_invalidations_for( + stylist, + sheet, + guard) } /// Insert a given stylesheet before another stylesheet in the document. - pub fn insert_stylesheet_before(&mut self, - sheet: &Arc<Stylesheet>, - unique_id: u64, - before_unique_id: u64) { + pub fn insert_stylesheet_before( + &mut self, + stylist: &Stylist, + sheet: &Arc<Stylesheet>, + unique_id: u64, + before_unique_id: u64, + guard: &SharedRwLockReadGuard) + { + debug!("StylesheetSet::insert_stylesheet_before"); self.remove_stylesheet_if_present(unique_id); let index = self.entries.iter().position(|x| { x.unique_id == before_unique_id @@ -98,21 +131,30 @@ impl StylesheetSet { sheet: sheet.clone(), }); self.dirty = true; + self.invalidations.collect_invalidations_for( + stylist, + sheet, + guard) } /// Remove a given stylesheet from the set. pub fn remove_stylesheet(&mut self, unique_id: u64) { + debug!("StylesheetSet::remove_stylesheet"); self.remove_stylesheet_if_present(unique_id); self.dirty = true; + // FIXME(emilio): We can do better! + self.invalidations.invalidate_fully(); } /// Notes that the author style has been disabled for this document. pub fn set_author_style_disabled(&mut self, disabled: bool) { + debug!("StylesheetSet::set_author_style_disabled"); if self.author_style_disabled == disabled { return; } self.author_style_disabled = disabled; self.dirty = true; + self.invalidations.invalidate_fully(); } /// Returns whether the given set has changed from the last flush. @@ -122,8 +164,17 @@ impl StylesheetSet { /// Flush the current set, unmarking it as dirty, and returns an iterator /// over the new stylesheet list. - pub fn flush(&mut self) -> StylesheetIterator { + pub fn flush<E>(&mut self, + document_element: Option<E>) + -> StylesheetIterator + where E: TElement, + { + debug!("StylesheetSet::flush"); + debug_assert!(self.dirty); + self.dirty = false; + self.invalidations.flush(document_element); + StylesheetIterator(self.entries.iter()) } @@ -133,5 +184,6 @@ impl StylesheetSet { /// FIXME(emilio): Make this more granular. pub fn force_dirty(&mut self) { self.dirty = true; + self.invalidations.invalidate_fully(); } } |