style/stylesheets/
appearance_base_rule.rs

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//! The `@appearance-base` rule, for UA stylesheet appearance-dependent styles.
6
7use crate::derives::*;
8use crate::shared_lock::{DeepCloneWithLock, Locked};
9use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
10use crate::stylesheets::CssRules;
11use cssparser::SourceLocation;
12#[cfg(feature = "gecko")]
13use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
14use servo_arc::Arc;
15use std::fmt::{self, Write};
16use style_traits::CssStringWriter;
17
18/// An `@appearance-base` rule.
19#[derive(Debug, ToShmem)]
20pub struct AppearanceBaseRule {
21    /// The nested rules inside this @appearance-base rule.
22    pub rules: Arc<Locked<CssRules>>,
23    /// The source position where this rule was found.
24    pub source_location: SourceLocation,
25}
26
27impl AppearanceBaseRule {
28    /// Measure heap usage.
29    #[cfg(feature = "gecko")]
30    pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
31        self.rules.unconditional_shallow_size_of(ops)
32            + self.rules.read_with(guard).size_of(guard, ops)
33    }
34}
35
36impl ToCssWithGuard for AppearanceBaseRule {
37    fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
38        dest.write_str("@appearance-base")?;
39        self.rules.read_with(guard).to_css_block(guard, dest)
40    }
41}
42
43impl DeepCloneWithLock for AppearanceBaseRule {
44    fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self {
45        let rules = self.rules.read_with(guard);
46        AppearanceBaseRule {
47            rules: Arc::new(lock.wrap(rules.deep_clone_with_lock(lock, guard))),
48            source_location: self.source_location.clone(),
49        }
50    }
51}