/* 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/. */
//! `<length>` computed values, and related ones.
usesuper::{Context, Number, ToComputedValue}; usecrate::values::animated::{Context as AnimatedContext, ToAnimatedValue}; usecrate::values::computed::{NonNegativeNumber, Zoom}; usecrate::values::generics::length as generics; usecrate::values::generics::length::{
GenericAnchorSizeFunction, GenericLengthOrNumber, GenericLengthPercentageOrNormal,
GenericMaxSize, GenericSize,
}; usecrate::values::generics::NonNegative; usecrate::values::resolved::{Context as ResolvedContext, ToResolvedValue}; usecrate::values::specified::length::{AbsoluteLength, FontBaseSize, LineHeightBase}; usecrate::values::{specified, CSSFloat}; usecrate::Zero; use app_units::Au; use std::fmt::{self, Write}; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub}; use style_traits::{CSSPixel, CssWriter, ToCss};
/// Some boilerplate to share between negative and non-negative /// length-percentage or auto.
macro_rules! computed_length_percentage_or_auto {
($inner:ty) => { /// Returns the used value. #[inline] pubfn to_used_value(&self, percentage_basis: Au) -> Option<Au> { match *self { Self::Auto => None, Self::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
}
}
/// Returns true if the computed value is absolute 0 or 0%. #[inline] pubfn is_definitely_zero(&self) -> bool { usecrate::values::generics::length::LengthPercentageOrAuto::*; match *self {
LengthPercentage(ref l) => l.is_definitely_zero(),
Auto => false,
}
}
};
}
/// A computed type for `<length-percentage> | auto`. pubtype LengthPercentageOrAuto = generics::GenericLengthPercentageOrAuto<LengthPercentage>;
impl LengthPercentageOrAuto { /// Clamps the value to a non-negative value. pubfn clamp_to_non_negative(self) -> Self { usecrate::values::generics::length::LengthPercentageOrAuto::*; matchself {
LengthPercentage(l) => LengthPercentage(l.clamp_to_non_negative()),
Auto => Auto,
}
}
/// Convert to have a borrow inside the enum pubfn as_ref(&self) -> generics::GenericLengthPercentageOrAuto<&LengthPercentage> { usecrate::values::generics::length::LengthPercentageOrAuto::*; match *self {
LengthPercentage(ref lp) => LengthPercentage(lp),
Auto => Auto,
}
}
/// A wrapper of LengthPercentageOrAuto, whose value must be >= 0. pubtype NonNegativeLengthPercentageOrAuto =
generics::GenericLengthPercentageOrAuto<NonNegativeLengthPercentage>;
impl CSSPixelLength { /// Return a new CSSPixelLength. #[inline] pubfn new(px: CSSFloat) -> Self {
CSSPixelLength(px)
}
/// Returns a normalized (NaN turned to zero) version of this length. #[inline] pubfn normalized(self) -> Self { Self::new(crate::values::normalize(self.0))
}
/// Returns a finite (normalized and clamped to float min and max) version of this length. #[inline] pubfn finite(self) -> Self { Self::new(crate::values::normalize(self.0).min(f32::MAX).max(f32::MIN))
}
/// Scale the length by a given amount. #[inline] pubfn scale_by(self, scale: CSSFloat) -> Self {
CSSPixelLength(self.0 * scale)
}
/// Return the length with app_unit i32 type. #[inline] pubfn to_i32_au(self) -> i32 {
Au::from(self).0
}
/// Return the absolute value of this length. #[inline] pubfn abs(self) -> Self {
CSSPixelLength::new(self.0.abs())
}
/// Return the clamped value of this length. #[inline] pubfn clamp_to_non_negative(self) -> Self {
CSSPixelLength::new(self.0.max(0.))
}
/// Returns the minimum between `self` and `other`. #[inline] pubfn min(self, other: Self) -> Self {
CSSPixelLength::new(self.0.min(other.0))
}
/// Returns the maximum between `self` and `other`. #[inline] pubfn max(self, other: Self) -> Self {
CSSPixelLength::new(self.0.max(other.0))
}
/// Sets `self` to the maximum between `self` and `other`. #[inline] pubfn max_assign(&mutself, other: Self) {
*self = self.max(other);
}
/// Clamp the value to a lower bound and an optional upper bound. /// /// Can be used for example with `min-width` and `max-width`. #[inline] pubfn clamp_between_extremums(self, min_size: Self, max_size: Option<Self>) -> Self { self.clamp_below_max(max_size).max(min_size)
}
/// Clamp the value to an optional upper bound. /// /// Can be used for example with `max-width`. #[inline] pubfn clamp_below_max(self, max_size: Option<Self>) -> Self { match max_size {
None => self,
Some(max_size) => self.min(max_size),
}
}
}
/// An alias of computed `<length>` value. pubtype Length = CSSPixelLength;
/// Either a computed `<length>` or the `auto` keyword. pubtype LengthOrAuto = generics::GenericLengthPercentageOrAuto<Length>;
/// Either a non-negative `<length>` or the `auto` keyword. pubtype NonNegativeLengthOrAuto = generics::GenericLengthPercentageOrAuto<NonNegativeLength>;
/// Either a computed `<length>` or a `<number>` value. pubtype LengthOrNumber = GenericLengthOrNumber<Length, Number>;
/// A wrapper of Length, whose value must be >= 0. pubtype NonNegativeLength = NonNegative<Length>;
impl ToAnimatedValue for NonNegativeLength { type AnimatedValue = Length;
impl From<NonNegativeLength> for Au { #[inline] fn from(non_negative_len: NonNegativeLength) -> Self {
Au::from(non_negative_len.0)
}
}
/// Either a computed NonNegativeLengthPercentage or the `normal` keyword. pubtype NonNegativeLengthPercentageOrNormal =
GenericLengthPercentageOrNormal<NonNegativeLengthPercentage>;
/// Either a non-negative `<length>` or a `<number>`. pubtype NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
/// A computed value for `min-width`, `min-height`, `width` or `height` property. pubtype Size = GenericSize<NonNegativeLengthPercentage>;
/// A computed value for `max-width` or `max-height` property. pubtype MaxSize = GenericMaxSize<NonNegativeLengthPercentage>;
/// A computed value for `anchor-size` runction. pubtype AnchorSizeFunction = GenericAnchorSizeFunction<LengthPercentage>;
/// A computed type for `margin` properties. pubtype Margin = generics::GenericMargin<LengthPercentage>;
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-06-19)
¤
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.