/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
//! Calculate [specified][specified] and [computed values][computed] from a //! tree of DOM nodes and a set of stylesheets. //! //! [computed]: https://drafts.csswg.org/css-cascade/#computed //! [specified]: https://drafts.csswg.org/css-cascade/#specified //! //! In particular, this crate contains the definitions of supported properties, //! the code to parse them into specified values and calculate the computed //! values based on the specified values, as well as the code to serialize both //! specified and computed values. //! //! The main entry point is [`recalc_style_at`][recalc_style_at]. //! //! [recalc_style_at]: traversal/fn.recalc_style_at.html //! //! Major dependencies are the [cssparser][cssparser] and [selectors][selectors] //! crates. //! //! [cssparser]: ../cssparser/index.html //! [selectors]: ../selectors/index.html
#[cfg(feature = "gecko")] pubusecrate::gecko_string_cache as string_cache; #[cfg(feature = "gecko")] pubusecrate::gecko_string_cache::Atom; /// The namespace prefix type for Gecko, which is just an atom. #[cfg(feature = "gecko")] pubtype Prefix = crate::values::AtomIdent; /// The local name of an element for Gecko, which is just an atom. #[cfg(feature = "gecko")] pubtype LocalName = crate::values::AtomIdent; #[cfg(feature = "gecko")] pubusecrate::gecko_string_cache::Namespace;
// uses a macro from properties #[cfg(feature = "servo")] #[allow(unsafe_code)] pubmod servo;
macro_rules! reexport_computed_values {
( $( { $name: ident } )+ ) => { /// Types for [computed values][computed]. /// /// [computed]: https://drafts.csswg.org/css-cascade/#computed pubmod computed_values {
$( pubusecrate::properties::longhands::$name::computed_value as $name;
)+ // Don't use a side-specific name needlessly: pubusecrate::properties::longhands::border_top_style::computed_value as border_style;
}
}
}
longhand_properties_idents!(reexport_computed_values); #[cfg(feature = "gecko")] usecrate::gecko_string_cache::WeakAtom; #[cfg(feature = "servo")] use servo_atoms::Atom as WeakAtom;
/// Extension methods for selectors::attr::CaseSensitivity pubtrait CaseSensitivityExt { /// Return whether two atoms compare equal according to this case sensitivity. fn eq_atom(self, a: &WeakAtom, b: &WeakAtom) -> bool;
}
/// A trait pretty much similar to num_traits::Zero, but without the need of /// implementing `Add`. pubtrait Zero { /// Returns the zero value. fn zero() -> Self;
/// Returns whether this value is zero. fn is_zero(&self) -> bool;
}
impl<T> Zero for T where
T: num_traits::Zero,
{ fn zero() -> Self {
<Selfas num_traits::Zero>::zero()
}
/// A trait implementing a function to tell if the number is zero without a percent pubtrait ZeroNoPercent { /// So, `0px` should return `true`, but `0%` or `1px` should return `false` fn is_zero_no_percent(&self) -> bool;
}
/// A trait pretty much similar to num_traits::One, but without the need of /// implementing `Mul`. pubtrait One { /// Reutrns the one value. fn one() -> Self;
/// Returns whether this value is one. fn is_one(&self) -> bool;
}
impl<T> One for T where
T: num_traits::One + PartialEq,
{ fn one() -> Self {
<Selfas num_traits::One>::one()
}
/// An allocation error. /// /// TODO(emilio): Would be nice to have more information here, or for SmallVec /// to return the standard error type (and then we can just return that). /// /// But given we use these mostly to bail out and ignore them, it's not a big /// deal. #[derive(Debug)] pubstruct AllocErr;
/// Shrink the capacity of the collection if needed. pub(crate) trait ShrinkIfNeeded { fn shrink_if_needed(&mutself);
}
/// We shrink the capacity of a collection if we're wasting more than a 25% of /// its capacity, and if the collection is arbitrarily big enough /// (>= CAPACITY_THRESHOLD entries). #[inline] fn should_shrink(len: usize, capacity: usize) -> bool { const CAPACITY_THRESHOLD: usize = 64;
capacity >= CAPACITY_THRESHOLD && len + capacity / 4 < capacity
}
impl<K, V, H> ShrinkIfNeeded for std::collections::HashMap<K, V, H> where
K: Eq + Hash,
H: BuildHasher,
{ fn shrink_if_needed(&mutself) { if should_shrink(self.len(), self.capacity()) { self.shrink_to_fit();
}
}
}
impl<T, H> ShrinkIfNeeded for std::collections::HashSet<T, H> where
T: Eq + Hash,
H: BuildHasher,
{ fn shrink_if_needed(&mutself) { if should_shrink(self.len(), self.capacity()) { self.shrink_to_fit();
}
}
}
// TODO(emilio): Measure and see if we're wasting a lot of memory on Vec / // SmallVec, and if so consider shrinking those as well.
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.