Skip to main content

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