lewp_css/domain/at_rules/page/
page_at_rule.rs

1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5    super::PageSelectorPseudoClass,
6    crate::domain::{
7        properties::{Importance, PropertyDeclaration, PropertyDeclarations},
8        HasPropertyDeclarations,
9    },
10    cssparser::ToCss,
11    std::fmt,
12};
13
14/// A [`@page`](crate::domain::CssRule::Page) rule.
15/// page: <https://drafts.csswg.org/css2/page.html#page-box>
16/// page-selectors: <https://drafts.csswg.org/css2/page.html#page-selectors>
17#[derive(Default, Debug, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
18pub struct PageAtRule {
19    pub page_selector_pseudo_class: Option<PageSelectorPseudoClass>,
20
21    /// The declaration block this page rule contains.
22    pub property_declarations: PropertyDeclarations<Importance>,
23}
24
25impl ToCss for PageAtRule {
26    fn to_css<W: fmt::Write>(&self, dest: &mut W) -> fmt::Result {
27        dest.write_str("@page")?;
28        if let Some(ref page_selector_pseudo_class) =
29            self.page_selector_pseudo_class
30        {
31            dest.write_char(' ')?;
32            page_selector_pseudo_class.to_css(dest)?;
33        }
34        dest.write_char('{')?;
35        self.property_declarations.to_css(dest)?;
36        dest.write_char('}')
37    }
38}
39
40impl HasPropertyDeclarations<Importance> for PageAtRule {
41    #[inline(always)]
42    fn property_declarations(&self) -> &PropertyDeclarations<Importance> {
43        &self.property_declarations
44    }
45
46    #[inline(always)]
47    fn property_declarations_mut(
48        &mut self,
49    ) -> &mut PropertyDeclarations<Importance> {
50        &mut self.property_declarations
51    }
52
53    #[inline(always)]
54    fn property_declarations_slice(
55        &self,
56    ) -> &[PropertyDeclaration<Importance>] {
57        &self.property_declarations.0[..]
58    }
59
60    #[inline(always)]
61    fn property_declarations_vec(
62        &self,
63    ) -> &Vec<PropertyDeclaration<Importance>> {
64        &self.property_declarations.0
65    }
66
67    #[inline(always)]
68    fn property_declarations_vec_mut(
69        &mut self,
70    ) -> &mut Vec<PropertyDeclaration<Importance>> {
71        &mut self.property_declarations.0
72    }
73}