style: Minor clean ups on top of the previous patch

Remove now dead Mul implementations. Use Self rather than the whole type
to shrink a bit the code.

Differential Revision: https://phabricator.services.mozilla.com/D173143
This commit is contained in:
Emilio Cobos Álvarez 2023-03-27 08:57:35 +00:00 committed by Martin Robinson
parent 241e6e256f
commit 398df68d38

View file

@ -22,7 +22,6 @@ use crate::{Zero, ZeroNoPercent};
use app_units::Au; use app_units::Au;
use cssparser::{Parser, Token}; use cssparser::{Parser, Token};
use std::cmp; use std::cmp;
use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType; use style_traits::values::specified::AllowedNumericType;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind, CssWriter, ToCss}; use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind, CssWriter, ToCss};
@ -107,7 +106,7 @@ impl FontRelativeLength {
FontRelativeLength::Ch(_) => "ch", FontRelativeLength::Ch(_) => "ch",
FontRelativeLength::Cap(_) => "cap", FontRelativeLength::Cap(_) => "cap",
FontRelativeLength::Ic(_) => "ic", FontRelativeLength::Ic(_) => "ic",
FontRelativeLength::Rem(_) => "rem" FontRelativeLength::Rem(_) => "rem",
} }
} }
@ -141,12 +140,12 @@ impl FontRelativeLength {
fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self { fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self {
match self { match self {
FontRelativeLength::Em(x) => FontRelativeLength::Em(op(*x)), Self::Em(x) => Self::Em(op(*x)),
FontRelativeLength::Ex(x) => FontRelativeLength::Ex(op(*x)), Self::Ex(x) => Self::Ex(op(*x)),
FontRelativeLength::Ch(x) => FontRelativeLength::Ch(op(*x)), Self::Ch(x) => Self::Ch(op(*x)),
FontRelativeLength::Cap(x) => FontRelativeLength::Cap(op(*x)), Self::Cap(x) => Self::Cap(op(*x)),
FontRelativeLength::Ic(x) => FontRelativeLength::Ic(op(*x)), Self::Ic(x) => Self::Ic(op(*x)),
FontRelativeLength::Rem(x) => FontRelativeLength::Rem(op(*x)), Self::Rem(x) => Self::Rem(op(*x)),
} }
} }
@ -526,30 +525,30 @@ impl ViewportPercentageLength {
fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self { fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self {
match self { match self {
ViewportPercentageLength::Vw(x) => ViewportPercentageLength::Vw(op(*x)), Self::Vw(x) => Self::Vw(op(*x)),
ViewportPercentageLength::Svw(x) => ViewportPercentageLength::Svw(op(*x)), Self::Svw(x) => Self::Svw(op(*x)),
ViewportPercentageLength::Lvw(x) => ViewportPercentageLength::Lvw(op(*x)), Self::Lvw(x) => Self::Lvw(op(*x)),
ViewportPercentageLength::Dvw(x) => ViewportPercentageLength::Dvw(op(*x)), Self::Dvw(x) => Self::Dvw(op(*x)),
ViewportPercentageLength::Vh(x) => ViewportPercentageLength::Vh(op(*x)), Self::Vh(x) => Self::Vh(op(*x)),
ViewportPercentageLength::Svh(x) => ViewportPercentageLength::Svh(op(*x)), Self::Svh(x) => Self::Svh(op(*x)),
ViewportPercentageLength::Lvh(x) => ViewportPercentageLength::Lvh(op(*x)), Self::Lvh(x) => Self::Lvh(op(*x)),
ViewportPercentageLength::Dvh(x) => ViewportPercentageLength::Dvh(op(*x)), Self::Dvh(x) => Self::Dvh(op(*x)),
ViewportPercentageLength::Vmin(x) => ViewportPercentageLength::Vmin(op(*x)), Self::Vmin(x) => Self::Vmin(op(*x)),
ViewportPercentageLength::Svmin(x) => ViewportPercentageLength::Svmin(op(*x)), Self::Svmin(x) => Self::Svmin(op(*x)),
ViewportPercentageLength::Lvmin(x) => ViewportPercentageLength::Lvmin(op(*x)), Self::Lvmin(x) => Self::Lvmin(op(*x)),
ViewportPercentageLength::Dvmin(x) => ViewportPercentageLength::Dvmin(op(*x)), Self::Dvmin(x) => Self::Dvmin(op(*x)),
ViewportPercentageLength::Vmax(x) => ViewportPercentageLength::Vmax(op(*x)), Self::Vmax(x) => Self::Vmax(op(*x)),
ViewportPercentageLength::Svmax(x) => ViewportPercentageLength::Svmax(op(*x)), Self::Svmax(x) => Self::Svmax(op(*x)),
ViewportPercentageLength::Lvmax(x) => ViewportPercentageLength::Lvmax(op(*x)), Self::Lvmax(x) => Self::Lvmax(op(*x)),
ViewportPercentageLength::Dvmax(x) => ViewportPercentageLength::Dvmax(op(*x)), Self::Dvmax(x) => Self::Dvmax(op(*x)),
ViewportPercentageLength::Vb(x) => ViewportPercentageLength::Vb(op(*x)), Self::Vb(x) => Self::Vb(op(*x)),
ViewportPercentageLength::Svb(x) => ViewportPercentageLength::Svb(op(*x)), Self::Svb(x) => Self::Svb(op(*x)),
ViewportPercentageLength::Lvb(x) => ViewportPercentageLength::Lvb(op(*x)), Self::Lvb(x) => Self::Lvb(op(*x)),
ViewportPercentageLength::Dvb(x) => ViewportPercentageLength::Dvb(op(*x)), Self::Dvb(x) => Self::Dvb(op(*x)),
ViewportPercentageLength::Vi(x) => ViewportPercentageLength::Vi(op(*x)), Self::Vi(x) => Self::Vi(op(*x)),
ViewportPercentageLength::Svi(x) => ViewportPercentageLength::Svi(op(*x)), Self::Svi(x) => Self::Svi(op(*x)),
ViewportPercentageLength::Lvi(x) => ViewportPercentageLength::Lvi(op(*x)), Self::Lvi(x) => Self::Lvi(op(*x)),
ViewportPercentageLength::Dvi(x) => ViewportPercentageLength::Dvi(op(*x)), Self::Dvi(x) => Self::Dvi(op(*x)),
} }
} }
@ -649,7 +648,7 @@ impl AbsoluteLength {
AbsoluteLength::Mm(_) => "mm", AbsoluteLength::Mm(_) => "mm",
AbsoluteLength::Q(_) => "q", AbsoluteLength::Q(_) => "q",
AbsoluteLength::Pt(_) => "pt", AbsoluteLength::Pt(_) => "pt",
AbsoluteLength::Pc(_) => "pc" AbsoluteLength::Pc(_) => "pc",
} }
} }
@ -675,15 +674,7 @@ impl AbsoluteLength {
} }
fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self { fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self {
match self { Self::Px(op(self.to_px()))
AbsoluteLength::Px(x) => AbsoluteLength::Px(op(*x)),
AbsoluteLength::In(x) => AbsoluteLength::In(op(*x)),
AbsoluteLength::Cm(x) => AbsoluteLength::Cm(op(*x)),
AbsoluteLength::Mm(x) => AbsoluteLength::Mm(op(*x)),
AbsoluteLength::Q(x) => AbsoluteLength::Q(op(*x)),
AbsoluteLength::Pt(x) => AbsoluteLength::Pt(op(*x)),
AbsoluteLength::Pc(x) => AbsoluteLength::Pc(op(*x)),
}
} }
} }
@ -705,15 +696,6 @@ impl PartialOrd for AbsoluteLength {
} }
} }
impl Mul<CSSFloat> for AbsoluteLength {
type Output = Self;
#[inline]
fn mul(self, scalar: CSSFloat) -> Self {
Self::Px(self.to_px() * scalar)
}
}
/// A container query length. /// A container query length.
/// ///
/// <https://drafts.csswg.org/css-contain-3/#container-lengths> /// <https://drafts.csswg.org/css-contain-3/#container-lengths>
@ -759,7 +741,7 @@ impl ContainerRelativeLength {
ContainerRelativeLength::Cqi(_) => "cqi", ContainerRelativeLength::Cqi(_) => "cqi",
ContainerRelativeLength::Cqb(_) => "cqb", ContainerRelativeLength::Cqb(_) => "cqb",
ContainerRelativeLength::Cqmin(_) => "cqmin", ContainerRelativeLength::Cqmin(_) => "cqmin",
ContainerRelativeLength::Cqmax(_) => "cqmax" ContainerRelativeLength::Cqmax(_) => "cqmax",
} }
} }
@ -795,12 +777,12 @@ impl ContainerRelativeLength {
pub(crate) fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self { pub(crate) fn map(&self, mut op: impl FnMut(f32) -> f32) -> Self {
match self { match self {
ContainerRelativeLength::Cqw(x) => ContainerRelativeLength::Cqw(op(*x)), Self::Cqw(x) => Self::Cqw(op(*x)),
ContainerRelativeLength::Cqh(x) => ContainerRelativeLength::Cqh(op(*x)), Self::Cqh(x) => Self::Cqh(op(*x)),
ContainerRelativeLength::Cqi(x) => ContainerRelativeLength::Cqi(op(*x)), Self::Cqi(x) => Self::Cqi(op(*x)),
ContainerRelativeLength::Cqb(x) => ContainerRelativeLength::Cqb(op(*x)), Self::Cqb(x) => Self::Cqb(op(*x)),
ContainerRelativeLength::Cqmin(x) => ContainerRelativeLength::Cqmin(op(*x)), Self::Cqmin(x) => Self::Cqmin(op(*x)),
ContainerRelativeLength::Cqmax(x) => ContainerRelativeLength::Cqmax(op(*x)), Self::Cqmax(x) => Self::Cqmax(op(*x)),
} }
} }
@ -871,21 +853,6 @@ pub enum NoCalcLength {
ServoCharacterWidth(CharacterWidth), ServoCharacterWidth(CharacterWidth),
} }
impl Mul<CSSFloat> for NoCalcLength {
type Output = NoCalcLength;
#[inline]
fn mul(self, scalar: CSSFloat) -> NoCalcLength {
match self {
NoCalcLength::Absolute(v) => NoCalcLength::Absolute(v * scalar),
NoCalcLength::FontRelative(v) => NoCalcLength::FontRelative(v * scalar),
NoCalcLength::ViewportPercentage(v) => NoCalcLength::ViewportPercentage(v * scalar),
NoCalcLength::ContainerRelative(v) => NoCalcLength::ContainerRelative(v * scalar),
NoCalcLength::ServoCharacterWidth(_) => panic!("Can't multiply ServoCharacterWidth!"),
}
}
}
impl NoCalcLength { impl NoCalcLength {
/// Return the unitless, raw value. /// Return the unitless, raw value.
pub fn unitless_value(&self) -> CSSFloat { pub fn unitless_value(&self) -> CSSFloat {
@ -905,7 +872,7 @@ impl NoCalcLength {
NoCalcLength::FontRelative(v) => v.unit(), NoCalcLength::FontRelative(v) => v.unit(),
NoCalcLength::ViewportPercentage(v) => v.unit(), NoCalcLength::ViewportPercentage(v) => v.unit(),
NoCalcLength::ContainerRelative(v) => v.unit(), NoCalcLength::ContainerRelative(v) => v.unit(),
NoCalcLength::ServoCharacterWidth(_) => "" NoCalcLength::ServoCharacterWidth(_) => "",
} }
} }
@ -1233,38 +1200,6 @@ impl PartialOrd for FontRelativeLength {
} }
} }
impl Mul<CSSFloat> for FontRelativeLength {
type Output = FontRelativeLength;
#[inline]
fn mul(self, scalar: CSSFloat) -> FontRelativeLength {
match self {
FontRelativeLength::Em(v) => FontRelativeLength::Em(v * scalar),
FontRelativeLength::Ex(v) => FontRelativeLength::Ex(v * scalar),
FontRelativeLength::Ch(v) => FontRelativeLength::Ch(v * scalar),
FontRelativeLength::Cap(v) => FontRelativeLength::Cap(v * scalar),
FontRelativeLength::Ic(v) => FontRelativeLength::Ic(v * scalar),
FontRelativeLength::Rem(v) => FontRelativeLength::Rem(v * scalar),
}
}
}
impl Mul<CSSFloat> for ContainerRelativeLength {
type Output = ContainerRelativeLength;
#[inline]
fn mul(self, scalar: CSSFloat) -> ContainerRelativeLength {
match self {
ContainerRelativeLength::Cqw(v) => ContainerRelativeLength::Cqw(v * scalar),
ContainerRelativeLength::Cqh(v) => ContainerRelativeLength::Cqh(v * scalar),
ContainerRelativeLength::Cqi(v) => ContainerRelativeLength::Cqi(v * scalar),
ContainerRelativeLength::Cqb(v) => ContainerRelativeLength::Cqb(v * scalar),
ContainerRelativeLength::Cqmin(v) => ContainerRelativeLength::Cqmin(v * scalar),
ContainerRelativeLength::Cqmax(v) => ContainerRelativeLength::Cqmax(v * scalar),
}
}
}
impl PartialOrd for ContainerRelativeLength { impl PartialOrd for ContainerRelativeLength {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
use self::ContainerRelativeLength::*; use self::ContainerRelativeLength::*;
@ -1294,40 +1229,6 @@ impl PartialOrd for ContainerRelativeLength {
} }
} }
impl Mul<CSSFloat> for ViewportPercentageLength {
type Output = ViewportPercentageLength;
#[inline]
fn mul(self, scalar: CSSFloat) -> ViewportPercentageLength {
match self {
ViewportPercentageLength::Vw(v) => ViewportPercentageLength::Vw(v * scalar),
ViewportPercentageLength::Svw(v) => ViewportPercentageLength::Svw(v * scalar),
ViewportPercentageLength::Lvw(v) => ViewportPercentageLength::Lvw(v * scalar),
ViewportPercentageLength::Dvw(v) => ViewportPercentageLength::Dvw(v * scalar),
ViewportPercentageLength::Vh(v) => ViewportPercentageLength::Vh(v * scalar),
ViewportPercentageLength::Svh(v) => ViewportPercentageLength::Svh(v * scalar),
ViewportPercentageLength::Lvh(v) => ViewportPercentageLength::Lvh(v * scalar),
ViewportPercentageLength::Dvh(v) => ViewportPercentageLength::Dvh(v * scalar),
ViewportPercentageLength::Vmin(v) => ViewportPercentageLength::Vmin(v * scalar),
ViewportPercentageLength::Svmin(v) => ViewportPercentageLength::Svmin(v * scalar),
ViewportPercentageLength::Lvmin(v) => ViewportPercentageLength::Lvmin(v * scalar),
ViewportPercentageLength::Dvmin(v) => ViewportPercentageLength::Dvmin(v * scalar),
ViewportPercentageLength::Vmax(v) => ViewportPercentageLength::Vmax(v * scalar),
ViewportPercentageLength::Svmax(v) => ViewportPercentageLength::Svmax(v * scalar),
ViewportPercentageLength::Lvmax(v) => ViewportPercentageLength::Lvmax(v * scalar),
ViewportPercentageLength::Dvmax(v) => ViewportPercentageLength::Dvmax(v * scalar),
ViewportPercentageLength::Vb(v) => ViewportPercentageLength::Vb(v * scalar),
ViewportPercentageLength::Svb(v) => ViewportPercentageLength::Svb(v * scalar),
ViewportPercentageLength::Lvb(v) => ViewportPercentageLength::Lvb(v * scalar),
ViewportPercentageLength::Dvb(v) => ViewportPercentageLength::Dvb(v * scalar),
ViewportPercentageLength::Vi(v) => ViewportPercentageLength::Vi(v * scalar),
ViewportPercentageLength::Svi(v) => ViewportPercentageLength::Svi(v * scalar),
ViewportPercentageLength::Lvi(v) => ViewportPercentageLength::Lvi(v * scalar),
ViewportPercentageLength::Dvi(v) => ViewportPercentageLength::Dvi(v * scalar),
}
}
}
impl PartialOrd for ViewportPercentageLength { impl PartialOrd for ViewportPercentageLength {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
use self::ViewportPercentageLength::*; use self::ViewportPercentageLength::*;