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

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

Issue 103413006: Implement parsing of the new ellipse shape syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years 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
Index: Source/core/css/BasicShapeFunctions.cpp
diff --git a/Source/core/css/BasicShapeFunctions.cpp b/Source/core/css/BasicShapeFunctions.cpp
index a49ea1495f13840133cffa33215d08677639a282..415d63736052c8aa96db4daf96dc989834ff6e41 100644
--- a/Source/core/css/BasicShapeFunctions.cpp
+++ b/Source/core/css/BasicShapeFunctions.cpp
@@ -33,12 +33,51 @@
#include "core/css/CSSBasicShapes.h"
#include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSValuePool.h"
+#include "core/css/Pair.h"
#include "core/css/resolver/StyleResolverState.h"
#include "core/rendering/style/BasicShapes.h"
#include "core/rendering/style/RenderStyle.h"
namespace WebCore {
+static PassRefPtr<CSSPrimitiveValue> valueForCenterCoordinate(CSSValuePool& pool, const RenderStyle& style, const BasicShapeCenterCoordinate& center)
+{
+ CSSValueID keyword = CSSValueInvalid;
+ switch (center.keyword()) {
+ case BasicShapeCenterCoordinate::None:
+ 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;
+ }
+
+ return pool.createValue(Pair::create(pool.createIdentifierValue(keyword), pool.createValue(center.length(), style), Pair::DropIdenticalValues));
+}
+
+static PassRefPtr<CSSPrimitiveValue> basicShapeRadiusToCSSValue(CSSValuePool& pool, const RenderStyle& style, const BasicShapeRadius& radius)
+{
+ switch (radius.type()) {
+ case BasicShapeRadius::Value:
+ return pool.createValue(radius.value(), style);
+ case BasicShapeRadius::ClosestSide:
+ return pool.createIdentifierValue(CSSValueClosestSide);
+ case BasicShapeRadius::FarthestSide:
+ return pool.createIdentifierValue(CSSValueFarthestSide);
+ }
+
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicShape* basicShape)
{
CSSValuePool& pool = cssValuePool();
@@ -59,9 +98,9 @@ PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
basicShapeValue = rectangleValue.release();
break;
}
- case BasicShape::BasicShapeCircleType: {
- const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape);
- RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
+ case BasicShape::DeprecatedBasicShapeCircleType: {
+ const DeprecatedBasicShapeCircle* circle = static_cast<const DeprecatedBasicShapeCircle*>(basicShape);
+ RefPtr<CSSDeprecatedBasicShapeCircle> circleValue = CSSDeprecatedBasicShapeCircle::create();
circleValue->setCenterX(pool.createValue(circle->centerX(), style));
circleValue->setCenterY(pool.createValue(circle->centerY(), style));
@@ -70,9 +109,19 @@ PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
basicShapeValue = circleValue.release();
break;
}
- case BasicShape::BasicShapeEllipseType: {
- const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
- RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create();
+ case BasicShape::BasicShapeCircleType: {
+ const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape);
+ RefPtr<CSSBasicShapeCircle> circleValue = CSSBasicShapeCircle::create();
+
+ circleValue->setCenterX(valueForCenterCoordinate(pool, style, circle->centerX()));
+ circleValue->setCenterY(valueForCenterCoordinate(pool, style, circle->centerY()));
+ circleValue->setRadius(basicShapeRadiusToCSSValue(pool, style, circle->radius()));
+ basicShapeValue = circleValue.release();
+ break;
+ }
+ case BasicShape::DeprecatedBasicShapeEllipseType: {
+ const DeprecatedBasicShapeEllipse* ellipse = static_cast<const DeprecatedBasicShapeEllipse*>(basicShape);
+ RefPtr<CSSDeprecatedBasicShapeEllipse> ellipseValue = CSSDeprecatedBasicShapeEllipse::create();
ellipseValue->setCenterX(pool.createValue(ellipse->centerX(), style));
ellipseValue->setCenterY(pool.createValue(ellipse->centerY(), style));
@@ -82,6 +131,17 @@ PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
basicShapeValue = ellipseValue.release();
break;
}
+ case BasicShape::BasicShapeEllipseType: {
+ const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
+ RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create();
+
+ ellipseValue->setCenterX(valueForCenterCoordinate(pool, style, ellipse->centerX()));
+ ellipseValue->setCenterY(valueForCenterCoordinate(pool, style, ellipse->centerY()));
+ ellipseValue->setRadiusX(basicShapeRadiusToCSSValue(pool, style, ellipse->radiusX()));
+ ellipseValue->setRadiusY(basicShapeRadiusToCSSValue(pool, style, ellipse->radiusY()));
+ basicShapeValue = ellipseValue.release();
+ break;
+ }
case BasicShape::BasicShapePolygonType: {
const BasicShapePolygon* polygon = static_cast<const BasicShapePolygon*>(basicShape);
RefPtr<CSSBasicShapePolygon> polygonValue = CSSBasicShapePolygon::create();
@@ -119,6 +179,53 @@ static Length convertToLength(const StyleResolverState& state, CSSPrimitiveValue
return value->convertToLength<FixedConversion | PercentConversion>(state.cssToLengthConversionData());
}
+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()));
+ }
+
+ return BasicShapeCenterCoordinate(convertToLength(state, value));
+}
+
+static BasicShapeRadius cssValueToBasicShapeRadius(const StyleResolverState& state, PassRefPtr<CSSPrimitiveValue> radius)
+{
+ if (!radius)
+ return BasicShapeRadius(BasicShapeRadius::ClosestSide);
+
+ if (radius->isValueID()) {
+ switch (radius->getValueID()) {
+ case CSSValueClosestSide:
+ return BasicShapeRadius(BasicShapeRadius::ClosestSide);
+ case CSSValueFarthestSide:
+ return BasicShapeRadius(BasicShapeRadius::FarthestSide);
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ }
+
+ return BasicShapeRadius(convertToLength(state, radius.get()));
+}
+
PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const CSSBasicShape* basicShapeValue)
{
RefPtr<BasicShape> basicShape;
@@ -146,9 +253,9 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
basicShape = rect.release();
break;
}
- case CSSBasicShape::CSSBasicShapeCircleType: {
- const CSSBasicShapeCircle* circleValue = static_cast<const CSSBasicShapeCircle *>(basicShapeValue);
- RefPtr<BasicShapeCircle> circle = BasicShapeCircle::create();
+ case CSSBasicShape::CSSDeprecatedBasicShapeCircleType: {
+ const CSSDeprecatedBasicShapeCircle* circleValue = static_cast<const CSSDeprecatedBasicShapeCircle *>(basicShapeValue);
+ RefPtr<DeprecatedBasicShapeCircle> circle = DeprecatedBasicShapeCircle::create();
circle->setCenterX(convertToLength(state, circleValue->centerX()));
circle->setCenterY(convertToLength(state, circleValue->centerY()));
@@ -157,9 +264,25 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
basicShape = circle.release();
break;
}
- case CSSBasicShape::CSSBasicShapeEllipseType: {
- const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicShapeEllipse *>(basicShapeValue);
- RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
+ case CSSBasicShape::CSSBasicShapeCircleType: {
+ 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->setRadius(cssValueToBasicShapeRadius(state, circleValue->radius()));
+
+ basicShape = circle.release();
+ break;
+ }
+ case CSSBasicShape::CSSDeprecatedBasicShapeEllipseType: {
+ const CSSDeprecatedBasicShapeEllipse* ellipseValue = static_cast<const CSSDeprecatedBasicShapeEllipse *>(basicShapeValue);
+ RefPtr<DeprecatedBasicShapeEllipse> ellipse = DeprecatedBasicShapeEllipse::create();
ellipse->setCenterX(convertToLength(state, ellipseValue->centerX()));
ellipse->setCenterY(convertToLength(state, ellipseValue->centerY()));
@@ -169,6 +292,23 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
basicShape = ellipse.release();
break;
}
+ case CSSBasicShape::CSSBasicShapeEllipseType: {
+ 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->setRadiusX(cssValueToBasicShapeRadius(state, ellipseValue->radiusX()));
+ ellipse->setRadiusY(cssValueToBasicShapeRadius(state, ellipseValue->radiusY()));
+
+ basicShape = ellipse.release();
+ break;
+ }
case CSSBasicShape::CSSBasicShapePolygonType: {
const CSSBasicShapePolygon* polygonValue = static_cast<const CSSBasicShapePolygon *>(basicShapeValue);
RefPtr<BasicShapePolygon> polygon = BasicShapePolygon::create();

Powered by Google App Engine
This is Rietveld 408576698