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

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

Issue 98723006: Parse new circle shape syntax (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix stated issues 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
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | Source/core/css/CSSBasicShapes.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 7692d2dcb90b49adbaf039d0f50f77957471c6d8..8f948ae8eeb4d49654c17aadd78c4d88f106699e 100644
--- a/Source/core/css/BasicShapeFunctions.cpp
+++ b/Source/core/css/BasicShapeFunctions.cpp
@@ -33,12 +33,36 @@
#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));
+}
+
PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicShape* basicShape)
{
CSSValuePool& pool = cssValuePool();
@@ -59,9 +83,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,6 +94,26 @@ PassRefPtr<CSSValue> valueForBasicShape(const RenderStyle& style, const BasicSha
basicShapeValue = circleValue.release();
break;
}
+ 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()));
+ switch (circle->radius().type()) {
+ case BasicShapeRadius::Value:
+ circleValue->setRadius(pool.createValue(circle->radius().value(), style));
+ break;
+ case BasicShapeRadius::ClosestSide:
+ circleValue->setRadius(pool.createIdentifierValue(CSSValueClosestSide));
+ break;
+ case BasicShapeRadius::FarthestSide:
+ circleValue->setRadius(pool.createIdentifierValue(CSSValueFarthestSide));
+ break;
+ }
+ basicShapeValue = circleValue.release();
+ break;
+ }
case BasicShape::BasicShapeEllipseType: {
const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape);
RefPtr<CSSBasicShapeEllipse> ellipseValue = CSSBasicShapeEllipse::create();
@@ -123,6 +167,33 @@ 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));
+}
+
PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const CSSBasicShape* basicShapeValue)
{
RefPtr<BasicShape> basicShape;
@@ -150,9 +221,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()));
@@ -161,6 +232,40 @@ PassRefPtr<BasicShape> basicShapeForValue(const StyleResolverState& state, const
basicShape = circle.release();
break;
}
+ 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)));
+ }
+ if (RefPtr<CSSPrimitiveValue> radius = circleValue->radius()) {
+ if (radius->isValueID()) {
+ switch (radius->getValueID()) {
+ case CSSValueClosestSide:
+ circle->setRadius(BasicShapeRadius(BasicShapeRadius::ClosestSide));
+ break;
+ case CSSValueFarthestSide:
+ circle->setRadius(BasicShapeRadius(BasicShapeRadius::FarthestSide));
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ break;
+ }
+ } else {
+ circle->setRadius(BasicShapeRadius(convertToLength(state, radius.get())));
+ }
+ } else {
+ circle->setRadius(BasicShapeRadius(BasicShapeRadius::ClosestSide));
+ }
+
+ basicShape = circle.release();
+ break;
+ }
case CSSBasicShape::CSSBasicShapeEllipseType: {
const CSSBasicShapeEllipse* ellipseValue = static_cast<const CSSBasicShapeEllipse *>(basicShapeValue);
RefPtr<BasicShapeEllipse> ellipse = BasicShapeEllipse::create();
« no previous file with comments | « LayoutTests/fast/shapes/parsing/parsing-test-utils.js ('k') | Source/core/css/CSSBasicShapes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698