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