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::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard}; 8 use crate::str::CssStringWriter; 9 use crate::{Namespace, Prefix}; 10 use cssparser::SourceLocation; 11 use std::fmt::{self, Write}; 12 use style_traits::{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 to_css(&self, _guard: &SharedRwLockReadGuard, dest_str: &mut CssStringWriter) -> fmt::Result28 fn to_css(&self, _guard: &SharedRwLockReadGuard, dest_str: &mut CssStringWriter) -> fmt::Result { 29 let mut dest = CssWriter::new(dest_str); 30 dest.write_str("@namespace ")?; 31 if let Some(ref prefix) = self.prefix { 32 prefix.to_css(&mut dest)?; 33 dest.write_char(' ')?; 34 } 35 dest.write_str("url(")?; 36 self.url.to_string().to_css(&mut dest)?; 37 dest.write_str(");") 38 } 39 } 40