Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5
//! A set of author stylesheets and their computed representation, such as the
6
//! ones used for ShadowRoot.
7
8
use crate::context::QuirksMode;
9
use crate::dom::TElement;
10
#[cfg(feature = "gecko")]
11
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
12
use crate::invalidation::media_queries::ToMediaListKey;
13
use crate::media_queries::Device;
14
use crate::shared_lock::SharedRwLockReadGuard;
15
use crate::stylesheet_set::AuthorStylesheetSet;
16
use crate::stylesheets::StylesheetInDocument;
17
use crate::stylist::CascadeData;
18
19
/// A set of author stylesheets and their computed representation, such as the
20
/// ones used for ShadowRoot.
21
#[derive(MallocSizeOf)]
22
pub struct AuthorStyles<S>
23
where
24
S: StylesheetInDocument + PartialEq + 'static,
25
{
26
/// The sheet collection, which holds the sheet pointers, the invalidations,
27
/// and all that stuff.
28
pub stylesheets: AuthorStylesheetSet<S>,
29
/// The actual cascade data computed from the stylesheets.
30
pub data: CascadeData,
31
}
32
33
impl<S> AuthorStyles<S>
34
where
35
S: StylesheetInDocument + PartialEq + 'static,
36
{
37
/// Create an empty AuthorStyles.
38
#[inline]
39
pub fn new() -> Self {
40
Self {
41
stylesheets: AuthorStylesheetSet::new(),
42
data: CascadeData::new(),
43
}
44
}
45
46
/// Flush the pending sheet changes, updating `data` as appropriate.
47
///
48
/// TODO(emilio): Need a host element and a snapshot map to do invalidation
49
/// properly.
50
#[inline]
51
pub fn flush<E>(
52
&mut self,
53
device: &Device,
54
quirks_mode: QuirksMode,
55
guard: &SharedRwLockReadGuard,
56
) where
57
E: TElement,
58
S: ToMediaListKey,
59
{
60
let flusher = self
61
.stylesheets
62
.flush::<E>(/* host = */ None, /* snapshot_map = */ None);
63
64
// Ignore OOM.
65
let _ = self
66
.data
67
.rebuild(device, quirks_mode, flusher.sheets, guard);
68
}
69
}
70
71
#[cfg(feature = "gecko")]
72
unsafe impl HasFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {
73
type FFIType = crate::gecko_bindings::structs::RawServoAuthorStyles;
74
}
75
#[cfg(feature = "gecko")]
76
unsafe impl HasSimpleFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}
77
#[cfg(feature = "gecko")]
78
unsafe impl HasBoxFFI for AuthorStyles<crate::gecko::data::GeckoStyleSheet> {}