From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- servo/components/style/author_styles.rs | 70 +++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 servo/components/style/author_styles.rs (limited to 'servo/components/style/author_styles.rs') diff --git a/servo/components/style/author_styles.rs b/servo/components/style/author_styles.rs new file mode 100644 index 0000000000..a0223dcecc --- /dev/null +++ b/servo/components/style/author_styles.rs @@ -0,0 +1,70 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! A set of author stylesheets and their computed representation, such as the +//! ones used for ShadowRoot. + +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; + +/// A set of author stylesheets and their computed representation, such as the +/// ones used for ShadowRoot. +#[derive(MallocSizeOf)] +pub struct GenericAuthorStyles +where + S: StylesheetInDocument + PartialEq + 'static, +{ + /// The sheet collection, which holds the sheet pointers, the invalidations, + /// and all that stuff. + pub stylesheets: AuthorStylesheetSet, + /// The actual cascade data computed from the stylesheets. + #[ignore_malloc_size_of = "Measured as part of the stylist"] + pub data: Arc, +} + +pub use self::GenericAuthorStyles as AuthorStyles; + +lazy_static! { + static ref EMPTY_CASCADE_DATA: Arc = Arc::new_leaked(CascadeData::new()); +} + +impl GenericAuthorStyles +where + S: StylesheetInDocument + PartialEq + 'static, +{ + /// Create an empty AuthorStyles. + #[inline] + pub fn new() -> Self { + Self { + stylesheets: AuthorStylesheetSet::new(), + data: EMPTY_CASCADE_DATA.clone(), + } + } + + /// Flush the pending sheet changes, updating `data` as appropriate. + /// + /// TODO(emilio): Need a host element and a snapshot map to do invalidation + /// properly. + #[inline] + pub fn flush(&mut self, stylist: &mut Stylist, guard: &SharedRwLockReadGuard) + where + E: TElement, + S: ToMediaListKey, + { + let flusher = self + .stylesheets + .flush::(/* host = */ None, /* snapshot_map = */ None); + + let result = stylist.rebuild_author_data(&self.data, flusher.sheets, guard); + if let Ok(Some(new_data)) = result { + self.data = new_data; + } + } +} -- cgit v1.2.3