Bug 1516454 - Make the generic size not use euclid under the hood. r=firefox-style-system-reviewers,boris

The euclid size is not really used for anything. Also rename it to Size2D to
avoid cbindgen conflicts with values::length::Size.

Depends on D20958

Differential Revision: https://phabricator.services.mozilla.com/D20959

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-02-25 03:05:39 +00:00
Родитель 76fb626711
Коммит a185f2109d
4 изменённых файлов: 32 добавлений и 55 удалений

Просмотреть файл

@ -12,7 +12,7 @@ use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice
use crate::values::generics::border::BorderRadius as GenericBorderRadius;
use crate::values::generics::border::BorderSpacing as GenericBorderSpacing;
use crate::values::generics::rect::Rect;
use crate::values::generics::size::Size;
use crate::values::generics::size::Size2D;
use crate::values::generics::NonNegative;
use app_units::Au;
@ -59,7 +59,7 @@ impl BorderImageSlice {
impl BorderSpacing {
/// Returns `0 0`.
pub fn zero() -> Self {
GenericBorderSpacing(Size::new(
GenericBorderSpacing(Size2D::new(
NonNegativeLength::zero(),
NonNegativeLength::zero(),
))
@ -79,7 +79,7 @@ impl BorderSpacing {
impl BorderCornerRadius {
/// Returns `0 0`.
pub fn zero() -> Self {
GenericBorderCornerRadius(Size::new(
GenericBorderCornerRadius(Size2D::new(
NonNegativeLengthPercentage::zero(),
NonNegativeLengthPercentage::zero(),
))

Просмотреть файл

@ -5,7 +5,7 @@
//! Generic types for CSS values related to borders.
use crate::values::generics::rect::Rect;
use crate::values::generics::size::Size;
use crate::values::generics::size::Size2D;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@ -53,12 +53,12 @@ pub use self::GenericBorderImageSlice as BorderImageSlice;
ToComputedValue,
ToCss,
)]
pub struct BorderCornerRadius<L>(#[css(field_bound)] pub Size<L>);
pub struct BorderCornerRadius<L>(#[css(field_bound)] pub Size2D<L>);
impl<L> BorderCornerRadius<L> {
/// Trivially create a `BorderCornerRadius`.
pub fn new(w: L, h: L) -> Self {
BorderCornerRadius(Size::new(w, h))
BorderCornerRadius(Size2D::new(w, h))
}
}
@ -77,12 +77,12 @@ impl<L> BorderCornerRadius<L> {
ToComputedValue,
ToCss,
)]
pub struct BorderSpacing<L>(#[css(field_bound)] pub Size<L>);
pub struct BorderSpacing<L>(#[css(field_bound)] pub Size2D<L>);
impl<L> BorderSpacing<L> {
/// Trivially create a `BorderCornerRadius`.
pub fn new(w: L, h: L) -> Self {
BorderSpacing(Size::new(w, h))
BorderSpacing(Size2D::new(w, h))
}
}
@ -168,8 +168,8 @@ where
bottom_left: BorderCornerRadius(ref bl),
} = *self;
let widths = Rect::new(&tl.0.width, &tr.0.width, &br.0.width, &bl.0.width);
let heights = Rect::new(&tl.0.height, &tr.0.height, &br.0.height, &bl.0.height);
let widths = Rect::new(&tl.width, &tr.width, &br.width, &bl.width);
let heights = Rect::new(&tl.height, &tr.height, &br.height, &bl.height);
Self::serialize_rects(widths, heights, dest)
}

Просмотреть файл

@ -5,11 +5,9 @@
//! Generic type for CSS properties that are composed by two dimensions.
use crate::parser::ParserContext;
use crate::values::animated::ToAnimatedValue;
use cssparser::Parser;
use euclid::Size2D;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, ToCss};
use style_traits::{CssWriter, ParseError, ToCss};
/// A generic size, for `border-*-radius` longhand properties, or
/// `border-spacing`.
@ -21,29 +19,35 @@ use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, ToCss};
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedZero,
ToAnimatedValue,
ToComputedValue,
)]
pub struct Size<L>(pub Size2D<L>);
#[allow(missing_docs)]
pub struct Size2D<L> {
pub width: L,
pub height: L,
}
impl<L> Size<L> {
impl<L> Size2D<L> {
#[inline]
/// Create a new `Size` for an area of given width and height.
pub fn new(width: L, height: L) -> Size<L> {
Size(Size2D::new(width, height))
/// Create a new `Size2D` for an area of given width and height.
pub fn new(width: L, height: L) -> Self {
Self { width, height }
}
/// Returns the width component.
pub fn width(&self) -> &L {
&self.0.width
&self.width
}
/// Returns the height component.
pub fn height(&self) -> &L {
&self.0.height
&self.height
}
/// Parse a `Size` with a given parsing function.
/// Parse a `Size2D` with a given parsing function.
pub fn parse_with<'i, 't, F>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
@ -61,7 +65,7 @@ impl<L> Size<L> {
}
}
impl<L> ToCss for Size<L>
impl<L> ToCss for Size2D<L>
where
L: ToCss + PartialEq,
{
@ -69,40 +73,13 @@ where
where
W: Write,
{
self.0.width.to_css(dest)?;
self.width.to_css(dest)?;
if self.0.height != self.0.width {
if self.height != self.width {
dest.write_str(" ")?;
self.0.height.to_css(dest)?;
self.height.to_css(dest)?;
}
Ok(())
}
}
impl<L> ToAnimatedValue for Size<L>
where
L: ToAnimatedValue,
{
type AnimatedValue = Size<L::AnimatedValue>;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
Size(Size2D::new(
self.0.width.to_animated_value(),
self.0.height.to_animated_value(),
))
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
Size(Size2D::new(
L::from_animated_value(animated.0.width),
L::from_animated_value(animated.0.height),
))
}
}
impl<L: SpecifiedValueInfo> SpecifiedValueInfo for Size<L> {
const SUPPORTED_TYPES: u8 = L::SUPPORTED_TYPES;
}

Просмотреть файл

@ -12,7 +12,7 @@ use crate::values::generics::border::BorderImageSlice as GenericBorderImageSlice
use crate::values::generics::border::BorderRadius as GenericBorderRadius;
use crate::values::generics::border::BorderSpacing as GenericBorderSpacing;
use crate::values::generics::rect::Rect;
use crate::values::generics::size::Size;
use crate::values::generics::size::Size2D;
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
use crate::values::specified::{AllowQuirks, NonNegativeNumber, NonNegativeNumberOrPercentage};
use cssparser::Parser;
@ -228,7 +228,7 @@ impl Parse for BorderCornerRadius {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Size::parse_with(context, input, NonNegativeLengthPercentage::parse)
Size2D::parse_with(context, input, NonNegativeLengthPercentage::parse)
.map(GenericBorderCornerRadius)
}
}
@ -238,7 +238,7 @@ impl Parse for BorderSpacing {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Size::parse_with(context, input, |context, input| {
Size2D::parse_with(context, input, |context, input| {
NonNegativeLength::parse_quirky(context, input, AllowQuirks::Yes).map(From::from)
})
.map(GenericBorderSpacing)