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