Auto merge of #17071 - servo:derive-all-the-things, r=emilio

Reuse Rect<T> some more

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17071)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-05-30 05:11:28 -05:00 committed by GitHub
commit 433d68955b
24 changed files with 324 additions and 355 deletions

View file

@ -7,14 +7,11 @@
use counter_style::{Symbols, parse_counter_style_name};
use cssparser::Parser;
use euclid::size::Size2D;
use parser::{Parse, ParserContext};
use std::fmt;
use style_traits::{HasViewportPercentage, OneOrMoreCommaSeparated, ToCss};
use style_traits::{OneOrMoreCommaSeparated, ToCss};
use super::CustomIdent;
pub use self::basic_shape::serialize_radius_values;
pub mod background;
pub mod basic_shape;
pub mod border;
@ -23,47 +20,6 @@ pub mod image;
pub mod position;
pub mod rect;
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// A type for representing CSS `width` and `height` values.
pub struct BorderRadiusSize<L>(pub Size2D<L>);
impl<L> HasViewportPercentage for BorderRadiusSize<L> {
#[inline]
fn has_viewport_percentage(&self) -> bool { false }
}
impl<L: Clone> From<L> for BorderRadiusSize<L> {
fn from(other: L) -> Self {
Self::new(other.clone(), other)
}
}
impl<L> BorderRadiusSize<L> {
#[inline]
/// Create a new `BorderRadiusSize` for an area of given width and height.
pub fn new(width: L, height: L) -> BorderRadiusSize<L> {
BorderRadiusSize(Size2D::new(width, height))
}
}
impl<L: Clone> BorderRadiusSize<L> {
#[inline]
/// Create a new `BorderRadiusSize` for a circle of given radius.
pub fn circle(radius: L) -> BorderRadiusSize<L> {
BorderRadiusSize(Size2D::new(radius.clone(), radius))
}
}
impl<L: ToCss> ToCss for BorderRadiusSize<L> {
#[inline]
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.0.width.to_css(dest)?;
dest.write_str(" ")?;
self.0.height.to_css(dest)
}
}
// https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type
define_css_keyword_enum! { SymbolsType:
"cyclic" => Cyclic,