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