style: Add a Zero trait that doesn't require Add, and use it in place of num_traits and IsZeroLength.

Use it to be consistent in InsetRect serialization and storage between Servo and
Gecko.

Differential Revision: https://phabricator.services.mozilla.com/D21493
This commit is contained in:
Emilio Cobos Álvarez 2019-02-28 19:03:03 +00:00
parent 4496411edc
commit 7d01114cbf
29 changed files with 179 additions and 186 deletions

View file

@ -12,11 +12,11 @@ use crate::values::generics::length as generics;
use crate::values::generics::length::{
GenericLengthOrNumber, MaxSize as GenericMaxSize, Size as GenericSize,
};
use crate::values::generics::transform::IsZeroLength;
use crate::values::generics::NonNegative;
use crate::values::specified::length::ViewportPercentageLength;
use crate::values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength};
use crate::values::{specified, Auto, CSSFloat, Either, Normal};
use crate::Zero;
use app_units::Au;
use ordered_float::NotNan;
use std::fmt::{self, Write};
@ -342,12 +342,6 @@ impl ToComputedValue for specified::CalcLengthPercentage {
}
impl LengthPercentage {
#[inline]
#[allow(missing_docs)]
pub fn zero() -> LengthPercentage {
LengthPercentage::new(Length::new(0.), None)
}
/// 1px length value for SVG defaults
#[inline]
pub fn one() -> LengthPercentage {
@ -442,9 +436,13 @@ impl ToComputedValue for specified::LengthPercentage {
}
}
impl IsZeroLength for LengthPercentage {
impl Zero for LengthPercentage {
fn zero() -> Self {
LengthPercentage::new(Length::zero(), None)
}
#[inline]
fn is_zero_length(&self) -> bool {
fn is_zero(&self) -> bool {
self.is_definitely_zero()
}
}
@ -453,12 +451,6 @@ impl IsZeroLength for LengthPercentage {
/// length-percentage or auto.
macro_rules! computed_length_percentage_or_auto {
($inner:ty) => {
/// Returns the `0` value.
#[inline]
pub fn zero() -> Self {
generics::LengthPercentageOrAuto::LengthPercentage(<$inner>::zero())
}
/// Returns the used value.
#[inline]
pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
@ -547,12 +539,6 @@ impl From<Au> for LengthPercentage {
}
impl NonNegativeLengthPercentage {
/// Get zero value.
#[inline]
pub fn zero() -> Self {
NonNegative(LengthPercentage::zero())
}
/// Returns true if the computed value is absolute 0 or 0%.
#[inline]
pub fn is_definitely_zero(&self) -> bool {
@ -656,12 +642,16 @@ impl CSSPixelLength {
pub fn clamp_to_non_negative(self) -> Self {
CSSPixelLength::new(self.0.max(0.))
}
}
/// Zero value
#[inline]
pub fn zero() -> Self {
impl Zero for CSSPixelLength {
fn zero() -> Self {
CSSPixelLength::new(0.)
}
fn is_zero(&self) -> bool {
self.px() == 0.
}
}
impl ToCss for CSSPixelLength {
@ -743,12 +733,6 @@ impl NonNegativeLength {
NonNegative(Length::new(px.max(0.)))
}
/// Return a zero value.
#[inline]
pub fn zero() -> Self {
Self::new(0.)
}
/// Return the pixel value of |NonNegativeLength|.
#[inline]
pub fn px(&self) -> CSSFloat {