namespace_rule.rs (1440B)
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 //! The `@namespace` at-rule. 6 7 use crate::derives::*; 8 use crate::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; 9 use crate::{Namespace, Prefix}; 10 use cssparser::SourceLocation; 11 use std::fmt::{self, Write}; 12 use style_traits::{CssStringWriter, CssWriter, ToCss}; 13 14 /// A `@namespace` rule. 15 #[derive(Clone, Debug, PartialEq, ToShmem)] 16 #[allow(missing_docs)] 17 pub struct NamespaceRule { 18 /// The namespace prefix, and `None` if it's the default Namespace 19 pub prefix: Option<Prefix>, 20 /// The actual namespace url. 21 pub url: Namespace, 22 /// The source location this rule was found at. 23 pub source_location: SourceLocation, 24 } 25 26 impl ToCssWithGuard for NamespaceRule { 27 // https://drafts.csswg.org/cssom/#serialize-a-css-rule CSSNamespaceRule 28 fn to_css( 29 &self, 30 _guard: &SharedRwLockReadGuard, 31 dest_str: &mut CssStringWriter, 32 ) -> fmt::Result { 33 let mut dest = CssWriter::new(dest_str); 34 dest.write_str("@namespace ")?; 35 if let Some(ref prefix) = self.prefix { 36 prefix.to_css(&mut dest)?; 37 dest.write_char(' ')?; 38 } 39 dest.write_str("url(")?; 40 self.url.to_string().to_css(&mut dest)?; 41 dest.write_str(");") 42 } 43 }