summaryrefslogtreecommitdiffstats
path: root/servo/components/style/author_styles.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /servo/components/style/author_styles.rs
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--servo/components/style/author_styles.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/servo/components/style/author_styles.rs b/servo/components/style/author_styles.rs
new file mode 100644
index 0000000000..58d9bda423
--- /dev/null
+++ b/servo/components/style/author_styles.rs
@@ -0,0 +1,78 @@
+/* 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::context::QuirksMode;
+use crate::dom::TElement;
+#[cfg(feature = "gecko")]
+use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
+use crate::invalidation::media_queries::ToMediaListKey;
+use crate::media_queries::Device;
+use crate::shared_lock::SharedRwLockReadGuard;
+use crate::stylesheet_set::AuthorStylesheetSet;
+use crate::stylesheets::StylesheetInDocument;
+use crate::stylist::CascadeData;
+
+/// A set of author stylesheets and their computed representation, such as the
+/// ones used for ShadowRoot.
+#[derive(MallocSizeOf)]
+pub struct AuthorStyles<S>
+where
+ S: StylesheetInDocument + PartialEq + 'static,
+{
+ /// The sheet collection, which holds the sheet pointers, the invalidations,
+ /// and all that stuff.
+ pub stylesheets: AuthorStylesheetSet<S>,
+ /// The actual cascade data computed from the stylesheets.
+ pub data: CascadeData,
+}
+
+impl<S> AuthorStyles<S>
+where
+ S: StylesheetInDocument + PartialEq + 'static,
+{
+ /// Create an empty AuthorStyles.
+ #[inline]
+ pub fn new() -> Self {
+ Self {
+ stylesheets: AuthorStylesheetSet::new(),
+ data: CascadeData::new(),
+ }
+ }
+
+ /// 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<E>(
+ &mut self,
+ device: &Device,
+ quirks_mode: QuirksMode,
+ guard: &SharedRwLockReadGuard,
+ ) where
+ E: TElement,
+ S: ToMediaListKey,
+ {
+ let flusher = self
+ .stylesheets
+ .flush::<E>(/* host = */ None, /* snapshot_map = */ None);
+
+ // Ignore OOM.
+ let _ = self
+ .data
+ .rebuild(device, quirks_mode, flusher.sheets, guard);
+ }
+}
+
+#[cfg(feature = "gecko")]
+unsafe impl HasFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {
+ type FFIType = crate::gecko_bindings::structs::RawServoAuthorStyles;
+}
+#[cfg(feature = "gecko")]
+unsafe impl HasSimpleFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}
+#[cfg(feature = "gecko")]
+unsafe impl HasBoxFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}