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

@ -362,13 +362,14 @@ pub mod basic_shape {
use gecko_bindings::structs::StyleGeometryBox;
use gecko_bindings::sugar::ns_style_coord::{CoordDataMut, CoordDataValue};
use std::borrow::Borrow;
use values::computed::{BorderRadiusSize, LengthOrPercentage};
use values::computed::basic_shape::{BasicShape, BorderRadius, ShapeRadius};
use values::computed::basic_shape::{BasicShape, ShapeRadius};
use values::computed::border::{BorderCornerRadius, BorderRadius};
use values::computed::length::LengthOrPercentage;
use values::computed::position;
use values::generics::BorderRadiusSize as GenericBorderRadiusSize;
use values::generics::basic_shape::{BasicShape as GenericBasicShape, InsetRect, Polygon};
use values::generics::basic_shape::{Circle, Ellipse, FillRule};
use values::generics::basic_shape::{GeometryBox, ShapeBox};
use values::generics::border::BorderRadius as GenericBorderRadius;
use values::generics::rect::Rect;
// using Borrow so that we can have a non-moving .into()
@ -435,14 +436,14 @@ pub mod basic_shape {
fn from(other: T) -> Self {
let other = other.borrow();
let get_corner = |index| {
GenericBorderRadiusSize::new(
BorderCornerRadius::new(
LengthOrPercentage::from_gecko_style_coord(&other.data_at(index))
.expect("<border-radius> should be a length, percentage, or calc value"),
LengthOrPercentage::from_gecko_style_coord(&other.data_at(index + 1))
.expect("<border-radius> should be a length, percentage, or calc value"))
};
BorderRadius {
GenericBorderRadius {
top_left: get_corner(0),
top_right: get_corner(2),
bottom_right: get_corner(4),
@ -456,7 +457,7 @@ pub mod basic_shape {
impl BorderRadius {
/// Set this `BorderRadius` into a given `nsStyleCoord`.
pub fn set_corners(&self, other: &mut nsStyleCorners) {
let mut set_corner = |field: &BorderRadiusSize, index| {
let mut set_corner = |field: &BorderCornerRadius, index| {
field.0.width.to_gecko_style_coord(&mut other.data_at_mut(index));
field.0.height.to_gecko_style_coord(&mut other.data_at_mut(index + 1));
};