1use crate::derives::*;
9use crate::invalidation::stylesheets::StylesheetInvalidationSet;
10use crate::shared_lock::SharedRwLockReadGuard;
11use crate::stylesheet_set::AuthorStylesheetSet;
12use crate::stylesheets::StylesheetInDocument;
13use crate::stylist::CascadeData;
14use crate::stylist::Stylist;
15use servo_arc::Arc;
16use std::sync::LazyLock;
17
18#[derive(MallocSizeOf)]
21pub struct GenericAuthorStyles<S>
22where
23 S: StylesheetInDocument + PartialEq + 'static,
24{
25 pub stylesheets: AuthorStylesheetSet<S>,
28 #[ignore_malloc_size_of = "Measured as part of the stylist"]
30 pub data: Arc<CascadeData>,
31}
32
33pub use self::GenericAuthorStyles as AuthorStyles;
34
35static EMPTY_CASCADE_DATA: LazyLock<Arc<CascadeData>> =
36 LazyLock::new(|| Arc::new_leaked(CascadeData::new()));
37
38impl<S> GenericAuthorStyles<S>
39where
40 S: StylesheetInDocument + PartialEq + 'static,
41{
42 #[inline]
44 pub fn new() -> Self {
45 Self {
46 stylesheets: AuthorStylesheetSet::new(),
47 data: EMPTY_CASCADE_DATA.clone(),
48 }
49 }
50
51 #[inline]
53 pub fn flush(
54 &mut self,
55 stylist: &mut Stylist,
56 guard: &SharedRwLockReadGuard,
57 ) -> StylesheetInvalidationSet {
58 let (flusher, mut invalidations) = self.stylesheets.flush();
59 let result = stylist.rebuild_author_data(
60 &self.data,
61 flusher.sheets,
62 guard,
63 &mut invalidations.cascade_data_difference,
64 );
65 if let Ok(Some(new_data)) = result {
66 self.data = new_data;
67 }
68 invalidations
69 }
70}