1use crate::dom::TElement;
9use crate::shared_lock::SharedRwLockReadGuard;
10use crate::stylesheet_set::AuthorStylesheetSet;
11use crate::stylesheets::StylesheetInDocument;
12use crate::stylist::CascadeData;
13use crate::stylist::Stylist;
14use servo_arc::Arc;
15
16#[derive(MallocSizeOf)]
19pub struct GenericAuthorStyles<S>
20where
21 S: StylesheetInDocument + PartialEq + 'static,
22{
23 pub stylesheets: AuthorStylesheetSet<S>,
26 #[ignore_malloc_size_of = "Measured as part of the stylist"]
28 pub data: Arc<CascadeData>,
29}
30
31pub use self::GenericAuthorStyles as AuthorStyles;
32
33lazy_static! {
34 static ref EMPTY_CASCADE_DATA: Arc<CascadeData> = Arc::new_leaked(CascadeData::new());
35}
36
37impl<S> GenericAuthorStyles<S>
38where
39 S: StylesheetInDocument + PartialEq + 'static,
40{
41 #[inline]
43 pub fn new() -> Self {
44 Self {
45 stylesheets: AuthorStylesheetSet::new(),
46 data: EMPTY_CASCADE_DATA.clone(),
47 }
48 }
49
50 #[inline]
55 pub fn flush<E>(&mut self, stylist: &mut Stylist, guard: &SharedRwLockReadGuard)
56 where
57 E: TElement,
58 {
59 let flusher = self
60 .stylesheets
61 .flush::<E>(None, None);
62
63 let result = stylist.rebuild_author_data(&self.data, flusher.sheets, guard);
64 if let Ok(Some(new_data)) = result {
65 self.data = new_data;
66 }
67 }
68}