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