/
inherited_box.mako.rs
235 lines (203 loc) · 9.06 KB
/
inherited_box.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* 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" />
<% data.new_style_struct("InheritedBox", inherited=True, gecko_name="Visibility") %>
// TODO: collapse. Well, do tables first.
${helpers.single_keyword("visibility",
"visible hidden",
extra_gecko_values="collapse",
gecko_ffi_name="mVisible",
animatable=True,
spec="https://drafts.csswg.org/css-box/#propdef-visibility")}
// CSS Writing Modes Level 3
// https://drafts.csswg.org/css-writing-modes-3
${helpers.single_keyword("writing-mode",
"horizontal-tb vertical-rl vertical-lr",
experimental=True,
need_clone=True,
animatable=False,
spec="https://drafts.csswg.org/css-writing-modes/#propdef-writing-mode")}
${helpers.single_keyword("direction", "ltr rtl", need_clone=True, animatable=False,
spec="https://drafts.csswg.org/css-writing-modes/#propdef-direction")}
// FIXME(SimonSapin): Add 'mixed' and 'upright' (needs vertical text support)
// FIXME(SimonSapin): initial (first) value should be 'mixed', when that's implemented
// FIXME(bholley): sideways-right is needed as an alias to sideways in gecko.
${helpers.single_keyword("text-orientation",
"sideways",
experimental=True,
need_clone=True,
extra_gecko_values="mixed upright",
extra_servo_values="sideways-right sideways-left",
animatable=False,
spec="https://drafts.csswg.org/css-writing-modes/#propdef-text-orientation")}
// CSS Color Module Level 4
// https://drafts.csswg.org/css-color/
${helpers.single_keyword("color-adjust",
"economy exact", products="gecko",
animatable=False,
spec="https://drafts.csswg.org/css-color/#propdef-color-adjust")}
<% image_rendering_custom_consts = { "crisp-edges": "CRISPEDGES" } %>
// According to to CSS-IMAGES-3, `optimizespeed` and `optimizequality` are synonyms for `auto`
// And, firefox doesn't support `pixelated` yet (https://bugzilla.mozilla.org/show_bug.cgi?id=856337)
${helpers.single_keyword("image-rendering",
"auto crisp-edges",
extra_gecko_values="optimizespeed optimizequality",
extra_servo_values="pixelated",
custom_consts=image_rendering_custom_consts,
animatable=False,
spec="https://drafts.csswg.org/css-images/#propdef-image-rendering")}
// Image Orientation
<%helpers:longhand name="image-orientation"
products="None"
animatable="False"
spec="https://drafts.csswg.org/css-images/#propdef-image-orientation, \
/// additional values in https://developer.mozilla.org/en-US/docs/Web/CSS/image-orientation">
use std::fmt;
use style_traits::ToCss;
use values::specified::Angle;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
use std::f32::consts::PI;
use values::CSSFloat;
const TWO_PI: CSSFloat = 2.0*PI;
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue {
pub angle: Option<Angle>,
pub flipped: bool
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if let Some(angle) = self.angle {
try!(angle.to_css(dest));
if self.flipped {
dest.write_str(" flipped")
} else {
Ok(())
}
} else {
if self.flipped {
dest.write_str("flipped")
} else {
dest.write_str("from-image")
}
}
}
}
pub mod computed_value {
use values::specified::Angle;
#[derive(Clone, PartialEq, Copy, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum T {
FromImage,
AngleWithFlipped(Angle, bool),
}
}
const INITIAL_ANGLE: Angle = Angle(0.0);
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T::AngleWithFlipped(INITIAL_ANGLE, false)
}
// According to CSS Content Module Level 3:
// The computed value of the property is calculated by rounding the specified angle
// to the nearest quarter-turn, rounding away from 0, then moduloing the value by 1 turn.
#[inline]
fn normalize_angle(angle: &Angle) -> Angle {
let radians = angle.radians();
let rounded_quarter_turns = (4.0 * radians / TWO_PI).round();
let normalized_quarter_turns = (rounded_quarter_turns % 4.0 + 4.0) % 4.0;
let normalized_radians = normalized_quarter_turns/4.0 * TWO_PI;
Angle::from_radians(normalized_radians)
}
impl ToComputedValue for SpecifiedValue {
type ComputedValue = computed_value::T;
#[inline]
fn to_computed_value(&self, _: &Context) -> computed_value::T {
if let Some(ref angle) = self.angle {
let normalized_angle = normalize_angle(angle);
computed_value::T::AngleWithFlipped(normalized_angle, self.flipped)
} else {
if self.flipped {
computed_value::T::AngleWithFlipped(INITIAL_ANGLE, true)
} else {
computed_value::T::FromImage
}
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
computed_value::T::FromImage => SpecifiedValue { angle: None, flipped: false },
computed_value::T::AngleWithFlipped(angle, flipped) =>
SpecifiedValue { angle: Some(angle), flipped: flipped },
}
}
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
computed_value::T::FromImage => dest.write_str("from-image"),
computed_value::T::AngleWithFlipped(angle, flipped) => {
try!(angle.to_css(dest));
if flipped {
try!(dest.write_str(" flipped"));
}
Ok(())
},
}
}
}
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
if input.try(|input| input.expect_ident_matching("from-image")).is_ok() {
// Handle from-image
Ok(SpecifiedValue { angle: None, flipped: false })
} else {
// Handle <angle> | <angle>? flip
let angle = input.try(|input| Angle::parse(context, input)).ok();
let flipped = input.try(|input| input.expect_ident_matching("flip")).is_ok();
let explicit_angle = if angle.is_none() && !flipped {
Some(INITIAL_ANGLE)
} else {
angle
};
Ok(SpecifiedValue { angle: explicit_angle, flipped: flipped })
}
}
</%helpers:longhand>
// Used in the bottom-up flow construction traversal to avoid constructing flows for
// descendants of nodes with `display: none`.
<%helpers:longhand name="-servo-under-display-none"
derived_from="display"
products="servo"
animatable="False"
spec="Nonstandard (internal layout use only)">
use std::fmt;
use style_traits::ToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
pub struct SpecifiedValue(pub bool);
pub mod computed_value {
pub type T = super::SpecifiedValue;
}
impl ComputedValueAsSpecified for SpecifiedValue {}
pub fn get_initial_value() -> computed_value::T {
SpecifiedValue(false)
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, _: &mut W) -> fmt::Result where W: fmt::Write {
Ok(()) // Internal property
}
}
#[inline]
pub fn derive_from_display(context: &mut Context) {
use super::display::computed_value::T as Display;
if context.style().get_box().clone_display() == Display::none {
context.mutate_style().mutate_inheritedbox()
.set__servo_under_display_none(SpecifiedValue(true));
}
}
</%helpers:longhand>