mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Various fixes in basic-shape parsing/serialization found by unit tests
This commit is contained in:
parent
e69f6396e2
commit
973796b989
2 changed files with 18 additions and 12 deletions
|
@ -170,12 +170,14 @@ impl Circle {
|
||||||
|
|
||||||
impl ToCss for Circle {
|
impl ToCss for Circle {
|
||||||
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 {
|
||||||
|
try!(dest.write_str("circle("));
|
||||||
if ShapeRadius::ClosestSide != self.radius {
|
if ShapeRadius::ClosestSide != self.radius {
|
||||||
try!(self.radius.to_css(dest));
|
try!(self.radius.to_css(dest));
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
}
|
}
|
||||||
try!(dest.write_str("at "));
|
try!(dest.write_str("at "));
|
||||||
self.position.to_css(dest)
|
try!(self.position.to_css(dest));
|
||||||
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +232,8 @@ impl Ellipse {
|
||||||
|
|
||||||
impl ToCss for Ellipse {
|
impl ToCss for Ellipse {
|
||||||
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 {
|
||||||
if ShapeRadius::ClosestSide != self.semiaxis_a &&
|
try!(dest.write_str("ellipse("));
|
||||||
|
if ShapeRadius::ClosestSide != self.semiaxis_a ||
|
||||||
ShapeRadius::ClosestSide != self.semiaxis_b {
|
ShapeRadius::ClosestSide != self.semiaxis_b {
|
||||||
try!(self.semiaxis_a.to_css(dest));
|
try!(self.semiaxis_a.to_css(dest));
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
|
@ -238,7 +241,8 @@ impl ToCss for Ellipse {
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
}
|
}
|
||||||
try!(dest.write_str("at "));
|
try!(dest.write_str("at "));
|
||||||
self.position.to_css(dest)
|
try!(self.position.to_css(dest));
|
||||||
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,6 +300,7 @@ impl Polygon {
|
||||||
|
|
||||||
impl ToCss for Polygon {
|
impl ToCss for Polygon {
|
||||||
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 {
|
||||||
|
try!(dest.write_str("polygon("));
|
||||||
let mut need_space = false;
|
let mut need_space = false;
|
||||||
if self.fill != Default::default() {
|
if self.fill != Default::default() {
|
||||||
try!(self.fill.to_css(dest));
|
try!(self.fill.to_css(dest));
|
||||||
|
@ -310,7 +315,7 @@ impl ToCss for Polygon {
|
||||||
try!(coord.1.to_css(dest));
|
try!(coord.1.to_css(dest));
|
||||||
need_space = true;
|
need_space = true;
|
||||||
}
|
}
|
||||||
Ok(())
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,8 +422,7 @@ impl ToCss for BorderRadius {
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
try!(self.bottom_left.0.height.to_css(dest));
|
try!(self.bottom_left.0.height.to_css(dest));
|
||||||
try!(dest.write_str(" "));
|
try!(dest.write_str(" "));
|
||||||
try!(self.bottom_right.0.height.to_css(dest));
|
self.bottom_right.0.height.to_css(dest)
|
||||||
dest.write_str(" ")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,10 +434,10 @@ impl BorderRadius {
|
||||||
heights = try!(parse_one_set_of_border_values(input));
|
heights = try!(parse_one_set_of_border_values(input));
|
||||||
}
|
}
|
||||||
Ok(BorderRadius {
|
Ok(BorderRadius {
|
||||||
top_left: BorderRadiusSize::new(widths[1], heights[1]),
|
top_left: BorderRadiusSize::new(widths[0], heights[0]),
|
||||||
top_right: BorderRadiusSize::new(widths[2], heights[2]),
|
top_right: BorderRadiusSize::new(widths[1], heights[1]),
|
||||||
bottom_left: BorderRadiusSize::new(widths[3], heights[3]),
|
bottom_left: BorderRadiusSize::new(widths[2], heights[2]),
|
||||||
bottom_right: BorderRadiusSize::new(widths[4], heights[4]),
|
bottom_right: BorderRadiusSize::new(widths[3], heights[3]),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,16 @@ impl Position {
|
||||||
-> Result<Position, ()> {
|
-> Result<Position, ()> {
|
||||||
let (horiz, vert) = match (category(first), category(second)) {
|
let (horiz, vert) = match (category(first), category(second)) {
|
||||||
// Don't allow two vertical keywords or two horizontal keywords.
|
// Don't allow two vertical keywords or two horizontal keywords.
|
||||||
|
// also don't allow length/percentage values in the wrong position
|
||||||
(PositionCategory::HorizontalKeyword, PositionCategory::HorizontalKeyword) |
|
(PositionCategory::HorizontalKeyword, PositionCategory::HorizontalKeyword) |
|
||||||
(PositionCategory::VerticalKeyword, PositionCategory::VerticalKeyword) => return Err(()),
|
(PositionCategory::VerticalKeyword, PositionCategory::VerticalKeyword) |
|
||||||
|
(PositionCategory::LengthOrPercentage, PositionCategory::HorizontalKeyword) |
|
||||||
|
(PositionCategory::VerticalKeyword, PositionCategory::LengthOrPercentage) => return Err(()),
|
||||||
|
|
||||||
// Swap if both are keywords and vertical precedes horizontal.
|
// Swap if both are keywords and vertical precedes horizontal.
|
||||||
(PositionCategory::VerticalKeyword, PositionCategory::HorizontalKeyword) |
|
(PositionCategory::VerticalKeyword, PositionCategory::HorizontalKeyword) |
|
||||||
(PositionCategory::VerticalKeyword, PositionCategory::OtherKeyword) |
|
(PositionCategory::VerticalKeyword, PositionCategory::OtherKeyword) |
|
||||||
(PositionCategory::OtherKeyword, PositionCategory::HorizontalKeyword) => (second, first),
|
(PositionCategory::OtherKeyword, PositionCategory::HorizontalKeyword) => (second, first),
|
||||||
|
|
||||||
// By default, horizontal is first.
|
// By default, horizontal is first.
|
||||||
_ => (first, second),
|
_ => (first, second),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue