From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- servo/components/style/values/generics/box.rs | 208 ++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 servo/components/style/values/generics/box.rs (limited to 'servo/components/style/values/generics/box.rs') diff --git a/servo/components/style/values/generics/box.rs b/servo/components/style/values/generics/box.rs new file mode 100644 index 0000000000..3cc2b05145 --- /dev/null +++ b/servo/components/style/values/generics/box.rs @@ -0,0 +1,208 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! Generic types for box properties. + +use crate::values::animated::ToAnimatedZero; +use std::fmt::{self, Write}; +use style_traits::{CssWriter, ToCss}; + +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + FromPrimitive, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(u8)] +#[allow(missing_docs)] +pub enum VerticalAlignKeyword { + Baseline, + Sub, + Super, + Top, + TextTop, + Middle, + Bottom, + TextBottom, + #[cfg(feature = "gecko")] + MozMiddleWithBaseline, +} + +/// A generic value for the `vertical-align` property. +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +pub enum GenericVerticalAlign { + /// One of the vertical-align keywords. + Keyword(VerticalAlignKeyword), + /// `` + Length(LengthPercentage), +} + +pub use self::GenericVerticalAlign as VerticalAlign; + +impl VerticalAlign { + /// Returns `baseline`. + #[inline] + pub fn baseline() -> Self { + VerticalAlign::Keyword(VerticalAlignKeyword::Baseline) + } +} + +impl ToAnimatedZero for VerticalAlign { + fn to_animated_zero(&self) -> Result { + Err(()) + } +} + +/// https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToAnimatedValue, + ToAnimatedZero, + ToResolvedValue, + ToShmem, +)] +#[value_info(other_values = "auto")] +#[repr(C, u8)] +pub enum GenericContainIntrinsicSize { + /// The keyword `none`. + None, + /// A non-negative length. + Length(L), + /// "auto " + AutoLength(L), +} + +pub use self::GenericContainIntrinsicSize as ContainIntrinsicSize; + +impl ToCss for ContainIntrinsicSize { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + match *self { + Self::None => dest.write_str("none"), + Self::Length(ref l) => l.to_css(dest), + Self::AutoLength(ref l) => { + dest.write_str("auto ")?; + l.to_css(dest) + }, + } + } +} + +/// Note that we only implement -webkit-line-clamp as a single, longhand +/// property for now, but the spec defines line-clamp as a shorthand for +/// separate max-lines, block-ellipsis, and continue properties. +/// +/// https://drafts.csswg.org/css-overflow-3/#line-clamp +#[derive( + Clone, + ComputeSquaredDistance, + Copy, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToAnimatedValue, + ToAnimatedZero, + ToResolvedValue, + ToShmem, +)] +#[repr(transparent)] +#[value_info(other_values = "none")] +pub struct GenericLineClamp(pub I); + +pub use self::GenericLineClamp as LineClamp; + +impl LineClamp { + /// Returns the `none` value. + pub fn none() -> Self { + Self(crate::Zero::zero()) + } + + /// Returns whether we're the `none` value. + pub fn is_none(&self) -> bool { + self.0.is_zero() + } +} + +impl ToCss for LineClamp { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result + where + W: Write, + { + if self.is_none() { + return dest.write_str("none"); + } + self.0.to_css(dest) + } +} + +/// A generic value for the `perspective` property. +#[derive( + Animate, + Clone, + ComputeSquaredDistance, + Copy, + Debug, + MallocSizeOf, + Parse, + PartialEq, + SpecifiedValueInfo, + ToAnimatedValue, + ToAnimatedZero, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +#[repr(C, u8)] +pub enum GenericPerspective { + /// A non-negative length. + Length(NonNegativeLength), + /// The keyword `none`. + None, +} + +pub use self::GenericPerspective as Perspective; + +impl Perspective { + /// Returns `none`. + #[inline] + pub fn none() -> Self { + Perspective::None + } +} -- cgit v1.2.3