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 owning_ref;
76
extern crate parking_lot;
77
extern crate precomputed_hash;
78
extern crate rayon;
79
extern crate selectors;
80
#[macro_use]
81
extern crate serde;
82
pub extern crate servo_arc;
83
#[cfg(feature = "servo")]
84
#[macro_use]
85
extern crate servo_atoms;
86
#[cfg(feature = "servo")]
87
extern crate servo_config;
88
#[cfg(feature = "servo")]
89
extern crate servo_url;
90
extern crate smallbitvec;
91
extern crate smallvec;
92
#[cfg(feature = "gecko")]
93
extern crate static_prefs;
94
#[cfg(feature = "servo")]
95
extern crate string_cache;
96
#[macro_use]
97
extern crate style_derive;
98
extern crate style_traits;
99
#[cfg(feature = "gecko")]
100
extern crate thin_slice;
101
extern crate time;
102
extern crate to_shmem;
103
#[macro_use]
104
extern crate to_shmem_derive;
105
extern crate uluru;
106
extern crate unicode_bidi;
107
#[allow(unused_extern_crates)]
108
extern crate unicode_segmentation;
109
extern crate void;
110
111
#[macro_use]
112
mod macros;
113
114
pub mod animation;
115
pub mod applicable_declarations;
116
#[allow(missing_docs)] // TODO.
117
#[cfg(feature = "servo")]
118
pub mod attr;
119
pub mod author_styles;
120
pub mod bezier;
121
pub mod bloom;
122
#[path = "properties/computed_value_flags.rs"]
123
pub mod computed_value_flags;
124
pub mod context;
125
pub mod counter_style;
126
pub mod custom_properties;
127
pub mod data;
128
pub mod dom;
129
pub mod dom_apis;
130
pub mod driver;
131
pub mod element_state;
132
#[cfg(feature = "servo")]
133
mod encoding_support;
134
pub mod error_reporting;
135
pub mod font_face;
136
pub mod font_metrics;
137
#[cfg(feature = "gecko")]
138
#[allow(unsafe_code)]
139
pub mod gecko_bindings;
140
pub mod global_style_data;
141
pub mod hash;
142
pub mod invalidation;
143
#[allow(missing_docs)] // TODO.
144
pub mod logical_geometry;
145
pub mod matching;
146
#[macro_use]
147
pub mod media_queries;
148
pub mod parallel;
149
pub mod parser;
150
pub mod rule_cache;
151
pub mod rule_collector;
152
pub mod rule_tree;
153
pub mod scoped_tls;
154
pub mod selector_map;
155
pub mod selector_parser;
156
pub mod shared_lock;
157
pub mod sharing;
158
pub mod str;
159
pub mod style_adjuster;
160
pub mod style_resolver;
161
pub mod stylesheet_set;
162
pub mod stylesheets;
163
pub mod stylist;
164
pub mod thread_state;
165
pub mod timer;
166
pub mod traversal;
167
pub mod traversal_flags;
168
pub mod use_counters;
169
#[macro_use]
170
#[allow(non_camel_case_types)]
171
pub mod values;
172
173
#[cfg(feature = "gecko")]
174
pub use crate::gecko_string_cache as string_cache;
175
#[cfg(feature = "gecko")]
176
pub use crate::gecko_string_cache::Atom;
177
/// The namespace prefix type for Gecko, which is just an atom.
178
#[cfg(feature = "gecko")]
179
pub type Prefix = crate::gecko_string_cache::Atom;
180
/// The local name of an element for Gecko, which is just an atom.
181
#[cfg(feature = "gecko")]
182
pub type LocalName = crate::gecko_string_cache::Atom;
183
#[cfg(feature = "gecko")]
184
pub use crate::gecko_string_cache::Namespace;
185
186
#[cfg(feature = "servo")]
187
pub use html5ever::LocalName;
188
#[cfg(feature = "servo")]
189
pub use html5ever::Namespace;
190
#[cfg(feature = "servo")]
191
pub use html5ever::Prefix;
192
#[cfg(feature = "servo")]
193
pub use servo_atoms::Atom;
194
195
pub use style_traits::arc_slice::ArcSlice;
196
pub use style_traits::owned_slice::OwnedSlice;
197
pub use style_traits::owned_str::OwnedStr;
198
199
/// The CSS properties supported by the style system.
200
/// Generated from the properties.mako.rs template by build.rs
201
#[macro_use]
202
#[allow(unsafe_code)]
203
#[deny(missing_docs)]
204
pub mod properties {
205
include!(concat!(env!("OUT_DIR"), "/properties.rs"));
206
}
207
208
#[cfg(feature = "gecko")]
209
#[allow(unsafe_code)]
210
pub mod gecko;
211
212
// uses a macro from properties
213
#[cfg(feature = "servo")]
214
#[allow(unsafe_code)]
215
pub mod servo;
216
217
#[cfg(feature = "gecko")]
218
#[allow(unsafe_code, missing_docs)]
219
pub mod gecko_properties {
220
include!(concat!(env!("OUT_DIR"), "/gecko_properties.rs"));
221
}
222
223
macro_rules! reexport_computed_values {
224
( $( { $name: ident, $boxed: expr } )+ ) => {
225
/// Types for [computed values][computed].
226
///
228
pub mod computed_values {
229
$(
230
pub use crate::properties::longhands::$name::computed_value as $name;
231
)+
232
// Don't use a side-specific name needlessly:
233
pub use crate::properties::longhands::border_top_style::computed_value as border_style;
234
}
235
}
236
}
237
longhand_properties_idents!(reexport_computed_values);
238
239
#[cfg(feature = "gecko")]
240
use crate::gecko_string_cache::WeakAtom;
241
#[cfg(feature = "servo")]
242
use servo_atoms::Atom as WeakAtom;
243
244
/// Extension methods for selectors::attr::CaseSensitivity
245
pub trait CaseSensitivityExt {
246
/// Return whether two atoms compare equal according to this case sensitivity.
247
fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool;
248
}
249
250
impl CaseSensitivityExt for selectors::attr::CaseSensitivity {
251
fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool {
252
match self {
253
selectors::attr::CaseSensitivity::CaseSensitive => a == b,
254
selectors::attr::CaseSensitivity::AsciiCaseInsensitive => a.eq_ignore_ascii_case(b),
255
}
256
}
257
}
258
259
/// A trait pretty much similar to num_traits::Zero, but without the need of
260
/// implementing `Add`.
261
pub trait Zero {
262
/// Returns the zero value.
263
fn zero() -> Self;
264
265
/// Returns whether this value is zero.
266
fn is_zero(&self) -> bool;
267
}
268
269
impl<T> Zero for T
270
where
271
T: num_traits::Zero,
272
{
273
fn zero() -> Self {
274
<Self as num_traits::Zero>::zero()
275
}
276
277
fn is_zero(&self) -> bool {
278
<Self as num_traits::Zero>::is_zero(self)
279
}
280
}