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