Commit 0b45a3d6 authored by rob.buis's avatar rob.buis Committed by Commit bot

Move text-shadow/box-shadow properties into CSSPropertyParser

Move text-shadow/box-shadow properties from
LegacyCSSPropertyParser into CSSPropertyParser.

BUG=499780

Review URL: https://codereview.chromium.org/1419223002

Cr-Commit-Position: refs/heads/master@{#357021}
parent d8379fad
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<style> <style>
.parent { .parent {
box-shadow: 30px 10px 30px 10px black, box-shadow: 30px 10px 30px 10px black;
} }
.target { .target {
display: inline-block; display: inline-block;
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
margin-right: 20px; margin-right: 20px;
margin-bottom: 30px; margin-bottom: 30px;
color: green; color: green;
box-shadow: 10px 30px 10px 30px black, box-shadow: 10px 30px 10px 30px black;
} }
.expected { .expected {
margin-right: 40px; margin-right: 40px;
......
...@@ -18,6 +18,16 @@ Negative blur radius value, with a negative spread defined : 10px 10px -1px -1px ...@@ -18,6 +18,16 @@ Negative blur radius value, with a negative spread defined : 10px 10px -1px -1px
PASS cssRule.type is 1 PASS cssRule.type is 1
PASS declaration.length is 0 PASS declaration.length is 0
PASS declaration.getPropertyValue('box-shadow') is "" PASS declaration.getPropertyValue('box-shadow') is ""
Extraneous commas at beginning : ,,,,,10px 10px rgb(255, 0, 0)
PASS cssRule.type is 1
PASS declaration.length is 0
PASS declaration.getPropertyValue('box-shadow') is ""
Extraneous commas at end : 10px 10px rgb(255, 0, 0),,,,,
PASS cssRule.type is 1
PASS declaration.length is 0
PASS declaration.getPropertyValue('box-shadow') is ""
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
...@@ -26,5 +26,7 @@ function testInvalidFilterRule(description, rule) ...@@ -26,5 +26,7 @@ function testInvalidFilterRule(description, rule)
testInvalidFilterRule("Negative blur radius value", "10px 10px -1px rgb(255, 0, 0)"); testInvalidFilterRule("Negative blur radius value", "10px 10px -1px rgb(255, 0, 0)");
testInvalidFilterRule("Negative blur radius value, with a spread defined", "10px 10px -1px 10px rgb(255, 0, 0)"); testInvalidFilterRule("Negative blur radius value, with a spread defined", "10px 10px -1px 10px rgb(255, 0, 0)");
testInvalidFilterRule("Negative blur radius value, with a negative spread defined", "10px 10px -1px -1px rgb(255, 0, 0)"); testInvalidFilterRule("Negative blur radius value, with a negative spread defined", "10px 10px -1px -1px rgb(255, 0, 0)");
testInvalidFilterRule("Extraneous commas at beginning", ",,,,,10px 10px rgb(255, 0, 0)");
testInvalidFilterRule("Extraneous commas at end", "10px 10px rgb(255, 0, 0),,,,,");
successfullyParsed = true; successfullyParsed = true;
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "core/css/CSSFontFeatureValue.h" #include "core/css/CSSFontFeatureValue.h"
#include "core/css/CSSPrimitiveValueMappings.h" #include "core/css/CSSPrimitiveValueMappings.h"
#include "core/css/CSSQuadValue.h" #include "core/css/CSSQuadValue.h"
#include "core/css/CSSShadowValue.h"
#include "core/css/CSSStringValue.h" #include "core/css/CSSStringValue.h"
#include "core/css/CSSTimingFunctionValue.h" #include "core/css/CSSTimingFunctionValue.h"
#include "core/css/CSSURIValue.h" #include "core/css/CSSURIValue.h"
...@@ -1144,13 +1145,6 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationIterationCount(CSSParser ...@@ -1144,13 +1145,6 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationIterationCount(CSSParser
return consumeNumber(range, ValueRangeNonNegative); return consumeNumber(range, ValueRangeNonNegative);
} }
static PassRefPtrWillBeRawPtr<CSSValue> consumeZIndex(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeInteger(range);
}
static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationPlayState(CSSParserTokenRange& range) static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationPlayState(CSSParserTokenRange& range)
{ {
CSSValueID id = range.peek().id(); CSSValueID id = range.peek().id();
...@@ -1257,7 +1251,6 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange& ...@@ -1257,7 +1251,6 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeCubicBezier(CSSParserTokenRange&
return nullptr; return nullptr;
} }
static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range) static PassRefPtrWillBeRawPtr<CSSValue> consumeAnimationTimingFunction(CSSParserTokenRange& range)
{ {
CSSValueID id = range.peek().id(); CSSValueID id = range.peek().id();
...@@ -1385,6 +1378,73 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeWidowsOrOrphans(CSSParserTokenRan ...@@ -1385,6 +1378,73 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeWidowsOrOrphans(CSSParserTokenRan
return consumePositiveInteger(range); return consumePositiveInteger(range);
} }
static PassRefPtrWillBeRawPtr<CSSValue> consumeZIndex(CSSParserTokenRange& range)
{
if (range.peek().id() == CSSValueAuto)
return consumeIdent(range);
return consumeInteger(range);
}
static PassRefPtrWillBeRawPtr<CSSShadowValue> parseSingleShadow(CSSParserTokenRange& range, const CSSParserContext& context, bool allowInset, bool allowSpread)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nullptr;
RefPtrWillBeRawPtr<CSSValue> color = nullptr;
if (range.atEnd())
return nullptr;
if (range.peek().id() == CSSValueInset) {
if (!allowInset)
return nullptr;
style = consumeIdent(range);
}
color = consumeColor(range, context);
RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalOffset = consumeLength(range, context.mode(), ValueRangeAll);
if (!horizontalOffset)
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalOffset = consumeLength(range, context.mode(), ValueRangeAll);
if (!verticalOffset)
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> blurRadius = consumeLength(range, context.mode(), ValueRangeAll);
RefPtrWillBeRawPtr<CSSPrimitiveValue> spreadDistance = nullptr;
if (blurRadius) {
// Blur radius must be non-negative.
if (blurRadius->getDoubleValue() < 0)
return nullptr;
if (allowSpread)
spreadDistance = consumeLength(range, context.mode(), ValueRangeAll);
}
if (!range.atEnd()) {
if (!color)
color = consumeColor(range, context);
if (range.peek().id() == CSSValueInset) {
if (!allowInset || style)
return nullptr;
style = consumeIdent(range);
}
}
return CSSShadowValue::create(horizontalOffset.release(), verticalOffset.release(), blurRadius.release(),
spreadDistance.release(), style.release(), color.release());
}
static PassRefPtrWillBeRawPtr<CSSValue> consumeShadow(CSSParserTokenRange& range, const CSSParserContext& context, bool isBoxShadowProperty)
{
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
RefPtrWillBeRawPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
do {
if (RefPtrWillBeRawPtr<CSSShadowValue> shadowValue = parseSingleShadow(range, context, isBoxShadowProperty, isBoxShadowProperty))
shadowValueList->append(shadowValue.release());
else
return nullptr;
} while (consumeCommaIncludingWhitespace(range));
return shadowValueList;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty) PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID unresolvedProperty)
{ {
CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty); CSSPropertyID property = resolveCSSPropertyID(unresolvedProperty);
...@@ -1489,6 +1549,9 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ...@@ -1489,6 +1549,9 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
return consumeColor(m_range, m_context, inQuirksMode()); return consumeColor(m_range, m_context, inQuirksMode());
case CSSPropertyZIndex: case CSSPropertyZIndex:
return consumeZIndex(m_range); return consumeZIndex(m_range);
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
case CSSPropertyBoxShadow:
return consumeShadow(m_range, m_context, property == CSSPropertyBoxShadow);
default: default:
return nullptr; return nullptr;
} }
......
...@@ -201,7 +201,6 @@ private: ...@@ -201,7 +201,6 @@ private:
PassRefPtrWillBeRawPtr<CSSValue> parsePaintOrder() const; PassRefPtrWillBeRawPtr<CSSValue> parsePaintOrder() const;
// CSS3 Parsing Routines (for properties specific to CSS3) // CSS3 Parsing Routines (for properties specific to CSS3)
PassRefPtrWillBeRawPtr<CSSValueList> parseShadow(CSSParserValueList*, CSSPropertyID);
PassRefPtrWillBeRawPtr<CSSShadowValue> parseSingleShadow(CSSParserValueList*, bool allowInset, bool allowSpread); PassRefPtrWillBeRawPtr<CSSShadowValue> parseSingleShadow(CSSParserValueList*, bool allowInset, bool allowSpread);
bool parseBorderImageShorthand(CSSPropertyID, bool important); bool parseBorderImageShorthand(CSSPropertyID, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseBorderImage(CSSPropertyID); PassRefPtrWillBeRawPtr<CSSValue> parseBorderImage(CSSPropertyID);
......
...@@ -761,13 +761,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import ...@@ -761,13 +761,6 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
case CSSPropertyOutlineOffset: case CSSPropertyOutlineOffset:
validPrimitive = validUnit(value, FLength); validPrimitive = validUnit(value, FLength);
break; break;
case CSSPropertyTextShadow: // CSS2 property, dropped in CSS2.1, back in CSS3, so treat as CSS3
case CSSPropertyBoxShadow:
if (id == CSSValueNone)
validPrimitive = true;
else
parsedValue = parseShadow(m_valueList, propId);
break;
case CSSPropertyWebkitBoxReflect: case CSSPropertyWebkitBoxReflect:
if (id == CSSValueNone) if (id == CSSValueNone)
validPrimitive = true; validPrimitive = true;
...@@ -1230,6 +1223,8 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import ...@@ -1230,6 +1223,8 @@ bool CSSPropertyParser::parseValue(CSSPropertyID unresolvedProperty, bool import
case CSSPropertyWebkitTextFillColor: case CSSPropertyWebkitTextFillColor:
case CSSPropertyColor: case CSSPropertyColor:
case CSSPropertyZIndex: case CSSPropertyZIndex:
case CSSPropertyTextShadow:
case CSSPropertyBoxShadow:
validPrimitive = false; validPrimitive = false;
break; break;
...@@ -3872,22 +3867,6 @@ bool CSSPropertyParser::parseColorFromValue(const CSSParserValue* value, RGBA32& ...@@ -3872,22 +3867,6 @@ bool CSSPropertyParser::parseColorFromValue(const CSSParserValue* value, RGBA32&
return true; return true;
} }
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseShadow(CSSParserValueList* valueList, CSSPropertyID propID)
{
RefPtrWillBeRawPtr<CSSValueList> shadowValueList = CSSValueList::createCommaSeparated();
const bool isBoxShadowProperty = propID == CSSPropertyBoxShadow;
while (RefPtrWillBeRawPtr<CSSShadowValue> shadowValue = parseSingleShadow(valueList, isBoxShadowProperty, isBoxShadowProperty)) {
shadowValueList->append(shadowValue);
if (!valueList->current())
break;
if (!consumeComma(valueList))
return nullptr;
}
if (shadowValueList->length() == 0)
return nullptr;
return shadowValueList;
}
PassRefPtrWillBeRawPtr<CSSShadowValue> CSSPropertyParser::parseSingleShadow(CSSParserValueList* valueList, bool allowInset, bool allowSpread) PassRefPtrWillBeRawPtr<CSSShadowValue> CSSPropertyParser::parseSingleShadow(CSSParserValueList* valueList, bool allowInset, bool allowSpread)
{ {
RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nullptr; RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment