aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/values/generics/basic_shape.rs
diff options
context:
space:
mode:
authorBoris Chiou <boris.chiou@gmail.com>2018-08-23 20:32:53 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-09-03 12:32:17 +0200
commite46daa09ea8a8fdfd9a39d51f748392321c962e2 (patch)
treed8db809207ae8d362c92b70a7d0a3375bf95ae71 /components/style/values/generics/basic_shape.rs
parentc587fa35867a0206a77ea67b7b8738045c7d42a9 (diff)
downloadservo-e46daa09ea8a8fdfd9a39d51f748392321c962e2.tar.gz
servo-e46daa09ea8a8fdfd9a39d51f748392321c962e2.zip
style: Drop the manually implementation of ToCSS for BasicShape::Polygon.
The implementation of ToCSS for Polygon has some rule, and we could use skip_if to handle and serialization of fill-rule. However, we should derive ToCSS for the pair of LengthOrPercentages, so define a new type for it. Differential Revision: https://phabricator.services.mozilla.com/D4153
Diffstat (limited to 'components/style/values/generics/basic_shape.rs')
-rw-r--r--components/style/values/generics/basic_shape.rs45
1 files changed, 16 insertions, 29 deletions
diff --git a/components/style/values/generics/basic_shape.rs b/components/style/values/generics/basic_shape.rs
index 3bad738c1e6..274673b9c61 100644
--- a/components/style/values/generics/basic_shape.rs
+++ b/components/style/values/generics/basic_shape.rs
@@ -113,16 +113,23 @@ pub enum ShapeRadius<LengthOrPercentage> {
/// A generic type for representing the `polygon()` function
///
/// <https://drafts.csswg.org/css-shapes/#funcdef-polygon>
-#[css(function)]
+#[css(comma, function)]
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
- ToComputedValue)]
+ ToComputedValue, ToCss)]
pub struct Polygon<LengthOrPercentage> {
/// The filling rule for a polygon.
+ #[css(skip_if = "fill_is_default")]
pub fill: FillRule,
/// A collection of (x, y) coordinates to draw the polygon.
- pub coordinates: Vec<(LengthOrPercentage, LengthOrPercentage)>,
+ #[css(iterable)]
+ pub coordinates: Vec<PolygonCoord<LengthOrPercentage>>,
}
+/// Coordinates for Polygon.
+#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo,
+ ToComputedValue, ToCss)]
+pub struct PolygonCoord<LengthOrPercentage>(pub LengthOrPercentage, pub LengthOrPercentage);
+
// https://drafts.csswg.org/css-shapes/#typedef-fill-rule
// NOTE: Basic shapes spec says that these are the only two values, however
// https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
@@ -203,7 +210,7 @@ where
.iter()
.zip(other.coordinates.iter())
.map(|(this, other)| {
- Ok((
+ Ok(PolygonCoord(
this.0.animate(&other.0, procedure)?,
this.1.animate(&other.1, procedure)?,
))
@@ -239,34 +246,14 @@ where
}
}
-impl<L: ToCss> ToCss for Polygon<L> {
- fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
- where
- W: Write,
- {
- dest.write_str("polygon(")?;
- if self.fill != FillRule::default() {
- self.fill.to_css(dest)?;
- dest.write_str(", ")?;
- }
-
- for (i, coord) in self.coordinates.iter().enumerate() {
- if i > 0 {
- dest.write_str(", ")?;
- }
-
- coord.0.to_css(dest)?;
- dest.write_str(" ")?;
- coord.1.to_css(dest)?;
- }
-
- dest.write_str(")")
- }
-}
-
impl Default for FillRule {
#[inline]
fn default() -> Self {
FillRule::Nonzero
}
}
+
+#[inline]
+fn fill_is_default(fill: &FillRule) -> bool {
+ *fill == FillRule::default()
+}