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)]
28#[repr(C, u8)]
29/// <https://drafts.csswg.org/css-ui/#propdef-outline-style>
30pub enum OutlineStyle {
31    /// auto
32    Auto,
33    /// <border-style>
34    BorderStyle(BorderStyle),
35}
36
37impl OutlineStyle {
38    #[inline]
39    /// Get default value as None
40    pub fn none() -> OutlineStyle {
41        OutlineStyle::BorderStyle(BorderStyle::None)
42    }
43
44    #[inline]
45    /// Get value for None or Hidden
46    pub fn none_or_hidden(&self) -> bool {
47        match *self {
48            OutlineStyle::Auto => false,
49            OutlineStyle::BorderStyle(ref style) => style.none_or_hidden(),
50        }
51    }
52}
53
54impl Parse for OutlineStyle {
55    fn parse<'i, 't>(
56        _context: &ParserContext,
57        input: &mut Parser<'i, 't>,
58    ) -> Result<OutlineStyle, ParseError<'i>> {
59        if let Ok(border_style) = input.try_parse(BorderStyle::parse) {
60            if let BorderStyle::Hidden = border_style {
61                return Err(input
62                    .new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into())));
63            }
64
65            return Ok(OutlineStyle::BorderStyle(border_style));
66        }
67
68        input.expect_ident_matching("auto")?;
69        Ok(OutlineStyle::Auto)
70    }
71}