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