Skip to content

Commit

Permalink
Bug 1473184: Remove serialize_basicshape_position. r=xidorn
Browse files Browse the repository at this point in the history
Per w3c/csswg-drafts#2274. There's a whole lot of new failures, but those need to be updated along with the spec changes in that issue.

We did resolve that position serialized the same everywhere though.

Differential Revision: https://phabricator.services.mozilla.com/D1933

UltraBlame original commit: cb6837c0ee5a192ff57bcba2e7dab3a9ff1a5580
  • Loading branch information
marco-c committed Oct 3, 2019
1 parent ce5d61c commit 796a1c1
Show file tree
Hide file tree
Showing 22 changed files with 2,710 additions and 82 deletions.
85 changes: 3 additions & 82 deletions servo/components/style/values/specified/basic_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,17 @@


use crate::parser::{Parse, ParserContext};
use crate::values::computed::Percentage;
use crate::values::generics::basic_shape as generic;
use crate::values::generics::basic_shape::{GeometryBox, Path, PolygonCoord};
use crate::values::generics::basic_shape::{ShapeBox, ShapeSource};
use crate::values::generics::rect::Rect;
use crate::values::specified::border::BorderRadius;
use crate::values::specified::image::Image;
use crate::values::specified::position::{HorizontalPosition, Position, PositionComponent};
use crate::values::specified::position::{Side, VerticalPosition};
use crate::values::specified::position::{HorizontalPosition, VerticalPosition, Position};
use crate::values::specified::url::SpecifiedUrl;
use crate::values::specified::LengthOrPercentage;
use crate::values::specified::SVGPathData;
use cssparser::Parser;
use std::borrow::Cow;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};

Expand Down Expand Up @@ -249,7 +246,7 @@ impl ToCss for Circle {
}

dest.write_str("at ")?;
serialize_basicshape_position(&self.position, dest)?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}
Expand Down Expand Up @@ -305,7 +302,7 @@ impl ToCss for Ellipse {
}

dest.write_str("at ")?;
serialize_basicshape_position(&self.position, dest)?;
self.position.to_css(dest)?;
dest.write_str(")")
}
}
Expand All @@ -326,82 +323,6 @@ impl Parse for ShapeRadius {
}
}







fn serialize_basicshape_position<W>(position: &Position, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
fn to_keyword_and_lop<S>(component: &PositionComponent<S>) -> (S, Cow<LengthOrPercentage>)
where
S: Copy + Side,
{
match *component {
PositionComponent::Center => (
S::start(),
Cow::Owned(LengthOrPercentage::Percentage(Percentage(0.5))),
),
PositionComponent::Side(keyword, None) => {


let p = if keyword.is_start() { 0. } else { 1. };
(
S::start(),
Cow::Owned(LengthOrPercentage::Percentage(Percentage(p))),
)
},
PositionComponent::Side(keyword, Some(ref lop)) if !keyword.is_start() => {
if let LengthOrPercentage::Percentage(p) = *to_non_zero_length(lop) {
(
S::start(),
Cow::Owned(LengthOrPercentage::Percentage(Percentage(1. - p.0))),
)
} else {
(keyword, Cow::Borrowed(lop))
}
},
PositionComponent::Length(ref lop) | PositionComponent::Side(_, Some(ref lop)) => {
(S::start(), to_non_zero_length(lop))
},
}
}

fn to_non_zero_length(lop: &LengthOrPercentage) -> Cow<LengthOrPercentage> {
match *lop {
LengthOrPercentage::Length(ref l) if l.is_zero() => {
Cow::Owned(LengthOrPercentage::Percentage(Percentage(0.)))
},
_ => Cow::Borrowed(lop),
}
}

fn write_pair<A, B, W>(a: &A, b: &B, dest: &mut CssWriter<W>) -> fmt::Result
where
A: ToCss,
B: ToCss,
W: Write,
{
a.to_css(dest)?;
dest.write_str(" ")?;
b.to_css(dest)
}

let (x_pos, x_lop) = to_keyword_and_lop(&position.horizontal);
let (y_pos, y_lop) = to_keyword_and_lop(&position.vertical);

if x_pos.is_start() && y_pos.is_start() {
return write_pair(&*x_lop, &*y_lop, dest);
}

write_pair(&x_pos, &*x_lop, dest)?;
dest.write_str(" ")?;
write_pair(&y_pos, &*y_lop, dest)
}

impl Parse for Polygon {
fn parse<'i, 't>(
context: &ParserContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,24 @@
[e.style['clip-path'\] = "border-box circle(7% at 8% 9%)" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "circle()" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "circle(1px)" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "circle(closest-side)" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "circle(farthest-side at center top)" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "circle(4% at top right)" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "ellipse()" should set the property value]
expected: FAIL

[e.style['clip-path'\] = "ellipse(farthest-side 4% at bottom left)" should set the property value]
expected: FAIL

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[basic-shape-circle-ellipse-serialization.html]
[Serialization of basic shapes]
expected: FAIL

[Serialization of basic shapes 1]
expected: FAIL

[Serialization of basic shapes 2]
expected: FAIL

[Serialization of basic shapes 3]
expected: FAIL

[Serialization of basic shapes 4]
expected: FAIL

[Serialization of basic shapes 5]
expected: FAIL

[Serialization of basic shapes 6]
expected: FAIL

[Serialization of basic shapes 7]
expected: FAIL

[Serialization of basic shapes 8]
expected: FAIL

[Serialization of basic shapes 9]
expected: FAIL

[Serialization of basic shapes 10]
expected: FAIL

[Serialization of basic shapes 11]
expected: FAIL

[Serialization of basic shapes 14]
expected: FAIL

[Serialization of basic shapes 15]
expected: FAIL

[Serialization of basic shapes 16]
expected: FAIL

[Serialization of basic shapes 17]
expected: FAIL

[Serialization of basic shapes 18]
expected: FAIL

[Serialization of basic shapes 23]
expected: FAIL

[Serialization of basic shapes 24]
expected: FAIL

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[shape-outside-valid-position.html]
[e.style['shape-outside'\] = "circle(at 10%)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at bottom 10% right 20%)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at bottom right)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at center)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at center left)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at left)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at top)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(at top center)" should set the property value]
expected: FAIL

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@
[e.style['shape-outside'\] = "cross-fade(url(\\"https://example.com/\\"), green)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle()" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(1px)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(closest-side)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(farthest-side at center top)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "circle(4% at top right)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "ellipse()" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "ellipse(3% 2%)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "ellipse(closest-side 1px)" should set the property value]
expected: FAIL

[e.style['shape-outside'\] = "ellipse(farthest-side 4% at bottom left)" should set the property value]
expected: FAIL

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
[Position argument only - computed]
expected: FAIL

[No arguments - inline]
expected: FAIL

[Radial argument only - inline]
expected: FAIL

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@
[circle(closest-side) - computed]
expected: FAIL

[circle() - inline]
expected: FAIL

[circle(50px) - inline]
expected: FAIL

[circle(50%) - inline]
expected: FAIL

[circle(closest-side) - inline]
expected: FAIL

[circle(farthest-side) - inline]
expected: FAIL

Loading

0 comments on commit 796a1c1

Please sign in to comment.