tor-browser

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

text.mako.rs (4386B)


      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="text-decoration"
      8                    engines="gecko servo"
      9                    sub_properties="text-decoration-color text-decoration-line text-decoration-style
     10                    ${' text-decoration-thickness' if engine == 'gecko' else ''}"
     11                    spec="https://drafts.csswg.org/css-text-decor/#propdef-text-decoration">
     12    use crate::properties::longhands::{text_decoration_color, text_decoration_line, text_decoration_style};
     13 
     14    % if engine == "gecko":
     15        use crate::properties::longhands::text_decoration_thickness;
     16    % endif
     17 
     18    pub fn parse_value<'i, 't>(
     19        context: &ParserContext,
     20        input: &mut Parser<'i, 't>,
     21    ) -> Result<Longhands, ParseError<'i>> {
     22        let (mut line, mut style, mut color, mut any) = (None, None, None, false);
     23        % if engine == "gecko":
     24            let mut thickness = None;
     25        % endif
     26 
     27        loop {
     28            macro_rules! parse_component {
     29                ($value:ident, $module:ident) => (
     30                    if $value.is_none() {
     31                        if let Ok(value) = input.try_parse(|input| $module::parse(context, input)) {
     32                            $value = Some(value);
     33                            any = true;
     34                            continue;
     35                        }
     36                    }
     37                )
     38            }
     39 
     40            parse_component!(line, text_decoration_line);
     41            parse_component!(style, text_decoration_style);
     42            parse_component!(color, text_decoration_color);
     43 
     44            % if engine == "gecko":
     45                parse_component!(thickness, text_decoration_thickness);
     46            % endif
     47 
     48            break;
     49        }
     50 
     51        if !any {
     52            return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
     53        }
     54 
     55        Ok(expanded! {
     56            text_decoration_line: unwrap_or_initial!(text_decoration_line, line),
     57            text_decoration_style: unwrap_or_initial!(text_decoration_style, style),
     58            text_decoration_color: unwrap_or_initial!(text_decoration_color, color),
     59 
     60            % if engine == "gecko":
     61                text_decoration_thickness: unwrap_or_initial!(text_decoration_thickness, thickness),
     62            % endif
     63        })
     64    }
     65 
     66    impl<'a> ToCss for LonghandsToSerialize<'a>  {
     67        #[allow(unused)]
     68        fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
     69            use crate::values::specified::TextDecorationLine;
     70            use crate::values::specified::Color;
     71 
     72            let (is_solid_style, is_current_color) =
     73            (
     74                *self.text_decoration_style == text_decoration_style::SpecifiedValue::Solid,
     75                *self.text_decoration_color == Color::CurrentColor,
     76            );
     77 
     78            % if engine == "gecko":
     79                let is_auto_thickness = self.text_decoration_thickness.is_auto();
     80            % else:
     81                let is_auto_thickness = true;
     82            % endif
     83 
     84 
     85            let mut has_value = false;
     86            let is_none = *self.text_decoration_line == TextDecorationLine::none();
     87            if (is_solid_style && is_current_color && is_auto_thickness) || !is_none {
     88                self.text_decoration_line.to_css(dest)?;
     89                has_value = true;
     90            }
     91 
     92            % if engine == "gecko":
     93            if !is_auto_thickness {
     94                if has_value {
     95                    dest.write_char(' ')?;
     96                }
     97                self.text_decoration_thickness.to_css(dest)?;
     98                has_value = true;
     99            }
    100            % endif
    101 
    102            if !is_solid_style {
    103                if has_value {
    104                    dest.write_char(' ')?;
    105                }
    106                self.text_decoration_style.to_css(dest)?;
    107                has_value = true;
    108            }
    109 
    110            if !is_current_color {
    111                if has_value {
    112                    dest.write_char(' ')?;
    113                }
    114                self.text_decoration_color.to_css(dest)?;
    115                has_value = true;
    116            }
    117 
    118            Ok(())
    119        }
    120    }
    121 </%helpers:shorthand>