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

@ -6,6 +6,7 @@
use crate::values::generics::rect::Rect;
use crate::values::generics::size::Size2D;
use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@ -65,6 +66,16 @@ impl<L> BorderCornerRadius<L> {
}
}
impl<L: Zero> Zero for BorderCornerRadius<L> {
fn zero() -> Self {
BorderCornerRadius(Size2D::zero())
}
fn is_zero(&self) -> bool {
self.0.is_zero()
}
}
/// A generic value for the `border-spacing` property.
#[derive(
Animate,
@ -135,12 +146,7 @@ impl<L> BorderRadius<L> {
bottom_left: bl,
}
}
}
impl<L> BorderRadius<L>
where
L: PartialEq + ToCss,
{
/// Serialises two given rects following the syntax of the `border-radius``
/// property.
pub fn serialize_rects<W>(
@ -149,6 +155,7 @@ where
dest: &mut CssWriter<W>,
) -> fmt::Result
where
L: PartialEq + ToCss,
W: Write,
{
widths.to_css(dest)?;
@ -160,6 +167,24 @@ where
}
}
impl<L: Zero> Zero for BorderRadius<L> {
fn zero() -> Self {
Self::new(
BorderCornerRadius::<L>::zero(),
BorderCornerRadius::<L>::zero(),
BorderCornerRadius::<L>::zero(),
BorderCornerRadius::<L>::zero(),
)
}
fn is_zero(&self) -> bool {
self.top_left.is_zero() &&
self.top_right.is_zero() &&
self.bottom_right.is_zero() &&
self.bottom_left.is_zero()
}
}
impl<L> ToCss for BorderRadius<L>
where
L: PartialEq + ToCss,