use crate::dom::TElement;
use crate::invalidation::media_queries::ToMediaListKey;
use crate::shared_lock::SharedRwLockReadGuard;
use crate::stylesheet_set::AuthorStylesheetSet;
use crate::stylesheets::StylesheetInDocument;
use crate::stylist::CascadeData;
use crate::stylist::Stylist;
use servo_arc::Arc;
#[derive(MallocSizeOf)]
pub struct GenericAuthorStyles<S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
pub stylesheets: AuthorStylesheetSet<S>,
#[ignore_malloc_size_of = "Measured as part of the stylist"]
pub data: Arc<CascadeData>,
}
pub use self::GenericAuthorStyles as AuthorStyles;
lazy_static! {
static ref EMPTY_CASCADE_DATA: Arc<CascadeData> = Arc::new_leaked(CascadeData::new());
}
impl<S> GenericAuthorStyles<S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
#[inline]
pub fn new() -> Self {
Self {
stylesheets: AuthorStylesheetSet::new(),
data: EMPTY_CASCADE_DATA.clone(),
}
}
#[inline]
pub fn flush<E>(&mut self, stylist: &mut Stylist, guard: &SharedRwLockReadGuard)
where
E: TElement,
S: ToMediaListKey,
{
let flusher = self
.stylesheets
.flush::<E>(None, None);
let result = stylist.rebuild_author_data(&self.data, flusher.sheets, guard);
if let Ok(Some(new_data)) = result {
self.data = new_data;
}
}
}