style/stylesheets/
starting_style_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//! before-change style: the `@starting-style` rules.
6//! https://drafts.csswg.org/css-transitions-2/#defining-before-change-style
7
8use crate::shared_lock::{DeepCloneWithLock, Locked};
9use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
10use crate::str::CssStringWriter;
11use crate::stylesheets::CssRules;
12use cssparser::SourceLocation;
13#[cfg(feature = "gecko")]
14use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
15use servo_arc::Arc;
16use std::fmt::{self, Debug, Write};
17
18/// A [`@starting-style`][starting-style] rule.
19///
20/// [starting-style]: https://drafts.csswg.org/css-transitions-2/#at-ruledef-starting-style
21#[derive(Debug, ToShmem)]
22pub struct StartingStyleRule {
23    /// The nested rules to this starting-style rule.
24    pub rules: Arc<Locked<CssRules>>,
25    /// The source position where this starting-style rule was found.
26    pub source_location: SourceLocation,
27}
28
29impl StartingStyleRule {
30    /// Measure heap usage.
31    #[cfg(feature = "gecko")]
32    pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
33        self.rules.unconditional_shallow_size_of(ops) +
34            self.rules.read_with(guard).size_of(guard, ops)
35    }
36}
37
38impl ToCssWithGuard for StartingStyleRule {
39    fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
40        dest.write_str("@starting-style")?;
41        self.rules.read_with(guard).to_css_block(guard, dest)
42    }
43}
44
45impl DeepCloneWithLock for StartingStyleRule {
46    fn deep_clone_with_lock(
47        &self,
48        lock: &SharedRwLock,
49        guard: &SharedRwLockReadGuard,
50    ) -> Self {
51        let rules = self.rules.read_with(guard);
52        StartingStyleRule {
53            rules: Arc::new(lock.wrap(rules.deep_clone_with_lock(lock, guard))),
54            source_location: self.source_location.clone(),
55        }
56    }
57}