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 thread_state;
118pub mod traversal;
119pub mod traversal_flags;
120pub mod typed_om;
121pub mod url;
122pub mod use_counters;
123
124#[macro_use]
125#[allow(non_camel_case_types)]
126pub mod values;
127
128#[cfg(all(doc, feature = "servo"))]
129pub mod docs {
131 pub mod supported_properties {
134 #![doc = include_str!(concat!(env!("OUT_DIR"), "/css-properties.html"))]
135 }
136}
137
138#[cfg(feature = "gecko")]
139pub use crate::gecko_string_cache as string_cache;
140#[cfg(feature = "gecko")]
141pub use crate::gecko_string_cache::Atom;
142#[cfg(feature = "gecko")]
144pub type Prefix = crate::values::AtomIdent;
145#[cfg(feature = "gecko")]
147pub type LocalName = crate::values::AtomIdent;
148#[cfg(feature = "gecko")]
149pub use crate::gecko_string_cache::Namespace;
150
151#[cfg(feature = "servo")]
152pub use stylo_atoms::Atom;
153
154#[cfg(feature = "servo")]
155#[allow(missing_docs)]
156pub type LocalName = crate::values::GenericAtomIdent<web_atoms::LocalNameStaticSet>;
157#[cfg(feature = "servo")]
158#[allow(missing_docs)]
159pub type Namespace = crate::values::GenericAtomIdent<web_atoms::NamespaceStaticSet>;
160#[cfg(feature = "servo")]
161#[allow(missing_docs)]
162pub type Prefix = crate::values::GenericAtomIdent<web_atoms::PrefixStaticSet>;
163
164pub use style_traits::arc_slice::ArcSlice;
165pub use style_traits::owned_array::OwnedArray;
166pub use style_traits::owned_slice::OwnedSlice;
167pub use style_traits::owned_str::OwnedStr;
168
169use std::hash::{BuildHasher, Hash};
170
171#[cfg_attr(feature = "servo", macro_use)]
172pub mod properties;
173
174#[cfg(feature = "gecko")]
175#[allow(unsafe_code)]
176pub mod gecko;
177
178#[cfg(feature = "servo")]
180#[allow(unsafe_code)]
181pub mod servo;
182#[cfg(feature = "servo")]
183pub use servo::{animation, attr};
184
185macro_rules! reexport_computed_values {
186 ( $( { $name: ident } )+ ) => {
187 pub mod computed_values {
191 $(
192 pub use crate::properties::longhands::$name::computed_value as $name;
193 )+
194 pub use crate::properties::longhands::border_top_style::computed_value as border_style;
196 }
197 }
198}
199longhand_properties_idents!(reexport_computed_values);
200#[cfg(feature = "gecko")]
201use crate::gecko_string_cache::WeakAtom;
202#[cfg(feature = "servo")]
203use stylo_atoms::Atom as WeakAtom;
204
205pub trait CaseSensitivityExt {
207 fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool;
209}
210
211impl CaseSensitivityExt for selectors::attr::CaseSensitivity {
212 #[inline]
213 fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool {
214 match self {
215 selectors::attr::CaseSensitivity::CaseSensitive => a == b,
216 selectors::attr::CaseSensitivity::AsciiCaseInsensitive => a.eq_ignore_ascii_case(b),
217 }
218 }
219}
220
221pub trait Zero {
224 fn zero() -> Self;
226
227 fn is_zero(&self) -> bool;
229}
230
231impl<T> Zero for T
232where
233 T: num_traits::Zero,
234{
235 fn zero() -> Self {
236 <Self as num_traits::Zero>::zero()
237 }
238
239 fn is_zero(&self) -> bool {
240 <Self as num_traits::Zero>::is_zero(self)
241 }
242}
243
244pub trait ZeroNoPercent {
246 fn is_zero_no_percent(&self) -> bool;
248}
249
250pub trait One {
253 fn one() -> Self;
255
256 fn is_one(&self) -> bool;
258}
259
260impl<T> One for T
261where
262 T: num_traits::One + PartialEq,
263{
264 fn one() -> Self {
265 <Self as num_traits::One>::one()
266 }
267
268 fn is_one(&self) -> bool {
269 *self == One::one()
270 }
271}
272
273#[derive(Debug)]
281pub struct AllocErr;
282
283impl From<smallvec::CollectionAllocErr> for AllocErr {
284 #[inline]
285 fn from(_: smallvec::CollectionAllocErr) -> Self {
286 Self
287 }
288}
289
290impl From<std::collections::TryReserveError> for AllocErr {
291 #[inline]
292 fn from(_: std::collections::TryReserveError) -> Self {
293 Self
294 }
295}
296
297pub(crate) trait ShrinkIfNeeded {
299 fn shrink_if_needed(&mut self);
300}
301
302#[inline]
306fn should_shrink(len: usize, capacity: usize) -> bool {
307 const CAPACITY_THRESHOLD: usize = 64;
308 capacity >= CAPACITY_THRESHOLD && len + capacity / 4 < capacity
309}
310
311impl<K, V, H> ShrinkIfNeeded for std::collections::HashMap<K, V, H>
312where
313 K: Eq + Hash,
314 H: BuildHasher,
315{
316 fn shrink_if_needed(&mut self) {
317 if should_shrink(self.len(), self.capacity()) {
318 self.shrink_to_fit();
319 }
320 }
321}
322
323impl<T, H> ShrinkIfNeeded for std::collections::HashSet<T, H>
324where
325 T: Eq + Hash,
326 H: BuildHasher,
327{
328 fn shrink_if_needed(&mut self) {
329 if should_shrink(self.len(), self.capacity()) {
330 self.shrink_to_fit();
331 }
332 }
333}
334
335