aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/stylesheet_set.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-05-02 18:15:05 -0500
committerGitHub <noreply@github.com>2017-05-02 18:15:05 -0500
commit536d63c67028c7368dff780945626283d2c48f1c (patch)
treec4064581f70b3cbc1871a4039c9a8e50dee03efb /components/style/stylesheet_set.rs
parent32f4273e38f362787bcc348577a3fce074447035 (diff)
parent2b6c494f858772dd539e4a06c18572cbd87189f5 (diff)
downloadservo-536d63c67028c7368dff780945626283d2c48f1c.tar.gz
servo-536d63c67028c7368dff780945626283d2c48f1c.zip
Auto merge of #16698 - bradwerth:cloneRight, r=heycam
Change StyleSet to track stylesheets by unique ID. MozReview-Commit-ID: Ky3P53o4Euw https://bugzilla.mozilla.org/show_bug.cgi?id=1348481 https://reviewboard.mozilla.org/r/128850/ --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [X] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/16698) <!-- Reviewable:end -->
Diffstat (limited to 'components/style/stylesheet_set.rs')
-rw-r--r--components/style/stylesheet_set.rs67
1 files changed, 44 insertions, 23 deletions
diff --git a/components/style/stylesheet_set.rs b/components/style/stylesheet_set.rs
index e1f782bbbbf..78e0c9cd558 100644
--- a/components/style/stylesheet_set.rs
+++ b/components/style/stylesheet_set.rs
@@ -4,19 +4,26 @@
//! A centralized set of stylesheets for a document.
-use arc_ptr_eq;
use std::sync::Arc;
use stylesheets::Stylesheet;
+/// Entry for a StylesheetSet. We don't bother creating a constructor, because
+/// there's no sensible defaults for the member variables.
+pub struct StylesheetSetEntry {
+ unique_id: u32,
+ sheet: Arc<Stylesheet>,
+}
+
/// The set of stylesheets effective for a given document.
pub struct StylesheetSet {
- /// The actual list of all the stylesheets that apply to the given document.
+ /// The actual list of all the stylesheets that apply to the given document,
+ /// each stylesheet associated with a unique ID.
///
/// This is only a list of top-level stylesheets, and as such it doesn't
/// include recursive `@import` rules.
- stylesheets: Vec<Arc<Stylesheet>>,
+ entries: Vec<StylesheetSetEntry>,
- /// Whether the stylesheets list above has changed since the last restyle.
+ /// Whether the entries list above has changed since the last restyle.
dirty: bool,
/// Has author style been disabled?
@@ -27,7 +34,7 @@ impl StylesheetSet {
/// Create a new empty StylesheetSet.
pub fn new() -> Self {
StylesheetSet {
- stylesheets: vec![],
+ entries: vec![],
dirty: false,
author_style_disabled: false,
}
@@ -39,39 +46,51 @@ impl StylesheetSet {
self.author_style_disabled
}
- fn remove_stylesheet_if_present(&mut self, sheet: &Arc<Stylesheet>) {
- self.stylesheets.retain(|x| !arc_ptr_eq(x, sheet));
+ fn remove_stylesheet_if_present(&mut self, unique_id: u32) {
+ self.entries.retain(|x| x.unique_id != unique_id);
}
/// Appends a new stylesheet to the current set.
- pub fn append_stylesheet(&mut self, sheet: &Arc<Stylesheet>) {
- self.remove_stylesheet_if_present(sheet);
- self.stylesheets.push(sheet.clone());
+ pub fn append_stylesheet(&mut self, sheet: &Arc<Stylesheet>,
+ unique_id: u32) {
+ self.remove_stylesheet_if_present(unique_id);
+ self.entries.push(StylesheetSetEntry {
+ unique_id: unique_id,
+ sheet: sheet.clone(),
+ });
self.dirty = true;
}
/// Prepend a new stylesheet to the current set.
- pub fn prepend_stylesheet(&mut self, sheet: &Arc<Stylesheet>) {
- self.remove_stylesheet_if_present(sheet);
- self.stylesheets.insert(0, sheet.clone());
+ pub fn prepend_stylesheet(&mut self, sheet: &Arc<Stylesheet>,
+ unique_id: u32) {
+ self.remove_stylesheet_if_present(unique_id);
+ self.entries.insert(0, StylesheetSetEntry {
+ unique_id: unique_id,
+ sheet: sheet.clone(),
+ });
self.dirty = true;
}
/// Insert a given stylesheet before another stylesheet in the document.
pub fn insert_stylesheet_before(&mut self,
sheet: &Arc<Stylesheet>,
- before: &Arc<Stylesheet>) {
- self.remove_stylesheet_if_present(sheet);
- let index = self.stylesheets.iter().position(|x| {
- arc_ptr_eq(x, before)
- }).expect("`before` stylesheet not found");
- self.stylesheets.insert(index, sheet.clone());
+ unique_id: u32,
+ before_unique_id: u32) {
+ self.remove_stylesheet_if_present(unique_id);
+ let index = self.entries.iter().position(|x| {
+ x.unique_id == before_unique_id
+ }).expect("`before_unique_id` stylesheet not found");
+ self.entries.insert(index, StylesheetSetEntry {
+ unique_id: unique_id,
+ sheet: sheet.clone(),
+ });
self.dirty = true;
}
/// Remove a given stylesheet from the set.
- pub fn remove_stylesheet(&mut self, sheet: &Arc<Stylesheet>) {
- self.remove_stylesheet_if_present(sheet);
+ pub fn remove_stylesheet(&mut self, unique_id: u32) {
+ self.remove_stylesheet_if_present(unique_id);
self.dirty = true;
}
@@ -90,9 +109,11 @@ impl StylesheetSet {
}
/// Flush the current set, unmarking it as dirty.
- pub fn flush(&mut self) -> &[Arc<Stylesheet>] {
+ pub fn flush(&mut self, sheets: &mut Vec<Arc<Stylesheet>>) {
self.dirty = false;
- &self.stylesheets
+ for entry in &self.entries {
+ sheets.push(entry.sheet.clone())
+ }
}
/// Mark the stylesheets as dirty, because something external may have