tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

outline.mako.rs (2893B)


      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 <%namespace name="helpers" file="/helpers.mako.rs" />
      6 
      7 <%helpers:shorthand name="outline"
      8                    engines="gecko servo"
      9                    sub_properties="outline-color outline-style outline-width"
     10                    spec="https://drafts.csswg.org/css-ui/#propdef-outline">
     11    use crate::properties::longhands::{outline_color, outline_width, outline_style};
     12    use crate::values::specified;
     13    use crate::parser::Parse;
     14 
     15    pub fn parse_value<'i, 't>(
     16        context: &ParserContext,
     17        input: &mut Parser<'i, 't>,
     18    ) -> Result<Longhands, ParseError<'i>> {
     19        let _unused = context;
     20        let mut color = None;
     21        let mut style = None;
     22        let mut width = None;
     23        let mut any = false;
     24        loop {
     25            if color.is_none() {
     26                if let Ok(value) = input.try_parse(|i| specified::Color::parse(context, i)) {
     27                    color = Some(value);
     28                    any = true;
     29                    continue
     30                }
     31            }
     32            if style.is_none() {
     33                if let Ok(value) = input.try_parse(|input| outline_style::parse(context, input)) {
     34                    style = Some(value);
     35                    any = true;
     36                    continue
     37                }
     38            }
     39            if width.is_none() {
     40                if let Ok(value) = input.try_parse(|input| outline_width::parse(context, input)) {
     41                    width = Some(value);
     42                    any = true;
     43                    continue
     44                }
     45            }
     46            break
     47        }
     48        if any {
     49            Ok(expanded! {
     50                outline_color: unwrap_or_initial!(outline_color, color),
     51                outline_style: unwrap_or_initial!(outline_style, style),
     52                outline_width: unwrap_or_initial!(outline_width, width),
     53            })
     54        } else {
     55            Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
     56        }
     57    }
     58 
     59    impl<'a> ToCss for LonghandsToSerialize<'a>  {
     60        fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
     61            let mut wrote_value = false;
     62 
     63            % for name in "color style width".split():
     64                if *self.outline_${name} != outline_${name}::get_initial_specified_value() {
     65                    if wrote_value {
     66                        dest.write_char(' ')?;
     67                    }
     68                    self.outline_${name}.to_css(dest)?;
     69                    wrote_value = true;
     70                }
     71            % endfor
     72 
     73            if !wrote_value {
     74                self.outline_style.to_css(dest)?;
     75            }
     76 
     77            Ok(())
     78        }
     79    }
     80 </%helpers:shorthand>