Skip to content

Commit

Permalink
style: Should not serialize default radius of circle.
Browse files Browse the repository at this point in the history
Should not serialize default shape-outside circle() function radius.

The ToCss impl of Circle and Ellipse turn out to be identical in specified and computed value, thus move them to generics.

Differential Revision: https://phabricator.services.mozilla.com/D35183
  • Loading branch information
violette77 authored and emilio committed Jun 25, 2019
1 parent c7c1fed commit e1e82db
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 71 deletions.
33 changes: 0 additions & 33 deletions components/style/values/computed/basic_shape.rs
Expand Up @@ -10,8 +10,6 @@
use crate::values::computed::url::ComputedUrl;
use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage};
use crate::values::generics::basic_shape as generic;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};

/// A computed alias for FillRule.
pub use crate::values::generics::basic_shape::FillRule;
Expand Down Expand Up @@ -42,34 +40,3 @@ pub type Ellipse =

/// The computed value of `ShapeRadius`
pub type ShapeRadius = generic::GenericShapeRadius<NonNegativeLengthPercentage>;

impl ToCss for Circle {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("circle(")?;
self.radius.to_css(dest)?;
dest.write_str(" at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}

impl ToCss for Ellipse {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("ellipse(")?;
if (self.semiaxis_x, self.semiaxis_y) != Default::default() {
self.semiaxis_x.to_css(dest)?;
dest.write_str(" ")?;
self.semiaxis_y.to_css(dest)?;
dest.write_str(" ")?;
}
dest.write_str("at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}
42 changes: 42 additions & 0 deletions components/style/values/generics/basic_shape.rs
Expand Up @@ -378,6 +378,48 @@ where
}
}

impl<H, V, NonNegativeLengthPercentage> ToCss for Circle<H, V, NonNegativeLengthPercentage>
where
GenericPosition<H, V>: ToCss,
NonNegativeLengthPercentage: ToCss + PartialEq,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("circle(")?;
if self.radius != Default::default() {
self.radius.to_css(dest)?;
dest.write_str(" ")?;
}
dest.write_str("at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}

impl<H, V, NonNegativeLengthPercentage> ToCss for Ellipse<H, V, NonNegativeLengthPercentage>
where
GenericPosition<H, V>: ToCss,
NonNegativeLengthPercentage: ToCss + PartialEq,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("ellipse(")?;
if self.semiaxis_x != Default::default() || self.semiaxis_y != Default::default() {
self.semiaxis_x.to_css(dest)?;
dest.write_str(" ")?;
self.semiaxis_y.to_css(dest)?;
dest.write_str(" ")?;
}
dest.write_str("at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}

impl<L> Default for ShapeRadius<L> {
#[inline]
fn default() -> Self {
Expand Down
39 changes: 1 addition & 38 deletions components/style/values/specified/basic_shape.rs
Expand Up @@ -20,8 +20,7 @@ use crate::values::specified::SVGPathData;
use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage};
use crate::Zero;
use cssparser::Parser;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use style_traits::{ParseError, StyleParseErrorKind};

/// A specified alias for FillRule.
pub use crate::values::generics::basic_shape::FillRule;
Expand Down Expand Up @@ -239,23 +238,6 @@ impl Circle {
}
}

impl ToCss for Circle {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("circle(")?;
if generic::ShapeRadius::ClosestSide != self.radius {
self.radius.to_css(dest)?;
dest.write_str(" ")?;
}

dest.write_str("at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}

impl Parse for Ellipse {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down Expand Up @@ -293,25 +275,6 @@ impl Ellipse {
}
}

impl ToCss for Ellipse {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
dest.write_str("ellipse(")?;
if self.semiaxis_x != ShapeRadius::default() || self.semiaxis_y != ShapeRadius::default() {
self.semiaxis_x.to_css(dest)?;
dest.write_str(" ")?;
self.semiaxis_y.to_css(dest)?;
dest.write_str(" ")?;
}

dest.write_str("at ")?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}

impl Parse for ShapeRadius {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down

0 comments on commit e1e82db

Please sign in to comment.