/* 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/. */
/// Trait to check if the value of a potentially-tree-scoped type T /// is actually tree-scoped. e.g. `none` value of `anchor-scope` should /// not be tree-scoped. pubtrait IsTreeScoped { /// Returns true if the current value should be considered tree-scoped. /// Default implementation assumes that the value is always tree-scoped. fn is_tree_scoped(&self) -> bool { true
}
}
/// A generic type for representing a value scoped to a specific cascade level /// in the shadow tree hierarchy. #[repr(C)] #[derive(
Clone,
Copy,
Debug,
MallocSizeOf,
SpecifiedValueInfo,
ToAnimatedValue,
ToCss,
ToResolvedValue,
ToShmem,
ToTyped,
Serialize,
Deserialize,
)] pubstruct TreeScoped<T> { /// The scoped value. pub value: T, /// The cascade level in the shadow tree hierarchy. #[css(skip)] pub scope: CascadeLevel,
}
impl<T: IsTreeScoped + PartialEq> PartialEq for TreeScoped<T> { fn eq(&self, other: &Self) -> bool { let tree_scoped = self.value.is_tree_scoped(); if tree_scoped != other.value.is_tree_scoped() { // Trivially different. returnfalse;
} let scopes_equal = self.scope == other.scope; if !scopes_equal && tree_scoped { // Scope difference matters if the name is actually tree-scoped. returnfalse;
} // Ok, do the actual value comparison. self.value == other.value
}
}
/// Creates a new `TreeScoped` value with the default cascade level /// (same tree author normal). pubfn with_default_level(value: T) -> Self { Self {
value,
scope: CascadeLevel::same_tree_author_normal(),
}
}
}
/// Implements a method that checks if the position is centered. pubtrait PositionComponent { /// Returns if the position component is 50% or center. /// For pixel lengths, it always returns false. fn is_center(&self) -> bool;
}
/// A generic type for representing an `Auto | <position>`. /// This is used by <offset-anchor> for now. /// https://drafts.fxtf.org/motion-1/#offset-anchor-property #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Deserialize,
MallocSizeOf,
Parse,
PartialEq,
Serialize,
SpecifiedValueInfo,
ToAnimatedZero,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
ToTyped,
)] #[repr(C, u8)] pubenum GenericPositionOrAuto<Pos> { /// The <position> value.
Position(Pos), /// The keyword `auto`.
Auto,
}
pubuseself::GenericPositionOrAuto as PositionOrAuto;
/// Returns the integer value if it is an integer, or `auto`. #[inline] pubfn integer_or(self, auto: Integer) -> Integer { matchself {
ZIndex::Integer(n) => n,
ZIndex::Auto => auto,
}
}
}
/// Ratio or None. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)] #[repr(C, u8)] pubenum PreferredRatio<N> { /// Without specified ratio #[css(skip)]
None, /// With specified ratio
Ratio( #[animation(field_bound)] #[css(field_bound)] #[distance(field_bound)]
Ratio<N>,
),
}
/// A generic value for the `aspect-ratio` property, the value is `auto || <ratio>`. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
ToTyped,
)] #[repr(C)] #[typed(todo_derive_fields)] pubstruct GenericAspectRatio<N> { /// Specifiy auto or not. #[animation(constant)] #[css(represents_keyword)] pub auto: bool, /// The preferred aspect-ratio value. #[animation(field_bound)] #[css(field_bound)] #[distance(field_bound)] pub ratio: PreferredRatio<N>,
}
/// Specified type for `inset` properties, which allows /// the use of the `anchor()` function. /// Note(dshin): `LengthPercentageOrAuto` is not used here because /// having `LengthPercentageOrAuto` and `AnchorFunction` in the enum /// pays the price of the discriminator for `LengthPercentage | Auto` /// as well as `LengthPercentageOrAuto | AnchorFunction`. This increases /// the size of the style struct, which would not be great. /// On the other hand, we trade for code duplication, so... :( #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
ToCss,
ToShmem,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
ToTyped,
)] #[repr(C)] pubenum GenericInset<P, LP> { /// A `<length-percentage>` value.
LengthPercentage(LP), /// An `auto` value.
Auto, /// Inset defined by the anchor element. /// /// <https://drafts.csswg.org/css-anchor-position-1/#anchor-pos>
AnchorFunction(Box<GenericAnchorFunction<P, Self>>), /// Inset defined by the size of the anchor element. /// /// <https://drafts.csswg.org/css-anchor-position-1/#anchor-pos>
AnchorSizeFunction(Box<GenericAnchorSizeFunction<Self>>), /// A `<length-percentage>` value, guaranteed to contain `calc()`, /// which then is guaranteed to contain `anchor()` or `anchor-size()`.
AnchorContainingCalcFunction(LP),
}
impl<P, LP> SpecifiedValueInfo for GenericInset<P, LP> where
LP: SpecifiedValueInfo,
{ fn collect_completion_keywords(f: style_traits::KeywordsCollectFn) {
LP::collect_completion_keywords(f);
f(&["auto"]); if static_prefs::pref!("layout.css.anchor-positioning.enabled") {
f(&["anchor", "anchor-size"]);
}
}
}
/// Return true if it is 'auto'. #[inline] #[cfg(feature = "servo")] pubfn is_auto(&self) -> bool {
matches!(self, Self::Auto)
}
}
pubuseself::GenericInset as Inset;
/// Anchor function used by inset properties. This resolves /// to length at computed time. /// /// https://drafts.csswg.org/css-anchor-position-1/#funcdef-anchor #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToShmem,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
Serialize,
Deserialize,
ToTyped,
)] #[repr(C)] #[typed(todo_derive_fields)] pubstruct GenericAnchorFunction<Percentage, Fallback> { /// Anchor name of the element to anchor to. /// If omitted, selects the implicit anchor element. /// The shadow cascade order of the tree-scoped anchor name /// associates the name with the host of the originating stylesheet. #[animation(constant)] pub target_element: TreeScoped<DashedIdent>, /// Where relative to the target anchor element to position /// the anchored element to. pub side: GenericAnchorSide<Percentage>, /// Value to use in case the anchor function is invalid. pub fallback: Optional<Fallback>,
}
impl<Percentage, Fallback> GenericAnchorFunction<Percentage, Fallback> { /// Is the anchor valid for given property? pubfn valid_for(&self, side: PhysicalSide, position_property: PositionProperty) -> bool {
position_property.is_absolutely_positioned() && self.side.valid_for(side)
}
}
/// Keyword values for the anchor positioning function. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToShmem,
Parse,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
Serialize,
Deserialize,
)] #[repr(u8)] pubenum AnchorSideKeyword { /// Inside relative (i.e. Same side) to the inset property it's used in.
Inside, /// Same as above, but outside (i.e. Opposite side).
Outside, /// Top of the anchor element.
Top, /// Left of the anchor element.
Left, /// Right of the anchor element.
Right, /// Bottom of the anchor element.
Bottom, /// Refers to the start side of the anchor element for the same axis of the inset /// property it's used in, resolved against the positioned element's containing /// block's writing mode.
Start, /// Same as above, but for the end side.
End, /// Same as `start`, resolved against the positioned element's writing mode.
SelfStart, /// Same as above, but for the end side.
SelfEnd, /// Halfway between `start` and `end` sides.
Center,
}
/// Anchor side for the anchor positioning function. #[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToCss,
ToShmem,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
Serialize,
Deserialize,
)] #[repr(C)] pubenum GenericAnchorSide<P> { /// A keyword value for the anchor side.
Keyword(AnchorSideKeyword), /// Percentage value between the `start` and `end` sides.
Percentage(P),
}
impl<P> GenericAnchorSide<P> { /// Is this anchor side valid for a given side? pubfn valid_for(&self, side: PhysicalSide) -> bool { matchself { Self::Keyword(k) => k.valid_for(side), Self::Percentage(_) => true,
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet am 2026-08-25)
¤
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.