style/values/specified/
outline.rs

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//! Specified values for outline properties
6
7use crate::parser::{Parse, ParserContext};
8use crate::values::specified::BorderStyle;
9use cssparser::Parser;
10use selectors::parser::SelectorParseErrorKind;
11use style_traits::ParseError;
12
13#[derive(
14    Clone,
15    Copy,
16    Debug,
17    Eq,
18    MallocSizeOf,
19    Ord,
20    PartialEq,
21    PartialOrd,
22    SpecifiedValueInfo,
23    ToComputedValue,
24    ToCss,
25    ToResolvedValue,
26    ToShmem,
27    ToTyped,
28)]
29#[repr(C, u8)]
30/// <https://drafts.csswg.org/css-ui/#propdef-outline-style>
31pub enum OutlineStyle {
32    /// auto
33    Auto,
34    /// <border-style>
35    BorderStyle(BorderStyle),
36}
37
38impl OutlineStyle {
39    #[inline]
40    /// Get default value as None
41    pub fn none() -> OutlineStyle {
42        OutlineStyle::BorderStyle(BorderStyle::None)
43    }
44
45    #[inline]
46    /// Get value for None or Hidden
47    pub fn none_or_hidden(&self) -> bool {
48        match *self {
49            OutlineStyle::Auto => false,
50            OutlineStyle::BorderStyle(ref style) => style.none_or_hidden(),
51        }
52    }
53}
54
55impl Parse for OutlineStyle {
56    fn parse<'i, 't>(
57        _context: &ParserContext,
58        input: &mut Parser<'i, 't>,
59    ) -> Result<OutlineStyle, ParseError<'i>> {
60        if let Ok(border_style) = input.try_parse(BorderStyle::parse) {
61            if let BorderStyle::Hidden = border_style {
62                return Err(input
63                    .new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into())));
64            }
65
66            return Ok(OutlineStyle::BorderStyle(border_style));
67        }
68
69        input.expect_ident_matching("auto")?;
70        Ok(OutlineStyle::Auto)
71    }
72}