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

Unified Diff: Source/core/css/CSSParser-in.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 | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSValueKeywords.in » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/CSSParser-in.cpp
diff --git a/Source/core/css/CSSParser-in.cpp b/Source/core/css/CSSParser-in.cpp
index 132b74d87b4636fc05205c29bf99b1fae646f71b..98689989b10e78d214f4559be623ce84e5ab1862 100755
--- a/Source/core/css/CSSParser-in.cpp
+++ b/Source/core/css/CSSParser-in.cpp
@@ -5157,15 +5157,73 @@ PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeInsetRectangle(CSSParserValu
return shape;
}
+PassRefPtr<CSSPrimitiveValue> CSSParser::parseShapeRadius(CSSParserValue* value)
+{
+ if (value->id == CSSValueClosestSide || value->id == CSSValueFarthestSide)
+ return cssValuePool().createIdentifierValue(value->id);
+
+ if (!validUnit(value, FLength | FPercent | FNonNeg))
+ return 0;
+
+ return createPrimitiveNumericValue(value);
+}
+
PassRefPtr<CSSBasicShape> CSSParser::parseBasicShapeCircle(CSSParserValueList* args)
{
ASSERT(args);
+ // circle(radius)
+ // circle(radius at <position>
+ // circle(at <position>)
+ // where position defines centerX and centerY using a CSS <position> data type.
+ RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
+
+ for (CSSParserValue* argument = args->current(); argument; argument = args->next()) {
+ // The call to parseFillPosition below should consume all of the
+ // arguments except the first two. Thus, and index greater than one
+ // indicates an invalid production.
+ if (args->currentIndex() > 1)
+ return 0;
+
+ if (!args->currentIndex() && argument->id != CSSValueAt) {
+ if (RefPtr<CSSPrimitiveValue> radius = parseShapeRadius(argument)) {
+ shape->setRadius(radius);
+ continue;
+ }
+
+ return 0;
+ }
+
+ if (argument->id == CSSValueAt) {
+ RefPtr<CSSValue> centerX;
+ RefPtr<CSSValue> centerY;
+ args->next(); // set list to start of position center
+ parseFillPosition(args, centerX, centerY);
+ if (centerX && centerY) {
+ ASSERT(centerX->isPrimitiveValue());
+ ASSERT(centerY->isPrimitiveValue());
+ shape->setCenterX(toCSSPrimitiveValue(centerX.get()));
+ shape->setCenterY(toCSSPrimitiveValue(centerY.get()));
+ } else {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+ }
+
+ return shape;
+}
+
+PassRefPtr<CSSBasicShape> CSSParser::parseDeprecatedBasicShapeCircle(CSSParserValueList* args)
+{
+ ASSERT(args);
+
// circle(centerX, centerY, radius)
if (args->size() != 5)
return 0;
- RefPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
+ RefPtr<CSSDeprecatedBasicShapeCircle> shape = CSSDeprecatedBasicShapeCircle::create();
unsigned argumentNumber = 0;
CSSParserValue* argument = args->current();
@@ -5324,6 +5382,20 @@ static bool isBoxValue(CSSValueID valueId)
return false;
}
+// FIXME This function is temporary to allow for an orderly transition between
+// the new CSS Shapes circle and ellipse syntax. It will be removed when the
+// old syntax is removed.
+static bool isDeprecatedBasicShape(CSSParserValueList* args)
+{
+ for (unsigned i = args->currentIndex(); i < args->size(); ++i) {
+ CSSParserValue* value = args->valueAt(i);
+ if (isComma(value))
+ return true;
+ }
+
+ return false;
+}
+
PassRefPtr<CSSValue> CSSParser::parseShapeProperty(CSSPropertyID propId)
{
if (!RuntimeEnabledFeatures::cssShapesEnabled())
@@ -5396,7 +5468,10 @@ PassRefPtr<CSSPrimitiveValue> CSSParser::parseBasicShape()
if (equalIgnoringCase(value->function->name, "rectangle("))
shape = parseBasicShapeRectangle(args);
else if (equalIgnoringCase(value->function->name, "circle("))
- shape = parseBasicShapeCircle(args);
+ if (isDeprecatedBasicShape(args))
+ shape = parseDeprecatedBasicShapeCircle(args);
+ else
+ shape = parseBasicShapeCircle(args);
else if (equalIgnoringCase(value->function->name, "ellipse("))
shape = parseBasicShapeEllipse(args);
else if (equalIgnoringCase(value->function->name, "polygon("))
« no previous file with comments | « Source/core/css/CSSParser.h ('k') | Source/core/css/CSSValueKeywords.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698