mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Make Rect<T> a struct tuple
It makes no sense to have named fields in some cases, notably to reuse Rect<T> in BorderRadius<T>.
This commit is contained in:
parent
4ec2e8b4c5
commit
4144dc74db
5 changed files with 41 additions and 55 deletions
|
@ -1424,10 +1424,10 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
details: BorderDetails::Image(ImageBorder {
|
details: BorderDetails::Image(ImageBorder {
|
||||||
image: webrender_image,
|
image: webrender_image,
|
||||||
fill: border_style_struct.border_image_slice.fill,
|
fill: border_style_struct.border_image_slice.fill,
|
||||||
slice: SideOffsets2D::new(corners.top.resolve(webrender_image.height),
|
slice: SideOffsets2D::new(corners.0.resolve(webrender_image.height),
|
||||||
corners.right.resolve(webrender_image.width),
|
corners.1.resolve(webrender_image.width),
|
||||||
corners.bottom.resolve(webrender_image.height),
|
corners.2.resolve(webrender_image.height),
|
||||||
corners.left.resolve(webrender_image.width)),
|
corners.3.resolve(webrender_image.width)),
|
||||||
// TODO(gw): Support border-image-outset
|
// TODO(gw): Support border-image-outset
|
||||||
outset: SideOffsets2D::zero(),
|
outset: SideOffsets2D::zero(),
|
||||||
repeat_horizontal: convert_repeat_mode(border_style_struct.border_image_repeat.0),
|
repeat_horizontal: convert_repeat_mode(border_style_struct.border_image_repeat.0),
|
||||||
|
|
|
@ -964,7 +964,7 @@ fn static_assert() {
|
||||||
|
|
||||||
pub fn set_border_image_outset(&mut self, v: longhands::border_image_outset::computed_value::T) {
|
pub fn set_border_image_outset(&mut self, v: longhands::border_image_outset::computed_value::T) {
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
v.${side.ident}.to_gecko_style_coord(&mut self.gecko.mBorderImageOutset.data_at_mut(${side.index}));
|
v.${side.index}.to_gecko_style_coord(&mut self.gecko.mBorderImageOutset.data_at_mut(${side.index}));
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1001,7 +1001,7 @@ fn static_assert() {
|
||||||
use values::generics::border::BorderImageWidthSide;
|
use values::generics::border::BorderImageWidthSide;
|
||||||
|
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
match v.${side.ident} {
|
match v.${side.index} {
|
||||||
BorderImageWidthSide::Auto => {
|
BorderImageWidthSide::Auto => {
|
||||||
self.gecko.mBorderImageWidth.data_at_mut(${side.index}).set_value(CoordDataValue::Auto)
|
self.gecko.mBorderImageWidth.data_at_mut(${side.index}).set_value(CoordDataValue::Auto)
|
||||||
},
|
},
|
||||||
|
@ -1026,7 +1026,7 @@ fn static_assert() {
|
||||||
use gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_SLICE_NOFILL, NS_STYLE_BORDER_IMAGE_SLICE_FILL};
|
use gecko_bindings::structs::{NS_STYLE_BORDER_IMAGE_SLICE_NOFILL, NS_STYLE_BORDER_IMAGE_SLICE_FILL};
|
||||||
|
|
||||||
% for side in SIDES:
|
% for side in SIDES:
|
||||||
v.offsets.${side.ident}.to_gecko_style_coord(&mut self.gecko.mBorderImageSlice.data_at_mut(${side.index}));
|
v.offsets.${side.index}.to_gecko_style_coord(&mut self.gecko.mBorderImageSlice.data_at_mut(${side.index}));
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
let fill = if v.fill {
|
let fill = if v.fill {
|
||||||
|
|
|
@ -901,8 +901,8 @@
|
||||||
% endif
|
% endif
|
||||||
})?;
|
})?;
|
||||||
Ok(expanded! {
|
Ok(expanded! {
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for index, side in enumerate(["top", "right", "bottom", "left"]):
|
||||||
${to_rust_ident(sub_property_pattern % side)}: rect.${side},
|
${to_rust_ident(sub_property_pattern % side)}: rect.${index},
|
||||||
% endfor
|
% endfor
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,20 +25,19 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
||||||
BorderWidth::parse_quirky(context, i, AllowQuirks::Yes)
|
BorderWidth::parse_quirky(context, i, AllowQuirks::Yes)
|
||||||
})?;
|
})?;
|
||||||
Ok(expanded! {
|
Ok(expanded! {
|
||||||
% for side in PHYSICAL_SIDES:
|
border_top_width: rect.0,
|
||||||
${to_rust_ident('border-%s-width' % side)}: rect.${side},
|
border_right_width: rect.1,
|
||||||
% endfor
|
border_bottom_width: rect.2,
|
||||||
|
border_left_width: rect.3,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
let rect = Rect {
|
% for side in PHYSICAL_SIDES:
|
||||||
% for side in PHYSICAL_SIDES:
|
let ${side} = &self.border_${side}_width;
|
||||||
${side}: &self.border_${side}_width,
|
% endfor
|
||||||
% endfor
|
Rect::new(top, right, bottom, left).to_css(dest)
|
||||||
};
|
|
||||||
rect.to_css(dest)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</%helpers:shorthand>
|
</%helpers:shorthand>
|
||||||
|
|
|
@ -9,29 +9,16 @@ use parser::{Parse, ParserContext};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
|
||||||
/// A CSS value made of four sides: top, right, bottom, and left.
|
/// A CSS value made of four components, where its `ToCss` impl will try to
|
||||||
|
/// serialize as few components as possible, like for example in `border-width`.
|
||||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct Rect<T> {
|
pub struct Rect<T>(pub T, pub T, pub T, pub T);
|
||||||
/// Top
|
|
||||||
pub top: T,
|
|
||||||
/// Right.
|
|
||||||
pub right: T,
|
|
||||||
/// Bottom.
|
|
||||||
pub bottom: T,
|
|
||||||
/// Left.
|
|
||||||
pub left: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Rect<T> {
|
impl<T> Rect<T> {
|
||||||
/// Returns a new `Rect<T>` value.
|
/// Returns a new `Rect<T>` value.
|
||||||
pub fn new(top: T, right: T, bottom: T, left: T) -> Self {
|
pub fn new(first: T, second: T, third: T, fourth: T) -> Self {
|
||||||
Rect {
|
Rect(first, second, third, fourth)
|
||||||
top: top,
|
|
||||||
right: right,
|
|
||||||
bottom: bottom,
|
|
||||||
left: left,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,21 +33,21 @@ impl<T> Rect<T>
|
||||||
-> Result<Self, ()>
|
-> Result<Self, ()>
|
||||||
where Parse: Fn(&ParserContext, &mut Parser) -> Result<T, ()>
|
where Parse: Fn(&ParserContext, &mut Parser) -> Result<T, ()>
|
||||||
{
|
{
|
||||||
let top = parse(context, input)?;
|
let first = parse(context, input)?;
|
||||||
let right = if let Ok(right) = input.try(|i| parse(context, i)) { right } else {
|
let second = if let Ok(second) = input.try(|i| parse(context, i)) { second } else {
|
||||||
// <top>
|
// <first>
|
||||||
return Ok(Self::new(top.clone(), top.clone(), top.clone(), top));
|
return Ok(Self::new(first.clone(), first.clone(), first.clone(), first));
|
||||||
};
|
};
|
||||||
let bottom = if let Ok(bottom) = input.try(|i| parse(context, i)) { bottom } else {
|
let third = if let Ok(third) = input.try(|i| parse(context, i)) { third } else {
|
||||||
// <top> <right>
|
// <first> <second>
|
||||||
return Ok(Self::new(top.clone(), right.clone(), top, right));
|
return Ok(Self::new(first.clone(), second.clone(), first, second));
|
||||||
};
|
};
|
||||||
let left = if let Ok(left) = input.try(|i| parse(context, i)) { left } else {
|
let fourth = if let Ok(fourth) = input.try(|i| parse(context, i)) { fourth } else {
|
||||||
// <top> <right> <bottom>
|
// <first> <second> <third>
|
||||||
return Ok(Self::new(top, right.clone(), bottom, right));
|
return Ok(Self::new(first, second.clone(), third, second));
|
||||||
};
|
};
|
||||||
// <top> <right> <bottom> <left>
|
// <first> <second> <third> <fourth>
|
||||||
Ok(Self::new(top, right, bottom, left))
|
Ok(Self::new(first, second, third, fourth))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,23 +75,23 @@ impl<T> ToCss for Rect<T>
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||||
where W: fmt::Write,
|
where W: fmt::Write,
|
||||||
{
|
{
|
||||||
self.top.to_css(dest)?;
|
self.0.to_css(dest)?;
|
||||||
let same_vertical = self.top == self.bottom;
|
let same_vertical = self.0 == self.2;
|
||||||
let same_horizontal = self.right == self.left;
|
let same_horizontal = self.1 == self.3;
|
||||||
if same_vertical && same_horizontal && self.top == self.right {
|
if same_vertical && same_horizontal && self.0 == self.1 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
dest.write_str(" ")?;
|
dest.write_str(" ")?;
|
||||||
self.right.to_css(dest)?;
|
self.1.to_css(dest)?;
|
||||||
if same_vertical && same_horizontal {
|
if same_vertical && same_horizontal {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
dest.write_str(" ")?;
|
dest.write_str(" ")?;
|
||||||
self.bottom.to_css(dest)?;
|
self.2.to_css(dest)?;
|
||||||
if same_horizontal {
|
if same_horizontal {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
dest.write_str(" ")?;
|
dest.write_str(" ")?;
|
||||||
self.left.to_css(dest)
|
self.3.to_css(dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue