servo/components/style/values/generics/box.rs
Ting-Yu Lin 3da52edffc style: Run "cargo +nightly fmt" for style components in servo
The directories changed:
* servo/components/selectors/
* servo/components/style/
* servo/components/style_derive/
* servo/ports/geckolib/

Per review request, disable rustfmt in `components_to_transform_3d_matrix()` to
preserve the format for a call to `Transform3D::new`.

My mozilla-central is at
https://hg.mozilla.org/mozilla-central/rev/d1ae84015c22f2034435b47194fdced878072035

My nightly rust is 1.66.0-nightly (8b705839c 2022-09-26).

Differential Revision: https://phabricator.services.mozilla.com/D158234
2023-11-03 08:59:49 +01:00

229 lines
4.8 KiB
Rust

/* 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<LengthPercentage> {
/// One of the vertical-align keywords.
Keyword(VerticalAlignKeyword),
/// `<length-percentage>`
Length(LengthPercentage),
}
pub use self::GenericVerticalAlign as VerticalAlign;
impl<L> VerticalAlign<L> {
/// Returns `baseline`.
#[inline]
pub fn baseline() -> Self {
VerticalAlign::Keyword(VerticalAlignKeyword::Baseline)
}
}
impl<L> ToAnimatedZero for VerticalAlign<L> {
fn to_animated_zero(&self) -> Result<Self, ()> {
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<L> {
/// The keyword `none`.
None,
/// A non-negative length.
Length(L),
/// "auto <Length>"
AutoLength(L),
}
pub use self::GenericContainIntrinsicSize as ContainIntrinsicSize;
impl<L: ToCss> ToCss for ContainIntrinsicSize<L> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> 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<I>(pub I);
pub use self::GenericLineClamp as LineClamp;
impl<I: crate::Zero> LineClamp<I> {
/// 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<I: crate::Zero + ToCss> ToCss for LineClamp<I> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
if self.is_none() {
return dest.write_str("none");
}
self.0.to_css(dest)
}
}
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
pub enum GenericAnimationIterationCount<Number> {
/// A `<number>` value.
Number(Number),
/// The `infinite` keyword.
Infinite,
}
pub use self::GenericAnimationIterationCount as AnimationIterationCount;
/// 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<NonNegativeLength> {
/// A non-negative length.
Length(NonNegativeLength),
/// The keyword `none`.
None,
}
pub use self::GenericPerspective as Perspective;
impl<L> Perspective<L> {
/// Returns `none`.
#[inline]
pub fn none() -> Self {
Perspective::None
}
}