/
position.mako.rs
105 lines (97 loc) · 3.16 KB
/
position.mako.rs
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
/* 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 http://mozilla.org/MPL/2.0/. */
<%namespace name="helpers" file="/helpers.mako.rs" />
<%helpers:shorthand name="flex-flow" sub_properties="flex-direction flex-wrap"
experimental="True">
use properties::longhands::{flex_direction, flex_wrap};
let mut direction = None;
let mut wrap = None;
let mut any = false;
loop {
if direction.is_none() {
if let Ok(value) = input.try(|input| flex_direction::parse(context, input)) {
direction = Some(value);
any = true;
continue
}
}
if wrap.is_none() {
if let Ok(value) = input.try(|input| flex_wrap::parse(context, input)) {
wrap = Some(value);
any = true;
continue
}
}
break
}
if any {
Ok(Longhands {
flex_direction: direction,
flex_wrap: wrap,
})
} else {
Err(())
}
</%helpers:shorthand>
<%helpers:shorthand name="flex" sub_properties="flex-grow flex-shrink flex-basis"
experimental="True">
use app_units::Au;
use values::specified::{Number, Length, LengthOrPercentageOrAutoOrContent};
pub fn parse_flexibility(input: &mut Parser)
-> Result<(Option<Number>, Option<Number>),()> {
let grow = Some(try!(Number::parse_non_negative(input)));
let shrink = input.try(Number::parse_non_negative).ok();
Ok((grow, shrink))
}
let mut grow = None;
let mut shrink = None;
let mut basis = None;
let mut any = false;
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
return Ok(Longhands {
flex_grow: Some(Number(0.0)),
flex_shrink: Some(Number(0.0)),
flex_basis: Some(LengthOrPercentageOrAutoOrContent::Auto)
})
}
loop {
if grow.is_none() {
if let Ok((flex_grow, flex_shrink)) = input.try(parse_flexibility) {
grow = flex_grow;
shrink = flex_shrink;
any = true;
continue
}
}
if basis.is_none() {
if let Ok(value) = input.try(LengthOrPercentageOrAutoOrContent::parse) {
basis = Some(value);
any = true;
continue
}
}
break
}
if any {
if grow == None {
grow = Some(Number(1.0));
}
if shrink == None && basis == None {
basis = Some(LengthOrPercentageOrAutoOrContent::Length(Length::Absolute(Au(0))));
}
if shrink == None {
shrink = Some(Number(1.0));
}
if basis == None {
basis = Some(LengthOrPercentageOrAutoOrContent::Auto);
}
Ok(Longhands {
flex_grow: grow,
flex_shrink: shrink,
flex_basis: basis,
})
} else {
Err(())
}
</%helpers:shorthand>