mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
style: Make the generic size not use euclid under the hood.
The euclid size is not really used for anything. Also rename it to Size2D to avoid cbindgen conflicts with values::length::Size. Differential Revision: https://phabricator.services.mozilla.com/D20959
This commit is contained in:
parent
ebeb7b228f
commit
aad4dac5b4
4 changed files with 32 additions and 55 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue