style: Should not serialize default radius of circle.

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
This commit is contained in:
violet 2019-06-18 11:54:41 +00:00 committed by Emilio Cobos Álvarez
parent c7c1fed95c
commit e1e82dbe5f
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
3 changed files with 43 additions and 71 deletions

View file

@ -10,8 +10,6 @@
use crate::values::computed::url::ComputedUrl; use crate::values::computed::url::ComputedUrl;
use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage}; use crate::values::computed::{Image, LengthPercentage, NonNegativeLengthPercentage};
use crate::values::generics::basic_shape as generic; use crate::values::generics::basic_shape as generic;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
/// A computed alias for FillRule. /// A computed alias for FillRule.
pub use crate::values::generics::basic_shape::FillRule; pub use crate::values::generics::basic_shape::FillRule;
@ -42,34 +40,3 @@ pub type Ellipse =
/// The computed value of `ShapeRadius` /// The computed value of `ShapeRadius`
pub type ShapeRadius = generic::GenericShapeRadius<NonNegativeLengthPercentage>; 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(")")
}
}

View file

@ -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> { impl<L> Default for ShapeRadius<L> {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {

View file

@ -20,8 +20,7 @@ use crate::values::specified::SVGPathData;
use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage}; use crate::values::specified::{LengthPercentage, NonNegativeLengthPercentage};
use crate::Zero; use crate::Zero;
use cssparser::Parser; use cssparser::Parser;
use std::fmt::{self, Write}; use style_traits::{ParseError, StyleParseErrorKind};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// A specified alias for FillRule. /// A specified alias for FillRule.
pub use crate::values::generics::basic_shape::FillRule; pub use crate::values::generics::basic_shape::FillRule;
@ -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 { impl Parse for Ellipse {
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,
@ -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 { impl Parse for ShapeRadius {
fn parse<'i, 't>( fn parse<'i, 't>(
context: &ParserContext, context: &ParserContext,