aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2023-03-27 08:57:35 +0000
committerMartin Robinson <mrobinson@igalia.com>2023-11-21 15:36:35 +0100
commit398df68d38b20572769388ef39eb710fd41d6f4c (patch)
treee225fe60da2aa0136aa178acbd032140cb573462
parent241e6e256fc4e048bcb1e8a972475541f60d9680 (diff)
downloadservo-398df68d38b20572769388ef39eb710fd41d6f4c.tar.gz
servo-398df68d38b20572769388ef39eb710fd41d6f4c.zip
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
-rw-r--r--components/style/values/specified/length.rs181
1 files changed, 41 insertions, 140 deletions
diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs
index 9512ca78054..5aa3eb65966 100644
--- a/components/style/values/specified/length.rs
+++ b/components/style/values/specified/length.rs
@@ -22,7 +22,6 @@ use crate::{Zero, ZeroNoPercent};
use app_units::Au;
use cssparser::{Parser, Token};
use std::cmp;
-use std::ops::Mul;
use style_traits::values::specified::AllowedNumericType;
use std::fmt::{self, Write};
use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind, CssWriter, ToCss};
@@ -107,7 +106,7 @@ impl FontRelativeLength {
FontRelativeLength::Ch(_) => "ch",
FontRelativeLength::Cap(_) => "cap",
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 {
match self {
- FontRelativeLength::Em(x) => FontRelativeLength::Em(op(*x)),
- FontRelativeLength::Ex(x) => FontRelativeLength::Ex(op(*x)),
- FontRelativeLength::Ch(x) => FontRelativeLength::Ch(op(*x)),
- FontRelativeLength::Cap(x) => FontRelativeLength::Cap(op(*x)),
- FontRelativeLength::Ic(x) => FontRelativeLength::Ic(op(*x)),
- FontRelativeLength::Rem(x) => FontRelativeLength::Rem(op(*x)),
+ Self::Em(x) => Self::Em(op(*x)),
+ Self::Ex(x) => Self::Ex(op(*x)),
+ Self::Ch(x) => Self::Ch(op(*x)),
+ Self::Cap(x) => Self::Cap(op(*x)),
+ Self::Ic(x) => Self::Ic(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 {
match self {
- ViewportPercentageLength::Vw(x) => ViewportPercentageLength::Vw(op(*x)),
- ViewportPercentageLength::Svw(x) => ViewportPercentageLength::Svw(op(*x)),
- ViewportPercentageLength::Lvw(x) => ViewportPercentageLength::Lvw(op(*x)),
- ViewportPercentageLength::Dvw(x) => ViewportPercentageLength::Dvw(op(*x)),
- ViewportPercentageLength::Vh(x) => ViewportPercentageLength::Vh(op(*x)),
- ViewportPercentageLength::Svh(x) => ViewportPercentageLength::Svh(op(*x)),
- ViewportPercentageLength::Lvh(x) => ViewportPercentageLength::Lvh(op(*x)),
- ViewportPercentageLength::Dvh(x) => ViewportPercentageLength::Dvh(op(*x)),
- ViewportPercentageLength::Vmin(x) => ViewportPercentageLength::Vmin(op(*x)),
- ViewportPercentageLength::Svmin(x) => ViewportPercentageLength::Svmin(op(*x)),
- ViewportPercentageLength::Lvmin(x) => ViewportPercentageLength::Lvmin(op(*x)),
- ViewportPercentageLength::Dvmin(x) => ViewportPercentageLength::Dvmin(op(*x)),
- ViewportPercentageLength::Vmax(x) => ViewportPercentageLength::Vmax(op(*x)),
- ViewportPercentageLength::Svmax(x) => ViewportPercentageLength::Svmax(op(*x)),
- ViewportPercentageLength::Lvmax(x) => ViewportPercentageLength::Lvmax(op(*x)),
- ViewportPercentageLength::Dvmax(x) => ViewportPercentageLength::Dvmax(op(*x)),
- ViewportPercentageLength::Vb(x) => ViewportPercentageLength::Vb(op(*x)),
- ViewportPercentageLength::Svb(x) => ViewportPercentageLength::Svb(op(*x)),
- ViewportPercentageLength::Lvb(x) => ViewportPercentageLength::Lvb(op(*x)),
- ViewportPercentageLength::Dvb(x) => ViewportPercentageLength::Dvb(op(*x)),
- ViewportPercentageLength::Vi(x) => ViewportPercentageLength::Vi(op(*x)),
- ViewportPercentageLength::Svi(x) => ViewportPercentageLength::Svi(op(*x)),
- ViewportPercentageLength::Lvi(x) => ViewportPercentageLength::Lvi(op(*x)),
- ViewportPercentageLength::Dvi(x) => ViewportPercentageLength::Dvi(op(*x)),
+ Self::Vw(x) => Self::Vw(op(*x)),
+ Self::Svw(x) => Self::Svw(op(*x)),
+ Self::Lvw(x) => Self::Lvw(op(*x)),
+ Self::Dvw(x) => Self::Dvw(op(*x)),
+ Self::Vh(x) => Self::Vh(op(*x)),
+ Self::Svh(x) => Self::Svh(op(*x)),
+ Self::Lvh(x) => Self::Lvh(op(*x)),
+ Self::Dvh(x) => Self::Dvh(op(*x)),
+ Self::Vmin(x) => Self::Vmin(op(*x)),
+ Self::Svmin(x) => Self::Svmin(op(*x)),
+ Self::Lvmin(x) => Self::Lvmin(op(*x)),
+ Self::Dvmin(x) => Self::Dvmin(op(*x)),
+ Self::Vmax(x) => Self::Vmax(op(*x)),
+ Self::Svmax(x) => Self::Svmax(op(*x)),
+ Self::Lvmax(x) => Self::Lvmax(op(*x)),
+ Self::Dvmax(x) => Self::Dvmax(op(*x)),
+ Self::Vb(x) => Self::Vb(op(*x)),
+ Self::Svb(x) => Self::Svb(op(*x)),
+ Self::Lvb(x) => Self::Lvb(op(*x)),
+ Self::Dvb(x) => Self::Dvb(op(*x)),
+ Self::Vi(x) => Self::Vi(op(*x)),
+ Self::Svi(x) => Self::Svi(op(*x)),
+ Self::Lvi(x) => Self::Lvi(op(*x)),
+ Self::Dvi(x) => Self::Dvi(op(*x)),
}
}
@@ -649,7 +648,7 @@ impl AbsoluteLength {
AbsoluteLength::Mm(_) => "mm",
AbsoluteLength::Q(_) => "q",
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 {
- match self {
- 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)),
- }
+ Self::Px(op(self.to_px()))
}
}
@@ -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.
///
/// <https://drafts.csswg.org/css-contain-3/#container-lengths>
@@ -759,7 +741,7 @@ impl ContainerRelativeLength {
ContainerRelativeLength::Cqi(_) => "cqi",
ContainerRelativeLength::Cqb(_) => "cqb",
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 {
match self {
- ContainerRelativeLength::Cqw(x) => ContainerRelativeLength::Cqw(op(*x)),
- ContainerRelativeLength::Cqh(x) => ContainerRelativeLength::Cqh(op(*x)),
- ContainerRelativeLength::Cqi(x) => ContainerRelativeLength::Cqi(op(*x)),
- ContainerRelativeLength::Cqb(x) => ContainerRelativeLength::Cqb(op(*x)),
- ContainerRelativeLength::Cqmin(x) => ContainerRelativeLength::Cqmin(op(*x)),
- ContainerRelativeLength::Cqmax(x) => ContainerRelativeLength::Cqmax(op(*x)),
+ Self::Cqw(x) => Self::Cqw(op(*x)),
+ Self::Cqh(x) => Self::Cqh(op(*x)),
+ Self::Cqi(x) => Self::Cqi(op(*x)),
+ Self::Cqb(x) => Self::Cqb(op(*x)),
+ Self::Cqmin(x) => Self::Cqmin(op(*x)),
+ Self::Cqmax(x) => Self::Cqmax(op(*x)),
}
}
@@ -871,21 +853,6 @@ pub enum NoCalcLength {
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 {
/// Return the unitless, raw value.
pub fn unitless_value(&self) -> CSSFloat {
@@ -905,7 +872,7 @@ impl NoCalcLength {
NoCalcLength::FontRelative(v) => v.unit(),
NoCalcLength::ViewportPercentage(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 {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
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 {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
use self::ViewportPercentageLength::*;