tor-browser

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

column.mako.rs (4058B)


      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="columns"
      8                    engines="gecko servo"
      9                    sub_properties="column-width column-count"
     10                    servo_pref="layout.columns.enabled"
     11                    spec="https://drafts.csswg.org/css-multicol/#propdef-columns">
     12    use crate::properties::longhands::{column_count, column_width};
     13 
     14    pub fn parse_value<'i, 't>(
     15        context: &ParserContext,
     16        input: &mut Parser<'i, 't>,
     17    ) -> Result<Longhands, ParseError<'i>> {
     18        let mut column_count = None;
     19        let mut column_width = None;
     20        let mut autos = 0;
     21 
     22        loop {
     23            if input.try_parse(|input| input.expect_ident_matching("auto")).is_ok() {
     24                // Leave the options to None, 'auto' is the initial value.
     25                autos += 1;
     26                continue
     27            }
     28 
     29            if column_count.is_none() {
     30                if let Ok(value) = input.try_parse(|input| column_count::parse(context, input)) {
     31                    column_count = Some(value);
     32                    continue
     33                }
     34            }
     35 
     36            if column_width.is_none() {
     37                if let Ok(value) = input.try_parse(|input| column_width::parse(context, input)) {
     38                    column_width = Some(value);
     39                    continue
     40                }
     41            }
     42 
     43            break
     44        }
     45 
     46        let values = autos + column_count.iter().len() + column_width.iter().len();
     47        if values == 0 || values > 2 {
     48            Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
     49        } else {
     50            Ok(expanded! {
     51                column_count: unwrap_or_initial!(column_count),
     52                column_width: unwrap_or_initial!(column_width),
     53            })
     54        }
     55    }
     56 
     57    impl<'a> ToCss for LonghandsToSerialize<'a> {
     58        fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
     59            if self.column_width.is_auto() {
     60                return self.column_count.to_css(dest)
     61            }
     62            self.column_width.to_css(dest)?;
     63            if !self.column_count.is_auto() {
     64                dest.write_char(' ')?;
     65                self.column_count.to_css(dest)?;
     66            }
     67            Ok(())
     68        }
     69    }
     70 </%helpers:shorthand>
     71 
     72 <%helpers:shorthand
     73    name="column-rule"
     74    engines="gecko"
     75    sub_properties="column-rule-width column-rule-style column-rule-color"
     76    derive_serialize="True"
     77    spec="https://drafts.csswg.org/css-multicol/#propdef-column-rule"
     78 >
     79    use crate::properties::longhands::{column_rule_width, column_rule_style};
     80    use crate::properties::longhands::column_rule_color;
     81 
     82    pub fn parse_value<'i, 't>(
     83        context: &ParserContext,
     84        input: &mut Parser<'i, 't>,
     85    ) -> Result<Longhands, ParseError<'i>> {
     86        % for name in "width style color".split():
     87        let mut column_rule_${name} = None;
     88        % endfor
     89        let mut any = false;
     90 
     91        loop {
     92            % for name in "width style color".split():
     93            if column_rule_${name}.is_none() {
     94                if let Ok(value) = input.try_parse(|input|
     95                        column_rule_${name}::parse(context, input)) {
     96                    column_rule_${name} = Some(value);
     97                    any = true;
     98                    continue
     99                }
    100            }
    101            % endfor
    102 
    103            break
    104        }
    105        if any {
    106            Ok(expanded! {
    107                column_rule_width: unwrap_or_initial!(column_rule_width),
    108                column_rule_style: unwrap_or_initial!(column_rule_style),
    109                column_rule_color: unwrap_or_initial!(column_rule_color),
    110            })
    111        } else {
    112            Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
    113        }
    114    }
    115 </%helpers:shorthand>