mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +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
|
@ -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