mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Make StylesheetSet an enum instead of a trait object
This commit is contained in:
parent
3e53962b25
commit
8b353ee3ce
4 changed files with 51 additions and 28 deletions
|
@ -155,7 +155,7 @@ use style::media_queries::{Device, MediaType};
|
|||
use style::selector_parser::{RestyleDamage, Snapshot};
|
||||
use style::shared_lock::SharedRwLock as StyleSharedRwLock;
|
||||
use style::str::{split_html_space_chars, str_join};
|
||||
use style::stylesheet_set::DocumentStylesheetSet;
|
||||
use style::stylesheet_set::{DocumentStylesheetSet, StylesheetSet};
|
||||
use style::stylesheets::{Origin, OriginSet, Stylesheet};
|
||||
use url::percent_encoding::percent_decode;
|
||||
use url::Host;
|
||||
|
@ -4643,9 +4643,9 @@ impl StyleSheetListOwner for Dom<Document> {
|
|||
))
|
||||
.unwrap();
|
||||
|
||||
self.document_or_shadow_root.add_stylesheet(
|
||||
DocumentOrShadowRoot::add_stylesheet(
|
||||
owner,
|
||||
stylesheets,
|
||||
StylesheetSet::Document(stylesheets),
|
||||
sheet,
|
||||
insertion_point,
|
||||
self.style_shared_lock(),
|
||||
|
@ -4660,10 +4660,10 @@ impl StyleSheetListOwner for Dom<Document> {
|
|||
.send(Msg::RemoveStylesheet(s.clone()))
|
||||
.unwrap();
|
||||
|
||||
self.document_or_shadow_root.remove_stylesheet(
|
||||
DocumentOrShadowRoot::remove_stylesheet(
|
||||
owner,
|
||||
s,
|
||||
&mut *self.stylesheets.borrow_mut(),
|
||||
StylesheetSet::Document(&mut *self.stylesheets.borrow_mut()),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -211,10 +211,9 @@ impl DocumentOrShadowRoot {
|
|||
/// Remove a stylesheet owned by `owner` from the list of document sheets.
|
||||
#[allow(unrooted_must_root)] // Owner needs to be rooted already necessarily.
|
||||
pub fn remove_stylesheet(
|
||||
&self,
|
||||
owner: &Element,
|
||||
s: &Arc<Stylesheet>,
|
||||
stylesheets: &mut StylesheetSet<StyleSheetInDocument>,
|
||||
mut stylesheets: StylesheetSet<StyleSheetInDocument>,
|
||||
) {
|
||||
let guard = s.shared_lock.read();
|
||||
|
||||
|
@ -233,9 +232,8 @@ impl DocumentOrShadowRoot {
|
|||
/// correct tree position.
|
||||
#[allow(unrooted_must_root)] // Owner needs to be rooted already necessarily.
|
||||
pub fn add_stylesheet(
|
||||
&self,
|
||||
owner: &Element,
|
||||
stylesheets: &mut StylesheetSet<StyleSheetInDocument>,
|
||||
mut stylesheets: StylesheetSet<StyleSheetInDocument>,
|
||||
sheet: Arc<Stylesheet>,
|
||||
insertion_point: Option<StyleSheetInDocument>,
|
||||
style_shared_lock: &StyleSharedRwLock,
|
||||
|
|
|
@ -24,6 +24,7 @@ use style::author_styles::AuthorStyles;
|
|||
use style::dom::TElement;
|
||||
use style::media_queries::Device;
|
||||
use style::shared_lock::SharedRwLockReadGuard;
|
||||
use style::stylesheet_set::StylesheetSet;
|
||||
use style::stylesheets::Stylesheet;
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-shadowroot
|
||||
|
@ -219,9 +220,9 @@ impl StyleSheetListOwner for Dom<ShadowRoot> {
|
|||
.is_before(sheet_in_shadow.owner.upcast())
|
||||
})
|
||||
.cloned();
|
||||
self.document_or_shadow_root.add_stylesheet(
|
||||
DocumentOrShadowRoot::add_stylesheet(
|
||||
owner,
|
||||
stylesheets,
|
||||
StylesheetSet::Author(stylesheets),
|
||||
sheet,
|
||||
insertion_point,
|
||||
self.document.style_shared_lock(),
|
||||
|
@ -231,10 +232,10 @@ impl StyleSheetListOwner for Dom<ShadowRoot> {
|
|||
/// Remove a stylesheet owned by `owner` from the list of shadow root sheets.
|
||||
#[allow(unrooted_must_root)] // Owner needs to be rooted already necessarily.
|
||||
fn remove_stylesheet(&self, owner: &Element, s: &Arc<Stylesheet>) {
|
||||
self.document_or_shadow_root.remove_stylesheet(
|
||||
DocumentOrShadowRoot::remove_stylesheet(
|
||||
owner,
|
||||
s,
|
||||
&mut self.author_styles.borrow_mut().stylesheets,
|
||||
StylesheetSet::Author(&mut self.author_styles.borrow_mut().stylesheets),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -374,36 +374,65 @@ where
|
|||
}
|
||||
|
||||
/// Functionality common to DocumentStylesheetSet and AuthorStylesheetSet.
|
||||
pub trait StylesheetSet<S>
|
||||
pub enum StylesheetSet<'a, S>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
/// Author stylesheet set.
|
||||
Author(&'a mut AuthorStylesheetSet<S>),
|
||||
/// Document stylesheet set.
|
||||
Document(&'a mut DocumentStylesheetSet<S>),
|
||||
}
|
||||
|
||||
impl<'a, S> StylesheetSet<'a, S>
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
/// Appends a new stylesheet to the current set.
|
||||
///
|
||||
/// No device implies not computing invalidations.
|
||||
fn append_stylesheet(
|
||||
pub fn append_stylesheet(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
);
|
||||
) {
|
||||
match self {
|
||||
StylesheetSet::Author(set) => set.append_stylesheet(device, sheet, guard),
|
||||
StylesheetSet::Document(set) => set.append_stylesheet(device, sheet, guard),
|
||||
}
|
||||
}
|
||||
|
||||
/// Insert a given stylesheet before another stylesheet in the document.
|
||||
fn insert_stylesheet_before(
|
||||
pub fn insert_stylesheet_before(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
before_sheet: S,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
);
|
||||
) {
|
||||
match self {
|
||||
StylesheetSet::Author(set) => {
|
||||
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
|
||||
},
|
||||
StylesheetSet::Document(set) => {
|
||||
set.insert_stylesheet_before(device, sheet, before_sheet, guard)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Remove a given stylesheet from the set.
|
||||
fn remove_stylesheet(
|
||||
pub fn remove_stylesheet(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
guard: &SharedRwLockReadGuard,
|
||||
);
|
||||
) {
|
||||
match self {
|
||||
StylesheetSet::Author(set) => set.remove_stylesheet(device, sheet, guard),
|
||||
StylesheetSet::Document(set) => set.remove_stylesheet(device, sheet, guard),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This macro defines methods common to DocumentStylesheetSet and
|
||||
|
@ -429,16 +458,11 @@ macro_rules! stylesheetset_impl {
|
|||
.collect_invalidations_for(device, sheet, guard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> StylesheetSet<S> for $set_type
|
||||
where
|
||||
S: StylesheetInDocument + PartialEq + 'static,
|
||||
{
|
||||
/// Appends a new stylesheet to the current set.
|
||||
///
|
||||
/// No device implies not computing invalidations.
|
||||
fn append_stylesheet(
|
||||
pub fn append_stylesheet(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
|
@ -451,7 +475,7 @@ macro_rules! stylesheetset_impl {
|
|||
}
|
||||
|
||||
/// Insert a given stylesheet before another stylesheet in the document.
|
||||
fn insert_stylesheet_before(
|
||||
pub fn insert_stylesheet_before(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
|
@ -466,7 +490,7 @@ macro_rules! stylesheetset_impl {
|
|||
}
|
||||
|
||||
/// Remove a given stylesheet from the set.
|
||||
fn remove_stylesheet(
|
||||
pub fn remove_stylesheet(
|
||||
&mut self,
|
||||
device: Option<&Device>,
|
||||
sheet: S,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue