Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5
//! Calculate [specified][specified] and [computed values][computed] from a
6
//! tree of DOM nodes and a set of stylesheets.
7
//!
10
//!
11
//! In particular, this crate contains the definitions of supported properties,
12
//! the code to parse them into specified values and calculate the computed
13
//! values based on the specified values, as well as the code to serialize both
14
//! specified and computed values.
15
//!
16
//! The main entry point is [`recalc_style_at`][recalc_style_at].
17
//!
18
//! [recalc_style_at]: traversal/fn.recalc_style_at.html
19
//!
20
//! Major dependencies are the [cssparser][cssparser] and [selectors][selectors]
21
//! crates.
22
//!
23
//! [cssparser]: ../cssparser/index.html
24
//! [selectors]: ../selectors/index.html
25
26
#![deny(missing_docs)]
27
28
extern crate app_units;
29
extern crate arrayvec;
30
extern crate atomic_refcell;
31
#[macro_use]
32
extern crate bitflags;
33
#[allow(unused_extern_crates)]
34
extern crate byteorder;
35
#[cfg(feature = "servo")]
36
extern crate crossbeam_channel;
37
#[macro_use]
38
extern crate cssparser;
39
#[macro_use]
40
extern crate debug_unreachable;
41
#[macro_use]
42
extern crate derive_more;
43
extern crate euclid;
44
extern crate fallible;
45
extern crate fxhash;
46
#[cfg(feature = "gecko")]
47
#[macro_use]
48
pub mod gecko_string_cache;
49
extern crate hashglobe;
50
#[cfg(feature = "servo")]
51
#[macro_use]
52
extern crate html5ever;
53
extern crate indexmap;
54
extern crate itertools;
55
extern crate itoa;
56
#[macro_use]
57
extern crate lazy_static;
58
#[macro_use]
59
extern crate log;
60
#[macro_use]
61
extern crate malloc_size_of;
62
#[macro_use]
63
extern crate malloc_size_of_derive;
64
#[allow(unused_extern_crates)]
65
#[macro_use]
66
extern crate matches;
67
#[cfg(feature = "gecko")]
68
pub extern crate nsstring;
69
#[cfg(feature = "gecko")]
70
extern crate num_cpus;
71
#[macro_use]
72
extern crate num_derive;
73
extern crate num_integer;
74
extern crate num_traits;
75
extern crate ordered_float;
76
extern crate owning_ref;
77
extern crate parking_lot;
78
extern crate precomputed_hash;
79
extern crate rayon;
80
extern crate selectors;
81
#[macro_use]
82
extern crate serde;
83
pub extern crate servo_arc;
84
#[cfg(feature = "servo")]
85
#[macro_use]
86
extern crate servo_atoms;
87
#[cfg(feature = "servo")]
88
extern crate servo_config;
89
#[cfg(feature = "servo")]
90
extern crate servo_url;
91
extern crate smallbitvec;
92
extern crate smallvec;
93
#[cfg(feature = "gecko")]
94
extern crate static_prefs;
95
#[cfg(feature = "servo")]
96
extern crate string_cache;
97
#[macro_use]
98
extern crate style_derive;
99
extern crate style_traits;
100
#[cfg(feature = "gecko")]
101
extern crate thin_slice;
102
extern crate time;
103
extern crate to_shmem;
104
#[macro_use]
105
extern crate to_shmem_derive;
106
extern crate uluru;
107
extern crate unicode_bidi;
108
#[allow(unused_extern_crates)]
109
extern crate unicode_segmentation;
110
extern crate void;
111
112
#[macro_use]
113
mod macros;
114
115
pub mod animation;
116
pub mod applicable_declarations;
117
#[allow(missing_docs)] // TODO.
118
#[cfg(feature = "servo")]
119
pub mod attr;
120
pub mod author_styles;
121
pub mod bezier;
122
pub mod bloom;
123
pub mod context;
124
pub mod counter_style;
125
pub mod custom_properties;
126
pub mod data;
127
pub mod dom;
128
pub mod dom_apis;
129
pub mod driver;
130
pub mod element_state;
131
#[cfg(feature = "servo")]
132
mod encoding_support;
133
pub mod error_reporting;
134
pub mod font_face;
135
pub mod font_metrics;
136
#[cfg(feature = "gecko")]
137
#[allow(unsafe_code)]
138
pub mod gecko_bindings;
139
pub mod global_style_data;
140
pub mod hash;
141
pub mod invalidation;
142
#[allow(missing_docs)] // TODO.
143
pub mod logical_geometry;
144
pub mod matching;
145
#[macro_use]
146
pub mod media_queries;
147
pub mod parallel;
148
pub mod parser;
149
pub mod rule_cache;
150
pub mod rule_collector;
151
pub mod rule_tree;
152
pub mod scoped_tls;
153
pub mod selector_map;
154
pub mod selector_parser;
155
pub mod shared_lock;
156
pub mod sharing;
157
pub mod str;
158
pub mod style_adjuster;
159
pub mod style_resolver;
160
pub mod stylesheet_set;
161
pub mod stylesheets;
162
pub mod stylist;
163
pub mod thread_state;
164
pub mod timer;
165
pub mod traversal;
166
pub mod traversal_flags;
167
pub mod use_counters;
168
#[macro_use]
169
#[allow(non_camel_case_types)]
170
pub mod values;
171
172
#[cfg(feature = "gecko")]
173
pub use crate::gecko_string_cache as string_cache;
174
#[cfg(feature = "gecko")]
175
pub use crate::gecko_string_cache::Atom;
176
#[cfg(feature = "gecko")]
177
pub use crate::gecko_string_cache::Atom as Prefix;
178
#[cfg(feature = "gecko")]
179
pub use crate::gecko_string_cache::Atom as LocalName;
180
#[cfg(feature = "gecko")]
181
pub use crate::gecko_string_cache::Namespace;
182
183
#[cfg(feature = "servo")]
184
pub use html5ever::LocalName;
185
#[cfg(feature = "servo")]
186
pub use html5ever::Namespace;
187
#[cfg(feature = "servo")]
188
pub use html5ever::Prefix;
189
#[cfg(feature = "servo")]
190
pub use servo_atoms::Atom;
191
192
pub use style_traits::arc_slice::ArcSlice;
193
pub use style_traits::owned_slice::OwnedSlice;
194
pub use style_traits::owned_str::OwnedStr;
195
196
/// The CSS properties supported by the style system.
197
/// Generated from the properties.mako.rs template by build.rs
198
#[macro_use]
199
#[allow(unsafe_code)]
200
#[deny(missing_docs)]
201
pub mod properties {
202
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
203
}
204
205
#[cfg(feature = "gecko")]
206
#[allow(unsafe_code)]
207
pub mod gecko;
208
209
// uses a macro from properties
210
#[cfg(feature = "servo")]
211
#[allow(unsafe_code)]
212
pub mod servo;
213
214
#[cfg(feature = "gecko")]
215
#[allow(unsafe_code, missing_docs)]
216
pub mod gecko_properties {
217
include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs"));
218
}
219
220
macro_rules! reexport_computed_values {
221
( $( { $name: ident, $boxed: expr } )+ ) => {
222
/// Types for [computed values][computed].
223
///
225
pub mod computed_values {
226
$(
227
pub use crate::properties::longhands::$name::computed_value as $name;
228
)+
229
// Don't use a side-specific name needlessly:
230
pub use crate::properties::longhands::border_top_style::computed_value as border_style;
231
}
232
}
233
}
234
longhand_properties_idents!(reexport_computed_values);
235
236
#[cfg(feature = "gecko")]
237
use crate::gecko_string_cache::WeakAtom;
238
#[cfg(feature = "servo")]
239
use servo_atoms::Atom as WeakAtom;
240
241
/// Extension methods for selectors::attr::CaseSensitivity
242
pub trait CaseSensitivityExt {
243
/// Return whether two atoms compare equal according to this case sensitivity.
244
fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool;
245
}
246
247
impl CaseSensitivityExt for selectors::attr::CaseSensitivity {
248
fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool {
249
match self {
250
selectors::attr::CaseSensitivity::CaseSensitive => a == b,
251
selectors::attr::CaseSensitivity::AsciiCaseInsensitive => a.eq_ignore_ascii_case(b),
252
}
253
}
254
}
255
256
/// A trait pretty much similar to num_traits::Zero, but without the need of
257
/// implementing `Add`.
258
pub trait Zero {
259
/// Returns the zero value.
260
fn zero() -> Self;
261
262
/// Returns whether this value is zero.
263
fn is_zero(&self) -> bool;
264
}
265
266
impl<T> Zero for T
267
where
268
T: num_traits::Zero,
269
{
270
fn zero() -> Self {
271
<Self as num_traits::Zero>::zero()
272
}
273
274
fn is_zero(&self) -> bool {
275
<Self as num_traits::Zero>::is_zero(self)
276
}
277
}