Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Unified Diff: Source/core/css/BasicShapeFunctions.cpp

Issue 144373002: [CSS Shapes] Basic shapes' computed position should be a horizontal and vertical offset (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add FAIL test for intermediate result Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | Source/core/rendering/style/BasicShapes.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/BasicShapeFunctions.cpp
diff --git a/Source/core/css/BasicShapeFunctions.cpp b/Source/core/css/BasicShapeFunctions.cpp
index 10b23f9344d67eddb35397f8cd0a9b770ddf3b1e..d482a76a4d9a7024d75172e299a34212aeb7ffbb 100644
--- a/Source/core/css/BasicShapeFunctions.cpp
+++ b/Source/core/css/BasicShapeFunctions.cpp
@@ -40,25 +40,12 @@
namespace WebCore {
-static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool, const RenderStyle& style, const BasicShapeCenterCoordinate& center)
+static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool, const RenderStyle& style, const BasicShapeCenterCoordinate& center, EBoxOrient orientation)
{
- CSSValueID keyword = CSSValueInvalid;
- switch (center.keyword()) {
- case BasicShapeCenterCoordinate::None:
+ if (center.direction() == BasicShapeCenterCoordinate::TopLeft)
return pool.createValue(center.length(), style);
- case BasicShapeCenterCoordinate::Top:
- keyword = CSSValueTop;
- break;
- case BasicShapeCenterCoordinate::Right:
- keyword = CSSValueRight;
- break;
- case BasicShapeCenterCoordinate::Bottom:
- keyword = CSSValueBottom;
- break;
- case BasicShapeCenterCoordinate::Left:
- keyword = CSSValueLeft;
- break;
- }
+
+ CSSValueID keyword = orientation == HORIZONTAL ? CSSValueRight : CSSValueBottom;
return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), pool.createValue(center.length(), style), Pair::DropIdenticalValues));
}
@@ -113,8 +100,8 @@ PassRefPtrWillBeRawPtr<CSSValue> valueForBasicShape(const RenderStyle& style, co
const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape);
RefPtrWillBeRawPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
- circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->centerX()));
- circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->centerY()));
+ circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->centerX(), HORIZONTAL));
+ circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->centerY(), VERTICAL));
circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->radius()));
basicShapeValue = circleValue.release();
break;
@@ -135,8 +122,8 @@ PassRefPtrWillBeRawPtr<CSSValue> valueForBasicShape(const RenderStyle& style, co
const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
RefPtrWillBeRawPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create();
- ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->centerX()));
- ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse->centerY()));
+ ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->centerX(), HORIZONTAL));
+ ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse->centerY(), VERTICAL));
ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse->radiusX()));
ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse->radiusY()));
basicShapeValue = ellipseValue.release();
@@ -213,29 +200,41 @@ static LengthSize convertToLengthSize(const StyleResolverState& state, CSSPrimit
static BasicShapeCenterCoordinate convertToCenterCoordinate(const StyleResolverState& state, CSSPrimitiveValue* value)
{
- if (Pair* pair = value->getPairValue()) {
- BasicShapeCenterCoordinate::Keyword keyword = BasicShapeCenterCoordinate::None;
- switch (pair->first()->getValueID()) {
- case CSSValueTop:
- keyword = BasicShapeCenterCoordinate::Top;
- break;
- case CSSValueRight:
- keyword = BasicShapeCenterCoordinate::Right;
- break;
- case CSSValueBottom:
- keyword = BasicShapeCenterCoordinate::Bottom;
- break;
- case CSSValueLeft:
- keyword = BasicShapeCenterCoordinate::Left;
- break;
- default:
- ASSERT_NOT_REACHED();
- break;
- }
- return BasicShapeCenterCoordinate(keyword, convertToLength(state, pair->second()));
+ BasicShapeCenterCoordinate::Direction direction;
+ Length offset = Length(0, Fixed);
+
+ CSSValueID keyword = CSSValueTop;
+ if (!value) {
+ keyword = CSSValueCenter;
+ } else if (value->isValueID()) {
+ keyword = value->getValueID();
+ } else if (Pair* pair = value->getPairValue()) {
+ keyword = pair->first()->getValueID();
+ offset = convertToLength(state, pair->second());
+ } else {
+ offset = convertToLength(state, value);
+ }
+
+ switch (keyword) {
+ case CSSValueTop:
+ case CSSValueLeft:
+ direction = BasicShapeCenterCoordinate::TopLeft;
+ break;
+ case CSSValueRight:
+ case CSSValueBottom:
+ direction = BasicShapeCenterCoordinate::BottomRight;
+ break;
+ case CSSValueCenter:
+ direction = BasicShapeCenterCoordinate::TopLeft;
+ offset = Length(50, Percent);
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ direction = BasicShapeCenterCoordinate::TopLeft;
+ break;
}
- return BasicShapeCenterCoordinate(convertToLength(state, value));
+ return BasicShapeCenterCoordinate(direction, offset);
}
static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& state, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> radius)
@@ -300,13 +299,8 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShapeCircle *>(basicShapeValue);
RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
- if (circleValue->centerX() && circleValue->centerY()) {
- circle->setCenterX(convertToCenterCoordinate(state, circleValue->centerX()));
- circle->setCenterY(convertToCenterCoordinate(state, circleValue->centerY()));
- } else {
- circle->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)));
- circle->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)));
- }
+ circle->setCenterX(convertToCenterCoordinate(state, circleValue->centerX()));
+ circle->setCenterY(convertToCenterCoordinate(state, circleValue->centerY()));
circle->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius()));
basicShape = circle.release();
@@ -328,13 +322,8 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicShapeEllipse *>(basicShapeValue);
RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
- if (ellipseValue->centerX() && ellipseValue->centerY()) {
- ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->centerX()));
- ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->centerY()));
- } else {
- ellipse->setCenterX(BasicShapeCenterCoordinate(Length(50, Percent)));
- ellipse->setCenterY(BasicShapeCenterCoordinate(Length(50, Percent)));
- }
+ ellipse->setCenterX(convertToCenterCoordinate(state, ellipseValue->centerX()));
+ ellipse->setCenterY(convertToCenterCoordinate(state, ellipseValue->centerY()));
ellipse->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radiusX()));
ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radiusY()));
@@ -406,31 +395,9 @@ FloatPoint floatPointForCenterCoordinate(const BasicShapeCenterCoordinate& cente
{
FloatPoint p;
float offset = floatValueForLength(centerX.length(), boxSize.width());
- switch (centerX.keyword()) {
- case BasicShapeCenterCoordinate::None:
- case BasicShapeCenterCoordinate::Left:
- p.setX(offset);
- break;
- case BasicShapeCenterCoordinate::Right:
- p.setX(boxSize.width() - offset);
- break;
- default:
- ASSERT_NOT_REACHED();
- }
-
+ p.setX(centerX.direction() == BasicShapeCenterCoordinate::TopLeft ? offset : boxSize.width() - offset);
offset = floatValueForLength(centerY.length(), boxSize.height());
- switch (centerY.keyword()) {
- case BasicShapeCenterCoordinate::None:
- case BasicShapeCenterCoordinate::Top:
- p.setY(offset);
- break;
- case BasicShapeCenterCoordinate::Bottom:
- p.setY(boxSize.height() - offset);
- break;
- default:
- ASSERT_NOT_REACHED();
- }
-
+ p.setY(centerY.direction() == BasicShapeCenterCoordinate::TopLeft ? offset : boxSize.height() - offset);
return p;
}
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | Source/core/rendering/style/BasicShapes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698