1#![deny(missing_docs)]
29
30#[macro_use]
31extern crate bitflags;
32#[macro_use]
33extern crate cssparser;
34#[macro_use]
35extern crate debug_unreachable;
36#[macro_use]
37extern crate derive_more;
38#[macro_use]
39#[cfg(feature = "gecko")]
40extern crate gecko_profiler;
41#[cfg(feature = "gecko")]
42#[macro_use]
43pub mod gecko_string_cache;
44#[macro_use]
45extern crate lazy_static;
46#[macro_use]
47extern crate log;
48#[macro_use]
49extern crate malloc_size_of;
50#[macro_use]
51extern crate malloc_size_of_derive;
52#[cfg(feature = "servo")]
53extern crate web_atoms;
54#[allow(unused_extern_crates)]
55#[macro_use]
56extern crate matches;
57#[cfg(feature = "gecko")]
58pub use nsstring;
59#[cfg(feature = "gecko")]
60extern crate num_cpus;
61#[macro_use]
62extern crate num_derive;
63#[macro_use]
64extern crate serde;
65pub use servo_arc;
66#[cfg(feature = "servo")]
67#[macro_use]
68extern crate stylo_atoms;
69#[macro_use]
70extern crate static_assertions;
71#[macro_use]
72extern crate style_derive;
73#[cfg(feature = "gecko")]
74#[macro_use]
75extern crate thin_vec;
76#[macro_use]
77extern crate to_shmem_derive;
78
79#[macro_use]
80mod macros;
81
82pub mod applicable_declarations;
83pub mod author_styles;
84pub mod bezier;
85pub mod bloom;
86pub mod color;
87#[path = "properties/computed_value_flags.rs"]
88pub mod computed_value_flags;
89pub mod context;
90pub mod counter_style;
91pub mod custom_properties;
92pub mod custom_properties_map;
93pub mod data;
94pub mod dom;
95pub mod dom_apis;
96pub mod driver;
97pub mod error_reporting;
98pub mod font_face;
99pub mod font_metrics;
100#[cfg(feature = "gecko")]
101#[allow(unsafe_code)]
102pub mod gecko_bindings;
103pub mod global_style_data;
104pub mod invalidation;
105#[allow(missing_docs)] pub mod logical_geometry;
107pub mod matching;
108pub mod media_queries;
109pub mod parallel;
110pub mod parser;
111pub mod piecewise_linear;
112pub mod properties_and_values;
113#[macro_use]
114pub mod queries;
115pub mod rule_cache;
116pub mod rule_collector;
117pub mod rule_tree;
118pub mod scoped_tls;
119pub mod selector_map;
120pub mod selector_parser;
121pub mod shared_lock;
122pub mod sharing;
123mod simple_buckets_map;
124pub mod str;
125pub mod style_adjuster;
126pub mod style_resolver;
127pub mod stylesheet_set;
128pub mod stylesheets;
129pub mod stylist;
130pub mod thread_state;
131pub mod traversal;
132pub mod traversal_flags;
133pub mod use_counters;
134
135#[macro_use]
136#[allow(non_camel_case_types)]
137pub mod values;
138
139#[cfg(all(doc, feature = "servo"))]
140pub mod docs {
142 pub mod supported_properties {
145 #![doc = include_str!(concat!(env!("OUT_DIR"), "/css-properties.html"))]
146 }
147}
148
149#[cfg(feature = "gecko")]
150pub use crate::gecko_string_cache as string_cache;
151#[cfg(feature = "gecko")]
152pub use crate::gecko_string_cache::Atom;
153#[cfg(feature = "gecko")]
155pub type Prefix = crate::values::AtomIdent;
156#[cfg(feature = "gecko")]
158pub type LocalName = crate::values::AtomIdent;
159#[cfg(feature = "gecko")]
160pub use crate::gecko_string_cache::Namespace;
161
162#[cfg(feature = "servo")]
163pub use stylo_atoms::Atom;
164
165#[cfg(feature = "servo")]
166#[allow(missing_docs)]
167pub type LocalName = crate::values::GenericAtomIdent<web_atoms::LocalNameStaticSet>;
168#[cfg(feature = "servo")]
169#[allow(missing_docs)]
170pub type Namespace = crate::values::GenericAtomIdent<web_atoms::NamespaceStaticSet>;
171#[cfg(feature = "servo")]
172#[allow(missing_docs)]
173pub type Prefix = crate::values::GenericAtomIdent<web_atoms::PrefixStaticSet>;
174
175pub use style_traits::arc_slice::ArcSlice;
176pub use style_traits::owned_slice::OwnedSlice;
177pub use style_traits::owned_str::OwnedStr;
178
179use std::hash::{BuildHasher, Hash};
180
181#[cfg_attr(feature = "servo", macro_use)]
182pub mod properties;
183
184#[cfg(feature = "gecko")]
185#[allow(unsafe_code)]
186pub mod gecko;
187
188#[cfg(feature = "servo")]
190#[allow(unsafe_code)]
191pub mod servo;
192#[cfg(feature = "servo")]
193pub use servo::{animation, attr};
194
195macro_rules! reexport_computed_values {
196 ( $( { $name: ident } )+ ) => {
197 pub mod computed_values {
201 $(
202 pub use crate::properties::longhands::$name::computed_value as $name;
203 )+
204 pub use crate::properties::longhands::border_top_style::computed_value as border_style;
206 }
207 }
208}
209longhand_properties_idents!(reexport_computed_values);
210#[cfg(feature = "gecko")]
211use crate::gecko_string_cache::WeakAtom;
212#[cfg(feature = "servo")]
213use stylo_atoms::Atom as WeakAtom;
214
215pub trait CaseSensitivityExt {
217 fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool;
219}
220
221impl CaseSensitivityExt for selectors::attr::CaseSensitivity {
222 #[inline]
223 fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool {
224 match self {
225 selectors::attr::CaseSensitivity::CaseSensitive => a == b,
226 selectors::attr::CaseSensitivity::AsciiCaseInsensitive => a.eq_ignore_ascii_case(b),
227 }
228 }
229}
230
231pub trait Zero {
234 fn zero() -> Self;
236
237 fn is_zero(&self) -> bool;
239}
240
241impl<T> Zero for T
242where
243 T: num_traits::Zero,
244{
245 fn zero() -> Self {
246 <Self as num_traits::Zero>::zero()
247 }
248
249 fn is_zero(&self) -> bool {
250 <Self as num_traits::Zero>::is_zero(self)
251 }
252}
253
254pub trait ZeroNoPercent {
256 fn is_zero_no_percent(&self) -> bool;
258}
259
260pub trait One {
263 fn one() -> Self;
265
266 fn is_one(&self) -> bool;
268}
269
270impl<T> One for T
271where
272 T: num_traits::One + PartialEq,
273{
274 fn one() -> Self {
275 <Self as num_traits::One>::one()
276 }
277
278 fn is_one(&self) -> bool {
279 *self == One::one()
280 }
281}
282
283#[derive(Debug)]
291pub struct AllocErr;
292
293impl From<smallvec::CollectionAllocErr> for AllocErr {
294 #[inline]
295 fn from(_: smallvec::CollectionAllocErr) -> Self {
296 Self
297 }
298}
299
300impl From<std::collections::TryReserveError> for AllocErr {
301 #[inline]
302 fn from(_: std::collections::TryReserveError) -> Self {
303 Self
304 }
305}
306
307pub(crate) trait ShrinkIfNeeded {
309 fn shrink_if_needed(&mut self);
310}
311
312#[inline]
316fn should_shrink(len: usize, capacity: usize) -> bool {
317 const CAPACITY_THRESHOLD: usize = 64;
318 capacity >= CAPACITY_THRESHOLD && len + capacity / 4 < capacity
319}
320
321impl<K, V, H> ShrinkIfNeeded for std::collections::HashMap<K, V, H>
322where
323 K: Eq + Hash,
324 H: BuildHasher,
325{
326 fn shrink_if_needed(&mut self) {
327 if should_shrink(self.len(), self.capacity()) {
328 self.shrink_to_fit();
329 }
330 }
331}
332
333impl<T, H> ShrinkIfNeeded for std::collections::HashSet<T, H>
334where
335 T: Eq + Hash,
336 H: BuildHasher,
337{
338 fn shrink_if_needed(&mut self) {
339 if should_shrink(self.len(), self.capacity()) {
340 self.shrink_to_fit();
341 }
342 }
343}
344
345