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
#![crate_name = "style_traits"]
#![crate_type = "rlib"]
#![deny(unsafe_code, missing_docs)]
extern crate app_units;
#[macro_use] extern crate bitflags;
#[macro_use] extern crate cssparser;
extern crate euclid;
extern crate malloc_size_of;
#[macro_use] extern crate malloc_size_of_derive;
extern crate selectors;
#[cfg(feature = "servo")] #[macro_use] extern crate serde;
#[cfg(feature = "servo")] extern crate webrender_api;
extern crate servo_arc;
#[cfg(feature = "servo")] extern crate servo_atoms;
#[cfg(feature = "servo")] pub use webrender_api::DevicePixel;
use cssparser::{CowRcStr, Token};
use selectors::parser::SelectorParseErrorKind;
#[cfg(feature = "servo")] use servo_atoms::Atom;
#[cfg(not(feature = "servo"))]
#[derive(Clone, Copy, Debug)]
pub enum DevicePixel {}
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize, MallocSizeOf))]
pub struct PinchZoomFactor(f32);
impl PinchZoomFactor {
pub fn new(scale: f32) -> PinchZoomFactor {
PinchZoomFactor(scale)
}
pub fn get(&self) -> f32 {
self.0
}
}
#[derive(Clone, Copy, Debug)]
pub enum CSSPixel {}
pub mod cursor;
#[macro_use]
pub mod values;
#[macro_use]
pub mod viewport;
pub use values::{Comma, CommaWithSpace, OneOrMoreSeparated, Separator, Space, ToCss};
pub type ParseError<'i> = cssparser::ParseError<'i, StyleParseErrorKind<'i>>;
pub type ValueParseError<'i> = cssparser::ParseError<'i, ValueParseErrorKind<'i>>;
#[derive(Clone, Debug, PartialEq)]
pub enum StyleParseErrorKind<'i> {
BadUrlInDeclarationValueBlock(CowRcStr<'i>),
BadStringInDeclarationValueBlock(CowRcStr<'i>),
UnbalancedCloseParenthesisInDeclarationValueBlock,
UnbalancedCloseSquareBracketInDeclarationValueBlock,
UnbalancedCloseCurlyBracketInDeclarationValueBlock,
PropertyDeclarationValueNotExhausted,
UnexpectedDimension(CowRcStr<'i>),
ExpectedIdentifier(Token<'i>),
MediaQueryExpectedFeatureName(CowRcStr<'i>),
MediaQueryExpectedFeatureValue,
RangedExpressionWithNoValue,
UnexpectedFunction(CowRcStr<'i>),
UnexpectedNamespaceRule,
UnexpectedImportRule,
UnexpectedCharsetRule,
UnsupportedAtRule(CowRcStr<'i>),
UnspecifiedError,
UnexpectedTokenWithinNamespace(Token<'i>),
ValueError(ValueParseErrorKind<'i>),
SelectorError(SelectorParseErrorKind<'i>),
UnknownProperty(CowRcStr<'i>),
UnknownVendorProperty,
ExperimentalProperty,
InvalidColor(CowRcStr<'i>, Token<'i>),
InvalidFilter(CowRcStr<'i>, Token<'i>),
OtherInvalidValue(CowRcStr<'i>),
AnimationPropertyInKeyframeBlock,
NotAllowedInPageRule,
}
impl<'i> From<ValueParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: ValueParseErrorKind<'i>) -> Self {
StyleParseErrorKind::ValueError(this)
}
}
impl<'i> From<SelectorParseErrorKind<'i>> for StyleParseErrorKind<'i> {
fn from(this: SelectorParseErrorKind<'i>) -> Self {
StyleParseErrorKind::SelectorError(this)
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ValueParseErrorKind<'i> {
InvalidColor(Token<'i>),
InvalidFilter(Token<'i>),
}
impl<'i> StyleParseErrorKind<'i> {
pub fn new_invalid(name: CowRcStr<'i>, value_error: ParseError<'i>) -> ParseError<'i> {
let variant = match value_error.kind {
cssparser::ParseErrorKind::Custom(StyleParseErrorKind::ValueError(e)) => {
match e {
ValueParseErrorKind::InvalidColor(token) => {
StyleParseErrorKind::InvalidColor(name, token)
}
ValueParseErrorKind::InvalidFilter(token) => {
StyleParseErrorKind::InvalidFilter(name, token)
}
}
}
_ => StyleParseErrorKind::OtherInvalidValue(name),
};
cssparser::ParseError {
kind: cssparser::ParseErrorKind::Custom(variant),
location: value_error.location,
}
}
}
bitflags! {
pub struct ParsingMode: u8 {
const DEFAULT = 0x00;
const ALLOW_UNITLESS_LENGTH = 0x01;
const ALLOW_ALL_NUMERIC_VALUES = 0x02;
}
}
impl ParsingMode {
pub fn allows_unitless_lengths(&self) -> bool {
self.intersects(ParsingMode::ALLOW_UNITLESS_LENGTH)
}
pub fn allows_all_numeric_values(&self) -> bool {
self.intersects(ParsingMode::ALLOW_ALL_NUMERIC_VALUES)
}
}
#[cfg(feature = "servo")]
pub trait SpeculativePainter: Send + Sync {
fn speculatively_draw_a_paint_image(&self, properties: Vec<(Atom, String)>, arguments: Vec<String>);
}