/
inherited_text.mako.rs
118 lines (103 loc) · 4.23 KB
/
inherited_text.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
106
107
108
109
110
111
112
113
114
115
116
117
118
/* 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="text-emphasis" products="gecko" sub_properties="text-emphasis-color
text-emphasis-style"
spec="https://drafts.csswg.org/css-text-decor-3/#text-emphasis-property">
use properties::longhands::{text_emphasis_color, text_emphasis_style};
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let mut color = None;
let mut style = None;
loop {
if color.is_none() {
if let Ok(value) = input.try(|input| text_emphasis_color::parse(context, input)) {
color = Some(value);
continue
}
}
if style.is_none() {
if let Ok(value) = input.try(|input| text_emphasis_style::parse(context, input)) {
style = Some(value);
continue
}
}
break
}
if color.is_some() || style.is_some() {
if style.is_none() {
style = Some(text_emphasis_style::get_initial_specified_value());
}
Ok(Longhands {
text_emphasis_color: color,
text_emphasis_style: style,
})
} else {
Err(())
}
}
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut style_present = false;
if let DeclaredValue::Value(ref value) = *self.text_emphasis_style {
style_present = true;
try!(value.to_css(dest));
}
if let DeclaredValue::Value(ref color) = *self.text_emphasis_color {
if style_present {
try!(write!(dest, " "));
}
try!(color.to_css(dest));
}
Ok(())
}
}
</%helpers:shorthand>
// CSS Compatibility
// https://compat.spec.whatwg.org/
<%helpers:shorthand name="-webkit-text-stroke"
sub_properties="-webkit-text-stroke-color
-webkit-text-stroke-width"
products="gecko"
spec="https://compat.spec.whatwg.org/#the-webkit-text-stroke">
use cssparser::Color as CSSParserColor;
use properties::longhands::{_webkit_text_stroke_color, _webkit_text_stroke_width};
use values::specified::CSSColor;
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
use values::specified::{BorderWidth, Length};
use app_units::Au;
let (mut color, mut width, mut any) = (None, None, false);
% for value in "color width".split():
if ${value}.is_none() {
if let Ok(value) = input.try(|input| _webkit_text_stroke_${value}::parse(context, input)) {
${value} = Some(value);
any = true;
}
}
% endfor
if !any {
return Err(());
}
Ok(Longhands {
_webkit_text_stroke_color: color.or(Some(CSSColor { parsed: CSSParserColor::CurrentColor,
authored: None })),
_webkit_text_stroke_width: width.or(Some(BorderWidth::from_length(Length::Absolute(Au::from_px(0))))),
})
}
impl<'a> LonghandsToSerialize<'a> {
fn to_css_declared<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
let mut style_present = false;
if let DeclaredValue::Value(ref width) = *self._webkit_text_stroke_width {
style_present = true;
try!(width.to_css(dest));
}
if let DeclaredValue::Value(ref color) = *self._webkit_text_stroke_color {
if style_present {
try!(write!(dest, " "));
}
try!(color.to_css(dest));
}
Ok(())
}
}
</%helpers:shorthand>