nested_declarations_rule.rs (1763B)
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 nested declarations rule. 6 //! https://drafts.csswg.org/css-nesting-1/#nested-declarations-rule 7 8 use crate::derives::*; 9 use crate::properties::PropertyDeclarationBlock; 10 use crate::shared_lock::{ 11 DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard, 12 }; 13 use cssparser::SourceLocation; 14 use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf}; 15 use servo_arc::Arc; 16 use style_traits::CssStringWriter; 17 18 /// A nested declarations rule. 19 #[derive(Clone, Debug, ToShmem)] 20 pub struct NestedDeclarationsRule { 21 /// The declarations. 22 pub block: Arc<Locked<PropertyDeclarationBlock>>, 23 /// The source position this rule was found at. 24 pub source_location: SourceLocation, 25 } 26 27 impl NestedDeclarationsRule { 28 /// Measure heap usage. 29 pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize { 30 self.block.unconditional_shallow_size_of(ops) + self.block.read_with(guard).size_of(ops) 31 } 32 } 33 34 impl DeepCloneWithLock for NestedDeclarationsRule { 35 fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self { 36 Self { 37 block: Arc::new(lock.wrap(self.block.read_with(&guard).clone())), 38 source_location: self.source_location.clone(), 39 } 40 } 41 } 42 43 impl ToCssWithGuard for NestedDeclarationsRule { 44 fn to_css( 45 &self, 46 guard: &SharedRwLockReadGuard, 47 dest: &mut CssStringWriter, 48 ) -> std::fmt::Result { 49 self.block.read_with(guard).to_css(dest) 50 } 51 }