style/stylesheets/
position_try_rule.rs1use std::fmt::Write;
10
11use crate::properties::PropertyDeclarationBlock;
12use crate::shared_lock::{
13 DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard,
14};
15use crate::values::DashedIdent;
16use cssparser::SourceLocation;
17#[cfg(feature = "gecko")]
18use malloc_size_of::{MallocSizeOf, MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
19use servo_arc::Arc;
20use style_traits::{CssStringWriter, CssWriter, ToCss};
21
22#[derive(Clone, Debug, ToShmem)]
24pub struct PositionTryRule {
25 pub name: DashedIdent,
27 pub block: Arc<Locked<PropertyDeclarationBlock>>,
29 pub source_location: SourceLocation,
31}
32
33impl PositionTryRule {
34 #[cfg(feature = "gecko")]
36 pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
37 self.block.unconditional_shallow_size_of(ops) + self.block.read_with(guard).size_of(ops)
38 }
39}
40
41impl DeepCloneWithLock for PositionTryRule {
42 fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self {
43 PositionTryRule {
44 name: self.name.clone(),
45 block: Arc::new(lock.wrap(self.block.read_with(&guard).clone())),
46 source_location: self.source_location.clone(),
47 }
48 }
49}
50
51impl ToCssWithGuard for PositionTryRule {
52 fn to_css(
53 &self,
54 guard: &SharedRwLockReadGuard,
55 dest: &mut CssStringWriter,
56 ) -> std::fmt::Result {
57 dest.write_str("@position-try ")?;
58 self.name.to_css(&mut CssWriter::new(dest))?;
59 dest.write_str(" { ")?;
60 let declarations = self.block.read_with(guard);
61 declarations.to_css(dest)?;
62 if !declarations.is_empty() {
63 dest.write_char(' ')?;
64 }
65 dest.write_char('}')
66 }
67}