mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +01:00
style: Replicate the list of stylesheets on the layout thread.
This is a patch that unifies a bit how Gecko and Stylo stylesheets work, in order to be able to eventually move the stylesheets into the stylist, and be able to incrementally update the invalidation map.
This commit is contained in:
parent
b8159e659e
commit
d1725b1f19
14 changed files with 413 additions and 198 deletions
|
@ -6,13 +6,14 @@
|
|||
|
||||
use dom::TElement;
|
||||
use invalidation::stylesheets::StylesheetInvalidationSet;
|
||||
use media_queries::Device;
|
||||
use shared_lock::SharedRwLockReadGuard;
|
||||
use std::slice;
|
||||
use stylesheets::{OriginSet, PerOrigin, StylesheetInDocument};
|
||||
use stylist::Stylist;
|
||||
|
||||
/// Entry for a StylesheetSet. We don't bother creating a constructor, because
|
||||
/// there's no sensible defaults for the member variables.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct StylesheetSetEntry<S>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
|
@ -38,6 +39,7 @@ where
|
|||
}
|
||||
|
||||
/// The set of stylesheets effective for a given document.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct StylesheetSet<S>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
|
@ -69,6 +71,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the number of stylesheets in the set.
|
||||
pub fn len(&self) -> usize {
|
||||
self.entries.len()
|
||||
}
|
||||
|
||||
/// Returns the number of stylesheets in the set.
|
||||
pub fn get(&self, index: usize) -> Option<&S> {
|
||||
self.entries.get(index).map(|s| &s.sheet)
|
||||
}
|
||||
|
||||
/// Returns whether author styles have been disabled for the current
|
||||
/// stylesheet set.
|
||||
pub fn author_style_disabled(&self) -> bool {
|
||||
|
@ -81,46 +93,57 @@ where
|
|||
|
||||
fn collect_invalidations_for(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
device: Option<&Device>,
|
||||
sheet: &S,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
) {
|
||||
let origin = sheet.contents(guard).origin;
|
||||
let data = self.invalidation_data.borrow_mut_for_origin(&origin);
|
||||
data.invalidations.collect_invalidations_for(stylist, sheet, guard);
|
||||
if let Some(device) = device {
|
||||
data.invalidations.collect_invalidations_for(device, sheet, guard);
|
||||
}
|
||||
data.dirty = true;
|
||||
}
|
||||
|
||||
/// Appends a new stylesheet to the current set.
|
||||
///
|
||||
/// FIXME(emilio): `device` shouldn't be optional, but a bunch of work needs
|
||||
/// to happen to make the invalidations work properly in servo.
|
||||
pub fn append_stylesheet(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
guard: &SharedRwLockReadGuard
|
||||
) {
|
||||
debug!("StylesheetSet::append_stylesheet");
|
||||
self.remove_stylesheet_if_present(&sheet);
|
||||
self.collect_invalidations_for(stylist, &sheet, guard);
|
||||
self.collect_invalidations_for(device, &sheet, guard);
|
||||
self.entries.push(StylesheetSetEntry { sheet });
|
||||
}
|
||||
|
||||
/// Prepend a new stylesheet to the current set.
|
||||
///
|
||||
/// FIXME(emilio): `device` shouldn't be optional, but a bunch of work needs
|
||||
/// to happen to make the invalidations work properly in servo.
|
||||
pub fn prepend_stylesheet(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
guard: &SharedRwLockReadGuard
|
||||
) {
|
||||
debug!("StylesheetSet::prepend_stylesheet");
|
||||
self.remove_stylesheet_if_present(&sheet);
|
||||
self.collect_invalidations_for(stylist, &sheet, guard);
|
||||
self.collect_invalidations_for(device, &sheet, guard);
|
||||
self.entries.insert(0, StylesheetSetEntry { sheet });
|
||||
}
|
||||
|
||||
/// Insert a given stylesheet before another stylesheet in the document.
|
||||
///
|
||||
/// FIXME(emilio): `device` shouldn't be optional, but a bunch of work needs
|
||||
/// to happen to make the invalidations work properly in servo.
|
||||
pub fn insert_stylesheet_before(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
before_sheet: S,
|
||||
guard: &SharedRwLockReadGuard
|
||||
|
@ -130,20 +153,23 @@ where
|
|||
let index = self.entries.iter().position(|entry| {
|
||||
entry.sheet == before_sheet
|
||||
}).expect("`before_sheet` stylesheet not found");
|
||||
self.collect_invalidations_for(stylist, &sheet, guard);
|
||||
self.collect_invalidations_for(device, &sheet, guard);
|
||||
self.entries.insert(index, StylesheetSetEntry { sheet });
|
||||
}
|
||||
|
||||
/// Remove a given stylesheet from the set.
|
||||
///
|
||||
/// FIXME(emilio): `device` shouldn't be optional, but a bunch of work needs
|
||||
/// to happen to make the invalidations work properly in servo.
|
||||
pub fn remove_stylesheet(
|
||||
&mut self,
|
||||
stylist: &Stylist,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
) {
|
||||
debug!("StylesheetSet::remove_stylesheet");
|
||||
self.remove_stylesheet_if_present(&sheet);
|
||||
self.collect_invalidations_for(stylist, &sheet, guard);
|
||||
self.collect_invalidations_for(device, &sheet, guard);
|
||||
}
|
||||
|
||||
/// Notes that the author style has been disabled for this document.
|
||||
|
@ -174,7 +200,6 @@ where
|
|||
E: TElement,
|
||||
{
|
||||
debug!("StylesheetSet::flush");
|
||||
debug_assert!(self.has_changed());
|
||||
|
||||
let mut origins = OriginSet::empty();
|
||||
for (data, origin) in self.invalidation_data.iter_mut_origins() {
|
||||
|
@ -188,6 +213,26 @@ where
|
|||
(self.iter(), origins)
|
||||
}
|
||||
|
||||
/// Flush stylesheets, but without running any of the invalidation passes.
|
||||
///
|
||||
/// FIXME(emilio): This should eventually disappear. Please keep this
|
||||
/// Servo-only.
|
||||
#[cfg(feature = "servo")]
|
||||
pub fn flush_without_invalidation(&mut self) -> (StylesheetIterator<S>, OriginSet) {
|
||||
debug!("StylesheetSet::flush_without_invalidation");
|
||||
|
||||
let mut origins = OriginSet::empty();
|
||||
for (data, origin) in self.invalidation_data.iter_mut_origins() {
|
||||
if data.dirty {
|
||||
data.invalidations.clear();
|
||||
data.dirty = false;
|
||||
origins |= origin;
|
||||
}
|
||||
}
|
||||
|
||||
(self.iter(), origins)
|
||||
}
|
||||
|
||||
/// Returns an iterator over the current list of stylesheets.
|
||||
pub fn iter(&self) -> StylesheetIterator<S> {
|
||||
StylesheetIterator(self.entries.iter())
|
||||
|
@ -204,6 +249,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
struct InvalidationData {
|
||||
/// The stylesheet invalidations for this origin that we still haven't
|
||||
/// processed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue