This source file includes following definitions.
- equal
- equalIgnoringCase
- equalIgnoringCase
- createPrimitiveValuePair
- m_hasSeenAnimationPropertyKeyword
- commitFirstAnimation
- hasCommittedFirstAnimation
- commitAnimationPropertyKeyword
- animationPropertyKeywordAllowed
- hasSeenAnimationPropertyKeyword
- sawAnimationPropertyKeyword
- m_implicitShorthand
- addPropertyWithPrefixingVariant
- addProperty
- rollbackLastProperties
- completeURL
- validCalculationUnit
- shouldAcceptUnitLessValues
- validUnit
- createPrimitiveNumericValue
- createPrimitiveStringValue
- isComma
- isForwardSlashOperator
- isGeneratedImageValue
- validWidthOrHeight
- parseValidPrimitive
- addExpandedPropertyForValue
- parseValue
- addFillValue
- parseBackgroundClip
- parseFillShorthand
- addAnimationValue
- parseAnimationShorthand
- parseTransitionShorthand
- parseColumnWidth
- parseColumnCount
- parseColumnsShorthand
- parseShorthand
- parse4Values
- parsePage
- parseSize
- parseSizeParameter
- parseQuotes
- parseContent
- parseAttr
- parseBackgroundColor
- parseFillImage
- parseFillPositionX
- parseFillPositionY
- parseFillPositionComponent
- isValueConflictingWithCurrentEdge
- isFillPositionKeyword
- parse4ValuesFillPosition
- parse3ValuesFillPosition
- isPotentialPositionValue
- parseFillPosition
- parse2ValuesFillPosition
- parseFillRepeat
- parseFillSize
- parseFillProperty
- parseAnimationDelay
- parseAnimationDirection
- parseAnimationDuration
- parseAnimationFillMode
- parseAnimationIterationCount
- parseAnimationName
- parseAnimationPlayState
- parseAnimationProperty
- parseWebkitTransformOriginShorthand
- parseCubicBezierTimingFunctionValue
- parseAnimationTimingFunction
- parseAnimationProperty
- parseIntegerOrStringFromGridPosition
- parseGridPosition
- gridMissingGridPositionValue
- parseGridItemPositionShorthand
- parseGridTemplateRowsAndAreas
- parseGridTemplateShorthand
- parseGridAreaShorthand
- parseSingleGridAreaLonghand
- parseGridLineNames
- parseGridTrackList
- parseGridTrackRepeatFunction
- parseGridTrackSize
- parseGridBreadth
- parseGridTemplateAreasRow
- parseGridTemplateAreas
- parseCounterContent
- parseClipShape
- completeBorderRadii
- parseInsetRoundedCorners
- parseBasicShapeInset
- isItemPositionKeyword
- parseItemPositionOverflowPosition
- parseShapeRadius
- parseBasicShapeCircle
- parseBasicShapeEllipse
- parseBasicShapePolygon
- isBoxValue
- parseShapeProperty
- parseBasicShapeAndOrBox
- parseBasicShape
- parseFont
- add
- commit
- parseFontFamily
- parseLineHeight
- parseFontSize
- parseFontVariant
- parseFontWeight
- parseFontFaceSrcURI
- parseFontFaceSrcLocal
- parseFontFaceSrc
- parseFontFaceUnicodeRange
- checkForValidDouble
- parseDouble
- parseColorIntOrPercentage
- isTenthAlpha
- parseAlphaValue
- mightBeRGBA
- mightBeRGB
- fastParseColorInternal
- fastParseColor
#include "config.h"
#include "core/css/parser/CSSPropertyParser.h"
#include "RuntimeEnabledFeatures.h"
#include "core/rendering/RenderTheme.h"
#include "core/svg/SVGPaint.h"
#include "CSSValueKeywords.h"
#include "RuntimeEnabledFeatures.h"
#include "StylePropertyShorthand.h"
#include "core/css/CSSArrayFunctionValue.h"
#include "core/css/CSSAspectRatioValue.h"
#include "core/css/CSSBasicShapes.h"
#include "core/css/CSSBorderImage.h"
#include "core/css/CSSCanvasValue.h"
#include "core/css/CSSCrossfadeValue.h"
#include "core/css/CSSCursorImageValue.h"
#include "core/css/CSSFontFaceSrcValue.h"
#include "core/css/CSSFontFeatureValue.h"
#include "core/css/CSSFunctionValue.h"
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSGridLineNamesValue.h"
#include "core/css/CSSGridTemplateAreasValue.h"
#include "core/css/CSSImageSetValue.h"
#include "core/css/CSSImageValue.h"
#include "core/css/CSSInheritedValue.h"
#include "core/css/CSSInitialValue.h"
#include "core/css/CSSKeyframeRule.h"
#include "core/css/CSSKeyframesRule.h"
#include "core/css/CSSLineBoxContainValue.h"
#include "core/css/CSSParserValues.h"
#include "core/css/CSSPrimitiveValue.h"
#include "core/css/CSSPropertySourceData.h"
#include "core/css/CSSReflectValue.h"
#include "core/css/CSSSVGDocumentValue.h"
#include "core/css/CSSSelector.h"
#include "core/css/CSSShadowValue.h"
#include "core/css/CSSTimingFunctionValue.h"
#include "core/css/CSSTransformValue.h"
#include "core/css/CSSUnicodeRangeValue.h"
#include "core/css/CSSValueList.h"
#include "core/css/CSSValuePool.h"
#include "core/css/Counter.h"
#include "core/css/HashTools.h"
#include "core/css/Pair.h"
#include "core/css/Rect.h"
#include "core/css/RuntimeCSSEnabled.h"
#include "core/css/parser/CSSParserIdioms.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/rendering/RenderTheme.h"
#include "core/svg/SVGParserUtilities.h"
#include "platform/FloatConversion.h"
#include "wtf/BitArray.h"
#include "wtf/HexNumber.h"
#include "wtf/text/StringBuffer.h"
#include "wtf/text/StringBuilder.h"
#include "wtf/text/StringImpl.h"
#include "wtf/text/TextEncoding.h"
#include <limits.h>
using namespace std;
namespace WebCore {
static const double MAX_SCALE = 1000000;
template <unsigned N>
static bool equal(const CSSParserString& a, const char (&b)[N])
{
unsigned length = N - 1;
if (a.length() != length)
return false;
return a.is8Bit() ? WTF::equal(a.characters8(), reinterpret_cast<const LChar*>(b), length) : WTF::equal(a.characters16(), reinterpret_cast<const LChar*>(b), length);
}
template <unsigned N>
static bool equalIgnoringCase(const CSSParserString& a, const char (&b)[N])
{
unsigned length = N - 1;
if (a.length() != length)
return false;
return a.is8Bit() ? WTF::equalIgnoringCase(b, a.characters8(), length) : WTF::equalIgnoringCase(b, a.characters16(), length);
}
template <unsigned N>
static bool equalIgnoringCase(CSSParserValue* value, const char (&b)[N])
{
ASSERT(value->unit == CSSPrimitiveValue::CSS_IDENT || value->unit == CSSPrimitiveValue::CSS_STRING);
return equalIgnoringCase(value->string, b);
}
static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createPrimitiveValuePair(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> first, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> second, Pair::IdenticalValuesPolicy identicalValuesPolicy = Pair::DropIdenticalValues)
{
return cssValuePool().createValue(Pair::create(first, second, identicalValuesPolicy));
}
class AnimationParseContext {
public:
AnimationParseContext()
: m_animationPropertyKeywordAllowed(true)
, m_firstAnimationCommitted(false)
, m_hasSeenAnimationPropertyKeyword(false)
{
}
void commitFirstAnimation()
{
m_firstAnimationCommitted = true;
}
bool hasCommittedFirstAnimation() const
{
return m_firstAnimationCommitted;
}
void commitAnimationPropertyKeyword()
{
m_animationPropertyKeywordAllowed = false;
}
bool animationPropertyKeywordAllowed() const
{
return m_animationPropertyKeywordAllowed;
}
bool hasSeenAnimationPropertyKeyword() const
{
return m_hasSeenAnimationPropertyKeyword;
}
void sawAnimationPropertyKeyword()
{
m_hasSeenAnimationPropertyKeyword = true;
}
private:
bool m_animationPropertyKeywordAllowed;
bool m_firstAnimationCommitted;
bool m_hasSeenAnimationPropertyKeyword;
};
CSSPropertyParser::CSSPropertyParser(OwnPtr<CSSParserValueList>& valueList,
const CSSParserContext& context, bool inViewport, bool savedImportant,
WillBeHeapVector<CSSProperty, 256>& parsedProperties, bool& hasFontFaceOnlyValues)
: m_valueList(valueList)
, m_context(context)
, m_inViewport(inViewport)
, m_important(savedImportant)
, m_parsedProperties(parsedProperties)
, m_hasFontFaceOnlyValues(hasFontFaceOnlyValues)
, m_inParseShorthand(0)
, m_currentShorthand(CSSPropertyInvalid)
, m_implicitShorthand(false)
{
}
CSSPropertyParser::~CSSPropertyParser()
{
}
void CSSPropertyParser::addPropertyWithPrefixingVariant(CSSPropertyID propId, PassRefPtrWillBeRawPtr<CSSValue> value, bool important, bool implicit)
{
RefPtrWillBeRawPtr<CSSValue> val = value.get();
addProperty(propId, value, important, implicit);
CSSPropertyID prefixingVariant = prefixingVariantForPropertyId(propId);
if (prefixingVariant == propId)
return;
if (m_currentShorthand) {
m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
addProperty(prefixingVariant, val.release(), important, implicit);
m_currentShorthand = prefixingVariantForPropertyId(m_currentShorthand);
} else {
addProperty(prefixingVariant, val.release(), important, implicit);
}
}
void CSSPropertyParser::addProperty(CSSPropertyID propId, PassRefPtrWillBeRawPtr<CSSValue> value, bool important, bool implicit)
{
if (!m_currentShorthand) {
m_parsedProperties.append(CSSProperty(propId, value, important, false, CSSPropertyInvalid, m_implicitShorthand || implicit));
return;
}
Vector<StylePropertyShorthand, 4> shorthands;
getMatchingShorthandsForLonghand(propId, &shorthands);
if (shorthands.size() == 1)
m_parsedProperties.append(CSSProperty(propId, value, important, true, CSSPropertyInvalid, m_implicitShorthand || implicit));
else
m_parsedProperties.append(CSSProperty(propId, value, important, true, indexOfShorthandForLonghand(m_currentShorthand, shorthands), m_implicitShorthand || implicit));
}
void CSSPropertyParser::rollbackLastProperties(int num)
{
ASSERT(num >= 0);
ASSERT(m_parsedProperties.size() >= static_cast<unsigned>(num));
m_parsedProperties.shrink(m_parsedProperties.size() - num);
}
KURL CSSPropertyParser::completeURL(const String& url) const
{
return m_context.completeURL(url);
}
bool CSSPropertyParser::validCalculationUnit(CSSParserValue* value, Units unitflags, ReleaseParsedCalcValueCondition releaseCalc)
{
bool mustBeNonNegative = unitflags & FNonNeg;
if (!parseCalculation(value, mustBeNonNegative ? ValueRangeNonNegative : ValueRangeAll))
return false;
bool b = false;
switch (m_parsedCalculation->category()) {
case CalcLength:
b = (unitflags & FLength);
break;
case CalcPercent:
b = (unitflags & FPercent);
if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
b = false;
break;
case CalcNumber:
b = (unitflags & FNumber);
if (!b && (unitflags & FInteger) && m_parsedCalculation->isInt())
b = true;
if (b && mustBeNonNegative && m_parsedCalculation->isNegative())
b = false;
break;
case CalcPercentLength:
b = (unitflags & FPercent) && (unitflags & FLength);
break;
case CalcPercentNumber:
b = (unitflags & FPercent) && (unitflags & FNumber);
break;
case CalcOther:
break;
}
if (!b || releaseCalc == ReleaseParsedCalcValue)
m_parsedCalculation.release();
return b;
}
inline bool CSSPropertyParser::shouldAcceptUnitLessValues(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode)
{
return (unitflags & (FLength | FAngle | FTime)) && (!value->fValue || isUnitLessLengthParsingEnabledForMode(cssParserMode));
}
bool CSSPropertyParser::validUnit(CSSParserValue* value, Units unitflags, CSSParserMode cssParserMode, ReleaseParsedCalcValueCondition releaseCalc)
{
if (isCalculation(value))
return validCalculationUnit(value, unitflags, releaseCalc);
bool b = false;
switch (value->unit) {
case CSSPrimitiveValue::CSS_NUMBER:
b = (unitflags & FNumber);
if (!b && shouldAcceptUnitLessValues(value, unitflags, cssParserMode)) {
value->unit = (unitflags & FLength) ? CSSPrimitiveValue::CSS_PX :
((unitflags & FAngle) ? CSSPrimitiveValue::CSS_DEG : CSSPrimitiveValue::CSS_MS);
b = true;
}
if (!b && (unitflags & FInteger) && value->isInt)
b = true;
if (!b && (unitflags & FPositiveInteger) && value->isInt && value->fValue > 0)
b = true;
break;
case CSSPrimitiveValue::CSS_PERCENTAGE:
b = (unitflags & FPercent);
break;
case CSSParserValue::Q_EMS:
case CSSPrimitiveValue::CSS_EMS:
case CSSPrimitiveValue::CSS_REMS:
case CSSPrimitiveValue::CSS_CHS:
case CSSPrimitiveValue::CSS_EXS:
case CSSPrimitiveValue::CSS_PX:
case CSSPrimitiveValue::CSS_CM:
case CSSPrimitiveValue::CSS_MM:
case CSSPrimitiveValue::CSS_IN:
case CSSPrimitiveValue::CSS_PT:
case CSSPrimitiveValue::CSS_PC:
case CSSPrimitiveValue::CSS_VW:
case CSSPrimitiveValue::CSS_VH:
case CSSPrimitiveValue::CSS_VMIN:
case CSSPrimitiveValue::CSS_VMAX:
b = (unitflags & FLength);
break;
case CSSPrimitiveValue::CSS_MS:
case CSSPrimitiveValue::CSS_S:
b = (unitflags & FTime);
break;
case CSSPrimitiveValue::CSS_DEG:
case CSSPrimitiveValue::CSS_RAD:
case CSSPrimitiveValue::CSS_GRAD:
case CSSPrimitiveValue::CSS_TURN:
b = (unitflags & FAngle);
break;
case CSSPrimitiveValue::CSS_DPPX:
case CSSPrimitiveValue::CSS_DPI:
case CSSPrimitiveValue::CSS_DPCM:
b = (unitflags & FResolution);
break;
case CSSPrimitiveValue::CSS_HZ:
case CSSPrimitiveValue::CSS_KHZ:
case CSSPrimitiveValue::CSS_DIMENSION:
default:
break;
}
if (b && unitflags & FNonNeg && value->fValue < 0)
b = false;
return b;
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveNumericValue(CSSParserValue* value)
{
if (m_parsedCalculation) {
ASSERT(isCalculation(value));
return CSSPrimitiveValue::create(m_parsedCalculation.release());
}
ASSERT((value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
|| (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
|| (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
|| (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM));
return cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit));
}
inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::createPrimitiveStringValue(CSSParserValue* value)
{
ASSERT(value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT);
return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
}
static inline bool isComma(CSSParserValue* value)
{
return value && value->unit == CSSParserValue::Operator && value->iValue == ',';
}
static inline bool isForwardSlashOperator(CSSParserValue* value)
{
ASSERT(value);
return value->unit == CSSParserValue::Operator && value->iValue == '/';
}
static bool isGeneratedImageValue(CSSParserValue* val)
{
if (val->unit != CSSParserValue::Function)
return false;
return equalIgnoringCase(val->function->name, "-webkit-gradient(")
|| equalIgnoringCase(val->function->name, "-webkit-linear-gradient(")
|| equalIgnoringCase(val->function->name, "linear-gradient(")
|| equalIgnoringCase(val->function->name, "-webkit-repeating-linear-gradient(")
|| equalIgnoringCase(val->function->name, "repeating-linear-gradient(")
|| equalIgnoringCase(val->function->name, "-webkit-radial-gradient(")
|| equalIgnoringCase(val->function->name, "radial-gradient(")
|| equalIgnoringCase(val->function->name, "-webkit-repeating-radial-gradient(")
|| equalIgnoringCase(val->function->name, "repeating-radial-gradient(")
|| equalIgnoringCase(val->function->name, "-webkit-canvas(")
|| equalIgnoringCase(val->function->name, "-webkit-cross-fade(");
}
bool CSSPropertyParser::validWidthOrHeight(CSSParserValue* value)
{
int id = value->id;
if (id == CSSValueIntrinsic || id == CSSValueMinIntrinsic || id == CSSValueWebkitMinContent || id == CSSValueWebkitMaxContent || id == CSSValueWebkitFillAvailable || id == CSSValueWebkitFitContent)
return true;
return !id && validUnit(value, FLength | FPercent | FNonNeg);
}
inline PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseValidPrimitive(CSSValueID identifier, CSSParserValue* value)
{
if (identifier)
return cssValuePool().createIdentifierValue(identifier);
if (value->unit == CSSPrimitiveValue::CSS_STRING)
return createPrimitiveStringValue(value);
if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
return createPrimitiveNumericValue(value);
if (value->unit >= CSSPrimitiveValue::CSS_TURN && value->unit <= CSSPrimitiveValue::CSS_CHS)
return createPrimitiveNumericValue(value);
if (value->unit >= CSSPrimitiveValue::CSS_VW && value->unit <= CSSPrimitiveValue::CSS_VMAX)
return createPrimitiveNumericValue(value);
if (value->unit >= CSSPrimitiveValue::CSS_DPPX && value->unit <= CSSPrimitiveValue::CSS_DPCM)
return createPrimitiveNumericValue(value);
if (value->unit >= CSSParserValue::Q_EMS)
return CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
if (isCalculation(value))
return CSSPrimitiveValue::create(m_parsedCalculation.release());
return nullptr;
}
void CSSPropertyParser::addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtrWillBeRawPtr<CSSValue> prpValue, bool important)
{
const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
unsigned shorthandLength = shorthand.length();
if (!shorthandLength) {
addProperty(propId, prpValue, important);
return;
}
RefPtrWillBeRawPtr<CSSValue> value = prpValue;
ShorthandScope scope(this, propId);
const CSSPropertyID* longhands = shorthand.properties();
for (unsigned i = 0; i < shorthandLength; ++i)
addProperty(longhands[i], value, important);
}
bool CSSPropertyParser::parseValue(CSSPropertyID propId, bool important)
{
if (!isInternalPropertyAndValueParsingEnabledForMode(m_context.mode()) && isInternalProperty(propId))
return false;
if (m_context.useCounter())
m_context.useCounter()->count(m_context, propId);
if (!m_valueList)
return false;
CSSParserValue* value = m_valueList->current();
if (!value)
return false;
if (inViewport()) {
if (!RuntimeEnabledFeatures::cssViewportEnabled() && !isUASheetBehavior(m_context.mode()))
return false;
return parseViewportProperty(propId, important);
}
ASSERT(!m_parsedCalculation);
CSSValueID id = value->id;
int num = inShorthand() ? 1 : m_valueList->size();
if (id == CSSValueInherit) {
if (num != 1)
return false;
addExpandedPropertyForValue(propId, cssValuePool().createInheritedValue(), important);
return true;
}
else if (id == CSSValueInitial) {
if (num != 1)
return false;
addExpandedPropertyForValue(propId, cssValuePool().createExplicitInitialValue(), important);
return true;
}
if (isKeywordPropertyID(propId)) {
if (!isValidKeywordPropertyAndValue(propId, id, m_context))
return false;
if (m_valueList->next() && !inShorthand())
return false;
addProperty(propId, cssValuePool().createIdentifierValue(id), important);
return true;
}
bool validPrimitive = false;
RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
switch (propId) {
case CSSPropertySize:
return parseSize(propId, important);
case CSSPropertyQuotes:
if (id)
validPrimitive = true;
else
return parseQuotes(propId, important);
break;
case CSSPropertyUnicodeBidi:
if (id == CSSValueNormal
|| id == CSSValueEmbed
|| id == CSSValueBidiOverride
|| id == CSSValueWebkitIsolate
|| id == CSSValueWebkitIsolateOverride
|| id == CSSValueWebkitPlaintext)
validPrimitive = true;
break;
case CSSPropertyContent:
return parseContent(propId, important);
case CSSPropertyClip:
if (id == CSSValueAuto)
validPrimitive = true;
else if (value->unit == CSSParserValue::Function)
return parseClipShape(propId, important);
break;
case CSSPropertyOverflow: {
ShorthandScope scope(this, propId);
if (num != 1 || !parseValue(CSSPropertyOverflowY, important))
return false;
RefPtrWillBeRawPtr<CSSValue> overflowXValue = nullptr;
if (id == CSSValueWebkitPagedX || id == CSSValueWebkitPagedY)
overflowXValue = cssValuePool().createIdentifierValue(CSSValueAuto);
else
overflowXValue = m_parsedProperties.last().value();
addProperty(CSSPropertyOverflowX, overflowXValue.release(), important);
return true;
}
case CSSPropertyTextAlign:
if ((id >= CSSValueWebkitAuto && id <= CSSValueWebkitMatchParent) || id == CSSValueStart || id == CSSValueEnd
|| value->unit == CSSPrimitiveValue::CSS_STRING)
validPrimitive = true;
break;
case CSSPropertyFontWeight: {
if (m_valueList->size() != 1)
return false;
return parseFontWeight(important);
}
case CSSPropertyBorderSpacing: {
if (num == 1) {
ShorthandScope scope(this, CSSPropertyBorderSpacing);
if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important))
return false;
CSSValue* value = m_parsedProperties.last().value();
addProperty(CSSPropertyWebkitBorderVerticalSpacing, value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSSPropertyBorderSpacing);
if (!parseValue(CSSPropertyWebkitBorderHorizontalSpacing, important) || !parseValue(CSSPropertyWebkitBorderVerticalSpacing, important))
return false;
return true;
}
return false;
}
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
validPrimitive = validUnit(value, FLength | FNonNeg);
break;
case CSSPropertyOutlineColor:
if (id == CSSValueInvert || id == CSSValueWebkitFocusRingColor) {
validPrimitive = true;
break;
}
case CSSPropertyBackgroundColor:
case CSSPropertyBorderTopColor:
case CSSPropertyBorderRightColor:
case CSSPropertyBorderBottomColor:
case CSSPropertyBorderLeftColor:
case CSSPropertyWebkitBorderStartColor:
case CSSPropertyWebkitBorderEndColor:
case CSSPropertyWebkitBorderBeforeColor:
case CSSPropertyWebkitBorderAfterColor:
case CSSPropertyColor:
case CSSPropertyTextDecorationColor:
case CSSPropertyTextLineThroughColor:
case CSSPropertyTextUnderlineColor:
case CSSPropertyTextOverlineColor:
case CSSPropertyWebkitColumnRuleColor:
case CSSPropertyWebkitTextEmphasisColor:
case CSSPropertyWebkitTextFillColor:
case CSSPropertyWebkitTextStrokeColor:
if (propId == CSSPropertyTextDecorationColor
&& !RuntimeEnabledFeatures::css3TextDecorationsEnabled())
return false;
if ((id >= CSSValueAqua && id <= CSSValueWebkitText) || id == CSSValueMenu) {
validPrimitive = isValueAllowedInMode(id, m_context.mode());
} else {
parsedValue = parseColor();
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyCursor: {
RefPtrWillBeRawPtr<CSSValueList> list = nullptr;
while (value) {
RefPtrWillBeRawPtr<CSSValue> image = nullptr;
if (value->unit == CSSPrimitiveValue::CSS_URI) {
String uri = value->string;
if (!uri.isNull())
image = CSSImageValue::create(uri, completeURL(uri));
} else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
image = parseImageSet(m_valueList.get());
if (!image)
break;
} else
break;
Vector<int> coords;
value = m_valueList->next();
while (value && value->unit == CSSPrimitiveValue::CSS_NUMBER) {
coords.append(int(value->fValue));
value = m_valueList->next();
}
bool hasHotSpot = false;
IntPoint hotSpot(-1, -1);
int nrcoords = coords.size();
if (nrcoords > 0 && nrcoords != 2)
return false;
if (nrcoords == 2) {
hasHotSpot = true;
hotSpot = IntPoint(coords[0], coords[1]);
}
if (!list)
list = CSSValueList::createCommaSeparated();
if (image)
list->append(CSSCursorImageValue::create(image, hasHotSpot, hotSpot));
if (!value || !(value->unit == CSSParserValue::Operator && value->iValue == ','))
return false;
value = m_valueList->next();
}
if (list) {
if (!value)
return false;
if (inQuirksMode() && value->id == CSSValueHand)
list->append(cssValuePool().createIdentifierValue(CSSValuePointer));
else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
list->append(cssValuePool().createIdentifierValue(value->id));
m_valueList->next();
parsedValue = list.release();
break;
} else if (value) {
id = value->id;
if (inQuirksMode() && value->id == CSSValueHand) {
id = CSSValuePointer;
validPrimitive = true;
} else if ((value->id >= CSSValueAuto && value->id <= CSSValueWebkitGrabbing) || value->id == CSSValueCopy || value->id == CSSValueNone)
validPrimitive = true;
} else {
ASSERT_NOT_REACHED();
return false;
}
break;
}
case CSSPropertyBackgroundBlendMode:
case CSSPropertyBackgroundAttachment:
case CSSPropertyBackgroundClip:
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundComposite:
case CSSPropertyBackgroundImage:
case CSSPropertyBackgroundOrigin:
case CSSPropertyMaskSourceType:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyBackgroundPosition:
case CSSPropertyBackgroundPositionX:
case CSSPropertyBackgroundPositionY:
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyBackgroundRepeat:
case CSSPropertyBackgroundRepeatX:
case CSSPropertyBackgroundRepeatY:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskComposite:
case CSSPropertyWebkitMaskImage:
case CSSPropertyWebkitMaskOrigin:
case CSSPropertyWebkitMaskPosition:
case CSSPropertyWebkitMaskPositionX:
case CSSPropertyWebkitMaskPositionY:
case CSSPropertyWebkitMaskSize:
case CSSPropertyWebkitMaskRepeat:
case CSSPropertyWebkitMaskRepeatX:
case CSSPropertyWebkitMaskRepeatY:
{
RefPtrWillBeRawPtr<CSSValue> val1 = nullptr;
RefPtrWillBeRawPtr<CSSValue> val2 = nullptr;
CSSPropertyID propId1, propId2;
bool result = false;
if (parseFillProperty(propId, propId1, propId2, val1, val2)) {
if (propId == CSSPropertyBackgroundPosition ||
propId == CSSPropertyBackgroundRepeat ||
propId == CSSPropertyWebkitMaskPosition ||
propId == CSSPropertyWebkitMaskRepeat) {
ShorthandScope scope(this, propId);
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
} else {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
}
result = true;
}
m_implicitShorthand = false;
return result;
}
case CSSPropertyObjectPosition:
return RuntimeEnabledFeatures::objectFitPositionEnabled() && parseObjectPosition(important);
case CSSPropertyListStyleImage:
case CSSPropertyBorderImageSource:
case CSSPropertyWebkitMaskBoxImageSource:
if (id == CSSValueNone) {
parsedValue = cssValuePool().createIdentifierValue(CSSValueNone);
m_valueList->next();
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSImageValue::create(value->string, completeURL(value->string));
m_valueList->next();
} else if (isGeneratedImageValue(value)) {
if (parseGeneratedImage(m_valueList.get(), parsedValue))
m_valueList->next();
else
return false;
}
else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "-webkit-image-set(")) {
parsedValue = parseImageSet(m_valueList.get());
if (!parsedValue)
return false;
m_valueList->next();
}
break;
case CSSPropertyWebkitTextStrokeWidth:
case CSSPropertyOutlineWidth:
case CSSPropertyBorderTopWidth:
case CSSPropertyBorderRightWidth:
case CSSPropertyBorderBottomWidth:
case CSSPropertyBorderLeftWidth:
case CSSPropertyWebkitBorderStartWidth:
case CSSPropertyWebkitBorderEndWidth:
case CSSPropertyWebkitBorderBeforeWidth:
case CSSPropertyWebkitBorderAfterWidth:
case CSSPropertyWebkitColumnRuleWidth:
if (id == CSSValueThin || id == CSSValueMedium || id == CSSValueThick)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength | FNonNeg);
break;
case CSSPropertyLetterSpacing:
case CSSPropertyWordSpacing:
if (id == CSSValueNormal)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength);
break;
case CSSPropertyTextIndent:
parsedValue = parseTextIndent();
break;
case CSSPropertyPaddingTop:
case CSSPropertyPaddingRight:
case CSSPropertyPaddingBottom:
case CSSPropertyPaddingLeft:
case CSSPropertyWebkitPaddingStart:
case CSSPropertyWebkitPaddingEnd:
case CSSPropertyWebkitPaddingBefore:
case CSSPropertyWebkitPaddingAfter:
validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
break;
case CSSPropertyMaxWidth:
case CSSPropertyWebkitMaxLogicalWidth:
case CSSPropertyMaxHeight:
case CSSPropertyWebkitMaxLogicalHeight:
validPrimitive = (id == CSSValueNone || validWidthOrHeight(value));
break;
case CSSPropertyMinWidth:
case CSSPropertyWebkitMinLogicalWidth:
case CSSPropertyMinHeight:
case CSSPropertyWebkitMinLogicalHeight:
validPrimitive = validWidthOrHeight(value);
break;
case CSSPropertyWidth:
case CSSPropertyWebkitLogicalWidth:
case CSSPropertyHeight:
case CSSPropertyWebkitLogicalHeight:
validPrimitive = (id == CSSValueAuto || validWidthOrHeight(value));
break;
case CSSPropertyFontSize:
return parseFontSize(important);
case CSSPropertyFontVariant:
return parseFontVariant(important);
case CSSPropertyVerticalAlign:
if (id >= CSSValueBaseline && id <= CSSValueWebkitBaselineMiddle)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FLength | FPercent));
break;
case CSSPropertyBottom:
case CSSPropertyLeft:
case CSSPropertyRight:
case CSSPropertyTop:
case CSSPropertyMarginTop:
case CSSPropertyMarginRight:
case CSSPropertyMarginBottom:
case CSSPropertyMarginLeft:
case CSSPropertyWebkitMarginStart:
case CSSPropertyWebkitMarginEnd:
case CSSPropertyWebkitMarginBefore:
case CSSPropertyWebkitMarginAfter:
if (id == CSSValueAuto)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FLength | FPercent));
break;
case CSSPropertyOrphans:
case CSSPropertyWidows:
if (id == CSSValueAuto)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FPositiveInteger, HTMLQuirksMode));
break;
case CSSPropertyZIndex:
if (id == CSSValueAuto)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FInteger, HTMLQuirksMode));
break;
case CSSPropertyLineHeight:
return parseLineHeight(important);
case CSSPropertyCounterIncrement:
if (id != CSSValueNone)
return parseCounter(propId, 1, important);
validPrimitive = true;
break;
case CSSPropertyCounterReset:
if (id != CSSValueNone)
return parseCounter(propId, 0, important);
validPrimitive = true;
break;
case CSSPropertyFontFamily:
{
parsedValue = parseFontFamily();
break;
}
case CSSPropertyTextDecoration:
if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()) {
return parseShorthand(CSSPropertyTextDecoration, textDecorationShorthand(), important);
}
case CSSPropertyWebkitTextDecorationsInEffect:
case CSSPropertyTextDecorationLine:
return parseTextDecoration(propId, important);
case CSSPropertyTextDecorationStyle:
if (RuntimeEnabledFeatures::css3TextDecorationsEnabled()
&& (id == CSSValueSolid || id == CSSValueDouble || id == CSSValueDotted || id == CSSValueDashed || id == CSSValueWavy))
validPrimitive = true;
break;
case CSSPropertyTextUnderlinePosition:
if (RuntimeEnabledFeatures::css3TextDecorationsEnabled())
return parseTextUnderlinePosition(important);
return false;
case CSSPropertyZoom:
if (id == CSSValueNormal || id == CSSValueReset || id == CSSValueDocument)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg, HTMLStandardMode));
break;
case CSSPropertySrc:
return parseFontFaceSrc();
case CSSPropertyUnicodeRange:
return parseFontFaceUnicodeRange();
case CSSPropertyBorderImage:
case CSSPropertyWebkitMaskBoxImage:
return parseBorderImageShorthand(propId, important);
case CSSPropertyWebkitBorderImage: {
if (RefPtrWillBeRawPtr<CSSValue> result = parseBorderImage(propId)) {
addProperty(propId, result, important);
return true;
}
return false;
}
case CSSPropertyBorderImageOutset:
case CSSPropertyWebkitMaskBoxImageOutset: {
RefPtrWillBeRawPtr<CSSPrimitiveValue> result = nullptr;
if (parseBorderImageOutset(result)) {
addProperty(propId, result, important);
return true;
}
break;
}
case CSSPropertyBorderImageRepeat:
case CSSPropertyWebkitMaskBoxImageRepeat: {
RefPtrWillBeRawPtr<CSSValue> result = nullptr;
if (parseBorderImageRepeat(result)) {
addProperty(propId, result, important);
return true;
}
break;
}
case CSSPropertyBorderImageSlice:
case CSSPropertyWebkitMaskBoxImageSlice: {
RefPtrWillBeRawPtr<CSSBorderImageSliceValue> result = nullptr;
if (parseBorderImageSlice(propId, result)) {
addProperty(propId, result, important);
return true;
}
break;
}
case CSSPropertyBorderImageWidth:
case CSSPropertyWebkitMaskBoxImageWidth: {
RefPtrWillBeRawPtr<CSSPrimitiveValue> result = nullptr;
if (parseBorderImageWidth(result)) {
addProperty(propId, result, important);
return true;
}
break;
}
case CSSPropertyBorderTopRightRadius:
case CSSPropertyBorderTopLeftRadius:
case CSSPropertyBorderBottomLeftRadius:
case CSSPropertyBorderBottomRightRadius: {
if (num != 1 && num != 2)
return false;
validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
if (!validPrimitive)
return false;
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue1 = createPrimitiveNumericValue(value);
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue2 = nullptr;
if (num == 2) {
value = m_valueList->next();
validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
if (!validPrimitive)
return false;
parsedValue2 = createPrimitiveNumericValue(value);
} else
parsedValue2 = parsedValue1;
addProperty(propId, createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release()), important);
return true;
}
case CSSPropertyTabSize:
validPrimitive = validUnit(value, FInteger | FNonNeg);
break;
case CSSPropertyWebkitAspectRatio:
return parseAspectRatio(important);
case CSSPropertyBorderRadius:
case CSSPropertyWebkitBorderRadius:
return parseBorderRadius(propId, important);
case CSSPropertyOutlineOffset:
validPrimitive = validUnit(value, FLength);
break;
case CSSPropertyTextShadow:
case CSSPropertyBoxShadow:
case CSSPropertyWebkitBoxShadow:
if (id == CSSValueNone)
validPrimitive = true;
else {
RefPtrWillBeRawPtr<CSSValueList> shadowValueList = parseShadow(m_valueList.get(), propId);
if (shadowValueList) {
addProperty(propId, shadowValueList.release(), important);
m_valueList->next();
return true;
}
return false;
}
break;
case CSSPropertyWebkitBoxReflect:
if (id == CSSValueNone)
validPrimitive = true;
else
return parseReflect(propId, important);
break;
case CSSPropertyOpacity:
validPrimitive = validUnit(value, FNumber);
break;
case CSSPropertyWebkitBoxFlex:
validPrimitive = validUnit(value, FNumber);
break;
case CSSPropertyWebkitBoxFlexGroup:
validPrimitive = validUnit(value, FInteger | FNonNeg, HTMLStandardMode);
break;
case CSSPropertyWebkitBoxOrdinalGroup:
validPrimitive = validUnit(value, FInteger | FNonNeg, HTMLStandardMode) && value->fValue;
break;
case CSSPropertyWebkitFilter:
if (id == CSSValueNone)
validPrimitive = true;
else {
RefPtrWillBeRawPtr<CSSValue> val = parseFilter();
if (val) {
addProperty(propId, val, important);
return true;
}
return false;
}
break;
case CSSPropertyFlex: {
ShorthandScope scope(this, propId);
if (id == CSSValueNone) {
addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER), important);
addProperty(CSSPropertyFlexBasis, cssValuePool().createIdentifierValue(CSSValueAuto), important);
return true;
}
return parseFlex(m_valueList.get(), important);
}
case CSSPropertyFlexBasis:
if (id == CSSValueAuto)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
break;
case CSSPropertyFlexGrow:
case CSSPropertyFlexShrink:
validPrimitive = validUnit(value, FNumber | FNonNeg);
break;
case CSSPropertyOrder:
validPrimitive = validUnit(value, FInteger, HTMLStandardMode);
break;
case CSSPropertyInternalMarqueeIncrement:
if (id == CSSValueSmall || id == CSSValueLarge || id == CSSValueMedium)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength | FPercent);
break;
case CSSPropertyInternalMarqueeRepetition:
if (id == CSSValueInfinite)
validPrimitive = true;
else
validPrimitive = validUnit(value, FInteger | FNonNeg);
break;
case CSSPropertyInternalMarqueeSpeed:
if (id == CSSValueNormal || id == CSSValueSlow || id == CSSValueFast)
validPrimitive = true;
else
validPrimitive = validUnit(value, FTime | FInteger | FNonNeg);
break;
case CSSPropertyTransform:
case CSSPropertyWebkitTransform:
if (id == CSSValueNone)
validPrimitive = true;
else {
RefPtrWillBeRawPtr<CSSValue> transformValue = parseTransform(propId);
if (transformValue) {
addProperty(propId, transformValue.release(), important);
return true;
}
return false;
}
break;
case CSSPropertyTransformOrigin: {
RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin();
if (!list)
return false;
if (list->length() == 1)
list->append(cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
if (list->length() == 2)
list->append(cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX));
addProperty(propId, list.release(), important);
return true;
}
case CSSPropertyWebkitTransformOrigin:
case CSSPropertyWebkitTransformOriginX:
case CSSPropertyWebkitTransformOriginY:
case CSSPropertyWebkitTransformOriginZ: {
RefPtrWillBeRawPtr<CSSValue> val1 = nullptr;
RefPtrWillBeRawPtr<CSSValue> val2 = nullptr;
RefPtrWillBeRawPtr<CSSValue> val3 = nullptr;
CSSPropertyID propId1, propId2, propId3;
if (parseWebkitTransformOrigin(propId, propId1, propId2, propId3, val1, val2, val3)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
if (val3)
addProperty(propId3, val3.release(), important);
return true;
}
return false;
}
case CSSPropertyPerspective:
if (id == CSSValueNone) {
validPrimitive = true;
} else if (validUnit(value, FLength | FNonNeg)) {
addProperty(propId, createPrimitiveNumericValue(value), important);
return true;
}
break;
case CSSPropertyWebkitPerspective:
if (id == CSSValueNone) {
validPrimitive = true;
} else if (validUnit(value, FNumber | FLength | FNonNeg)) {
addProperty(propId, createPrimitiveNumericValue(value), important);
return true;
}
break;
case CSSPropertyPerspectiveOrigin: {
RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin();
if (!list || list->length() == 3)
return false;
if (list->length() == 1)
list->append(cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
addProperty(propId, list.release(), important);
return true;
}
case CSSPropertyWebkitPerspectiveOrigin:
case CSSPropertyWebkitPerspectiveOriginX:
case CSSPropertyWebkitPerspectiveOriginY: {
RefPtrWillBeRawPtr<CSSValue> val1 = nullptr;
RefPtrWillBeRawPtr<CSSValue> val2 = nullptr;
CSSPropertyID propId1, propId2;
if (parseWebkitPerspectiveOrigin(propId, propId1, propId2, val1, val2)) {
addProperty(propId1, val1.release(), important);
if (val2)
addProperty(propId2, val2.release(), important);
return true;
}
return false;
}
case CSSPropertyAnimationDelay:
case CSSPropertyAnimationDirection:
case CSSPropertyAnimationDuration:
case CSSPropertyAnimationFillMode:
case CSSPropertyAnimationName:
case CSSPropertyAnimationPlayState:
case CSSPropertyAnimationIterationCount:
case CSSPropertyAnimationTimingFunction:
if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled())
break;
case CSSPropertyWebkitAnimationDelay:
case CSSPropertyWebkitAnimationDirection:
case CSSPropertyWebkitAnimationDuration:
case CSSPropertyWebkitAnimationFillMode:
case CSSPropertyWebkitAnimationName:
case CSSPropertyWebkitAnimationPlayState:
case CSSPropertyWebkitAnimationIterationCount:
case CSSPropertyWebkitAnimationTimingFunction:
case CSSPropertyTransitionDelay:
case CSSPropertyTransitionDuration:
case CSSPropertyTransitionTimingFunction:
case CSSPropertyTransitionProperty:
case CSSPropertyWebkitTransitionDelay:
case CSSPropertyWebkitTransitionDuration:
case CSSPropertyWebkitTransitionTimingFunction:
case CSSPropertyWebkitTransitionProperty: {
RefPtrWillBeRawPtr<CSSValue> val = nullptr;
AnimationParseContext context;
if (parseAnimationProperty(propId, val, context)) {
addPropertyWithPrefixingVariant(propId, val.release(), important);
return true;
}
return false;
}
case CSSPropertyJustifySelf:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
return parseItemPositionOverflowPosition(propId, important);
case CSSPropertyGridAutoColumns:
case CSSPropertyGridAutoRows:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
parsedValue = parseGridTrackSize(*m_valueList);
break;
case CSSPropertyGridTemplateColumns:
case CSSPropertyGridTemplateRows:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
parsedValue = parseGridTrackList(important);
break;
case CSSPropertyGridColumnEnd:
case CSSPropertyGridColumnStart:
case CSSPropertyGridRowEnd:
case CSSPropertyGridRowStart:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
parsedValue = parseGridPosition();
break;
case CSSPropertyGridColumn:
case CSSPropertyGridRow:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
return parseGridItemPositionShorthand(propId, important);
case CSSPropertyGridArea:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
return parseGridAreaShorthand(important);
case CSSPropertyGridTemplateAreas:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
parsedValue = parseGridTemplateAreas();
break;
case CSSPropertyGridTemplate:
if (!RuntimeEnabledFeatures::cssGridLayoutEnabled())
return false;
return parseGridTemplateShorthand(important);
case CSSPropertyWebkitMarginCollapse: {
if (num == 1) {
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important))
return false;
CSSValue* value = m_parsedProperties.last().value();
addProperty(webkitMarginCollapseShorthand().properties()[1], value, important);
return true;
}
else if (num == 2) {
ShorthandScope scope(this, CSSPropertyWebkitMarginCollapse);
if (!parseValue(webkitMarginCollapseShorthand().properties()[0], important) || !parseValue(webkitMarginCollapseShorthand().properties()[1], important))
return false;
return true;
}
return false;
}
case CSSPropertyTextLineThroughWidth:
case CSSPropertyTextOverlineWidth:
case CSSPropertyTextUnderlineWidth:
if (id == CSSValueAuto || id == CSSValueNormal || id == CSSValueThin ||
id == CSSValueMedium || id == CSSValueThick)
validPrimitive = true;
else
validPrimitive = !id && validUnit(value, FNumber | FLength | FPercent);
break;
case CSSPropertyWebkitColumnCount:
parsedValue = parseColumnCount();
break;
case CSSPropertyWebkitColumnGap:
if (id == CSSValueNormal)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength | FNonNeg);
break;
case CSSPropertyWebkitColumnSpan:
if (id == CSSValueAll || id == CSSValueNone)
validPrimitive = true;
else
validPrimitive = validUnit(value, FNumber | FNonNeg) && value->fValue == 1;
break;
case CSSPropertyWebkitColumnWidth:
parsedValue = parseColumnWidth();
break;
case CSSPropertyWillChange:
if (!RuntimeEnabledFeatures::cssWillChangeEnabled())
return false;
return parseWillChange(important);
case CSSPropertyWebkitLineClamp:
validPrimitive = (!id && (value->unit == CSSPrimitiveValue::CSS_PERCENTAGE || value->fValue) && validUnit(value, FInteger | FPercent | FNonNeg, HTMLQuirksMode));
break;
case CSSPropertyWebkitFontSizeDelta:
validPrimitive = validUnit(value, FLength);
break;
case CSSPropertyWebkitHighlight:
if (id == CSSValueNone || value->unit == CSSPrimitiveValue::CSS_STRING)
validPrimitive = true;
break;
case CSSPropertyWebkitHyphenateCharacter:
if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
validPrimitive = true;
break;
case CSSPropertyWebkitLocale:
if (id == CSSValueAuto || value->unit == CSSPrimitiveValue::CSS_STRING)
validPrimitive = true;
break;
case CSSPropertyWebkitAppRegion:
if (id >= CSSValueDrag && id <= CSSValueNoDrag)
validPrimitive = true;
break;
case CSSPropertyWebkitTapHighlightColor:
if ((id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu
|| (id >= CSSValueWebkitFocusRingColor && id < CSSValueWebkitText && inQuirksMode())) {
validPrimitive = true;
} else {
parsedValue = parseColor();
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyBackground: {
const CSSPropertyID properties[] = { CSSPropertyBackgroundImage, CSSPropertyBackgroundRepeat,
CSSPropertyBackgroundAttachment, CSSPropertyBackgroundPosition, CSSPropertyBackgroundOrigin,
CSSPropertyBackgroundClip, CSSPropertyBackgroundColor, CSSPropertyBackgroundSize };
return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
}
case CSSPropertyWebkitMask: {
const CSSPropertyID properties[] = { CSSPropertyWebkitMaskImage, CSSPropertyWebkitMaskRepeat,
CSSPropertyWebkitMaskPosition, CSSPropertyWebkitMaskOrigin, CSSPropertyWebkitMaskClip, CSSPropertyWebkitMaskSize };
return parseFillShorthand(propId, properties, WTF_ARRAY_LENGTH(properties), important);
}
case CSSPropertyBorder:
{
if (parseShorthand(propId, parsingShorthandForProperty(CSSPropertyBorder), important)) {
addExpandedPropertyForValue(CSSPropertyBorderImage, cssValuePool().createImplicitInitialValue(), important);
return true;
}
return false;
}
case CSSPropertyBorderTop:
return parseShorthand(propId, borderTopShorthand(), important);
case CSSPropertyBorderRight:
return parseShorthand(propId, borderRightShorthand(), important);
case CSSPropertyBorderBottom:
return parseShorthand(propId, borderBottomShorthand(), important);
case CSSPropertyBorderLeft:
return parseShorthand(propId, borderLeftShorthand(), important);
case CSSPropertyWebkitBorderStart:
return parseShorthand(propId, webkitBorderStartShorthand(), important);
case CSSPropertyWebkitBorderEnd:
return parseShorthand(propId, webkitBorderEndShorthand(), important);
case CSSPropertyWebkitBorderBefore:
return parseShorthand(propId, webkitBorderBeforeShorthand(), important);
case CSSPropertyWebkitBorderAfter:
return parseShorthand(propId, webkitBorderAfterShorthand(), important);
case CSSPropertyOutline:
return parseShorthand(propId, outlineShorthand(), important);
case CSSPropertyBorderColor:
return parse4Values(propId, borderColorShorthand().properties(), important);
case CSSPropertyBorderWidth:
return parse4Values(propId, borderWidthShorthand().properties(), important);
case CSSPropertyBorderStyle:
return parse4Values(propId, borderStyleShorthand().properties(), important);
case CSSPropertyMargin:
return parse4Values(propId, marginShorthand().properties(), important);
case CSSPropertyPadding:
return parse4Values(propId, paddingShorthand().properties(), important);
case CSSPropertyFlexFlow:
return parseShorthand(propId, flexFlowShorthand(), important);
case CSSPropertyFont:
if (id >= CSSValueCaption && id <= CSSValueStatusBar)
validPrimitive = true;
else
return parseFont(important);
break;
case CSSPropertyListStyle:
return parseShorthand(propId, listStyleShorthand(), important);
case CSSPropertyWebkitColumns:
return parseColumnsShorthand(important);
case CSSPropertyWebkitColumnRule:
return parseShorthand(propId, webkitColumnRuleShorthand(), important);
case CSSPropertyWebkitTextStroke:
return parseShorthand(propId, webkitTextStrokeShorthand(), important);
case CSSPropertyAnimation:
if (!RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled())
break;
case CSSPropertyWebkitAnimation:
return parseAnimationShorthand(propId, important);
case CSSPropertyTransition:
case CSSPropertyWebkitTransition:
return parseTransitionShorthand(propId, important);
case CSSPropertyInvalid:
return false;
case CSSPropertyPage:
return parsePage(propId, important);
case CSSPropertyFontStretch:
return false;
case CSSPropertyWebkitTextEmphasis:
return parseShorthand(propId, webkitTextEmphasisShorthand(), important);
case CSSPropertyWebkitTextEmphasisStyle:
return parseTextEmphasisStyle(important);
case CSSPropertyWebkitTextOrientation:
if (id == CSSValueSideways || id == CSSValueSidewaysRight || id == CSSValueVerticalRight || id == CSSValueUpright)
validPrimitive = true;
break;
case CSSPropertyWebkitLineBoxContain:
if (id == CSSValueNone)
validPrimitive = true;
else
return parseLineBoxContain(important);
break;
case CSSPropertyWebkitFontFeatureSettings:
if (id == CSSValueNormal)
validPrimitive = true;
else
return parseFontFeatureSettings(important);
break;
case CSSPropertyFontVariantLigatures:
if (id == CSSValueNormal)
validPrimitive = true;
else
return parseFontVariantLigatures(important);
break;
case CSSPropertyWebkitClipPath:
if (id == CSSValueNone) {
validPrimitive = true;
} else if (value->unit == CSSParserValue::Function) {
parsedValue = parseBasicShape();
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_URI);
addProperty(propId, parsedValue.release(), important);
return true;
}
break;
case CSSPropertyShapeOutside:
parsedValue = parseShapeProperty(propId);
break;
case CSSPropertyShapeMargin:
validPrimitive = (RuntimeEnabledFeatures::cssShapesEnabled() && !id && validUnit(value, FLength | FNonNeg));
break;
case CSSPropertyShapeImageThreshold:
validPrimitive = (RuntimeEnabledFeatures::cssShapesEnabled() && !id && validUnit(value, FNumber));
break;
case CSSPropertyTouchAction:
return parseTouchAction(important);
case CSSPropertyAlignSelf:
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
return parseItemPositionOverflowPosition(propId, important);
case CSSPropertyAlignItems:
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
return parseItemPositionOverflowPosition(propId, important);
case CSSPropertyBorderBottomStyle:
case CSSPropertyBorderCollapse:
case CSSPropertyBorderLeftStyle:
case CSSPropertyBorderRightStyle:
case CSSPropertyBorderTopStyle:
case CSSPropertyBoxSizing:
case CSSPropertyCaptionSide:
case CSSPropertyClear:
case CSSPropertyDirection:
case CSSPropertyDisplay:
case CSSPropertyEmptyCells:
case CSSPropertyFloat:
case CSSPropertyFontStyle:
case CSSPropertyImageRendering:
case CSSPropertyListStylePosition:
case CSSPropertyListStyleType:
case CSSPropertyObjectFit:
case CSSPropertyOutlineStyle:
case CSSPropertyOverflowWrap:
case CSSPropertyOverflowX:
case CSSPropertyOverflowY:
case CSSPropertyPageBreakAfter:
case CSSPropertyPageBreakBefore:
case CSSPropertyPageBreakInside:
case CSSPropertyPointerEvents:
case CSSPropertyPosition:
case CSSPropertyResize:
case CSSPropertySpeak:
case CSSPropertyTableLayout:
case CSSPropertyTextAlignLast:
case CSSPropertyTextJustify:
case CSSPropertyTextLineThroughMode:
case CSSPropertyTextLineThroughStyle:
case CSSPropertyTextOverflow:
case CSSPropertyTextOverlineMode:
case CSSPropertyTextOverlineStyle:
case CSSPropertyTextRendering:
case CSSPropertyTextTransform:
case CSSPropertyTextUnderlineMode:
case CSSPropertyTextUnderlineStyle:
case CSSPropertyTouchActionDelay:
case CSSPropertyVisibility:
case CSSPropertyWebkitAppearance:
case CSSPropertyBackfaceVisibility:
case CSSPropertyWebkitBackfaceVisibility:
case CSSPropertyWebkitBorderAfterStyle:
case CSSPropertyWebkitBorderBeforeStyle:
case CSSPropertyWebkitBorderEndStyle:
case CSSPropertyWebkitBorderFit:
case CSSPropertyWebkitBorderStartStyle:
case CSSPropertyWebkitBoxAlign:
case CSSPropertyWebkitBoxDecorationBreak:
case CSSPropertyWebkitBoxDirection:
case CSSPropertyWebkitBoxLines:
case CSSPropertyWebkitBoxOrient:
case CSSPropertyWebkitBoxPack:
case CSSPropertyInternalCallback:
case CSSPropertyWebkitColumnBreakAfter:
case CSSPropertyWebkitColumnBreakBefore:
case CSSPropertyWebkitColumnBreakInside:
case CSSPropertyColumnFill:
case CSSPropertyWebkitColumnRuleStyle:
case CSSPropertyAlignContent:
case CSSPropertyFlexDirection:
case CSSPropertyFlexWrap:
case CSSPropertyJustifyContent:
case CSSPropertyFontKerning:
case CSSPropertyWebkitFontSmoothing:
case CSSPropertyGridAutoFlow:
case CSSPropertyWebkitLineBreak:
case CSSPropertyWebkitMarginAfterCollapse:
case CSSPropertyWebkitMarginBeforeCollapse:
case CSSPropertyWebkitMarginBottomCollapse:
case CSSPropertyWebkitMarginTopCollapse:
case CSSPropertyInternalMarqueeDirection:
case CSSPropertyInternalMarqueeStyle:
case CSSPropertyWebkitPrintColorAdjust:
case CSSPropertyWebkitRtlOrdering:
case CSSPropertyWebkitRubyPosition:
case CSSPropertyWebkitTextCombine:
case CSSPropertyWebkitTextEmphasisPosition:
case CSSPropertyWebkitTextSecurity:
case CSSPropertyTransformStyle:
case CSSPropertyWebkitTransformStyle:
case CSSPropertyWebkitUserDrag:
case CSSPropertyWebkitUserModify:
case CSSPropertyWebkitUserSelect:
case CSSPropertyWebkitWrapFlow:
case CSSPropertyWebkitWrapThrough:
case CSSPropertyWebkitWritingMode:
case CSSPropertyWhiteSpace:
case CSSPropertyWordBreak:
case CSSPropertyWordWrap:
case CSSPropertyMixBlendMode:
case CSSPropertyIsolation:
ASSERT_NOT_REACHED();
return false;
case CSSPropertyMaxZoom:
case CSSPropertyMinZoom:
case CSSPropertyOrientation:
case CSSPropertyUserZoom:
validPrimitive = false;
break;
default:
return parseSVGValue(propId, important);
}
if (validPrimitive) {
parsedValue = parseValidPrimitive(id, value);
m_valueList->next();
}
ASSERT(!m_parsedCalculation);
if (parsedValue) {
if (!m_valueList->current() || inShorthand()) {
addProperty(propId, parsedValue.release(), important);
return true;
}
}
return false;
}
void CSSPropertyParser::addFillValue(RefPtrWillBeRawPtr<CSSValue>& lval, PassRefPtrWillBeRawPtr<CSSValue> rval)
{
if (lval) {
if (lval->isBaseValueList())
toCSSValueList(lval.get())->append(rval);
else {
PassRefPtrWillBeRawPtr<CSSValue> oldlVal(lval.release());
PassRefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
list->append(oldlVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtrWillBeRawPtr<CSSValue>& cssValue)
{
if (parserValue->id == CSSValueBorderBox || parserValue->id == CSSValuePaddingBox
|| parserValue->id == CSSValueContentBox || parserValue->id == CSSValueWebkitText) {
cssValue = cssValuePool().createIdentifierValue(parserValue->id);
return true;
}
return false;
}
const int cMaxFillProperties = 9;
bool CSSPropertyParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
{
ASSERT(numProperties <= cMaxFillProperties);
if (numProperties > cMaxFillProperties)
return false;
ShorthandScope scope(this, propId);
bool parsedProperty[cMaxFillProperties] = { false };
RefPtrWillBeRawPtr<CSSValue> values[cMaxFillProperties];
#if ENABLE(OILPAN)
memset(&values, 0, sizeof(values));
#endif
RefPtrWillBeRawPtr<CSSValue> clipValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> positionYValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> repeatYValue = nullptr;
bool foundClip = false;
int i;
bool foundPositionCSSProperty = false;
while (m_valueList->current()) {
CSSParserValue* val = m_valueList->current();
if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
m_valueList->next();
for (i = 0; i < numProperties; ++i) {
if (properties[i] == CSSPropertyBackgroundColor && parsedProperty[i])
return false;
if (!parsedProperty[i] && properties[i] != CSSPropertyBackgroundColor) {
addFillValue(values[i], cssValuePool().createImplicitInitialValue());
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
if ((properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) && !parsedProperty[i]) {
addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
}
}
parsedProperty[i] = false;
}
if (!m_valueList->current())
break;
}
bool sizeCSSPropertyExpected = false;
if (isForwardSlashOperator(val) && foundPositionCSSProperty) {
sizeCSSPropertyExpected = true;
m_valueList->next();
}
foundPositionCSSProperty = false;
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (sizeCSSPropertyExpected && (properties[i] != CSSPropertyBackgroundSize && properties[i] != CSSPropertyWebkitMaskSize))
continue;
if (!sizeCSSPropertyExpected && (properties[i] == CSSPropertyBackgroundSize || properties[i] == CSSPropertyWebkitMaskSize))
continue;
if (!parsedProperty[i]) {
RefPtrWillBeRawPtr<CSSValue> val1 = nullptr;
RefPtrWillBeRawPtr<CSSValue> val2 = nullptr;
CSSPropertyID propId1, propId2;
CSSParserValue* parserValue = m_valueList->current();
if (parseFillProperty(properties[i], propId1, propId2, val1, val2)) {
parsedProperty[i] = found = true;
addFillValue(values[i], val1.release());
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, val2.release());
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
addFillValue(repeatYValue, val2.release());
if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
if (parseBackgroundClip(parserValue, val1))
addFillValue(clipValue, val1.release());
else
addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
}
if (properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) {
addFillValue(clipValue, val1.release());
foundClip = true;
}
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
foundPositionCSSProperty = true;
}
}
}
if (!found) {
m_implicitShorthand = false;
return false;
}
}
for (i = 0; i < numProperties; i++) {
if (!parsedProperty[i]) {
addFillValue(values[i], cssValuePool().createImplicitInitialValue());
if (properties[i] == CSSPropertyBackgroundPosition || properties[i] == CSSPropertyWebkitMaskPosition)
addFillValue(positionYValue, cssValuePool().createImplicitInitialValue());
if (properties[i] == CSSPropertyBackgroundRepeat || properties[i] == CSSPropertyWebkitMaskRepeat)
addFillValue(repeatYValue, cssValuePool().createImplicitInitialValue());
if (properties[i] == CSSPropertyBackgroundOrigin || properties[i] == CSSPropertyWebkitMaskOrigin) {
addFillValue(clipValue, cssValuePool().createImplicitInitialValue());
}
}
if (properties[i] == CSSPropertyBackgroundPosition) {
addProperty(CSSPropertyBackgroundPositionX, values[i].release(), important);
addProperty(CSSPropertyBackgroundPositionY, positionYValue.release(), important);
} else if (properties[i] == CSSPropertyWebkitMaskPosition) {
addProperty(CSSPropertyWebkitMaskPositionX, values[i].release(), important);
addProperty(CSSPropertyWebkitMaskPositionY, positionYValue.release(), important);
} else if (properties[i] == CSSPropertyBackgroundRepeat) {
addProperty(CSSPropertyBackgroundRepeatX, values[i].release(), important);
addProperty(CSSPropertyBackgroundRepeatY, repeatYValue.release(), important);
} else if (properties[i] == CSSPropertyWebkitMaskRepeat) {
addProperty(CSSPropertyWebkitMaskRepeatX, values[i].release(), important);
addProperty(CSSPropertyWebkitMaskRepeatY, repeatYValue.release(), important);
} else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
continue;
else if (properties[i] == CSSPropertyBackgroundSize && !parsedProperty[i] && m_context.useLegacyBackgroundSizeShorthandBehavior())
continue;
else
addProperty(properties[i], values[i].release(), important);
if (properties[i] == CSSPropertyBackgroundOrigin && !foundClip)
addProperty(CSSPropertyBackgroundClip, clipValue.release(), important);
else if (properties[i] == CSSPropertyWebkitMaskOrigin && !foundClip)
addProperty(CSSPropertyWebkitMaskClip, clipValue.release(), important);
}
m_implicitShorthand = false;
return true;
}
void CSSPropertyParser::addAnimationValue(RefPtrWillBeRawPtr<CSSValue>& lval, PassRefPtrWillBeRawPtr<CSSValue> rval)
{
if (lval) {
if (lval->isValueList())
toCSSValueList(lval.get())->append(rval);
else {
PassRefPtrWillBeRawPtr<CSSValue> oldVal(lval.release());
PassRefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
list->append(oldVal);
list->append(rval);
lval = list;
}
}
else
lval = rval;
}
bool CSSPropertyParser::parseAnimationShorthand(CSSPropertyID propId, bool important)
{
const StylePropertyShorthand& animationProperties = parsingShorthandForProperty(propId);
const unsigned numProperties = 8;
ASSERT(numProperties == animationProperties.length());
ASSERT(numProperties == shorthandForProperty(propId).length());
ShorthandScope scope(this, propId);
bool parsedProperty[numProperties] = { false };
AnimationParseContext context;
RefPtrWillBeRawPtr<CSSValue> values[numProperties];
#if ENABLE(OILPAN)
memset(&values, 0, sizeof(values));
#endif
unsigned i;
while (m_valueList->current()) {
CSSParserValue* val = m_valueList->current();
if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
m_valueList->next();
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
parsedProperty[i] = false;
}
if (!m_valueList->current())
break;
context.commitFirstAnimation();
}
bool found = false;
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtrWillBeRawPtr<CSSValue> val = nullptr;
if (parseAnimationProperty(animationProperties.properties()[i], val, context)) {
parsedProperty[i] = found = true;
addAnimationValue(values[i], val.release());
break;
}
}
}
if (!found)
return false;
}
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
if (RuntimeEnabledFeatures::cssAnimationUnprefixedEnabled())
addPropertyWithPrefixingVariant(animationProperties.properties()[i], values[i].release(), important);
else
addProperty(animationProperties.properties()[i], values[i].release(), important);
}
return true;
}
bool CSSPropertyParser::parseTransitionShorthand(CSSPropertyID propId, bool important)
{
const unsigned numProperties = 4;
const StylePropertyShorthand& shorthand = shorthandForProperty(propId);
ASSERT(numProperties == shorthand.length());
ShorthandScope scope(this, propId);
bool parsedProperty[numProperties] = { false };
AnimationParseContext context;
RefPtrWillBeRawPtr<CSSValue> values[numProperties];
#if ENABLE(OILPAN)
memset(&values, 0, sizeof(values));
#endif
unsigned i;
while (m_valueList->current()) {
CSSParserValue* val = m_valueList->current();
if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
m_valueList->next();
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
parsedProperty[i] = false;
}
if (!m_valueList->current())
break;
context.commitFirstAnimation();
}
bool found = false;
for (i = 0; !found && i < numProperties; ++i) {
if (!parsedProperty[i]) {
RefPtrWillBeRawPtr<CSSValue> val = nullptr;
if (parseAnimationProperty(shorthand.properties()[i], val, context)) {
parsedProperty[i] = found = true;
addAnimationValue(values[i], val.release());
}
if (!context.animationPropertyKeywordAllowed() && context.hasCommittedFirstAnimation())
return false;
}
}
if (!found)
return false;
}
for (i = 0; i < numProperties; ++i) {
if (!parsedProperty[i])
addAnimationValue(values[i], cssValuePool().createImplicitInitialValue());
}
for (i = 0; i < numProperties; i++)
addPropertyWithPrefixingVariant(shorthand.properties()[i], values[i].release(), important);
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColumnWidth()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueAuto
|| (validUnit(value, FLength | FNonNeg, HTMLStandardMode) && value->fValue)) {
RefPtrWillBeRawPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value);
m_valueList->next();
return parsedValue;
}
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseColumnCount()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueAuto
|| (!value->id && validUnit(value, FPositiveInteger, HTMLQuirksMode))) {
RefPtrWillBeRawPtr<CSSValue> parsedValue = parseValidPrimitive(value->id, value);
m_valueList->next();
return parsedValue;
}
return nullptr;
}
bool CSSPropertyParser::parseColumnsShorthand(bool important)
{
RefPtrWillBeRawPtr<CSSValue> columnWidth = nullptr;
RefPtrWillBeRawPtr<CSSValue> columnCount = nullptr;
bool hasPendingExplicitAuto = false;
for (unsigned propertiesParsed = 0; CSSParserValue* value = m_valueList->current(); propertiesParsed++) {
if (propertiesParsed >= 2)
return false;
if (!propertiesParsed && value->id == CSSValueAuto) {
m_valueList->next();
hasPendingExplicitAuto = true;
} else {
if (!columnWidth) {
if ((columnWidth = parseColumnWidth()))
continue;
}
if (!columnCount) {
if ((columnCount = parseColumnCount()))
continue;
}
return false;
}
}
if (hasPendingExplicitAuto) {
if (!columnWidth) {
columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto);
} else {
ASSERT(!columnCount);
columnCount = cssValuePool().createIdentifierValue(CSSValueAuto);
}
}
ASSERT(columnCount || columnWidth);
if (columnWidth)
addProperty(CSSPropertyWebkitColumnWidth, columnWidth, important);
else
addProperty(CSSPropertyWebkitColumnWidth, cssValuePool().createIdentifierValue(CSSValueAuto), important, true );
if (columnCount)
addProperty(CSSPropertyWebkitColumnCount, columnCount, important);
else
addProperty(CSSPropertyWebkitColumnCount, cssValuePool().createIdentifierValue(CSSValueAuto), important, true );
return true;
}
bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, const StylePropertyShorthand& shorthand, bool important)
{
ShorthandScope scope(this, propId);
bool found = false;
unsigned propertiesParsed = 0;
bool propertyFound[6] = { false, false, false, false, false, false };
while (m_valueList->current()) {
found = false;
for (unsigned propIndex = 0; !found && propIndex < shorthand.length(); ++propIndex) {
if (!propertyFound[propIndex] && parseValue(shorthand.properties()[propIndex], important)) {
propertyFound[propIndex] = found = true;
propertiesParsed++;
}
}
if (!found)
return false;
}
if (propertiesParsed == shorthand.length())
return true;
ImplicitScope implicitScope(this, PropertyImplicit);
const StylePropertyShorthand* const* const propertiesForInitialization = shorthand.propertiesForInitialization();
for (unsigned i = 0; i < shorthand.length(); ++i) {
if (propertyFound[i])
continue;
if (propertiesForInitialization) {
const StylePropertyShorthand& initProperties = *(propertiesForInitialization[i]);
for (unsigned propIndex = 0; propIndex < initProperties.length(); ++propIndex)
addProperty(initProperties.properties()[propIndex], cssValuePool().createImplicitInitialValue(), important);
} else
addProperty(shorthand.properties()[i], cssValuePool().createImplicitInitialValue(), important);
}
return true;
}
bool CSSPropertyParser::parse4Values(CSSPropertyID propId, const CSSPropertyID *properties, bool important)
{
int num = inShorthand() ? 1 : m_valueList->size();
ShorthandScope scope(this, propId);
switch (num) {
case 1: {
if (!parseValue(properties[0], important))
return false;
CSSValue* value = m_parsedProperties.last().value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[1], value, important);
addProperty(properties[2], value, important);
addProperty(properties[3], value, important);
break;
}
case 2: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important))
return false;
CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[2], value, important);
value = m_parsedProperties[m_parsedProperties.size() - 2].value();
addProperty(properties[3], value, important);
break;
}
case 3: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) || !parseValue(properties[2], important))
return false;
CSSValue* value = m_parsedProperties[m_parsedProperties.size() - 2].value();
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(properties[3], value, important);
break;
}
case 4: {
if (!parseValue(properties[0], important) || !parseValue(properties[1], important) ||
!parseValue(properties[2], important) || !parseValue(properties[3], important))
return false;
break;
}
default: {
return false;
}
}
return true;
}
bool CSSPropertyParser::parsePage(CSSPropertyID propId, bool important)
{
ASSERT(propId == CSSPropertyPage);
if (m_valueList->size() != 1)
return false;
CSSParserValue* value = m_valueList->current();
if (!value)
return false;
if (value->id == CSSValueAuto) {
addProperty(propId, cssValuePool().createIdentifierValue(value->id), important);
return true;
} else if (value->id == 0 && value->unit == CSSPrimitiveValue::CSS_IDENT) {
addProperty(propId, createPrimitiveStringValue(value), important);
return true;
}
return false;
}
bool CSSPropertyParser::parseSize(CSSPropertyID propId, bool important)
{
ASSERT(propId == CSSPropertySize);
if (m_valueList->size() > 2)
return false;
CSSParserValue* value = m_valueList->current();
if (!value)
return false;
RefPtrWillBeRawPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
SizeParameterType paramType = parseSizeParameter(parsedValues.get(), value, None);
if (paramType == None)
return false;
value = m_valueList->next();
if (value) {
paramType = parseSizeParameter(parsedValues.get(), value, paramType);
if (paramType == None)
return false;
}
addProperty(propId, parsedValues.release(), important);
return true;
}
CSSPropertyParser::SizeParameterType CSSPropertyParser::parseSizeParameter(CSSValueList* parsedValues, CSSParserValue* value, SizeParameterType prevParamType)
{
switch (value->id) {
case CSSValueAuto:
if (prevParamType == None) {
parsedValues->append(cssValuePool().createIdentifierValue(value->id));
return Auto;
}
return None;
case CSSValueLandscape:
case CSSValuePortrait:
if (prevParamType == None || prevParamType == PageSize) {
parsedValues->append(cssValuePool().createIdentifierValue(value->id));
return Orientation;
}
return None;
case CSSValueA3:
case CSSValueA4:
case CSSValueA5:
case CSSValueB4:
case CSSValueB5:
case CSSValueLedger:
case CSSValueLegal:
case CSSValueLetter:
if (prevParamType == None || prevParamType == Orientation) {
parsedValues->prepend(cssValuePool().createIdentifierValue(value->id));
return PageSize;
}
return None;
case 0:
if (validUnit(value, FLength | FNonNeg) && (prevParamType == None || prevParamType == Length)) {
parsedValues->append(createPrimitiveNumericValue(value));
return Length;
}
return None;
default:
return None;
}
}
bool CSSPropertyParser::parseQuotes(CSSPropertyID propId, bool important)
{
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
while (CSSParserValue* val = m_valueList->current()) {
RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
if (val->unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = CSSPrimitiveValue::create(val->string, CSSPrimitiveValue::CSS_STRING);
else
break;
values->append(parsedValue.release());
m_valueList->next();
}
if (values->length()) {
addProperty(propId, values.release(), important);
m_valueList->next();
return true;
}
return false;
}
bool CSSPropertyParser::parseContent(CSSPropertyID propId, bool important)
{
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
while (CSSParserValue* val = m_valueList->current()) {
RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
if (val->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSImageValue::create(val->string, completeURL(val->string));
} else if (val->unit == CSSParserValue::Function) {
CSSParserValueList* args = val->function->args.get();
if (!args)
return false;
if (equalIgnoringCase(val->function->name, "attr(")) {
parsedValue = parseAttr(args);
if (!parsedValue)
return false;
} else if (equalIgnoringCase(val->function->name, "counter(")) {
parsedValue = parseCounterContent(args, false);
if (!parsedValue)
return false;
} else if (equalIgnoringCase(val->function->name, "counters(")) {
parsedValue = parseCounterContent(args, true);
if (!parsedValue)
return false;
} else if (equalIgnoringCase(val->function->name, "-webkit-image-set(")) {
parsedValue = parseImageSet(m_valueList.get());
if (!parsedValue)
return false;
} else if (isGeneratedImageValue(val)) {
if (!parseGeneratedImage(m_valueList.get(), parsedValue))
return false;
} else
return false;
} else if (val->unit == CSSPrimitiveValue::CSS_IDENT) {
switch (val->id) {
case CSSValueOpenQuote:
case CSSValueCloseQuote:
case CSSValueNoOpenQuote:
case CSSValueNoCloseQuote:
case CSSValueNone:
case CSSValueNormal:
parsedValue = cssValuePool().createIdentifierValue(val->id);
default:
break;
}
} else if (val->unit == CSSPrimitiveValue::CSS_STRING) {
parsedValue = createPrimitiveStringValue(val);
}
if (!parsedValue)
break;
values->append(parsedValue.release());
m_valueList->next();
}
if (values->length()) {
addProperty(propId, values.release(), important);
m_valueList->next();
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAttr(CSSParserValueList* args)
{
if (args->size() != 1)
return nullptr;
CSSParserValue* a = args->current();
if (a->unit != CSSPrimitiveValue::CSS_IDENT)
return nullptr;
String attrName = a->string;
if (attrName[0] == '-')
return nullptr;
if (m_context.isHTMLDocument())
attrName = attrName.lower();
return cssValuePool().createValue(attrName, CSSPrimitiveValue::CSS_ATTR);
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseBackgroundColor()
{
CSSValueID id = m_valueList->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor ||
(id >= CSSValueGrey && id < CSSValueWebkitText && inQuirksMode()))
return cssValuePool().createIdentifierValue(id);
return parseColor();
}
bool CSSPropertyParser::parseFillImage(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value)
{
if (valueList->current()->id == CSSValueNone) {
value = cssValuePool().createIdentifierValue(CSSValueNone);
return true;
}
if (valueList->current()->unit == CSSPrimitiveValue::CSS_URI) {
value = CSSImageValue::create(valueList->current()->string, completeURL(valueList->current()->string));
return true;
}
if (isGeneratedImageValue(valueList->current()))
return parseGeneratedImage(valueList, value);
if (valueList->current()->unit == CSSParserValue::Function && equalIgnoringCase(valueList->current()->function->name, "-webkit-image-set(")) {
value = parseImageSet(m_valueList.get());
if (value)
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseFillPositionX(CSSParserValueList* valueList)
{
int id = valueList->current()->id;
if (id == CSSValueLeft || id == CSSValueRight || id == CSSValueCenter) {
int percent = 0;
if (id == CSSValueRight)
percent = 100;
else if (id == CSSValueCenter)
percent = 50;
return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (validUnit(valueList->current(), FPercent | FLength))
return createPrimitiveNumericValue(valueList->current());
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseFillPositionY(CSSParserValueList* valueList)
{
int id = valueList->current()->id;
if (id == CSSValueTop || id == CSSValueBottom || id == CSSValueCenter) {
int percent = 0;
if (id == CSSValueBottom)
percent = 100;
else if (id == CSSValueCenter)
percent = 50;
return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (validUnit(valueList->current(), FPercent | FLength))
return createPrimitiveNumericValue(valueList->current());
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseFillPositionComponent(CSSParserValueList* valueList, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode parsingMode)
{
CSSValueID id = valueList->current()->id;
if (id == CSSValueLeft || id == CSSValueTop || id == CSSValueRight || id == CSSValueBottom || id == CSSValueCenter) {
int percent = 0;
if (id == CSSValueLeft || id == CSSValueRight) {
if (cumulativeFlags & XFillPosition)
return nullptr;
cumulativeFlags |= XFillPosition;
individualFlag = XFillPosition;
if (id == CSSValueRight)
percent = 100;
}
else if (id == CSSValueTop || id == CSSValueBottom) {
if (cumulativeFlags & YFillPosition)
return nullptr;
cumulativeFlags |= YFillPosition;
individualFlag = YFillPosition;
if (id == CSSValueBottom)
percent = 100;
} else if (id == CSSValueCenter) {
percent = 50;
cumulativeFlags |= AmbiguousFillPosition;
individualFlag = AmbiguousFillPosition;
}
if (parsingMode == ResolveValuesAsKeyword)
return cssValuePool().createIdentifierValue(id);
return cssValuePool().createValue(percent, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (validUnit(valueList->current(), FPercent | FLength)) {
if (!cumulativeFlags) {
cumulativeFlags |= XFillPosition;
individualFlag = XFillPosition;
} else if (cumulativeFlags & (XFillPosition | AmbiguousFillPosition)) {
cumulativeFlags |= YFillPosition;
individualFlag = YFillPosition;
} else {
if (m_parsedCalculation)
m_parsedCalculation.release();
return nullptr;
}
return createPrimitiveNumericValue(valueList->current());
}
return nullptr;
}
static bool isValueConflictingWithCurrentEdge(int value1, int value2)
{
if ((value1 == CSSValueLeft || value1 == CSSValueRight) && (value2 == CSSValueLeft || value2 == CSSValueRight))
return true;
if ((value1 == CSSValueTop || value1 == CSSValueBottom) && (value2 == CSSValueTop || value2 == CSSValueBottom))
return true;
return false;
}
static bool isFillPositionKeyword(CSSValueID value)
{
return value == CSSValueLeft || value == CSSValueTop || value == CSSValueBottom || value == CSSValueRight || value == CSSValueCenter;
}
void CSSPropertyParser::parse4ValuesFillPosition(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue1, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue2)
{
if (isFillPositionKeyword(parsedValue2->getValueID()))
return;
unsigned cumulativeFlags = 0;
FillPositionFlag value3Flag = InvalidFillPosition;
RefPtrWillBeRawPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cumulativeFlags, value3Flag, ResolveValuesAsKeyword);
if (!value3)
return;
CSSValueID ident1 = parsedValue1->getValueID();
CSSValueID ident3 = value3->getValueID();
if (ident1 == CSSValueCenter)
return;
if (!isFillPositionKeyword(ident3) || ident3 == CSSValueCenter)
return;
if (isValueConflictingWithCurrentEdge(ident1, ident3))
return;
valueList->next();
cumulativeFlags = 0;
FillPositionFlag value4Flag = InvalidFillPosition;
RefPtrWillBeRawPtr<CSSPrimitiveValue> value4 = parseFillPositionComponent(valueList, cumulativeFlags, value4Flag, ResolveValuesAsKeyword);
if (!value4)
return;
if (isFillPositionKeyword(value4->getValueID()))
return;
value1 = createPrimitiveValuePair(parsedValue1, parsedValue2);
value2 = createPrimitiveValuePair(value3, value4);
if (ident1 == CSSValueTop || ident1 == CSSValueBottom)
value1.swap(value2);
valueList->next();
}
void CSSPropertyParser::parse3ValuesFillPosition(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue1, PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue2)
{
unsigned cumulativeFlags = 0;
FillPositionFlag value3Flag = InvalidFillPosition;
RefPtrWillBeRawPtr<CSSPrimitiveValue> value3 = parseFillPositionComponent(valueList, cumulativeFlags, value3Flag, ResolveValuesAsKeyword);
if (!value3)
return;
valueList->next();
bool swapNeeded = false;
CSSValueID ident1 = parsedValue1->getValueID();
CSSValueID ident2 = parsedValue2->getValueID();
CSSValueID ident3 = value3->getValueID();
CSSValueID firstPositionKeyword;
CSSValueID secondPositionKeyword;
if (ident1 == CSSValueCenter) {
if (!isFillPositionKeyword(ident2))
return;
if (isFillPositionKeyword(ident3))
return;
firstPositionKeyword = CSSValueLeft;
if (ident2 == CSSValueLeft || ident2 == CSSValueRight) {
firstPositionKeyword = CSSValueTop;
swapNeeded = true;
}
value1 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(firstPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
value2 = createPrimitiveValuePair(parsedValue2, value3);
} else if (ident3 == CSSValueCenter) {
if (isFillPositionKeyword(ident2))
return;
secondPositionKeyword = CSSValueTop;
if (ident1 == CSSValueTop || ident1 == CSSValueBottom) {
secondPositionKeyword = CSSValueLeft;
swapNeeded = true;
}
value1 = createPrimitiveValuePair(parsedValue1, parsedValue2);
value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(secondPositionKeyword), cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE));
} else {
RefPtrWillBeRawPtr<CSSPrimitiveValue> firstPositionValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> secondPositionValue = nullptr;
if (isFillPositionKeyword(ident2)) {
ASSERT(ident2 != CSSValueCenter);
if (isFillPositionKeyword(ident3))
return;
secondPositionValue = value3;
secondPositionKeyword = ident2;
firstPositionValue = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENTAGE);
} else {
if (!isFillPositionKeyword(ident3))
return;
firstPositionValue = parsedValue2;
secondPositionKeyword = ident3;
secondPositionValue = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PERCENTAGE);
}
if (isValueConflictingWithCurrentEdge(ident1, secondPositionKeyword))
return;
value1 = createPrimitiveValuePair(parsedValue1, firstPositionValue);
value2 = createPrimitiveValuePair(cssValuePool().createIdentifierValue(secondPositionKeyword), secondPositionValue);
}
if (ident1 == CSSValueTop || ident1 == CSSValueBottom || swapNeeded)
value1.swap(value2);
#ifndef NDEBUG
CSSPrimitiveValue* first = toCSSPrimitiveValue(value1.get());
CSSPrimitiveValue* second = toCSSPrimitiveValue(value2.get());
ident1 = first->getPairValue()->first()->getValueID();
ident2 = second->getPairValue()->first()->getValueID();
ASSERT(ident1 == CSSValueLeft || ident1 == CSSValueRight);
ASSERT(ident2 == CSSValueBottom || ident2 == CSSValueTop);
#endif
}
inline bool CSSPropertyParser::isPotentialPositionValue(CSSParserValue* value)
{
return isFillPositionKeyword(value->id) || validUnit(value, FPercent | FLength, ReleaseParsedCalcValue);
}
void CSSPropertyParser::parseFillPosition(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2)
{
unsigned numberOfValues = 0;
for (unsigned i = valueList->currentIndex(); i < valueList->size(); ++i, ++numberOfValues) {
CSSParserValue* current = valueList->valueAt(i);
if (isComma(current) || !current || isForwardSlashOperator(current) || !isPotentialPositionValue(current))
break;
}
if (numberOfValues > 4)
return;
if (numberOfValues <= 2) {
parse2ValuesFillPosition(valueList, value1, value2);
return;
}
ASSERT(numberOfValues > 2 && numberOfValues <= 4);
CSSParserValue* value = valueList->current();
if (!isFillPositionKeyword(value->id))
return;
unsigned cumulativeFlags = 0;
FillPositionFlag value1Flag = InvalidFillPosition;
FillPositionFlag value2Flag = InvalidFillPosition;
value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag, ResolveValuesAsKeyword);
if (!value1)
return;
valueList->next();
cumulativeFlags = AmbiguousFillPosition;
value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Flag, ResolveValuesAsKeyword);
if (value2)
valueList->next();
else {
value1.clear();
return;
}
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue1 = toCSSPrimitiveValue(value1.get());
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue2 = toCSSPrimitiveValue(value2.get());
value1.clear();
value2.clear();
if (parsedValue2->getValueID() == CSSValueCenter)
return;
if (numberOfValues == 3)
parse3ValuesFillPosition(valueList, value1, value2, parsedValue1.release(), parsedValue2.release());
else
parse4ValuesFillPosition(valueList, value1, value2, parsedValue1.release(), parsedValue2.release());
}
void CSSPropertyParser::parse2ValuesFillPosition(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2)
{
unsigned cumulativeFlags = 0;
FillPositionFlag value1Flag = InvalidFillPosition;
FillPositionFlag value2Flag = InvalidFillPosition;
value1 = parseFillPositionComponent(valueList, cumulativeFlags, value1Flag);
if (!value1)
return;
CSSParserValue* value = valueList->next();
if (isComma(value))
value = 0;
if (value) {
value2 = parseFillPositionComponent(valueList, cumulativeFlags, value2Flag);
if (value2)
valueList->next();
else {
if (!inShorthand()) {
value1.clear();
return;
}
}
}
if (!value2)
value2 = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE);
if (value1Flag == YFillPosition || value2Flag == XFillPosition)
value1.swap(value2);
}
void CSSPropertyParser::parseFillRepeat(RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2)
{
CSSValueID id = m_valueList->current()->id;
if (id == CSSValueRepeatX) {
m_implicitShorthand = true;
value1 = cssValuePool().createIdentifierValue(CSSValueRepeat);
value2 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
m_valueList->next();
return;
}
if (id == CSSValueRepeatY) {
m_implicitShorthand = true;
value1 = cssValuePool().createIdentifierValue(CSSValueNoRepeat);
value2 = cssValuePool().createIdentifierValue(CSSValueRepeat);
m_valueList->next();
return;
}
if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace)
value1 = cssValuePool().createIdentifierValue(id);
else {
value1 = nullptr;
return;
}
CSSParserValue* value = m_valueList->next();
if (value && !isComma(value)) {
id = value->id;
if (id == CSSValueRepeat || id == CSSValueNoRepeat || id == CSSValueRound || id == CSSValueSpace) {
value2 = cssValuePool().createIdentifierValue(id);
m_valueList->next();
return;
}
}
m_implicitShorthand = true;
value2 = cssValuePool().createIdentifierValue(toCSSPrimitiveValue(value1.get())->getValueID());
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseFillSize(CSSPropertyID propId, bool& allowComma)
{
allowComma = true;
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueContain || value->id == CSSValueCover)
return cssValuePool().createIdentifierValue(value->id);
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue1 = nullptr;
if (value->id == CSSValueAuto)
parsedValue1 = cssValuePool().createIdentifierValue(CSSValueAuto);
else {
if (!validUnit(value, FLength | FPercent))
return nullptr;
parsedValue1 = createPrimitiveNumericValue(value);
}
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue2 = nullptr;
if ((value = m_valueList->next())) {
if (value->unit == CSSParserValue::Operator && value->iValue == ',')
allowComma = false;
else if (value->id != CSSValueAuto) {
if (!validUnit(value, FLength | FPercent)) {
if (!inShorthand())
return nullptr;
m_valueList->previous();
} else
parsedValue2 = createPrimitiveNumericValue(value);
}
} else if (!parsedValue2 && propId == CSSPropertyWebkitBackgroundSize) {
parsedValue2 = parsedValue1;
}
if (!parsedValue2)
return parsedValue1;
return createPrimitiveValuePair(parsedValue1.release(), parsedValue2.release());
}
bool CSSPropertyParser::parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2,
RefPtrWillBeRawPtr<CSSValue>& retValue1, RefPtrWillBeRawPtr<CSSValue>& retValue2)
{
RefPtrWillBeRawPtr<CSSValueList> values = nullptr;
RefPtrWillBeRawPtr<CSSValueList> values2 = nullptr;
CSSParserValue* val;
RefPtrWillBeRawPtr<CSSValue> value = nullptr;
RefPtrWillBeRawPtr<CSSValue> value2 = nullptr;
bool allowComma = false;
retValue1 = retValue2 = nullptr;
propId1 = propId;
propId2 = propId;
if (propId == CSSPropertyBackgroundPosition) {
propId1 = CSSPropertyBackgroundPositionX;
propId2 = CSSPropertyBackgroundPositionY;
} else if (propId == CSSPropertyWebkitMaskPosition) {
propId1 = CSSPropertyWebkitMaskPositionX;
propId2 = CSSPropertyWebkitMaskPositionY;
} else if (propId == CSSPropertyBackgroundRepeat) {
propId1 = CSSPropertyBackgroundRepeatX;
propId2 = CSSPropertyBackgroundRepeatY;
} else if (propId == CSSPropertyWebkitMaskRepeat) {
propId1 = CSSPropertyWebkitMaskRepeatX;
propId2 = CSSPropertyWebkitMaskRepeatY;
}
while ((val = m_valueList->current())) {
RefPtrWillBeRawPtr<CSSValue> currValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> currValue2 = nullptr;
if (allowComma) {
if (!isComma(val))
return false;
m_valueList->next();
allowComma = false;
} else {
allowComma = true;
switch (propId) {
case CSSPropertyBackgroundColor:
currValue = parseBackgroundColor();
if (currValue)
m_valueList->next();
break;
case CSSPropertyBackgroundAttachment:
if (val->id == CSSValueScroll || val->id == CSSValueFixed || val->id == CSSValueLocal) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundImage:
case CSSPropertyWebkitMaskImage:
if (parseFillImage(m_valueList.get(), currValue))
m_valueList->next();
break;
case CSSPropertyWebkitBackgroundClip:
case CSSPropertyWebkitBackgroundOrigin:
case CSSPropertyWebkitMaskClip:
case CSSPropertyWebkitMaskOrigin:
if (val->id == CSSValueBorder || val->id == CSSValuePadding || val->id == CSSValueContent ||
val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox ||
((propId == CSSPropertyWebkitBackgroundClip || propId == CSSPropertyWebkitMaskClip) &&
(val->id == CSSValueText || val->id == CSSValueWebkitText))) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundClip:
if (parseBackgroundClip(val, currValue))
m_valueList->next();
break;
case CSSPropertyBackgroundOrigin:
if (val->id == CSSValueBorderBox || val->id == CSSValuePaddingBox || val->id == CSSValueContentBox) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundPosition:
case CSSPropertyWebkitMaskPosition:
parseFillPosition(m_valueList.get(), currValue, currValue2);
break;
case CSSPropertyBackgroundPositionX:
case CSSPropertyWebkitMaskPositionX: {
currValue = parseFillPositionX(m_valueList.get());
if (currValue)
m_valueList->next();
break;
}
case CSSPropertyBackgroundPositionY:
case CSSPropertyWebkitMaskPositionY: {
currValue = parseFillPositionY(m_valueList.get());
if (currValue)
m_valueList->next();
break;
}
case CSSPropertyWebkitBackgroundComposite:
case CSSPropertyWebkitMaskComposite:
if (val->id >= CSSValueClear && val->id <= CSSValuePlusLighter) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundBlendMode:
if (val->id == CSSValueNormal || val->id == CSSValueMultiply
|| val->id == CSSValueScreen || val->id == CSSValueOverlay || val->id == CSSValueDarken
|| val->id == CSSValueLighten || val->id == CSSValueColorDodge || val->id == CSSValueColorBurn
|| val->id == CSSValueHardLight || val->id == CSSValueSoftLight || val->id == CSSValueDifference
|| val->id == CSSValueExclusion || val->id == CSSValueHue || val->id == CSSValueSaturation
|| val->id == CSSValueColor || val->id == CSSValueLuminosity) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
}
break;
case CSSPropertyBackgroundRepeat:
case CSSPropertyWebkitMaskRepeat:
parseFillRepeat(currValue, currValue2);
break;
case CSSPropertyBackgroundSize:
case CSSPropertyWebkitBackgroundSize:
case CSSPropertyWebkitMaskSize: {
currValue = parseFillSize(propId, allowComma);
if (currValue)
m_valueList->next();
break;
}
case CSSPropertyMaskSourceType: {
if (RuntimeEnabledFeatures::cssMaskSourceTypeEnabled()) {
if (val->id == CSSValueAuto || val->id == CSSValueAlpha || val->id == CSSValueLuminance) {
currValue = cssValuePool().createIdentifierValue(val->id);
m_valueList->next();
} else {
currValue = nullptr;
}
}
break;
}
default:
break;
}
if (!currValue)
return false;
if (value && !values) {
values = CSSValueList::createCommaSeparated();
values->append(value.release());
}
if (value2 && !values2) {
values2 = CSSValueList::createCommaSeparated();
values2->append(value2.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
if (currValue2) {
if (values2)
values2->append(currValue2.release());
else
value2 = currValue2.release();
}
}
if (inShorthand())
break;
}
if (values && values->length()) {
retValue1 = values.release();
if (values2 && values2->length())
retValue2 = values2.release();
return true;
}
if (value) {
retValue1 = value.release();
retValue2 = value2.release();
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationDelay()
{
CSSParserValue* value = m_valueList->current();
if (validUnit(value, FTime))
return createPrimitiveNumericValue(value);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationDirection()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueNormal || value->id == CSSValueAlternate || value->id == CSSValueReverse || value->id == CSSValueAlternateReverse)
return cssValuePool().createIdentifierValue(value->id);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationDuration()
{
CSSParserValue* value = m_valueList->current();
if (validUnit(value, FTime | FNonNeg))
return createPrimitiveNumericValue(value);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationFillMode()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueNone || value->id == CSSValueForwards || value->id == CSSValueBackwards || value->id == CSSValueBoth)
return cssValuePool().createIdentifierValue(value->id);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationIterationCount()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueInfinite)
return cssValuePool().createIdentifierValue(value->id);
if (validUnit(value, FNumber | FNonNeg))
return createPrimitiveNumericValue(value);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationName()
{
CSSParserValue* value = m_valueList->current();
if (value->unit == CSSPrimitiveValue::CSS_STRING || value->unit == CSSPrimitiveValue::CSS_IDENT) {
if (value->id == CSSValueNone || (value->unit == CSSPrimitiveValue::CSS_STRING && equalIgnoringCase(value, "none"))) {
return cssValuePool().createIdentifierValue(CSSValueNone);
} else {
return createPrimitiveStringValue(value);
}
}
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationPlayState()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueRunning || value->id == CSSValuePaused)
return cssValuePool().createIdentifierValue(value->id);
return nullptr;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationProperty(AnimationParseContext& context)
{
CSSParserValue* value = m_valueList->current();
if (value->unit != CSSPrimitiveValue::CSS_IDENT)
return nullptr;
CSSPropertyID result = cssPropertyID(value->string);
if (result && RuntimeCSSEnabled::isCSSPropertyEnabled(result))
return cssValuePool().createIdentifierValue(result);
if (equalIgnoringCase(value, "all")) {
context.sawAnimationPropertyKeyword();
return cssValuePool().createIdentifierValue(CSSValueAll);
}
if (equalIgnoringCase(value, "none")) {
context.commitAnimationPropertyKeyword();
context.sawAnimationPropertyKeyword();
return cssValuePool().createIdentifierValue(CSSValueNone);
}
return nullptr;
}
bool CSSPropertyParser::parseWebkitTransformOriginShorthand(RefPtrWillBeRawPtr<CSSValue>& value1, RefPtrWillBeRawPtr<CSSValue>& value2, RefPtrWillBeRawPtr<CSSValue>& value3)
{
parse2ValuesFillPosition(m_valueList.get(), value1, value2);
if (m_valueList->current()) {
if (validUnit(m_valueList->current(), FLength)) {
value3 = createPrimitiveNumericValue(m_valueList->current());
m_valueList->next();
return true;
}
return false;
}
value3 = cssValuePool().createImplicitInitialValue();
return true;
}
bool CSSPropertyParser::parseCubicBezierTimingFunctionValue(CSSParserValueList*& args, double& result)
{
CSSParserValue* v = args->current();
if (!validUnit(v, FNumber))
return false;
result = v->fValue;
v = args->next();
if (!v)
return true;
if (!isComma(v))
return false;
args->next();
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseAnimationTimingFunction()
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueEase || value->id == CSSValueLinear || value->id == CSSValueEaseIn || value->id == CSSValueEaseOut
|| value->id == CSSValueEaseInOut || value->id == CSSValueStepStart || value->id == CSSValueStepEnd
|| (value->id == CSSValueStepMiddle && RuntimeEnabledFeatures::webAnimationsAPIEnabled()))
return cssValuePool().createIdentifierValue(value->id);
if (value->unit != CSSParserValue::Function)
return nullptr;
CSSParserValueList* args = value->function->args.get();
if (equalIgnoringCase(value->function->name, "steps(")) {
if (!args || (args->size() != 1 && args->size() != 3))
return nullptr;
int numSteps;
StepsTimingFunction::StepAtPosition stepAtPosition = StepsTimingFunction::StepAtEnd;
CSSParserValue* v = args->current();
if (!validUnit(v, FInteger))
return nullptr;
numSteps = clampToInteger(v->fValue);
if (numSteps < 1)
return nullptr;
v = args->next();
if (v) {
if (!isComma(v))
return nullptr;
v = args->next();
switch (v->id) {
case CSSValueMiddle:
if (!RuntimeEnabledFeatures::webAnimationsAPIEnabled())
return nullptr;
stepAtPosition = StepsTimingFunction::StepAtMiddle;
break;
case CSSValueStart:
stepAtPosition = StepsTimingFunction::StepAtStart;
break;
case CSSValueEnd:
stepAtPosition = StepsTimingFunction::StepAtEnd;
break;
default:
return nullptr;
}
}
return CSSStepsTimingFunctionValue::create(numSteps, stepAtPosition);
}
if (equalIgnoringCase(value->function->name, "cubic-bezier(")) {
if (!args || args->size() != 7)
return nullptr;
double x1, y1, x2, y2;
if (!parseCubicBezierTimingFunctionValue(args, x1))
return nullptr;
if (x1 < 0 || x1 > 1)
return nullptr;
if (!parseCubicBezierTimingFunctionValue(args, y1))
return nullptr;
if (!parseCubicBezierTimingFunctionValue(args, x2))
return nullptr;
if (x2 < 0 || x2 > 1)
return nullptr;
if (!parseCubicBezierTimingFunctionValue(args, y2))
return nullptr;
return CSSCubicBezierTimingFunctionValue::create(x1, y1, x2, y2);
}
return nullptr;
}
bool CSSPropertyParser::parseAnimationProperty(CSSPropertyID propId, RefPtrWillBeRawPtr<CSSValue>& result, AnimationParseContext& context)
{
RefPtrWillBeRawPtr<CSSValueList> values = nullptr;
CSSParserValue* val;
RefPtrWillBeRawPtr<CSSValue> value = nullptr;
bool allowComma = false;
result = nullptr;
while ((val = m_valueList->current())) {
RefPtrWillBeRawPtr<CSSValue> currValue = nullptr;
if (allowComma) {
if (!isComma(val))
return false;
m_valueList->next();
allowComma = false;
}
else {
switch (propId) {
case CSSPropertyAnimationDelay:
case CSSPropertyWebkitAnimationDelay:
case CSSPropertyTransitionDelay:
case CSSPropertyWebkitTransitionDelay:
currValue = parseAnimationDelay();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationDirection:
case CSSPropertyWebkitAnimationDirection:
currValue = parseAnimationDirection();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationDuration:
case CSSPropertyWebkitAnimationDuration:
case CSSPropertyTransitionDuration:
case CSSPropertyWebkitTransitionDuration:
currValue = parseAnimationDuration();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationFillMode:
case CSSPropertyWebkitAnimationFillMode:
currValue = parseAnimationFillMode();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationIterationCount:
case CSSPropertyWebkitAnimationIterationCount:
currValue = parseAnimationIterationCount();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationName:
case CSSPropertyWebkitAnimationName:
currValue = parseAnimationName();
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationPlayState:
case CSSPropertyWebkitAnimationPlayState:
currValue = parseAnimationPlayState();
if (currValue)
m_valueList->next();
break;
case CSSPropertyTransitionProperty:
case CSSPropertyWebkitTransitionProperty:
currValue = parseAnimationProperty(context);
if (value && !context.animationPropertyKeywordAllowed())
return false;
if (currValue)
m_valueList->next();
break;
case CSSPropertyAnimationTimingFunction:
case CSSPropertyWebkitAnimationTimingFunction:
case CSSPropertyTransitionTimingFunction:
case CSSPropertyWebkitTransitionTimingFunction:
currValue = parseAnimationTimingFunction();
if (currValue)
m_valueList->next();
break;
default:
ASSERT_NOT_REACHED();
return false;
}
if (!currValue)
return false;
if (value && !values) {
values = CSSValueList::createCommaSeparated();
values->append(value.release());
}
if (values)
values->append(currValue.release());
else
value = currValue.release();
allowComma = true;
}
if (inShorthand())
break;
}
if (values && values->length()) {
result = values.release();
return true;
}
if (value) {
result = value.release();
return true;
}
return false;
}
bool CSSPropertyParser::parseIntegerOrStringFromGridPosition(RefPtrWillBeRawPtr<CSSPrimitiveValue>& numericValue, RefPtrWillBeRawPtr<CSSPrimitiveValue>& gridLineName)
{
CSSParserValue* value = m_valueList->current();
if (validUnit(value, FInteger) && value->fValue) {
numericValue = createPrimitiveNumericValue(value);
value = m_valueList->next();
if (value && value->unit == CSSPrimitiveValue::CSS_STRING) {
gridLineName = createPrimitiveStringValue(m_valueList->current());
m_valueList->next();
}
return true;
}
if (value->unit == CSSPrimitiveValue::CSS_STRING) {
gridLineName = createPrimitiveStringValue(m_valueList->current());
value = m_valueList->next();
if (value && validUnit(value, FInteger) && value->fValue) {
numericValue = createPrimitiveNumericValue(value);
m_valueList->next();
}
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridPosition()
{
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueAuto) {
m_valueList->next();
return cssValuePool().createIdentifierValue(CSSValueAuto);
}
if (value->id != CSSValueSpan && value->unit == CSSPrimitiveValue::CSS_IDENT) {
m_valueList->next();
return cssValuePool().createValue(value->string, CSSPrimitiveValue::CSS_STRING);
}
RefPtrWillBeRawPtr<CSSPrimitiveValue> numericValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> gridLineName = nullptr;
bool hasSeenSpanKeyword = false;
if (parseIntegerOrStringFromGridPosition(numericValue, gridLineName)) {
value = m_valueList->current();
if (value && value->id == CSSValueSpan) {
hasSeenSpanKeyword = true;
m_valueList->next();
}
} else if (value->id == CSSValueSpan) {
hasSeenSpanKeyword = true;
if (m_valueList->next())
parseIntegerOrStringFromGridPosition(numericValue, gridLineName);
}
if (m_valueList->current() && !isForwardSlashOperator(m_valueList->current()))
return nullptr;
if (!hasSeenSpanKeyword && !gridLineName && !numericValue)
return nullptr;
if (hasSeenSpanKeyword && numericValue && numericValue->getIntValue() < 0)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
if (hasSeenSpanKeyword)
values->append(cssValuePool().createIdentifierValue(CSSValueSpan));
if (numericValue)
values->append(numericValue.release());
if (gridLineName)
values->append(gridLineName.release());
ASSERT(values->length());
return values.release();
}
static PassRefPtrWillBeRawPtr<CSSValue> gridMissingGridPositionValue(CSSValue* value)
{
if (value->isPrimitiveValue() && toCSSPrimitiveValue(value)->isString())
return value;
return cssValuePool().createIdentifierValue(CSSValueAuto);
}
bool CSSPropertyParser::parseGridItemPositionShorthand(CSSPropertyID shorthandId, bool important)
{
ShorthandScope scope(this, shorthandId);
const StylePropertyShorthand& shorthand = shorthandForProperty(shorthandId);
ASSERT(shorthand.length() == 2);
RefPtrWillBeRawPtr<CSSValue> startValue = parseGridPosition();
if (!startValue)
return false;
RefPtrWillBeRawPtr<CSSValue> endValue = nullptr;
if (m_valueList->current()) {
if (!isForwardSlashOperator(m_valueList->current()))
return false;
if (!m_valueList->next())
return false;
endValue = parseGridPosition();
if (!endValue || m_valueList->current())
return false;
} else {
endValue = gridMissingGridPositionValue(startValue.get());
}
addProperty(shorthand.properties()[0], startValue, important);
addProperty(shorthand.properties()[1], endValue, important);
return true;
}
bool CSSPropertyParser::parseGridTemplateRowsAndAreas(PassRefPtrWillBeRawPtr<CSSValue> templateColumns, bool important)
{
NamedGridAreaMap gridAreaMap;
size_t rowCount = 0;
size_t columnCount = 0;
bool trailingIdentWasAdded = false;
RefPtrWillBeRawPtr<CSSValueList> templateRows = CSSValueList::createSpaceSeparated();
if (!m_valueList->current())
return false;
while (m_valueList->current()) {
if (m_valueList->current()->unit == CSSParserValue::ValueList) {
if (trailingIdentWasAdded) {
parseGridLineNames(*m_valueList, *templateRows, static_cast<CSSGridLineNamesValue*>(templateRows->item(templateRows->length() - 1)));
} else {
parseGridLineNames(*m_valueList, *templateRows);
}
}
if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
return false;
++rowCount;
if (m_valueList->current() && m_valueList->current()->unit != CSSParserValue::ValueList && m_valueList->current()->unit != CSSPrimitiveValue::CSS_STRING) {
RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
if (!value)
return false;
templateRows->append(value);
} else {
templateRows->append(cssValuePool().createIdentifierValue(CSSValueAuto));
}
trailingIdentWasAdded = false;
if (m_valueList->current() && m_valueList->current()->unit == CSSParserValue::ValueList) {
parseGridLineNames(*m_valueList, *templateRows);
trailingIdentWasAdded = true;
}
}
if (templateColumns)
addProperty(CSSPropertyGridTemplateColumns, templateColumns, important);
else
addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentifierValue(CSSValueNone), important);
RefPtrWillBeRawPtr<CSSValue> templateAreas = CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount);
addProperty(CSSPropertyGridTemplateAreas, templateAreas.release(), important);
addProperty(CSSPropertyGridTemplateRows, templateRows.release(), important);
return true;
}
bool CSSPropertyParser::parseGridTemplateShorthand(bool important)
{
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
ShorthandScope scope(this, CSSPropertyGridTemplate);
ASSERT(gridTemplateShorthand().length() == 3);
if (!m_valueList->current())
return false;
bool firstValueIsNone = m_valueList->current()->id == CSSValueNone;
if (firstValueIsNone && !m_valueList->next()) {
addProperty(CSSPropertyGridTemplateColumns, cssValuePool().createIdentifierValue(CSSValueNone), important);
addProperty(CSSPropertyGridTemplateRows, cssValuePool().createIdentifierValue(CSSValueNone), important);
addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifierValue(CSSValueNone), important);
return true;
}
unsigned index = 0;
RefPtrWillBeRawPtr<CSSValue> columnsValue = nullptr;
if (firstValueIsNone) {
columnsValue = cssValuePool().createIdentifierValue(CSSValueNone);
} else {
columnsValue = parseGridTrackList(important);
}
if (columnsValue) {
if (!(m_valueList->current() && isForwardSlashOperator(m_valueList->current()) && m_valueList->next()))
return false;
index = m_valueList->currentIndex();
if (RefPtrWillBeRawPtr<CSSValue> rowsValue = parseGridTrackList(important)) {
if (m_valueList->current())
return false;
addProperty(CSSPropertyGridTemplateColumns, columnsValue, important);
addProperty(CSSPropertyGridTemplateRows, rowsValue, important);
addProperty(CSSPropertyGridTemplateAreas, cssValuePool().createIdentifierValue(CSSValueNone), important);
return true;
}
}
if (firstValueIsNone)
return false;
m_valueList->setCurrentIndex(index);
return parseGridTemplateRowsAndAreas(columnsValue, important);
}
bool CSSPropertyParser::parseGridAreaShorthand(bool important)
{
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
ShorthandScope scope(this, CSSPropertyGridArea);
const StylePropertyShorthand& shorthand = gridAreaShorthand();
ASSERT_UNUSED(shorthand, shorthand.length() == 4);
RefPtrWillBeRawPtr<CSSValue> rowStartValue = parseGridPosition();
if (!rowStartValue)
return false;
RefPtrWillBeRawPtr<CSSValue> columnStartValue = nullptr;
if (!parseSingleGridAreaLonghand(columnStartValue))
return false;
RefPtrWillBeRawPtr<CSSValue> rowEndValue = nullptr;
if (!parseSingleGridAreaLonghand(rowEndValue))
return false;
RefPtrWillBeRawPtr<CSSValue> columnEndValue = nullptr;
if (!parseSingleGridAreaLonghand(columnEndValue))
return false;
if (!columnStartValue)
columnStartValue = gridMissingGridPositionValue(rowStartValue.get());
if (!rowEndValue)
rowEndValue = gridMissingGridPositionValue(rowStartValue.get());
if (!columnEndValue)
columnEndValue = gridMissingGridPositionValue(columnStartValue.get());
addProperty(CSSPropertyGridRowStart, rowStartValue, important);
addProperty(CSSPropertyGridColumnStart, columnStartValue, important);
addProperty(CSSPropertyGridRowEnd, rowEndValue, important);
addProperty(CSSPropertyGridColumnEnd, columnEndValue, important);
return true;
}
bool CSSPropertyParser::parseSingleGridAreaLonghand(RefPtrWillBeRawPtr<CSSValue>& property)
{
if (!m_valueList->current())
return true;
if (!isForwardSlashOperator(m_valueList->current()))
return false;
if (!m_valueList->next())
return false;
property = parseGridPosition();
return true;
}
void CSSPropertyParser::parseGridLineNames(CSSParserValueList& inputList, CSSValueList& valueList, CSSGridLineNamesValue* previousNamedAreaTrailingLineNames)
{
ASSERT(inputList.current() && inputList.current()->unit == CSSParserValue::ValueList);
CSSParserValueList* identList = inputList.current()->valueList;
if (!identList->size()) {
inputList.next();
return;
}
identList->setCurrentIndex(0);
RefPtrWillBeRawPtr<CSSGridLineNamesValue> lineNames = previousNamedAreaTrailingLineNames;
if (!lineNames)
lineNames = CSSGridLineNamesValue::create();
while (CSSParserValue* identValue = identList->current()) {
ASSERT(identValue->unit == CSSPrimitiveValue::CSS_IDENT);
RefPtrWillBeRawPtr<CSSPrimitiveValue> lineName = createPrimitiveStringValue(identValue);
lineNames->append(lineName.release());
identList->next();
}
if (!previousNamedAreaTrailingLineNames)
valueList.append(lineNames.release());
inputList.next();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackList(bool important)
{
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueNone) {
m_valueList->next();
return cssValuePool().createIdentifierValue(CSSValueNone);
}
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createSpaceSeparated();
value = m_valueList->current();
if (value && value->unit == CSSParserValue::ValueList)
parseGridLineNames(*m_valueList, *values);
bool seenTrackSizeOrRepeatFunction = false;
while (CSSParserValue* currentValue = m_valueList->current()) {
if (isForwardSlashOperator(currentValue))
break;
if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase(currentValue->function->name, "repeat(")) {
if (!parseGridTrackRepeatFunction(*values))
return nullptr;
seenTrackSizeOrRepeatFunction = true;
} else {
RefPtrWillBeRawPtr<CSSValue> value = parseGridTrackSize(*m_valueList);
if (!value)
return nullptr;
values->append(value);
seenTrackSizeOrRepeatFunction = true;
}
value = m_valueList->current();
if (value && value->unit == CSSParserValue::ValueList)
parseGridLineNames(*m_valueList, *values);
}
if (!seenTrackSizeOrRepeatFunction)
return nullptr;
return values;
}
bool CSSPropertyParser::parseGridTrackRepeatFunction(CSSValueList& list)
{
CSSParserValueList* arguments = m_valueList->current()->function->args.get();
if (!arguments || arguments->size() < 3 || !validUnit(arguments->valueAt(0), FPositiveInteger) || !isComma(arguments->valueAt(1)))
return false;
ASSERT_WITH_SECURITY_IMPLICATION(arguments->valueAt(0)->fValue > 0);
size_t repetitions = arguments->valueAt(0)->fValue;
RefPtrWillBeRawPtr<CSSValueList> repeatedValues = CSSValueList::createSpaceSeparated();
arguments->next();
arguments->next();
CSSParserValue* currentValue = arguments->current();
if (currentValue && currentValue->unit == CSSParserValue::ValueList)
parseGridLineNames(*arguments, *repeatedValues);
while (arguments->current()) {
RefPtrWillBeRawPtr<CSSValue> trackSize = parseGridTrackSize(*arguments);
if (!trackSize)
return false;
repeatedValues->append(trackSize);
currentValue = arguments->current();
if (currentValue && currentValue->unit == CSSParserValue::ValueList)
parseGridLineNames(*arguments, *repeatedValues);
}
for (size_t i = 0; i < repetitions; ++i) {
for (size_t j = 0; j < repeatedValues->length(); ++j)
list.append(repeatedValues->itemWithoutBoundsCheck(j));
}
m_valueList->next();
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTrackSize(CSSParserValueList& inputList)
{
ASSERT(RuntimeEnabledFeatures::cssGridLayoutEnabled());
CSSParserValue* currentValue = inputList.current();
inputList.next();
if (currentValue->id == CSSValueAuto)
return cssValuePool().createIdentifierValue(CSSValueAuto);
if (currentValue->unit == CSSParserValue::Function && equalIgnoringCase(currentValue->function->name, "minmax(")) {
CSSParserValueList* arguments = currentValue->function->args.get();
if (!arguments || arguments->size() != 3 || !isComma(arguments->valueAt(1)))
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> minTrackBreadth = parseGridBreadth(arguments->valueAt(0));
if (!minTrackBreadth)
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> maxTrackBreadth = parseGridBreadth(arguments->valueAt(2));
if (!maxTrackBreadth)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> parsedArguments = CSSValueList::createCommaSeparated();
parsedArguments->append(minTrackBreadth);
parsedArguments->append(maxTrackBreadth);
return CSSFunctionValue::create("minmax(", parsedArguments);
}
return parseGridBreadth(currentValue);
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseGridBreadth(CSSParserValue* currentValue)
{
if (currentValue->id == CSSValueMinContent || currentValue->id == CSSValueMaxContent)
return cssValuePool().createIdentifierValue(currentValue->id);
if (currentValue->unit == CSSPrimitiveValue::CSS_FR) {
double flexValue = currentValue->fValue;
if (flexValue <= 0)
return nullptr;
return cssValuePool().createValue(flexValue, CSSPrimitiveValue::CSS_FR);
}
if (!validUnit(currentValue, FNonNeg | FLength | FPercent))
return nullptr;
return createPrimitiveNumericValue(currentValue);
}
bool CSSPropertyParser::parseGridTemplateAreasRow(NamedGridAreaMap& gridAreaMap, const size_t rowCount, size_t& columnCount)
{
CSSParserValue* currentValue = m_valueList->current();
if (!currentValue || currentValue->unit != CSSPrimitiveValue::CSS_STRING)
return false;
String gridRowNames = currentValue->string;
if (!gridRowNames.length())
return false;
Vector<String> columnNames;
gridRowNames.split(' ', columnNames);
if (!columnCount) {
columnCount = columnNames.size();
ASSERT(columnCount);
} else if (columnCount != columnNames.size()) {
return false;
}
for (size_t currentCol = 0; currentCol < columnCount; ++currentCol) {
const String& gridAreaName = columnNames[currentCol];
if (gridAreaName == ".")
continue;
size_t lookAheadCol;
for (lookAheadCol = currentCol; lookAheadCol < (columnCount - 1); ++lookAheadCol) {
if (columnNames[lookAheadCol + 1] != gridAreaName)
break;
}
NamedGridAreaMap::iterator gridAreaIt = gridAreaMap.find(gridAreaName);
if (gridAreaIt == gridAreaMap.end()) {
gridAreaMap.add(gridAreaName, GridCoordinate(GridSpan(rowCount, rowCount), GridSpan(currentCol, lookAheadCol)));
} else {
GridCoordinate& gridCoordinate = gridAreaIt->value;
if (rowCount != gridCoordinate.rows.finalPositionIndex + 1)
return false;
if (currentCol != gridCoordinate.columns.initialPositionIndex)
return false;
if (lookAheadCol != gridCoordinate.columns.finalPositionIndex)
return false;
++gridCoordinate.rows.finalPositionIndex;
}
currentCol = lookAheadCol;
}
m_valueList->next();
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseGridTemplateAreas()
{
NamedGridAreaMap gridAreaMap;
size_t rowCount = 0;
size_t columnCount = 0;
while (m_valueList->current()) {
if (!parseGridTemplateAreasRow(gridAreaMap, rowCount, columnCount))
return nullptr;
++rowCount;
}
if (!rowCount || !columnCount)
return nullptr;
return CSSGridTemplateAreasValue::create(gridAreaMap, rowCount, columnCount);
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseCounterContent(CSSParserValueList* args, bool counters)
{
unsigned numArgs = args->size();
if (counters && numArgs != 3 && numArgs != 5)
return nullptr;
if (!counters && numArgs != 1 && numArgs != 3)
return nullptr;
CSSParserValue* i = args->current();
if (i->unit != CSSPrimitiveValue::CSS_IDENT)
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> identifier = createPrimitiveStringValue(i);
RefPtrWillBeRawPtr<CSSPrimitiveValue> separator = nullptr;
if (!counters)
separator = cssValuePool().createValue(String(), CSSPrimitiveValue::CSS_STRING);
else {
i = args->next();
if (i->unit != CSSParserValue::Operator || i->iValue != ',')
return nullptr;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_STRING)
return nullptr;
separator = createPrimitiveStringValue(i);
}
RefPtrWillBeRawPtr<CSSPrimitiveValue> listStyle = nullptr;
i = args->next();
if (!i)
listStyle = cssValuePool().createIdentifierValue(CSSValueDecimal);
else {
if (i->unit != CSSParserValue::Operator || i->iValue != ',')
return nullptr;
i = args->next();
if (i->unit != CSSPrimitiveValue::CSS_IDENT)
return nullptr;
CSSValueID listStyleID = CSSValueInvalid;
if (i->id == CSSValueNone || (i->id >= CSSValueDisc && i->id <= CSSValueKatakanaIroha))
listStyleID = i->id;
else
return nullptr;
listStyle = cssValuePool().createIdentifierValue(listStyleID);
}
return cssValuePool().createValue(Counter::create(identifier.release(), listStyle.release(), separator.release()));
}
bool CSSPropertyParser::parseClipShape(CSSPropertyID propId, bool important)
{
CSSParserValue* value = m_valueList->current();
CSSParserValueList* args = value->function->args.get();
if (!equalIgnoringCase(value->function->name, "rect(") || !args)
return false;
if (args->size() != 4 && args->size() != 7)
return false;
RefPtrWillBeRawPtr<Rect> rect = Rect::create();
bool valid = true;
int i = 0;
CSSParserValue* a = args->current();
while (a) {
valid = a->id == CSSValueAuto || validUnit(a, FLength);
if (!valid)
break;
RefPtrWillBeRawPtr<CSSPrimitiveValue> length = a->id == CSSValueAuto ?
cssValuePool().createIdentifierValue(CSSValueAuto) :
createPrimitiveNumericValue(a);
if (i == 0)
rect->setTop(length);
else if (i == 1)
rect->setRight(length);
else if (i == 2)
rect->setBottom(length);
else
rect->setLeft(length);
a = args->next();
if (a && args->size() == 7) {
if (a->unit == CSSParserValue::Operator && a->iValue == ',') {
a = args->next();
} else {
valid = false;
break;
}
}
i++;
}
if (valid) {
addProperty(propId, cssValuePool().createValue(rect.release()), important);
m_valueList->next();
return true;
}
return false;
}
static void completeBorderRadii(RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[4])
{
if (radii[3])
return;
if (!radii[2]) {
if (!radii[1])
radii[1] = radii[0];
radii[2] = radii[0];
}
radii[3] = radii[1];
}
PassRefPtrWillBeRawPtr<CSSBasicShape> CSSPropertyParser::parseInsetRoundedCorners(PassRefPtrWillBeRawPtr<CSSBasicShapeInset> shape, CSSParserValueList* args)
{
CSSParserValue* argument = args->next();
if (!argument)
return nullptr;
Vector<CSSParserValue*> radiusArguments;
while (argument) {
radiusArguments.append(argument);
argument = args->next();
}
unsigned num = radiusArguments.size();
if (!num || num > 9)
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[2][4];
#if ENABLE(OILPAN)
memset(&radii, 0, sizeof(radii));
#endif
unsigned indexAfterSlash = 0;
for (unsigned i = 0; i < num; ++i) {
CSSParserValue* value = radiusArguments.at(i);
if (value->unit == CSSParserValue::Operator) {
if (value->iValue != '/')
return nullptr;
if (!i || indexAfterSlash || i + 1 == num)
return nullptr;
indexAfterSlash = i + 1;
completeBorderRadii(radii[0]);
continue;
}
if (i - indexAfterSlash >= 4)
return nullptr;
if (!validUnit(value, FLength | FPercent | FNonNeg))
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> radius = createPrimitiveNumericValue(value);
if (!indexAfterSlash)
radii[0][i] = radius;
else
radii[1][i - indexAfterSlash] = radius.release();
}
if (!indexAfterSlash) {
completeBorderRadii(radii[0]);
for (unsigned i = 0; i < 4; ++i)
radii[1][i] = radii[0][i];
} else {
completeBorderRadii(radii[1]);
}
shape->setTopLeftRadius(createPrimitiveValuePair(radii[0][0].release(), radii[1][0].release()));
shape->setTopRightRadius(createPrimitiveValuePair(radii[0][1].release(), radii[1][1].release()));
shape->setBottomRightRadius(createPrimitiveValuePair(radii[0][2].release(), radii[1][2].release()));
shape->setBottomLeftRadius(createPrimitiveValuePair(radii[0][3].release(), radii[1][3].release()));
return shape;
}
PassRefPtrWillBeRawPtr<CSSBasicShape> CSSPropertyParser::parseBasicShapeInset(CSSParserValueList* args)
{
ASSERT(args);
RefPtrWillBeRawPtr<CSSBasicShapeInset> shape = CSSBasicShapeInset::create();
CSSParserValue* argument = args->current();
WillBeHeapVector<RefPtrWillBeMember<CSSPrimitiveValue> > widthArguments;
bool hasRoundedInset = false;
while (argument) {
if (argument->unit == CSSPrimitiveValue::CSS_IDENT && equalIgnoringCase(argument->string, "round")) {
hasRoundedInset = true;
break;
}
Units unitFlags = FLength | FPercent;
if (!validUnit(argument, unitFlags) || widthArguments.size() > 4)
return nullptr;
widthArguments.append(createPrimitiveNumericValue(argument));
argument = args->next();
}
switch (widthArguments.size()) {
case 1: {
shape->updateShapeSize1Value(widthArguments[0].get());
break;
}
case 2: {
shape->updateShapeSize2Values(widthArguments[0].get(), widthArguments[1].get());
break;
}
case 3: {
shape->updateShapeSize3Values(widthArguments[0].get(), widthArguments[1].get(), widthArguments[2].get());
break;
}
case 4: {
shape->updateShapeSize4Values(widthArguments[0].get(), widthArguments[1].get(), widthArguments[2].get(), widthArguments[3].get());
break;
}
default:
return nullptr;
}
if (hasRoundedInset)
return parseInsetRoundedCorners(shape, args);
return shape;
}
static bool isItemPositionKeyword(CSSValueID id)
{
return id == CSSValueStart || id == CSSValueEnd || id == CSSValueCenter
|| id == CSSValueSelfStart || id == CSSValueSelfEnd || id == CSSValueFlexStart
|| id == CSSValueFlexEnd || id == CSSValueLeft || id == CSSValueRight;
}
bool CSSPropertyParser::parseItemPositionOverflowPosition(CSSPropertyID propId, bool important)
{
CSSParserValue* value = m_valueList->current();
if (value->id == CSSValueAuto || value->id == CSSValueBaseline || value->id == CSSValueStretch) {
if (m_valueList->next())
return false;
addProperty(propId, cssValuePool().createIdentifierValue(value->id), important);
return true;
}
RefPtrWillBeRawPtr<CSSPrimitiveValue> position = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> overflowAlignmentKeyword = nullptr;
if (isItemPositionKeyword(value->id)) {
position = cssValuePool().createIdentifierValue(value->id);
value = m_valueList->next();
if (value) {
if (value->id == CSSValueTrue || value->id == CSSValueSafe)
overflowAlignmentKeyword = cssValuePool().createIdentifierValue(value->id);
else
return false;
}
} else if (value->id == CSSValueTrue || value->id == CSSValueSafe) {
overflowAlignmentKeyword = cssValuePool().createIdentifierValue(value->id);
value = m_valueList->next();
if (value) {
if (isItemPositionKeyword(value->id))
position = cssValuePool().createIdentifierValue(value->id);
else
return false;
}
} else {
return false;
}
if (m_valueList->next())
return false;
ASSERT(position);
if (overflowAlignmentKeyword)
addProperty(propId, createPrimitiveValuePair(position, overflowAlignmentKeyword), important);
else
addProperty(propId, position.release(), important);
return true;
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseShapeRadius(CSSParserValue* value)
{
if (value->id == CSSValueClosestSide || value->id == CSSValueFarthestSide)
return cssValuePool().createIdentifierValue(value->id);
if (!validUnit(value, FLength | FPercent | FNonNeg))
return nullptr;
return createPrimitiveNumericValue(value);
}
PassRefPtrWillBeRawPtr<CSSBasicShape> CSSPropertyParser::parseBasicShapeCircle(CSSParserValueList* args)
{
ASSERT(args);
RefPtrWillBeRawPtr<CSSBasicShapeCircle> shape = CSSBasicShapeCircle::create();
for (CSSParserValue* argument = args->current(); argument; argument = args->next()) {
if (args->currentIndex() > 1)
return nullptr;
if (!args->currentIndex() && argument->id != CSSValueAt) {
if (RefPtrWillBeRawPtr<CSSPrimitiveValue> radius = parseShapeRadius(argument)) {
shape->setRadius(radius);
continue;
}
return nullptr;
}
if (argument->id == CSSValueAt && args->next()) {
RefPtrWillBeRawPtr<CSSValue> centerX = nullptr;
RefPtrWillBeRawPtr<CSSValue> centerY = nullptr;
parseFillPosition(args, centerX, centerY);
if (centerX && centerY && !args->current()) {
ASSERT(centerX->isPrimitiveValue());
ASSERT(centerY->isPrimitiveValue());
shape->setCenterX(toCSSPrimitiveValue(centerX.get()));
shape->setCenterY(toCSSPrimitiveValue(centerY.get()));
} else {
return nullptr;
}
} else {
return nullptr;
}
}
return shape;
}
PassRefPtrWillBeRawPtr<CSSBasicShape> CSSPropertyParser::parseBasicShapeEllipse(CSSParserValueList* args)
{
ASSERT(args);
RefPtrWillBeRawPtr<CSSBasicShapeEllipse> shape = CSSBasicShapeEllipse::create();
for (CSSParserValue* argument = args->current(); argument; argument = args->next()) {
if (args->currentIndex() > 2)
return nullptr;
if (args->currentIndex() < 2 && argument->id != CSSValueAt) {
if (RefPtrWillBeRawPtr<CSSPrimitiveValue> radius = parseShapeRadius(argument)) {
if (!shape->radiusX())
shape->setRadiusX(radius);
else
shape->setRadiusY(radius);
continue;
}
return nullptr;
}
if (argument->id != CSSValueAt || !args->next())
return nullptr;
RefPtrWillBeRawPtr<CSSValue> centerX = nullptr;
RefPtrWillBeRawPtr<CSSValue> centerY = nullptr;
parseFillPosition(args, centerX, centerY);
if (!centerX || !centerY || args->current())
return nullptr;
ASSERT(centerX->isPrimitiveValue());
ASSERT(centerY->isPrimitiveValue());
shape->setCenterX(toCSSPrimitiveValue(centerX.get()));
shape->setCenterY(toCSSPrimitiveValue(centerY.get()));
}
return shape;
}
PassRefPtrWillBeRawPtr<CSSBasicShape> CSSPropertyParser::parseBasicShapePolygon(CSSParserValueList* args)
{
ASSERT(args);
unsigned size = args->size();
if (!size)
return nullptr;
RefPtrWillBeRawPtr<CSSBasicShapePolygon> shape = CSSBasicShapePolygon::create();
CSSParserValue* argument = args->current();
if (argument->id == CSSValueEvenodd || argument->id == CSSValueNonzero) {
shape->setWindRule(argument->id == CSSValueEvenodd ? RULE_EVENODD : RULE_NONZERO);
if (!isComma(args->next()))
return nullptr;
argument = args->next();
size -= 2;
}
if (!size || (size % 3) - 2)
return nullptr;
CSSParserValue* argumentX = argument;
while (argumentX) {
if (!validUnit(argumentX, FLength | FPercent))
return nullptr;
CSSParserValue* argumentY = args->next();
if (!argumentY || !validUnit(argumentY, FLength | FPercent))
return nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> xLength = createPrimitiveNumericValue(argumentX);
RefPtrWillBeRawPtr<CSSPrimitiveValue> yLength = createPrimitiveNumericValue(argumentY);
shape->appendPoint(xLength.release(), yLength.release());
CSSParserValue* commaOrNull = args->next();
if (!commaOrNull)
argumentX = 0;
else if (!isComma(commaOrNull))
return nullptr;
else
argumentX = args->next();
}
return shape;
}
static bool isBoxValue(CSSValueID valueId)
{
switch (valueId) {
case CSSValueContentBox:
case CSSValuePaddingBox:
case CSSValueBorderBox:
case CSSValueMarginBox:
return true;
default:
break;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseShapeProperty(CSSPropertyID propId)
{
if (!RuntimeEnabledFeatures::cssShapesEnabled())
return nullptr;
CSSParserValue* value = m_valueList->current();
CSSValueID valueId = value->id;
if (valueId == CSSValueNone) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> keywordValue = parseValidPrimitive(valueId, value);
m_valueList->next();
return keywordValue.release();
}
RefPtrWillBeRawPtr<CSSValue> imageValue = nullptr;
if (valueId != CSSValueNone && parseFillImage(m_valueList.get(), imageValue)) {
m_valueList->next();
return imageValue.release();
}
return parseBasicShapeAndOrBox();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseBasicShapeAndOrBox()
{
CSSParserValue* value = m_valueList->current();
bool shapeFound = false;
bool boxFound = false;
CSSValueID valueId;
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
for (unsigned i = 0; i < 2; ++i) {
if (!value)
break;
valueId = value->id;
if (value->unit == CSSParserValue::Function && !shapeFound) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> shapeValue = parseBasicShape();
if (!shapeValue)
return nullptr;
list->append(shapeValue.release());
shapeFound = true;
} else if (isBoxValue(valueId) && !boxFound) {
list->append(parseValidPrimitive(valueId, value));
boxFound = true;
m_valueList->next();
} else {
return nullptr;
}
value = m_valueList->current();
}
if (m_valueList->current())
return nullptr;
return list.release();
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseBasicShape()
{
CSSParserValue* value = m_valueList->current();
ASSERT(value->unit == CSSParserValue::Function);
CSSParserValueList* args = value->function->args.get();
if (!args)
return nullptr;
RefPtrWillBeRawPtr<CSSBasicShape> shape = nullptr;
if (equalIgnoringCase(value->function->name, "circle("))
shape = parseBasicShapeCircle(args);
else if (equalIgnoringCase(value->function->name, "ellipse("))
shape = parseBasicShapeEllipse(args);
else if (equalIgnoringCase(value->function->name, "polygon("))
shape = parseBasicShapePolygon(args);
else if (equalIgnoringCase(value->function->name, "inset("))
shape = parseBasicShapeInset(args);
if (!shape)
return nullptr;
m_valueList->next();
return cssValuePool().createValue(shape.release());
}
bool CSSPropertyParser::parseFont(bool important)
{
for (unsigned i = 0; i < m_valueList->size(); ++i) {
if (m_valueList->valueAt(i)->id == CSSValueInherit || m_valueList->valueAt(i)->id == CSSValueInitial)
return false;
}
ShorthandScope scope(this, CSSPropertyFont);
bool fontStyleParsed = false;
bool fontVariantParsed = false;
bool fontWeightParsed = false;
CSSParserValue* value;
while ((value = m_valueList->current())) {
if (!fontStyleParsed && isValidKeywordPropertyAndValue(CSSPropertyFontStyle, value->id, m_context)) {
addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(value->id), important);
fontStyleParsed = true;
} else if (!fontVariantParsed && (value->id == CSSValueNormal || value->id == CSSValueSmallCaps)) {
addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(value->id), important);
fontVariantParsed = true;
} else if (!fontWeightParsed && parseFontWeight(important))
fontWeightParsed = true;
else
break;
m_valueList->next();
}
if (!value)
return false;
if (!fontStyleParsed)
addProperty(CSSPropertyFontStyle, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
if (!fontVariantParsed)
addProperty(CSSPropertyFontVariant, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
if (!fontWeightParsed)
addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
if (!parseFontSize(important))
return false;
value = m_valueList->current();
if (!value)
return false;
if (isForwardSlashOperator(value)) {
value = m_valueList->next();
if (!value)
return false;
if (!parseLineHeight(important))
return false;
} else
addProperty(CSSPropertyLineHeight, cssValuePool().createIdentifierValue(CSSValueNormal), important, true);
RefPtrWillBeRawPtr<CSSValue> parsedFamilyValue = parseFontFamily();
if (!parsedFamilyValue)
return false;
addProperty(CSSPropertyFontFamily, parsedFamilyValue.release(), important);
if (m_valueList->current())
return false;
return true;
}
class FontFamilyValueBuilder {
DISALLOW_ALLOCATION();
public:
FontFamilyValueBuilder(CSSValueList* list)
: m_list(list)
{
}
void add(const CSSParserString& string)
{
if (!m_builder.isEmpty())
m_builder.append(' ');
if (string.is8Bit()) {
m_builder.append(string.characters8(), string.length());
return;
}
m_builder.append(string.characters16(), string.length());
}
void commit()
{
if (m_builder.isEmpty())
return;
m_list->append(cssValuePool().createFontFamilyValue(m_builder.toString()));
m_builder.clear();
}
private:
StringBuilder m_builder;
CSSValueList* m_list;
};
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFontFamily()
{
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
CSSParserValue* value = m_valueList->current();
FontFamilyValueBuilder familyBuilder(list.get());
bool inFamily = false;
while (value) {
CSSParserValue* nextValue = m_valueList->next();
bool nextValBreaksFont = !nextValue ||
(nextValue->unit == CSSParserValue::Operator && nextValue->iValue == ',');
bool nextValIsFontName = nextValue &&
((nextValue->id >= CSSValueSerif && nextValue->id <= CSSValueWebkitBody) ||
(nextValue->unit == CSSPrimitiveValue::CSS_STRING || nextValue->unit == CSSPrimitiveValue::CSS_IDENT));
bool valueIsKeyword = value->id == CSSValueInitial || value->id == CSSValueInherit || value->id == CSSValueDefault;
if (valueIsKeyword && !inFamily) {
if (nextValBreaksFont)
value = m_valueList->next();
else if (nextValIsFontName)
value = nextValue;
continue;
}
if (value->id >= CSSValueSerif && value->id <= CSSValueWebkitBody) {
if (inFamily)
familyBuilder.add(value->string);
else if (nextValBreaksFont || !nextValIsFontName)
list->append(cssValuePool().createIdentifierValue(value->id));
else {
familyBuilder.commit();
familyBuilder.add(value->string);
inFamily = true;
}
} else if (value->unit == CSSPrimitiveValue::CSS_STRING) {
inFamily = false;
familyBuilder.commit();
list->append(cssValuePool().createFontFamilyValue(value->string));
} else if (value->unit == CSSPrimitiveValue::CSS_IDENT) {
if (inFamily)
familyBuilder.add(value->string);
else if (nextValBreaksFont || !nextValIsFontName)
list->append(cssValuePool().createFontFamilyValue(value->string));
else {
familyBuilder.commit();
familyBuilder.add(value->string);
inFamily = true;
}
} else {
break;
}
if (!nextValue)
break;
if (nextValBreaksFont) {
value = m_valueList->next();
familyBuilder.commit();
inFamily = false;
}
else if (nextValIsFontName)
value = nextValue;
else
break;
}
familyBuilder.commit();
if (!list->length())
list = nullptr;
return list.release();
}
bool CSSPropertyParser::parseLineHeight(bool important)
{
CSSParserValue* value = m_valueList->current();
CSSValueID id = value->id;
bool validPrimitive = false;
if (id == CSSValueNormal)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FNumber | FLength | FPercent | FNonNeg));
if (validPrimitive && (!m_valueList->next() || inShorthand()))
addProperty(CSSPropertyLineHeight, parseValidPrimitive(id, value), important);
return validPrimitive;
}
bool CSSPropertyParser::parseFontSize(bool important)
{
CSSParserValue* value = m_valueList->current();
CSSValueID id = value->id;
bool validPrimitive = false;
if (id >= CSSValueXxSmall && id <= CSSValueLarger)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
if (validPrimitive && (!m_valueList->next() || inShorthand()))
addProperty(CSSPropertyFontSize, parseValidPrimitive(id, value), important);
return validPrimitive;
}
bool CSSPropertyParser::parseFontVariant(bool important)
{
RefPtrWillBeRawPtr<CSSValueList> values = nullptr;
if (m_valueList->size() > 1)
values = CSSValueList::createCommaSeparated();
CSSParserValue* val;
bool expectComma = false;
while ((val = m_valueList->current())) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = nullptr;
if (!expectComma) {
expectComma = true;
if (val->id == CSSValueNormal || val->id == CSSValueSmallCaps)
parsedValue = cssValuePool().createIdentifierValue(val->id);
else if (val->id == CSSValueAll && !values) {
values = CSSValueList::createCommaSeparated();
parsedValue = cssValuePool().createIdentifierValue(val->id);
}
} else if (val->unit == CSSParserValue::Operator && val->iValue == ',') {
expectComma = false;
m_valueList->next();
continue;
}
if (!parsedValue)
return false;
m_valueList->next();
if (values)
values->append(parsedValue.release());
else {
addProperty(CSSPropertyFontVariant, parsedValue.release(), important);
return true;
}
}
if (values && values->length()) {
m_hasFontFaceOnlyValues = true;
addProperty(CSSPropertyFontVariant, values.release(), important);
return true;
}
return false;
}
bool CSSPropertyParser::parseFontWeight(bool important)
{
CSSParserValue* value = m_valueList->current();
if ((value->id >= CSSValueNormal) && (value->id <= CSSValue900)) {
addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(value->id), important);
return true;
}
if (validUnit(value, FInteger | FNonNeg, HTMLQuirksMode)) {
int weight = static_cast<int>(value->fValue);
if (!(weight % 100) && weight >= 100 && weight <= 900) {
addProperty(CSSPropertyFontWeight, cssValuePool().createIdentifierValue(static_cast<CSSValueID>(CSSValue100 + weight / 100 - 1)), important);
return true;
}
}
return false;
}
bool CSSPropertyParser::parseFontFaceSrcURI(CSSValueList* valueList)
{
RefPtrWillBeRawPtr<CSSFontFaceSrcValue> uriValue(CSSFontFaceSrcValue::create(completeURL(m_valueList->current()->string)));
CSSParserValue* value = m_valueList->next();
if (!value) {
valueList->append(uriValue.release());
return true;
}
if (value->unit == CSSParserValue::Operator && value->iValue == ',') {
m_valueList->next();
valueList->append(uriValue.release());
return true;
}
if (value->unit != CSSParserValue::Function || !equalIgnoringCase(value->function->name, "format("))
return false;
CSSParserValueList* args = value->function->args.get();
if (!args || args->size() != 1 || (args->current()->unit != CSSPrimitiveValue::CSS_STRING && args->current()->unit != CSSPrimitiveValue::CSS_IDENT))
return false;
uriValue->setFormat(args->current()->string);
valueList->append(uriValue.release());
value = m_valueList->next();
if (value && value->unit == CSSParserValue::Operator && value->iValue == ',')
m_valueList->next();
return true;
}
bool CSSPropertyParser::parseFontFaceSrcLocal(CSSValueList* valueList)
{
CSSParserValueList* args = m_valueList->current()->function->args.get();
if (!args || !args->size())
return false;
if (args->size() == 1 && args->current()->unit == CSSPrimitiveValue::CSS_STRING)
valueList->append(CSSFontFaceSrcValue::createLocal(args->current()->string));
else if (args->current()->unit == CSSPrimitiveValue::CSS_IDENT) {
StringBuilder builder;
for (CSSParserValue* localValue = args->current(); localValue; localValue = args->next()) {
if (localValue->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
if (!builder.isEmpty())
builder.append(' ');
builder.append(localValue->string);
}
valueList->append(CSSFontFaceSrcValue::createLocal(builder.toString()));
} else
return false;
if (CSSParserValue* value = m_valueList->next()) {
if (value->unit == CSSParserValue::Operator && value->iValue == ',')
m_valueList->next();
}
return true;
}
bool CSSPropertyParser::parseFontFaceSrc()
{
RefPtrWillBeRawPtr<CSSValueList> values(CSSValueList::createCommaSeparated());
while (CSSParserValue* value = m_valueList->current()) {
if (value->unit == CSSPrimitiveValue::CSS_URI) {
if (!parseFontFaceSrcURI(values.get()))
return false;
} else if (value->unit == CSSParserValue::Function && equalIgnoringCase(value->function->name, "local(")) {
if (!parseFontFaceSrcLocal(values.get()))
return false;
} else
return false;
}
if (!values->length())
return false;
addProperty(CSSPropertySrc, values.release(), m_important);
m_valueList->next();
return true;
}
bool CSSPropertyParser::parseFontFaceUnicodeRange()
{
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
bool failed = false;
bool operatorExpected = false;
for (; m_valueList->current(); m_valueList->next(), operatorExpected = !operatorExpected) {
if (operatorExpected) {
if (m_valueList->current()->unit == CSSParserValue::Operator && m_valueList->current()->iValue == ',')
continue;
failed = true;
break;
}
if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) {
failed = true;
break;
}
String rangeString = m_valueList->current()->string;
UChar32 from = 0;
UChar32 to = 0;
unsigned length = rangeString.length();
if (length < 3) {
failed = true;
break;
}
unsigned i = 2;
while (i < length) {
UChar c = rangeString[i];
if (c == '-' || c == '?')
break;
from *= 16;
if (c >= '0' && c <= '9')
from += c - '0';
else if (c >= 'A' && c <= 'F')
from += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
from += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
if (i == length)
to = from;
else if (rangeString[i] == '?') {
unsigned span = 1;
while (i < length && rangeString[i] == '?') {
span *= 16;
from *= 16;
i++;
}
if (i < length)
failed = true;
to = from + span - 1;
} else {
if (length < i + 2) {
failed = true;
break;
}
i++;
while (i < length) {
UChar c = rangeString[i];
to *= 16;
if (c >= '0' && c <= '9')
to += c - '0';
else if (c >= 'A' && c <= 'F')
to += 10 + c - 'A';
else if (c >= 'a' && c <= 'f')
to += 10 + c - 'a';
else {
failed = true;
break;
}
i++;
}
if (failed)
break;
}
if (from <= to)
values->append(CSSUnicodeRangeValue::create(from, to));
}
if (failed || !values->length())
return false;
addProperty(CSSPropertyUnicodeRange, values.release(), m_important);
return true;
}
template <typename CharacterType>
static int checkForValidDouble(const CharacterType* string, const CharacterType* end, const char terminator)
{
int length = end - string;
if (length < 1)
return 0;
bool decimalMarkSeen = false;
int processedLength = 0;
for (int i = 0; i < length; ++i) {
if (string[i] == terminator) {
processedLength = i;
break;
}
if (!isASCIIDigit(string[i])) {
if (!decimalMarkSeen && string[i] == '.')
decimalMarkSeen = true;
else
return 0;
}
}
if (decimalMarkSeen && processedLength == 1)
return 0;
return processedLength;
}
template <typename CharacterType>
static int parseDouble(const CharacterType* string, const CharacterType* end, const char terminator, double& value)
{
int length = checkForValidDouble(string, end, terminator);
if (!length)
return 0;
int position = 0;
double localValue = 0;
for (; position < length; ++position) {
if (string[position] == '.')
break;
localValue = localValue * 10 + string[position] - '0';
}
if (++position == length) {
value = localValue;
return length;
}
double fraction = 0;
double scale = 1;
while (position < length && scale < MAX_SCALE) {
fraction = fraction * 10 + string[position++] - '0';
scale *= 10;
}
value = localValue + fraction / scale;
return length;
}
template <typename CharacterType>
static bool parseColorIntOrPercentage(const CharacterType*& string, const CharacterType* end, const char terminator, CSSPrimitiveValue::UnitTypes& expect, int& value)
{
const CharacterType* current = string;
double localValue = 0;
bool negative = false;
while (current != end && isHTMLSpace<CharacterType>(*current))
current++;
if (current != end && *current == '-') {
negative = true;
current++;
}
if (current == end || !isASCIIDigit(*current))
return false;
while (current != end && isASCIIDigit(*current)) {
double newValue = localValue * 10 + *current++ - '0';
if (newValue >= 255) {
localValue = 255;
while (current != end && isASCIIDigit(*current))
++current;
break;
}
localValue = newValue;
}
if (current == end)
return false;
if (expect == CSSPrimitiveValue::CSS_NUMBER && (*current == '.' || *current == '%'))
return false;
if (*current == '.') {
double percentage = 0;
int numCharactersParsed = parseDouble(current, end, '%', percentage);
if (!numCharactersParsed)
return false;
current += numCharactersParsed;
if (*current != '%')
return false;
localValue += percentage;
}
if (expect == CSSPrimitiveValue::CSS_PERCENTAGE && *current != '%')
return false;
if (*current == '%') {
expect = CSSPrimitiveValue::CSS_PERCENTAGE;
localValue = localValue / 100.0 * 256.0;
if (localValue > 255)
localValue = 255;
current++;
} else
expect = CSSPrimitiveValue::CSS_NUMBER;
while (current != end && isHTMLSpace<CharacterType>(*current))
current++;
if (current == end || *current++ != terminator)
return false;
value = negative ? 0 : static_cast<int>(localValue);
string = current;
return true;
}
template <typename CharacterType>
static inline bool isTenthAlpha(const CharacterType* string, const int length)
{
if (length == 3 && string[0] == '0' && string[1] == '.' && isASCIIDigit(string[2]))
return true;
if (length == 2 && string[0] == '.' && isASCIIDigit(string[1]))
return true;
return false;
}
template <typename CharacterType>
static inline bool parseAlphaValue(const CharacterType*& string, const CharacterType* end, const char terminator, int& value)
{
while (string != end && isHTMLSpace<CharacterType>(*string))
string++;
bool negative = false;
if (string != end && *string == '-') {
negative = true;
string++;
}
value = 0;
int length = end - string;
if (length < 2)
return false;
if (string[length - 1] != terminator || !isASCIIDigit(string[length - 2]))
return false;
if (string[0] != '0' && string[0] != '1' && string[0] != '.') {
if (checkForValidDouble(string, end, terminator)) {
value = negative ? 0 : 255;
string = end;
return true;
}
return false;
}
if (length == 2 && string[0] != '.') {
value = !negative && string[0] == '1' ? 255 : 0;
string = end;
return true;
}
if (isTenthAlpha(string, length - 1)) {
static const int tenthAlphaValues[] = { 0, 25, 51, 76, 102, 127, 153, 179, 204, 230 };
value = negative ? 0 : tenthAlphaValues[string[length - 2] - '0'];
string = end;
return true;
}
double alpha = 0;
if (!parseDouble(string, end, terminator, alpha))
return false;
value = negative ? 0 : static_cast<int>(alpha * nextafter(256.0, 0.0));
string = end;
return true;
}
template <typename CharacterType>
static inline bool mightBeRGBA(const CharacterType* characters, unsigned length)
{
if (length < 5)
return false;
return characters[4] == '('
&& isASCIIAlphaCaselessEqual(characters[0], 'r')
&& isASCIIAlphaCaselessEqual(characters[1], 'g')
&& isASCIIAlphaCaselessEqual(characters[2], 'b')
&& isASCIIAlphaCaselessEqual(characters[3], 'a');
}
template <typename CharacterType>
static inline bool mightBeRGB(const CharacterType* characters, unsigned length)
{
if (length < 4)
return false;
return characters[3] == '('
&& isASCIIAlphaCaselessEqual(characters[0], 'r')
&& isASCIIAlphaCaselessEqual(characters[1], 'g')
&& isASCIIAlphaCaselessEqual(characters[2], 'b');
}
template <typename CharacterType>
static inline bool fastParseColorInternal(RGBA32& rgb, const CharacterType* characters, unsigned length , bool strict)
{
CSSPrimitiveValue::UnitTypes expect = CSSPrimitiveValue::CSS_UNKNOWN;
if (!strict && length >= 3) {
if (characters[0] == '#') {
if (Color::parseHexColor(characters + 1, length - 1, rgb))
return true;
} else {
if (Color::parseHexColor(characters, length, rgb))
return true;
}
}
if (mightBeRGBA(characters, length)) {
const CharacterType* current = characters + 5;
const CharacterType* end = characters + length;
int red;
int green;
int blue;
int alpha;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, blue))
return false;
if (!parseAlphaValue(current, end, ')', alpha))
return false;
if (current != end)
return false;
rgb = makeRGBA(red, green, blue, alpha);
return true;
}
if (mightBeRGB(characters, length)) {
const CharacterType* current = characters + 4;
const CharacterType* end = characters + length;
int red;
int green;
int blue;
if (!parseColorIntOrPercentage(current, end, ',', expect, red))
return false;
if (!parseColorIntOrPercentage(current, end, ',', expect, green))
return false;
if (!parseColorIntOrPercentage(current, end, ')', expect, blue))
return false;
if (current != end)
return false;
rgb = makeRGB(red, green, blue);
return true;
}
return false;
}
template<typename StringType>
bool CSSPropertyParser::fastParseColor(RGBA32& rgb, const StringType& name, bool strict)
{
unsigned length = name.length();
bool parseResult;
if (!length)
return false;
if (name.is8Bit())
parseResult = fastParseColorInternal(rgb, name.characters8(), length, strict);
else
parseResult = fastParseColorInternal(rgb, name.characters16(), length, strict);
if (parseResult)
return true;
Color tc;
if (!tc.setNamedColor(name))
return false;
rgb = tc.rgb();
return true;
}
template bool CSSPropertyParser::fastParseColor(RGBA32&, const String&, bool strict);
inline double CSSPropertyParser::parsedDouble(CSSParserValue *v, ReleaseParsedCalcValueCondition releaseCalc)
{
const double result = m_parsedCalculation ? m_parsedCalculation->doubleValue() : v->fValue;
if (releaseCalc == ReleaseParsedCalcValue)
m_parsedCalculation.release();
return result;
}
bool CSSPropertyParser::isCalculation(CSSParserValue* value)
{
return (value->unit == CSSParserValue::Function)
&& (equalIgnoringCase(value->function->name, "calc(")
|| equalIgnoringCase(value->function->name, "-webkit-calc(")
|| equalIgnoringCase(value->function->name, "-webkit-min(")
|| equalIgnoringCase(value->function->name, "-webkit-max("));
}
inline int CSSPropertyParser::colorIntFromValue(CSSParserValue* v)
{
bool isPercent;
if (m_parsedCalculation)
isPercent = m_parsedCalculation->category() == CalcPercent;
else
isPercent = v->unit == CSSPrimitiveValue::CSS_PERCENTAGE;
const double value = parsedDouble(v, ReleaseParsedCalcValue);
if (value <= 0.0)
return 0;
if (isPercent) {
if (value >= 100.0)
return 255;
return static_cast<int>(value * 256.0 / 100.0);
}
if (value >= 255.0)
return 255;
return static_cast<int>(value);
}
bool CSSPropertyParser::parseColorParameters(CSSParserValue* value, int* colorArray, bool parseAlpha)
{
CSSParserValueList* args = value->function->args.get();
CSSParserValue* v = args->current();
Units unitType = FUnknown;
if (validUnit(v, FInteger, HTMLStandardMode))
unitType = FInteger;
else if (validUnit(v, FPercent, HTMLStandardMode))
unitType = FPercent;
else
return false;
colorArray[0] = colorIntFromValue(v);
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != CSSParserValue::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, unitType, HTMLStandardMode))
return false;
colorArray[i] = colorIntFromValue(v);
}
if (parseAlpha) {
v = args->next();
if (v->unit != CSSParserValue::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, HTMLStandardMode))
return false;
const double value = parsedDouble(v, ReleaseParsedCalcValue);
colorArray[3] = static_cast<int>(max(0.0, min(1.0, value)) * nextafter(256.0, 0.0));
}
return true;
}
bool CSSPropertyParser::parseHSLParameters(CSSParserValue* value, double* colorArray, bool parseAlpha)
{
CSSParserValueList* args = value->function->args.get();
CSSParserValue* v = args->current();
if (!validUnit(v, FNumber, HTMLStandardMode))
return false;
colorArray[0] = (((static_cast<int>(parsedDouble(v, ReleaseParsedCalcValue)) % 360) + 360) % 360) / 360.0;
for (int i = 1; i < 3; i++) {
v = args->next();
if (v->unit != CSSParserValue::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FPercent, HTMLStandardMode))
return false;
colorArray[i] = max(0.0, min(100.0, parsedDouble(v, ReleaseParsedCalcValue))) / 100.0;
}
if (parseAlpha) {
v = args->next();
if (v->unit != CSSParserValue::Operator && v->iValue != ',')
return false;
v = args->next();
if (!validUnit(v, FNumber, HTMLStandardMode))
return false;
colorArray[3] = max(0.0, min(1.0, parsedDouble(v, ReleaseParsedCalcValue)));
}
return true;
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> CSSPropertyParser::parseColor(CSSParserValue* value)
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(value ? value : m_valueList->current(), c))
return nullptr;
return cssValuePool().createColorValue(c);
}
bool CSSPropertyParser::parseColorFromValue(CSSParserValue* value, RGBA32& c)
{
if (inQuirksMode() && value->unit == CSSPrimitiveValue::CSS_NUMBER
&& value->fValue >= 0. && value->fValue < 1000000.) {
String str = String::format("%06d", static_cast<int>((value->fValue+.5)));
if (!fastParseColor(c, str, !inQuirksMode()))
return false;
} else if (value->unit == CSSPrimitiveValue::CSS_PARSER_HEXCOLOR ||
value->unit == CSSPrimitiveValue::CSS_IDENT ||
(inQuirksMode() && value->unit == CSSPrimitiveValue::CSS_DIMENSION)) {
if (!fastParseColor(c, value->string, !inQuirksMode() && value->unit == CSSPrimitiveValue::CSS_IDENT))
return false;
} else if (value->unit == CSSParserValue::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 &&
equalIgnoringCase(value->function->name, "rgb(")) {
int colorValues[3];
if (!parseColorParameters(value, colorValues, false))
return false;
c = makeRGB(colorValues[0], colorValues[1], colorValues[2]);
} else {
if (value->unit == CSSParserValue::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 &&
equalIgnoringCase(value->function->name, "rgba(")) {
int colorValues[4];
if (!parseColorParameters(value, colorValues, true))
return false;
c = makeRGBA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else if (value->unit == CSSParserValue::Function &&
value->function->args != 0 &&
value->function->args->size() == 5 &&
equalIgnoringCase(value->function->name, "hsl(")) {
double colorValues[3];
if (!parseHSLParameters(value, colorValues, false))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], 1.0);
} else if (value->unit == CSSParserValue::Function &&
value->function->args != 0 &&
value->function->args->size() == 7 &&
equalIgnoringCase(value->function->name, "hsla(")) {
double colorValues[4];
if (!parseHSLParameters(value, colorValues, true))
return false;
c = makeRGBAFromHSLA(colorValues[0], colorValues[1], colorValues[2], colorValues[3]);
} else
return false;
}
return true;
}
class ShadowParseContext {
STACK_ALLOCATED();
public:
ShadowParseContext(CSSPropertyID prop, CSSPropertyParser* parser)
: property(prop)
, m_parser(parser)
, allowX(true)
, allowY(false)
, allowBlur(false)
, allowSpread(false)
, allowColor(true)
, allowStyle(prop == CSSPropertyWebkitBoxShadow || prop == CSSPropertyBoxShadow)
, allowBreak(true)
{
}
bool allowLength() { return allowX || allowY || allowBlur || allowSpread; }
void commitValue()
{
if (x || y || blur || spread || color || style) {
if (!values)
values = CSSValueList::createCommaSeparated();
values->append(CSSShadowValue::create(x.release(), y.release(), blur.release(), spread.release(), style.release(), color.release()));
}
x = nullptr;
y = nullptr;
blur = nullptr;
spread = nullptr;
style = nullptr;
color = nullptr;
allowX = true;
allowColor = true;
allowBreak = true;
allowY = false;
allowBlur = false;
allowSpread = false;
allowStyle = property == CSSPropertyWebkitBoxShadow || property == CSSPropertyBoxShadow;
}
void commitLength(CSSParserValue* v)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v);
if (allowX) {
x = val.release();
allowX = false;
allowY = true;
allowColor = false;
allowStyle = false;
allowBreak = false;
} else if (allowY) {
y = val.release();
allowY = false;
allowBlur = true;
allowColor = true;
allowStyle = property == CSSPropertyWebkitBoxShadow || property == CSSPropertyBoxShadow;
allowBreak = true;
} else if (allowBlur) {
blur = val.release();
allowBlur = false;
allowSpread = property == CSSPropertyWebkitBoxShadow || property == CSSPropertyBoxShadow;
} else if (allowSpread) {
spread = val.release();
allowSpread = false;
}
}
void commitColor(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val)
{
color = val;
allowColor = false;
if (allowX) {
allowStyle = false;
allowBreak = false;
} else {
allowBlur = false;
allowSpread = false;
allowStyle = property == CSSPropertyWebkitBoxShadow || property == CSSPropertyBoxShadow;
}
}
void commitStyle(CSSParserValue* v)
{
style = cssValuePool().createIdentifierValue(v->id);
allowStyle = false;
if (allowX)
allowBreak = false;
else {
allowBlur = false;
allowSpread = false;
allowColor = false;
}
}
CSSPropertyID property;
CSSPropertyParser* m_parser;
RefPtrWillBeMember<CSSValueList> values;
RefPtrWillBeMember<CSSPrimitiveValue> x;
RefPtrWillBeMember<CSSPrimitiveValue> y;
RefPtrWillBeMember<CSSPrimitiveValue> blur;
RefPtrWillBeMember<CSSPrimitiveValue> spread;
RefPtrWillBeMember<CSSPrimitiveValue> style;
RefPtrWillBeMember<CSSPrimitiveValue> color;
bool allowX;
bool allowY;
bool allowBlur;
bool allowSpread;
bool allowColor;
bool allowStyle;
bool allowBreak;
};
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseShadow(CSSParserValueList* valueList, CSSPropertyID propId)
{
ShadowParseContext context(propId, this);
CSSParserValue* val;
while ((val = valueList->current())) {
if (val->unit == CSSParserValue::Operator) {
if (val->iValue != ',' || !context.allowBreak) {
return nullptr;
}
context.commitValue();
} else if (validUnit(val, FLength, HTMLStandardMode)) {
if (!context.allowLength())
return nullptr;
if (context.allowBlur && !validUnit(val, FLength | FNonNeg, HTMLStandardMode))
return nullptr;
context.commitLength(val);
} else if (val->id == CSSValueInset) {
if (!context.allowStyle)
return nullptr;
context.commitStyle(val);
} else {
RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedColor = nullptr;
bool isColor = ((val->id >= CSSValueAqua && val->id <= CSSValueWindowtext) || val->id == CSSValueMenu
|| (val->id >= CSSValueWebkitFocusRingColor && val->id <= CSSValueWebkitText && inQuirksMode())
|| val->id == CSSValueCurrentcolor);
if (isColor) {
if (!context.allowColor)
return nullptr;
parsedColor = cssValuePool().createIdentifierValue(val->id);
}
if (!parsedColor)
parsedColor = parseColor(val);
if (!parsedColor || !context.allowColor)
return nullptr;
context.commitColor(parsedColor.release());
}
valueList->next();
}
if (context.allowBreak) {
context.commitValue();
if (context.values && context.values->length())
return context.values.release();
}
return nullptr;
}
bool CSSPropertyParser::parseReflect(CSSPropertyID propId, bool important)
{
CSSParserValue* val = m_valueList->current();
RefPtrWillBeRawPtr<CSSPrimitiveValue> direction = nullptr;
switch (val->id) {
case CSSValueAbove:
case CSSValueBelow:
case CSSValueLeft:
case CSSValueRight:
direction = cssValuePool().createIdentifierValue(val->id);
break;
default:
return false;
}
val = m_valueList->next();
RefPtrWillBeRawPtr<CSSPrimitiveValue> offset = nullptr;
if (!val)
offset = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX);
else {
if (!validUnit(val, FLength | FPercent))
return false;
offset = createPrimitiveNumericValue(val);
}
RefPtrWillBeRawPtr<CSSValue> mask = nullptr;
val = m_valueList->next();
if (val) {
mask = parseBorderImage(propId);
if (!mask)
return false;
}
RefPtrWillBeRawPtr<CSSReflectValue> reflectValue = CSSReflectValue::create(direction.release(), offset.release(), mask.release());
addProperty(propId, reflectValue.release(), important);
m_valueList->next();
return true;
}
bool CSSPropertyParser::parseFlex(CSSParserValueList* args, bool important)
{
if (!args || !args->size() || args->size() > 3)
return false;
static const double unsetValue = -1;
double flexGrow = unsetValue;
double flexShrink = unsetValue;
RefPtrWillBeRawPtr<CSSPrimitiveValue> flexBasis = nullptr;
while (CSSParserValue* arg = args->current()) {
if (validUnit(arg, FNumber | FNonNeg)) {
if (flexGrow == unsetValue)
flexGrow = arg->fValue;
else if (flexShrink == unsetValue)
flexShrink = arg->fValue;
else if (!arg->fValue) {
flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX);
} else {
return false;
}
} else if (!flexBasis && (arg->id == CSSValueAuto || validUnit(arg, FLength | FPercent | FNonNeg)))
flexBasis = parseValidPrimitive(arg->id, arg);
else {
return false;
}
args->next();
}
if (flexGrow == unsetValue)
flexGrow = 1;
if (flexShrink == unsetValue)
flexShrink = 1;
if (!flexBasis)
flexBasis = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_PX);
addProperty(CSSPropertyFlexGrow, cssValuePool().createValue(clampToFloat(flexGrow), CSSPrimitiveValue::CSS_NUMBER), important);
addProperty(CSSPropertyFlexShrink, cssValuePool().createValue(clampToFloat(flexShrink), CSSPrimitiveValue::CSS_NUMBER), important);
addProperty(CSSPropertyFlexBasis, flexBasis, important);
return true;
}
bool CSSPropertyParser::parseObjectPosition(bool important)
{
RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
parseFillPosition(m_valueList.get(), xValue, yValue);
if (!xValue || !yValue)
return false;
addProperty(
CSSPropertyObjectPosition,
createPrimitiveValuePair(toCSSPrimitiveValue(xValue.get()), toCSSPrimitiveValue(yValue.get()), Pair::KeepIdenticalValues),
important);
return true;
}
class BorderImageParseContext {
STACK_ALLOCATED();
public:
BorderImageParseContext()
: m_canAdvance(false)
, m_allowCommit(true)
, m_allowImage(true)
, m_allowImageSlice(true)
, m_allowRepeat(true)
, m_allowForwardSlashOperator(false)
, m_requireWidth(false)
, m_requireOutset(false)
{}
bool canAdvance() const { return m_canAdvance; }
void setCanAdvance(bool canAdvance) { m_canAdvance = canAdvance; }
bool allowCommit() const { return m_allowCommit; }
bool allowImage() const { return m_allowImage; }
bool allowImageSlice() const { return m_allowImageSlice; }
bool allowRepeat() const { return m_allowRepeat; }
bool allowForwardSlashOperator() const { return m_allowForwardSlashOperator; }
bool requireWidth() const { return m_requireWidth; }
bool requireOutset() const { return m_requireOutset; }
void commitImage(PassRefPtrWillBeRawPtr<CSSValue> image)
{
m_image = image;
m_canAdvance = true;
m_allowCommit = true;
m_allowImage = m_allowForwardSlashOperator = m_requireWidth = m_requireOutset = false;
m_allowImageSlice = !m_imageSlice;
m_allowRepeat = !m_repeat;
}
void commitImageSlice(PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> slice)
{
m_imageSlice = slice;
m_canAdvance = true;
m_allowCommit = m_allowForwardSlashOperator = true;
m_allowImageSlice = m_requireWidth = m_requireOutset = false;
m_allowImage = !m_image;
m_allowRepeat = !m_repeat;
}
void commitForwardSlashOperator()
{
m_canAdvance = true;
m_allowCommit = m_allowImage = m_allowImageSlice = m_allowRepeat = m_allowForwardSlashOperator = false;
if (!m_borderSlice) {
m_requireWidth = true;
m_requireOutset = false;
} else {
m_requireOutset = true;
m_requireWidth = false;
}
}
void commitBorderWidth(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> slice)
{
m_borderSlice = slice;
m_canAdvance = true;
m_allowCommit = m_allowForwardSlashOperator = true;
m_allowImageSlice = m_requireWidth = m_requireOutset = false;
m_allowImage = !m_image;
m_allowRepeat = !m_repeat;
}
void commitBorderOutset(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> outset)
{
m_outset = outset;
m_canAdvance = true;
m_allowCommit = true;
m_allowImageSlice = m_allowForwardSlashOperator = m_requireWidth = m_requireOutset = false;
m_allowImage = !m_image;
m_allowRepeat = !m_repeat;
}
void commitRepeat(PassRefPtrWillBeRawPtr<CSSValue> repeat)
{
m_repeat = repeat;
m_canAdvance = true;
m_allowCommit = true;
m_allowRepeat = m_allowForwardSlashOperator = m_requireWidth = m_requireOutset = false;
m_allowImageSlice = !m_imageSlice;
m_allowImage = !m_image;
}
PassRefPtrWillBeRawPtr<CSSValue> commitCSSValue()
{
return createBorderImageValue(m_image, m_imageSlice.get(), m_borderSlice.get(), m_outset.get(), m_repeat.get());
}
void commitMaskBoxImage(CSSPropertyParser* parser, bool important)
{
commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageSource, parser, m_image, important);
commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageSlice, parser, m_imageSlice.get(), important);
commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageWidth, parser, m_borderSlice.get(), important);
commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageOutset, parser, m_outset.get(), important);
commitBorderImageProperty(CSSPropertyWebkitMaskBoxImageRepeat, parser, m_repeat.get(), important);
}
void commitBorderImage(CSSPropertyParser* parser, bool important)
{
commitBorderImageProperty(CSSPropertyBorderImageSource, parser, m_image, important);
commitBorderImageProperty(CSSPropertyBorderImageSlice, parser, m_imageSlice.get(), important);
commitBorderImageProperty(CSSPropertyBorderImageWidth, parser, m_borderSlice.get(), important);
commitBorderImageProperty(CSSPropertyBorderImageOutset, parser, m_outset.get(), important);
commitBorderImageProperty(CSSPropertyBorderImageRepeat, parser, m_repeat, important);
}
void commitBorderImageProperty(CSSPropertyID propId, CSSPropertyParser* parser, PassRefPtrWillBeRawPtr<CSSValue> value, bool important)
{
if (value)
parser->addProperty(propId, value, important);
else
parser->addProperty(propId, cssValuePool().createImplicitInitialValue(), important, true);
}
static bool buildFromParser(CSSPropertyParser&, CSSPropertyID, BorderImageParseContext&);
bool m_canAdvance;
bool m_allowCommit;
bool m_allowImage;
bool m_allowImageSlice;
bool m_allowRepeat;
bool m_allowForwardSlashOperator;
bool m_requireWidth;
bool m_requireOutset;
RefPtrWillBeMember<CSSValue> m_image;
RefPtrWillBeMember<CSSBorderImageSliceValue> m_imageSlice;
RefPtrWillBeMember<CSSPrimitiveValue> m_borderSlice;
RefPtrWillBeMember<CSSPrimitiveValue> m_outset;
RefPtrWillBeMember<CSSValue> m_repeat;
};
bool BorderImageParseContext::buildFromParser(CSSPropertyParser& parser, CSSPropertyID propId, BorderImageParseContext& context)
{
CSSPropertyParser::ShorthandScope scope(&parser, propId);
while (CSSParserValue* val = parser.m_valueList->current()) {
context.setCanAdvance(false);
if (!context.canAdvance() && context.allowForwardSlashOperator() && isForwardSlashOperator(val))
context.commitForwardSlashOperator();
if (!context.canAdvance() && context.allowImage()) {
if (val->unit == CSSPrimitiveValue::CSS_URI) {
context.commitImage(CSSImageValue::create(val->string, parser.m_context.completeURL(val->string)));
} else if (isGeneratedImageValue(val)) {
RefPtrWillBeRawPtr<CSSValue> value = nullptr;
if (parser.parseGeneratedImage(parser.m_valueList.get(), value))
context.commitImage(value.release());
else
return false;
} else if (val->unit == CSSParserValue::Function && equalIgnoringCase(val->function->name, "-webkit-image-set(")) {
RefPtrWillBeRawPtr<CSSValue> value = parser.parseImageSet(parser.m_valueList.get());
if (value)
context.commitImage(value.release());
else
return false;
} else if (val->id == CSSValueNone)
context.commitImage(cssValuePool().createIdentifierValue(CSSValueNone));
}
if (!context.canAdvance() && context.allowImageSlice()) {
RefPtrWillBeRawPtr<CSSBorderImageSliceValue> imageSlice = nullptr;
if (parser.parseBorderImageSlice(propId, imageSlice))
context.commitImageSlice(imageSlice.release());
}
if (!context.canAdvance() && context.allowRepeat()) {
RefPtrWillBeRawPtr<CSSValue> repeat = nullptr;
if (parser.parseBorderImageRepeat(repeat))
context.commitRepeat(repeat.release());
}
if (!context.canAdvance() && context.requireWidth()) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> borderSlice = nullptr;
if (parser.parseBorderImageWidth(borderSlice))
context.commitBorderWidth(borderSlice.release());
}
if (!context.canAdvance() && context.requireOutset()) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> borderOutset = nullptr;
if (parser.parseBorderImageOutset(borderOutset))
context.commitBorderOutset(borderOutset.release());
}
if (!context.canAdvance())
return false;
parser.m_valueList->next();
}
return context.allowCommit();
}
bool CSSPropertyParser::parseBorderImageShorthand(CSSPropertyID propId, bool important)
{
BorderImageParseContext context;
if (BorderImageParseContext::buildFromParser(*this, propId, context)) {
switch (propId) {
case CSSPropertyWebkitMaskBoxImage:
context.commitMaskBoxImage(this, important);
return true;
case CSSPropertyBorderImage:
context.commitBorderImage(this, important);
return true;
default:
ASSERT_NOT_REACHED();
return false;
}
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseBorderImage(CSSPropertyID propId)
{
BorderImageParseContext context;
if (BorderImageParseContext::buildFromParser(*this, propId, context)) {
return context.commitCSSValue();
}
return nullptr;
}
static bool isBorderImageRepeatKeyword(int id)
{
return id == CSSValueStretch || id == CSSValueRepeat || id == CSSValueSpace || id == CSSValueRound;
}
bool CSSPropertyParser::parseBorderImageRepeat(RefPtrWillBeRawPtr<CSSValue>& result)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> firstValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> secondValue = nullptr;
CSSParserValue* val = m_valueList->current();
if (!val)
return false;
if (isBorderImageRepeatKeyword(val->id))
firstValue = cssValuePool().createIdentifierValue(val->id);
else
return false;
val = m_valueList->next();
if (val) {
if (isBorderImageRepeatKeyword(val->id))
secondValue = cssValuePool().createIdentifierValue(val->id);
else if (!inShorthand()) {
return false;
} else {
m_valueList->previous();
secondValue = firstValue;
}
} else
secondValue = firstValue;
result = createPrimitiveValuePair(firstValue, secondValue);
return true;
}
class BorderImageSliceParseContext {
STACK_ALLOCATED();
public:
BorderImageSliceParseContext(CSSPropertyParser* parser)
: m_parser(parser)
, m_allowNumber(true)
, m_allowFill(true)
, m_allowFinalCommit(false)
, m_fill(false)
{ }
bool allowNumber() const { return m_allowNumber; }
bool allowFill() const { return m_allowFill; }
bool allowFinalCommit() const { return m_allowFinalCommit; }
CSSPrimitiveValue* top() const { return m_top.get(); }
void commitNumber(CSSParserValue* v)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> val = m_parser->createPrimitiveNumericValue(v);
if (!m_top)
m_top = val;
else if (!m_right)
m_right = val;
else if (!m_bottom)
m_bottom = val;
else {
ASSERT(!m_left);
m_left = val;
}
m_allowNumber = !m_left;
m_allowFinalCommit = true;
}
void commitFill() { m_fill = true; m_allowFill = false; m_allowNumber = !m_top; }
PassRefPtrWillBeRawPtr<CSSBorderImageSliceValue> commitBorderImageSlice()
{
ASSERT(m_top);
if (!m_right) {
m_right = m_top;
m_bottom = m_top;
m_left = m_top;
}
if (!m_bottom) {
m_bottom = m_top;
m_left = m_right;
}
if (!m_left)
m_left = m_right;
RefPtrWillBeRawPtr<Quad> quad = Quad::create();
quad->setTop(m_top);
quad->setRight(m_right);
quad->setBottom(m_bottom);
quad->setLeft(m_left);
return CSSBorderImageSliceValue::create(cssValuePool().createValue(quad.release()), m_fill);
}
private:
CSSPropertyParser* m_parser;
bool m_allowNumber;
bool m_allowFill;
bool m_allowFinalCommit;
RefPtrWillBeMember<CSSPrimitiveValue> m_top;
RefPtrWillBeMember<CSSPrimitiveValue> m_right;
RefPtrWillBeMember<CSSPrimitiveValue> m_bottom;
RefPtrWillBeMember<CSSPrimitiveValue> m_left;
bool m_fill;
};
bool CSSPropertyParser::parseBorderImageSlice(CSSPropertyID propId, RefPtrWillBeRawPtr<CSSBorderImageSliceValue>& result)
{
BorderImageSliceParseContext context(this);
CSSParserValue* val;
while ((val = m_valueList->current())) {
if (context.allowNumber() && !isCalculation(val) && validUnit(val, FInteger | FNonNeg | FPercent, HTMLStandardMode)) {
context.commitNumber(val);
} else if (context.allowFill() && val->id == CSSValueFill)
context.commitFill();
else if (!inShorthand()) {
return false;
} else {
if (context.allowFinalCommit()) {
m_valueList->previous();
}
break;
}
m_valueList->next();
}
if (context.allowFinalCommit()) {
if (propId == CSSPropertyWebkitBorderImage || propId == CSSPropertyWebkitMaskBoxImage || propId == CSSPropertyWebkitBoxReflect)
context.commitFill();
result = context.commitBorderImageSlice();
return true;
}
return false;
}
class BorderImageQuadParseContext {
STACK_ALLOCATED();
public:
BorderImageQuadParseContext(CSSPropertyParser* parser)
: m_parser(parser)
, m_allowNumber(true)
, m_allowFinalCommit(false)
{ }
bool allowNumber() const { return m_allowNumber; }
bool allowFinalCommit() const { return m_allowFinalCommit; }
CSSPrimitiveValue* top() const { return m_top.get(); }
void commitNumber(CSSParserValue* v)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> val = nullptr;
if (v->id == CSSValueAuto)
val = cssValuePool().createIdentifierValue(v->id);
else
val = m_parser->createPrimitiveNumericValue(v);
if (!m_top)
m_top = val;
else if (!m_right)
m_right = val;
else if (!m_bottom)
m_bottom = val;
else {
ASSERT(!m_left);
m_left = val;
}
m_allowNumber = !m_left;
m_allowFinalCommit = true;
}
void setAllowFinalCommit() { m_allowFinalCommit = true; }
void setTop(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> val) { m_top = val; }
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> commitBorderImageQuad()
{
ASSERT(m_top);
if (!m_right) {
m_right = m_top;
m_bottom = m_top;
m_left = m_top;
}
if (!m_bottom) {
m_bottom = m_top;
m_left = m_right;
}
if (!m_left)
m_left = m_right;
RefPtrWillBeRawPtr<Quad> quad = Quad::create();
quad->setTop(m_top);
quad->setRight(m_right);
quad->setBottom(m_bottom);
quad->setLeft(m_left);
return cssValuePool().createValue(quad.release());
}
private:
CSSPropertyParser* m_parser;
bool m_allowNumber;
bool m_allowFinalCommit;
RefPtrWillBeMember<CSSPrimitiveValue> m_top;
RefPtrWillBeMember<CSSPrimitiveValue> m_right;
RefPtrWillBeMember<CSSPrimitiveValue> m_bottom;
RefPtrWillBeMember<CSSPrimitiveValue> m_left;
};
bool CSSPropertyParser::parseBorderImageQuad(Units validUnits, RefPtrWillBeRawPtr<CSSPrimitiveValue>& result)
{
BorderImageQuadParseContext context(this);
CSSParserValue* val;
while ((val = m_valueList->current())) {
if (context.allowNumber() && (validUnit(val, validUnits, HTMLStandardMode) || val->id == CSSValueAuto)) {
context.commitNumber(val);
} else if (!inShorthand()) {
return false;
} else {
if (context.allowFinalCommit())
m_valueList->previous();
break;
}
m_valueList->next();
}
if (context.allowFinalCommit()) {
result = context.commitBorderImageQuad();
return true;
}
return false;
}
bool CSSPropertyParser::parseBorderImageWidth(RefPtrWillBeRawPtr<CSSPrimitiveValue>& result)
{
return parseBorderImageQuad(FLength | FNumber | FNonNeg | FPercent, result);
}
bool CSSPropertyParser::parseBorderImageOutset(RefPtrWillBeRawPtr<CSSPrimitiveValue>& result)
{
return parseBorderImageQuad(FLength | FNumber | FNonNeg, result);
}
bool CSSPropertyParser::parseBorderRadius(CSSPropertyID propId, bool important)
{
unsigned num = m_valueList->size();
if (num > 9)
return false;
ShorthandScope scope(this, propId);
RefPtrWillBeRawPtr<CSSPrimitiveValue> radii[2][4];
#if ENABLE(OILPAN)
memset(&radii, 0, sizeof(radii));
#endif
unsigned indexAfterSlash = 0;
for (unsigned i = 0; i < num; ++i) {
CSSParserValue* value = m_valueList->valueAt(i);
if (value->unit == CSSParserValue::Operator) {
if (value->iValue != '/')
return false;
if (!i || indexAfterSlash || i + 1 == num || num > i + 5)
return false;
indexAfterSlash = i + 1;
completeBorderRadii(radii[0]);
continue;
}
if (i - indexAfterSlash >= 4)
return false;
if (!validUnit(value, FLength | FPercent | FNonNeg))
return false;
RefPtrWillBeRawPtr<CSSPrimitiveValue> radius = createPrimitiveNumericValue(value);
if (!indexAfterSlash) {
radii[0][i] = radius;
if (num == 2 && propId == CSSPropertyWebkitBorderRadius) {
indexAfterSlash = 1;
completeBorderRadii(radii[0]);
}
} else
radii[1][i - indexAfterSlash] = radius.release();
}
if (!indexAfterSlash) {
completeBorderRadii(radii[0]);
for (unsigned i = 0; i < 4; ++i)
radii[1][i] = radii[0][i];
} else
completeBorderRadii(radii[1]);
ImplicitScope implicitScope(this, PropertyImplicit);
addProperty(CSSPropertyBorderTopLeftRadius, createPrimitiveValuePair(radii[0][0].release(), radii[1][0].release()), important);
addProperty(CSSPropertyBorderTopRightRadius, createPrimitiveValuePair(radii[0][1].release(), radii[1][1].release()), important);
addProperty(CSSPropertyBorderBottomRightRadius, createPrimitiveValuePair(radii[0][2].release(), radii[1][2].release()), important);
addProperty(CSSPropertyBorderBottomLeftRadius, createPrimitiveValuePair(radii[0][3].release(), radii[1][3].release()), important);
return true;
}
bool CSSPropertyParser::parseAspectRatio(bool important)
{
unsigned num = m_valueList->size();
if (num == 1 && m_valueList->valueAt(0)->id == CSSValueNone) {
addProperty(CSSPropertyWebkitAspectRatio, cssValuePool().createIdentifierValue(CSSValueNone), important);
return true;
}
if (num != 3)
return false;
CSSParserValue* lvalue = m_valueList->valueAt(0);
CSSParserValue* op = m_valueList->valueAt(1);
CSSParserValue* rvalue = m_valueList->valueAt(2);
if (!isForwardSlashOperator(op))
return false;
if (!validUnit(lvalue, FNumber | FNonNeg) || !validUnit(rvalue, FNumber | FNonNeg))
return false;
if (!lvalue->fValue || !rvalue->fValue)
return false;
addProperty(CSSPropertyWebkitAspectRatio, CSSAspectRatioValue::create(narrowPrecisionToFloat(lvalue->fValue), narrowPrecisionToFloat(rvalue->fValue)), important);
return true;
}
bool CSSPropertyParser::parseCounter(CSSPropertyID propId, int defaultValue, bool important)
{
enum { ID, VAL } state = ID;
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
RefPtrWillBeRawPtr<CSSPrimitiveValue> counterName = nullptr;
while (true) {
CSSParserValue* val = m_valueList->current();
switch (state) {
case ID:
if (val && val->unit == CSSPrimitiveValue::CSS_IDENT) {
counterName = createPrimitiveStringValue(val);
state = VAL;
m_valueList->next();
continue;
}
break;
case VAL: {
int i = defaultValue;
if (val && val->unit == CSSPrimitiveValue::CSS_NUMBER) {
i = clampToInteger(val->fValue);
m_valueList->next();
}
list->append(createPrimitiveValuePair(counterName.release(),
cssValuePool().createValue(i, CSSPrimitiveValue::CSS_NUMBER)));
state = ID;
continue;
}
}
break;
}
if (list->length() > 0) {
addProperty(propId, list.release(), important);
return true;
}
return false;
}
static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseDeprecatedGradientPoint(CSSParserValue* a, bool horizontal)
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> result = nullptr;
if (a->unit == CSSPrimitiveValue::CSS_IDENT) {
if ((equalIgnoringCase(a, "left") && horizontal)
|| (equalIgnoringCase(a, "top") && !horizontal))
result = cssValuePool().createValue(0., CSSPrimitiveValue::CSS_PERCENTAGE);
else if ((equalIgnoringCase(a, "right") && horizontal)
|| (equalIgnoringCase(a, "bottom") && !horizontal))
result = cssValuePool().createValue(100., CSSPrimitiveValue::CSS_PERCENTAGE);
else if (equalIgnoringCase(a, "center"))
result = cssValuePool().createValue(50., CSSPrimitiveValue::CSS_PERCENTAGE);
} else if (a->unit == CSSPrimitiveValue::CSS_NUMBER || a->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
result = cssValuePool().createValue(a->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(a->unit));
return result;
}
bool parseDeprecatedGradientColorStop(CSSPropertyParser* p, CSSParserValue* a, CSSGradientColorStop& stop)
{
if (a->unit != CSSParserValue::Function)
return false;
if (!equalIgnoringCase(a->function->name, "from(") &&
!equalIgnoringCase(a->function->name, "to(") &&
!equalIgnoringCase(a->function->name, "color-stop("))
return false;
CSSParserValueList* args = a->function->args.get();
if (!args)
return false;
if (equalIgnoringCase(a->function->name, "from(")
|| equalIgnoringCase(a->function->name, "to(")) {
if (args->size() != 1)
return false;
if (equalIgnoringCase(a->function->name, "from("))
stop.m_position = cssValuePool().createValue(0, CSSPrimitiveValue::CSS_NUMBER);
else
stop.m_position = cssValuePool().createValue(1, CSSPrimitiveValue::CSS_NUMBER);
CSSValueID id = args->current()->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color = cssValuePool().createIdentifierValue(id);
else
stop.m_color = p->parseColor(args->current());
if (!stop.m_color)
return false;
}
if (equalIgnoringCase(a->function->name, "color-stop(")) {
if (args->size() != 3)
return false;
CSSParserValue* stopArg = args->current();
if (stopArg->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
stop.m_position = cssValuePool().createValue(stopArg->fValue / 100, CSSPrimitiveValue::CSS_NUMBER);
else if (stopArg->unit == CSSPrimitiveValue::CSS_NUMBER)
stop.m_position = cssValuePool().createValue(stopArg->fValue, CSSPrimitiveValue::CSS_NUMBER);
else
return false;
stopArg = args->next();
if (stopArg->unit != CSSParserValue::Operator || stopArg->iValue != ',')
return false;
stopArg = args->next();
CSSValueID id = stopArg->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu)
stop.m_color = cssValuePool().createIdentifierValue(id);
else
stop.m_color = p->parseColor(stopArg);
if (!stop.m_color)
return false;
}
return true;
}
bool CSSPropertyParser::parseDeprecatedGradient(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& gradient)
{
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || args->size() == 0)
return false;
CSSGradientType gradientType;
CSSParserValue* a = args->current();
if (!a || a->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
if (equalIgnoringCase(a, "linear"))
gradientType = CSSDeprecatedLinearGradient;
else if (equalIgnoringCase(a, "radial"))
gradientType = CSSDeprecatedRadialGradient;
else
return false;
RefPtrWillBeRawPtr<CSSGradientValue> result = nullptr;
switch (gradientType) {
case CSSDeprecatedLinearGradient:
result = CSSLinearGradientValue::create(NonRepeating, gradientType);
break;
case CSSDeprecatedRadialGradient:
result = CSSRadialGradientValue::create(NonRepeating, gradientType);
break;
default:
ASSERT_NOT_REACHED();
}
a = args->next();
if (!isComma(a))
return false;
a = args->next();
if (!a)
return false;
RefPtrWillBeRawPtr<CSSPrimitiveValue> point = parseDeprecatedGradientPoint(a, true);
if (!point)
return false;
result->setFirstX(point.release());
a = args->next();
if (!a)
return false;
point = parseDeprecatedGradientPoint(a, false);
if (!point)
return false;
result->setFirstY(point.release());
a = args->next();
if (!isComma(a))
return false;
if (gradientType == CSSDeprecatedRadialGradient) {
a = args->next();
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
return false;
toCSSRadialGradientValue(result.get())->setFirstRadius(createPrimitiveNumericValue(a));
a = args->next();
if (!isComma(a))
return false;
}
a = args->next();
if (!a)
return false;
point = parseDeprecatedGradientPoint(a, true);
if (!point)
return false;
result->setSecondX(point.release());
a = args->next();
if (!a)
return false;
point = parseDeprecatedGradientPoint(a, false);
if (!point)
return false;
result->setSecondY(point.release());
if (gradientType == CSSDeprecatedRadialGradient) {
a = args->next();
if (!isComma(a))
return false;
a = args->next();
if (!a || a->unit != CSSPrimitiveValue::CSS_NUMBER)
return false;
toCSSRadialGradientValue(result.get())->setSecondRadius(createPrimitiveNumericValue(a));
}
a = args->next();
while (a) {
if (!isComma(a))
return false;
a = args->next();
if (!a)
return false;
CSSGradientColorStop stop;
if (!parseDeprecatedGradientColorStop(this, a, stop))
return false;
result->addStop(stop);
a = args->next();
}
gradient = result.release();
return true;
}
static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> valueFromSideKeyword(CSSParserValue* a, bool& isHorizontal)
{
if (a->unit != CSSPrimitiveValue::CSS_IDENT)
return nullptr;
switch (a->id) {
case CSSValueLeft:
case CSSValueRight:
isHorizontal = true;
break;
case CSSValueTop:
case CSSValueBottom:
isHorizontal = false;
break;
default:
return nullptr;
}
return cssValuePool().createIdentifierValue(a->id);
}
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSPropertyParser* p, CSSParserValue* value)
{
CSSValueID id = value->id;
if (id == CSSValueWebkitText || (id >= CSSValueAqua && id <= CSSValueWindowtext) || id == CSSValueMenu || id == CSSValueCurrentcolor)
return cssValuePool().createIdentifierValue(id);
return p->parseColor(value);
}
bool CSSPropertyParser::parseDeprecatedLinearGradient(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& gradient, CSSGradientRepeat repeating)
{
RefPtrWillBeRawPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repeating, CSSPrefixedLinearGradient);
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || !args->size())
return false;
CSSParserValue* a = args->current();
if (!a)
return false;
bool expectComma = false;
if (validUnit(a, FAngle, HTMLStandardMode)) {
result->setAngle(createPrimitiveNumericValue(a));
args->next();
expectComma = true;
} else {
RefPtrWillBeRawPtr<CSSPrimitiveValue> startX = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> startY = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> location = nullptr;
bool isHorizontal = false;
if ((location = valueFromSideKeyword(a, isHorizontal))) {
if (isHorizontal)
startX = location;
else
startY = location;
if ((a = args->next())) {
if ((location = valueFromSideKeyword(a, isHorizontal))) {
if (isHorizontal) {
if (startX)
return false;
startX = location;
} else {
if (startY)
return false;
startY = location;
}
args->next();
}
}
expectComma = true;
}
if (!startX && !startY)
startY = cssValuePool().createIdentifierValue(CSSValueTop);
result->setFirstX(startX.release());
result->setFirstY(startY.release());
}
if (!parseGradientColorStops(args, result.get(), expectComma))
return false;
if (!result->stopCount())
return false;
gradient = result.release();
return true;
}
bool CSSPropertyParser::parseDeprecatedRadialGradient(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& gradient, CSSGradientRepeat repeating)
{
RefPtrWillBeRawPtr<CSSRadialGradientValue> result = CSSRadialGradientValue::create(repeating, CSSPrefixedRadialGradient);
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || !args->size())
return false;
CSSParserValue* a = args->current();
if (!a)
return false;
bool expectComma = false;
RefPtrWillBeRawPtr<CSSValue> centerX = nullptr;
RefPtrWillBeRawPtr<CSSValue> centerY = nullptr;
parse2ValuesFillPosition(args, centerX, centerY);
a = args->current();
if (!a)
return false;
if (centerX || centerY) {
if (!isComma(a))
return false;
a = args->next();
if (!a)
return false;
}
result->setFirstX(toCSSPrimitiveValue(centerX.get()));
result->setSecondX(toCSSPrimitiveValue(centerX.get()));
result->setFirstY(toCSSPrimitiveValue(centerY.get()));
result->setSecondY(toCSSPrimitiveValue(centerY.get()));
RefPtrWillBeRawPtr<CSSPrimitiveValue> shapeValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> sizeValue = nullptr;
for (int i = 0; i < 2; ++i) {
if (a->unit != CSSPrimitiveValue::CSS_IDENT)
break;
bool foundValue = false;
switch (a->id) {
case CSSValueCircle:
case CSSValueEllipse:
shapeValue = cssValuePool().createIdentifierValue(a->id);
foundValue = true;
break;
case CSSValueClosestSide:
case CSSValueClosestCorner:
case CSSValueFarthestSide:
case CSSValueFarthestCorner:
case CSSValueContain:
case CSSValueCover:
sizeValue = cssValuePool().createIdentifierValue(a->id);
foundValue = true;
break;
default:
break;
}
if (foundValue) {
a = args->next();
if (!a)
return false;
expectComma = true;
}
}
result->setShape(shapeValue);
result->setSizingBehavior(sizeValue);
RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalSize = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalSize = nullptr;
if (!shapeValue && !sizeValue) {
if (validUnit(a, FLength | FPercent)) {
horizontalSize = createPrimitiveNumericValue(a);
a = args->next();
if (!a)
return false;
expectComma = true;
}
if (validUnit(a, FLength | FPercent)) {
verticalSize = createPrimitiveNumericValue(a);
a = args->next();
if (!a)
return false;
expectComma = true;
}
}
if (!horizontalSize != !verticalSize)
return false;
result->setEndHorizontalSize(horizontalSize);
result->setEndVerticalSize(verticalSize);
if (!parseGradientColorStops(args, result.get(), expectComma))
return false;
gradient = result.release();
return true;
}
bool CSSPropertyParser::parseLinearGradient(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& gradient, CSSGradientRepeat repeating)
{
RefPtrWillBeRawPtr<CSSLinearGradientValue> result = CSSLinearGradientValue::create(repeating, CSSLinearGradient);
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || !args->size())
return false;
CSSParserValue* a = args->current();
if (!a)
return false;
bool expectComma = false;
if (validUnit(a, FAngle, HTMLStandardMode)) {
result->setAngle(createPrimitiveNumericValue(a));
args->next();
expectComma = true;
} else if (a->unit == CSSPrimitiveValue::CSS_IDENT && equalIgnoringCase(a, "to")) {
a = args->next();
if (!a)
return false;
RefPtrWillBeRawPtr<CSSPrimitiveValue> endX = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> endY = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> location = nullptr;
bool isHorizontal = false;
location = valueFromSideKeyword(a, isHorizontal);
if (!location)
return false;
if (isHorizontal)
endX = location;
else
endY = location;
a = args->next();
if (!a)
return false;
location = valueFromSideKeyword(a, isHorizontal);
if (location) {
if (isHorizontal) {
if (endX)
return false;
endX = location;
} else {
if (endY)
return false;
endY = location;
}
args->next();
}
expectComma = true;
result->setFirstX(endX.release());
result->setFirstY(endY.release());
}
if (!parseGradientColorStops(args, result.get(), expectComma))
return false;
if (!result->stopCount())
return false;
gradient = result.release();
return true;
}
bool CSSPropertyParser::parseRadialGradient(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& gradient, CSSGradientRepeat repeating)
{
RefPtrWillBeRawPtr<CSSRadialGradientValue> result = CSSRadialGradientValue::create(repeating, CSSRadialGradient);
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || !args->size())
return false;
CSSParserValue* a = args->current();
if (!a)
return false;
bool expectComma = false;
RefPtrWillBeRawPtr<CSSPrimitiveValue> shapeValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> sizeValue = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> horizontalSize = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> verticalSize = nullptr;
for (int i = 0; i < 3; ++i) {
if (a->unit == CSSPrimitiveValue::CSS_IDENT) {
bool badIdent = false;
switch (a->id) {
case CSSValueCircle:
case CSSValueEllipse:
if (shapeValue)
return false;
shapeValue = cssValuePool().createIdentifierValue(a->id);
break;
case CSSValueClosestSide:
case CSSValueClosestCorner:
case CSSValueFarthestSide:
case CSSValueFarthestCorner:
if (sizeValue || horizontalSize)
return false;
sizeValue = cssValuePool().createIdentifierValue(a->id);
break;
default:
badIdent = true;
}
if (badIdent)
break;
a = args->next();
if (!a)
return false;
} else if (validUnit(a, FLength | FPercent)) {
if (sizeValue || horizontalSize)
return false;
horizontalSize = createPrimitiveNumericValue(a);
a = args->next();
if (!a)
return false;
if (validUnit(a, FLength | FPercent)) {
verticalSize = createPrimitiveNumericValue(a);
++i;
a = args->next();
if (!a)
return false;
}
} else
break;
}
if (sizeValue && horizontalSize)
return false;
if (shapeValue && shapeValue->getValueID() == CSSValueCircle && verticalSize)
return false;
if (shapeValue && shapeValue->getValueID() == CSSValueEllipse && horizontalSize && !verticalSize)
return false;
if (!verticalSize && horizontalSize && horizontalSize->isPercentage())
return false;
result->setShape(shapeValue);
result->setSizingBehavior(sizeValue);
result->setEndHorizontalSize(horizontalSize);
result->setEndVerticalSize(verticalSize);
RefPtrWillBeRawPtr<CSSValue> centerX = nullptr;
RefPtrWillBeRawPtr<CSSValue> centerY = nullptr;
if (a->unit == CSSPrimitiveValue::CSS_IDENT && equalIgnoringCase(a, "at")) {
a = args->next();
if (!a)
return false;
parseFillPosition(args, centerX, centerY);
if (!(centerX && centerY))
return false;
a = args->current();
if (!a)
return false;
result->setFirstX(toCSSPrimitiveValue(centerX.get()));
result->setFirstY(toCSSPrimitiveValue(centerY.get()));
result->setSecondX(toCSSPrimitiveValue(centerX.get()));
result->setSecondY(toCSSPrimitiveValue(centerY.get()));
}
if (shapeValue || sizeValue || horizontalSize || centerX || centerY)
expectComma = true;
if (!parseGradientColorStops(args, result.get(), expectComma))
return false;
gradient = result.release();
return true;
}
bool CSSPropertyParser::parseGradientColorStops(CSSParserValueList* valueList, CSSGradientValue* gradient, bool expectComma)
{
CSSParserValue* a = valueList->current();
while (a) {
if (expectComma) {
if (!isComma(a))
return false;
a = valueList->next();
if (!a)
return false;
}
CSSGradientColorStop stop;
stop.m_color = parseGradientColorOrKeyword(this, a);
if (!stop.m_color)
return false;
a = valueList->next();
if (a) {
if (validUnit(a, FLength | FPercent)) {
stop.m_position = createPrimitiveNumericValue(a);
a = valueList->next();
}
}
gradient->addStop(stop);
expectComma = true;
}
return gradient->stopCount() >= 2;
}
bool CSSPropertyParser::parseGeneratedImage(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& value)
{
CSSParserValue* val = valueList->current();
if (val->unit != CSSParserValue::Function)
return false;
if (equalIgnoringCase(val->function->name, "-webkit-gradient(")) {
if (m_context.useCounter())
m_context.useCounter()->count(UseCounter::DeprecatedWebKitGradient);
return parseDeprecatedGradient(valueList, value);
}
if (equalIgnoringCase(val->function->name, "-webkit-linear-gradient(")) {
if (m_context.useCounter())
m_context.useCounter()->count(UseCounter::DeprecatedWebKitLinearGradient);
return parseDeprecatedLinearGradient(valueList, value, NonRepeating);
}
if (equalIgnoringCase(val->function->name, "linear-gradient("))
return parseLinearGradient(valueList, value, NonRepeating);
if (equalIgnoringCase(val->function->name, "-webkit-repeating-linear-gradient(")) {
if (m_context.useCounter())
m_context.useCounter()->count(UseCounter::DeprecatedWebKitRepeatingLinearGradient);
return parseDeprecatedLinearGradient(valueList, value, Repeating);
}
if (equalIgnoringCase(val->function->name, "repeating-linear-gradient("))
return parseLinearGradient(valueList, value, Repeating);
if (equalIgnoringCase(val->function->name, "-webkit-radial-gradient(")) {
if (m_context.useCounter())
m_context.useCounter()->count(UseCounter::DeprecatedWebKitRadialGradient);
return parseDeprecatedRadialGradient(valueList, value, NonRepeating);
}
if (equalIgnoringCase(val->function->name, "radial-gradient("))
return parseRadialGradient(valueList, value, NonRepeating);
if (equalIgnoringCase(val->function->name, "-webkit-repeating-radial-gradient(")) {
if (m_context.useCounter())
m_context.useCounter()->count(UseCounter::DeprecatedWebKitRepeatingRadialGradient);
return parseDeprecatedRadialGradient(valueList, value, Repeating);
}
if (equalIgnoringCase(val->function->name, "repeating-radial-gradient("))
return parseRadialGradient(valueList, value, Repeating);
if (equalIgnoringCase(val->function->name, "-webkit-canvas("))
return parseCanvas(valueList, value);
if (equalIgnoringCase(val->function->name, "-webkit-cross-fade("))
return parseCrossfade(valueList, value);
return false;
}
bool CSSPropertyParser::parseCrossfade(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& crossfade)
{
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || args->size() != 5)
return false;
CSSParserValue* a = args->current();
RefPtrWillBeRawPtr<CSSValue> fromImageValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> toImageValue = nullptr;
if (!a || !parseFillImage(args, fromImageValue))
return false;
a = args->next();
if (!isComma(a))
return false;
a = args->next();
if (!a || !parseFillImage(args, toImageValue))
return false;
a = args->next();
if (!isComma(a))
return false;
a = args->next();
RefPtrWillBeRawPtr<CSSPrimitiveValue> percentage = nullptr;
if (!a)
return false;
if (a->unit == CSSPrimitiveValue::CSS_PERCENTAGE)
percentage = cssValuePool().createValue(clampTo<double>(a->fValue / 100, 0, 1), CSSPrimitiveValue::CSS_NUMBER);
else if (a->unit == CSSPrimitiveValue::CSS_NUMBER)
percentage = cssValuePool().createValue(clampTo<double>(a->fValue, 0, 1), CSSPrimitiveValue::CSS_NUMBER);
else
return false;
RefPtrWillBeRawPtr<CSSCrossfadeValue> result = CSSCrossfadeValue::create(fromImageValue, toImageValue);
result->setPercentage(percentage);
crossfade = result;
return true;
}
bool CSSPropertyParser::parseCanvas(CSSParserValueList* valueList, RefPtrWillBeRawPtr<CSSValue>& canvas)
{
CSSParserValueList* args = valueList->current()->function->args.get();
if (!args || args->size() != 1)
return false;
CSSParserValue* value = args->current();
if (!value || value->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
canvas = CSSCanvasValue::create(value->string);
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseImageSet(CSSParserValueList* valueList)
{
CSSParserValue* function = valueList->current();
if (function->unit != CSSParserValue::Function)
return nullptr;
CSSParserValueList* functionArgs = valueList->current()->function->args.get();
if (!functionArgs || !functionArgs->size() || !functionArgs->current())
return nullptr;
RefPtrWillBeRawPtr<CSSImageSetValue> imageSet = CSSImageSetValue::create();
CSSParserValue* arg = functionArgs->current();
while (arg) {
if (arg->unit != CSSPrimitiveValue::CSS_URI)
return nullptr;
RefPtrWillBeRawPtr<CSSImageValue> image = CSSImageValue::create(arg->string, completeURL(arg->string));
imageSet->append(image);
arg = functionArgs->next();
if (!arg || arg->unit != CSSPrimitiveValue::CSS_DIMENSION)
return nullptr;
double imageScaleFactor = 0;
const String& string = arg->string;
unsigned length = string.length();
if (!length)
return nullptr;
if (string.is8Bit()) {
const LChar* start = string.characters8();
parseDouble(start, start + length, 'x', imageScaleFactor);
} else {
const UChar* start = string.characters16();
parseDouble(start, start + length, 'x', imageScaleFactor);
}
if (imageScaleFactor <= 0)
return nullptr;
imageSet->append(cssValuePool().createValue(imageScaleFactor, CSSPrimitiveValue::CSS_NUMBER));
arg = functionArgs->next();
if (!arg)
break;
if (!isComma(arg))
return nullptr;
arg = functionArgs->next();
}
return imageSet.release();
}
bool CSSPropertyParser::parseWillChange(bool important)
{
ASSERT(RuntimeEnabledFeatures::cssWillChangeEnabled());
RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated();
if (m_valueList->current()->id == CSSValueAuto) {
if (m_valueList->next())
return false;
}
CSSParserValue* currentValue;
bool expectComma = false;
while ((currentValue = m_valueList->current())) {
if (expectComma) {
if (!isComma(currentValue))
return false;
expectComma = false;
m_valueList->next();
continue;
}
if (currentValue->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
CSSPropertyID property = cssPropertyID(currentValue->string);
if (property && RuntimeCSSEnabled::isCSSPropertyEnabled(property)) {
if (property == CSSPropertyWillChange)
return false;
values->append(cssValuePool().createIdentifierValue(property));
} else {
switch (currentValue->id) {
case CSSValueNone:
case CSSValueAll:
case CSSValueAuto:
case CSSValueDefault:
case CSSValueInitial:
case CSSValueInherit:
return false;
case CSSValueContents:
case CSSValueScrollPosition:
values->append(cssValuePool().createIdentifierValue(currentValue->id));
break;
default:
break;
}
}
expectComma = true;
m_valueList->next();
}
addProperty(CSSPropertyWillChange, values.release(), important);
return true;
}
bool CSSPropertyParser::isBlendMode(CSSValueID valueID)
{
return (valueID >= CSSValueMultiply && valueID <= CSSValueLuminosity)
|| valueID == CSSValueNormal
|| valueID == CSSValueOverlay;
}
bool CSSPropertyParser::isCompositeOperator(CSSValueID valueID)
{
return valueID >= CSSValueClear && valueID <= CSSValueXor;
}
static void filterInfoForName(const CSSParserString& name, CSSFilterValue::FilterOperationType& filterType, unsigned& maximumArgumentCount)
{
if (equalIgnoringCase(name, "grayscale("))
filterType = CSSFilterValue::GrayscaleFilterOperation;
else if (equalIgnoringCase(name, "sepia("))
filterType = CSSFilterValue::SepiaFilterOperation;
else if (equalIgnoringCase(name, "saturate("))
filterType = CSSFilterValue::SaturateFilterOperation;
else if (equalIgnoringCase(name, "hue-rotate("))
filterType = CSSFilterValue::HueRotateFilterOperation;
else if (equalIgnoringCase(name, "invert("))
filterType = CSSFilterValue::InvertFilterOperation;
else if (equalIgnoringCase(name, "opacity("))
filterType = CSSFilterValue::OpacityFilterOperation;
else if (equalIgnoringCase(name, "brightness("))
filterType = CSSFilterValue::BrightnessFilterOperation;
else if (equalIgnoringCase(name, "contrast("))
filterType = CSSFilterValue::ContrastFilterOperation;
else if (equalIgnoringCase(name, "blur("))
filterType = CSSFilterValue::BlurFilterOperation;
else if (equalIgnoringCase(name, "drop-shadow(")) {
filterType = CSSFilterValue::DropShadowFilterOperation;
maximumArgumentCount = 4;
}
}
PassRefPtrWillBeRawPtr<CSSFilterValue> CSSPropertyParser::parseBuiltinFilterArguments(CSSParserValueList* args, CSSFilterValue::FilterOperationType filterType)
{
RefPtrWillBeRawPtr<CSSFilterValue> filterValue = CSSFilterValue::create(filterType);
ASSERT(args);
switch (filterType) {
case CSSFilterValue::GrayscaleFilterOperation:
case CSSFilterValue::SepiaFilterOperation:
case CSSFilterValue::SaturateFilterOperation:
case CSSFilterValue::InvertFilterOperation:
case CSSFilterValue::OpacityFilterOperation:
case CSSFilterValue::ContrastFilterOperation: {
if (args->size() > 1)
return nullptr;
if (args->size()) {
CSSParserValue* value = args->current();
if (!validUnit(value, FNumber | FPercent | FNonNeg, HTMLStandardMode))
return nullptr;
double amount = value->fValue;
if (filterType != CSSFilterValue::SaturateFilterOperation
&& filterType != CSSFilterValue::ContrastFilterOperation) {
double maxAllowed = value->unit == CSSPrimitiveValue::CSS_PERCENTAGE ? 100.0 : 1.0;
if (amount > maxAllowed)
return nullptr;
}
filterValue->append(cssValuePool().createValue(amount, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit)));
}
break;
}
case CSSFilterValue::BrightnessFilterOperation: {
if (args->size() > 1)
return nullptr;
if (args->size()) {
CSSParserValue* value = args->current();
if (!validUnit(value, FNumber | FPercent, HTMLStandardMode))
return nullptr;
filterValue->append(cssValuePool().createValue(value->fValue, static_cast<CSSPrimitiveValue::UnitTypes>(value->unit)));
}
break;
}
case CSSFilterValue::HueRotateFilterOperation: {
if (args->size() > 1)
return nullptr;
if (args->size()) {
CSSParserValue* argument = args->current();
if (!validUnit(argument, FAngle, HTMLStandardMode))
return nullptr;
filterValue->append(createPrimitiveNumericValue(argument));
}
break;
}
case CSSFilterValue::BlurFilterOperation: {
if (args->size() > 1)
return nullptr;
if (args->size()) {
CSSParserValue* argument = args->current();
if (!validUnit(argument, FLength | FNonNeg, HTMLStandardMode))
return nullptr;
filterValue->append(createPrimitiveNumericValue(argument));
}
break;
}
case CSSFilterValue::DropShadowFilterOperation: {
RefPtrWillBeRawPtr<CSSValueList> shadowValueList = parseShadow(args, CSSPropertyWebkitFilter);
if (!shadowValueList || shadowValueList->length() != 1)
return nullptr;
filterValue->append((shadowValueList.release())->itemWithoutBoundsCheck(0));
break;
}
default:
ASSERT_NOT_REACHED();
}
return filterValue.release();
}
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseFilter()
{
if (!m_valueList)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
if (value->unit != CSSPrimitiveValue::CSS_URI && (value->unit != CSSParserValue::Function || !value->function))
return nullptr;
CSSFilterValue::FilterOperationType filterType = CSSFilterValue::UnknownFilterOperation;
if (value->unit == CSSPrimitiveValue::CSS_URI) {
RefPtrWillBeRawPtr<CSSFilterValue> referenceFilterValue = CSSFilterValue::create(CSSFilterValue::ReferenceFilterOperation);
list->append(referenceFilterValue);
referenceFilterValue->append(CSSSVGDocumentValue::create(value->string));
} else {
const CSSParserString name = value->function->name;
unsigned maximumArgumentCount = 1;
filterInfoForName(name, filterType, maximumArgumentCount);
if (filterType == CSSFilterValue::UnknownFilterOperation)
return nullptr;
CSSParserValueList* args = value->function->args.get();
if (!args)
return nullptr;
RefPtrWillBeRawPtr<CSSFilterValue> filterValue = parseBuiltinFilterArguments(args, filterType);
if (!filterValue)
return nullptr;
list->append(filterValue);
}
}
return list.release();
}
PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseTransformOrigin()
{
CSSParserValue* value = m_valueList->current();
CSSValueID id = value->id;
RefPtrWillBeRawPtr<CSSValue> xValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> yValue = nullptr;
RefPtrWillBeRawPtr<CSSValue> zValue = nullptr;
if (id == CSSValueLeft || id == CSSValueRight) {
xValue = cssValuePool().createIdentifierValue(id);
} else if (id == CSSValueTop || id == CSSValueBottom) {
yValue = cssValuePool().createIdentifierValue(id);
} else if (id == CSSValueCenter) {
} else if (validUnit(value, FPercent | FLength)) {
xValue = createPrimitiveNumericValue(value);
} else {
return nullptr;
}
if ((value = m_valueList->next())) {
id = value->id;
if (!xValue && (id == CSSValueLeft || id == CSSValueRight)) {
xValue = cssValuePool().createIdentifierValue(id);
} else if (!yValue && (id == CSSValueTop || id == CSSValueBottom)) {
yValue = cssValuePool().createIdentifierValue(id);
} else if (id == CSSValueCenter) {
} else if (!yValue && validUnit(value, FPercent | FLength)) {
yValue = createPrimitiveNumericValue(value);
} else {
return nullptr;
}
if (!xValue)
xValue = cssValuePool().createIdentifierValue(CSSValueCenter);
if (!yValue)
yValue = cssValuePool().createIdentifierValue(CSSValueCenter);
if ((value = m_valueList->next())) {
if (!validUnit(value, FLength))
return nullptr;
zValue = createPrimitiveNumericValue(value);
if ((value = m_valueList->next()))
return nullptr;
}
} else if (!xValue) {
if (yValue) {
xValue = cssValuePool().createValue(50, CSSPrimitiveValue::CSS_PERCENTAGE);
} else {
xValue = cssValuePool().createIdentifierValue(CSSValueCenter);
}
}
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
list->append(xValue.release());
if (yValue)
list->append(yValue.release());
if (zValue)
list->append(zValue.release());
return list.release();
}
bool CSSPropertyParser::parseWebkitTransformOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, CSSPropertyID& propId3, RefPtrWillBeRawPtr<CSSValue>& value, RefPtrWillBeRawPtr<CSSValue>& value2, RefPtrWillBeRawPtr<CSSValue>& value3)
{
propId1 = propId;
propId2 = propId;
propId3 = propId;
if (propId == CSSPropertyWebkitTransformOrigin) {
propId1 = CSSPropertyWebkitTransformOriginX;
propId2 = CSSPropertyWebkitTransformOriginY;
propId3 = CSSPropertyWebkitTransformOriginZ;
}
switch (propId) {
case CSSPropertyWebkitTransformOrigin:
if (!parseWebkitTransformOriginShorthand(value, value2, value3))
return false;
break;
case CSSPropertyWebkitTransformOriginX: {
value = parseFillPositionX(m_valueList.get());
if (value)
m_valueList->next();
break;
}
case CSSPropertyWebkitTransformOriginY: {
value = parseFillPositionY(m_valueList.get());
if (value)
m_valueList->next();
break;
}
case CSSPropertyWebkitTransformOriginZ: {
if (validUnit(m_valueList->current(), FLength))
value = createPrimitiveNumericValue(m_valueList->current());
if (value)
m_valueList->next();
break;
}
default:
ASSERT_NOT_REACHED();
return false;
}
return value;
}
bool CSSPropertyParser::parseWebkitPerspectiveOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtrWillBeRawPtr<CSSValue>& value, RefPtrWillBeRawPtr<CSSValue>& value2)
{
propId1 = propId;
propId2 = propId;
if (propId == CSSPropertyWebkitPerspectiveOrigin) {
propId1 = CSSPropertyWebkitPerspectiveOriginX;
propId2 = CSSPropertyWebkitPerspectiveOriginY;
}
switch (propId) {
case CSSPropertyWebkitPerspectiveOrigin:
if (m_valueList->size() > 2)
return false;
parse2ValuesFillPosition(m_valueList.get(), value, value2);
break;
case CSSPropertyWebkitPerspectiveOriginX: {
value = parseFillPositionX(m_valueList.get());
if (value)
m_valueList->next();
break;
}
case CSSPropertyWebkitPerspectiveOriginY: {
value = parseFillPositionY(m_valueList.get());
if (value)
m_valueList->next();
break;
}
default:
ASSERT_NOT_REACHED();
return false;
}
return value;
}
bool CSSPropertyParser::parseTouchAction(bool important)
{
if (!RuntimeEnabledFeatures::cssTouchActionEnabled())
return false;
CSSParserValue* value = m_valueList->current();
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
if (m_valueList->size() == 1 && value && (value->id == CSSValueAuto || value->id == CSSValueNone || value->id == CSSValueManipulation)) {
list->append(cssValuePool().createIdentifierValue(value->id));
addProperty(CSSPropertyTouchAction, list.release(), important);
m_valueList->next();
return true;
}
bool isValid = true;
while (isValid && value) {
switch (value->id) {
case CSSValuePanX:
case CSSValuePanY: {
RefPtrWillBeRawPtr<CSSValue> panValue = cssValuePool().createIdentifierValue(value->id);
if (list->hasValue(panValue.get())) {
isValid = false;
break;
}
list->append(panValue.release());
break;
}
default:
isValid = false;
break;
}
if (isValid)
value = m_valueList->next();
}
if (list->length() && isValid) {
addProperty(CSSPropertyTouchAction, list.release(), important);
return true;
}
return false;
}
void CSSPropertyParser::addTextDecorationProperty(CSSPropertyID propId, PassRefPtrWillBeRawPtr<CSSValue> value, bool important)
{
if (propId == CSSPropertyTextDecoration && !important && !inShorthand()) {
for (unsigned i = 0; i < m_parsedProperties.size(); ++i) {
if (m_parsedProperties[i].id() == CSSPropertyTextDecorationLine)
return;
}
}
addProperty(propId, value, important);
}
bool CSSPropertyParser::parseTextDecoration(CSSPropertyID propId, bool important)
{
if (propId == CSSPropertyTextDecorationLine
&& !RuntimeEnabledFeatures::css3TextDecorationsEnabled())
return false;
CSSParserValue* value = m_valueList->current();
if (value && value->id == CSSValueNone) {
addTextDecorationProperty(propId, cssValuePool().createIdentifierValue(CSSValueNone), important);
m_valueList->next();
return true;
}
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
bool isValid = true;
while (isValid && value) {
switch (value->id) {
case CSSValueUnderline:
case CSSValueOverline:
case CSSValueLineThrough:
case CSSValueBlink:
list->append(cssValuePool().createIdentifierValue(value->id));
break;
default:
isValid = false;
break;
}
if (isValid)
value = m_valueList->next();
}
if (list->length() && (isValid || inShorthand())) {
addTextDecorationProperty(propId, list.release(), important);
return true;
}
return false;
}
bool CSSPropertyParser::parseTextUnderlinePosition(bool important)
{
CSSParserValue* value = m_valueList->current();
switch (value->id) {
case CSSValueAuto:
case CSSValueUnder:
if (m_valueList->next())
return false;
addProperty(CSSPropertyTextUnderlinePosition, cssValuePool().createIdentifierValue(value->id), important);
return true;
default:
return false;
}
}
bool CSSPropertyParser::parseTextEmphasisStyle(bool important)
{
unsigned valueListSize = m_valueList->size();
RefPtrWillBeRawPtr<CSSPrimitiveValue> fill = nullptr;
RefPtrWillBeRawPtr<CSSPrimitiveValue> shape = nullptr;
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
if (value->unit == CSSPrimitiveValue::CSS_STRING) {
if (fill || shape || (valueListSize != 1 && !inShorthand()))
return false;
addProperty(CSSPropertyWebkitTextEmphasisStyle, createPrimitiveStringValue(value), important);
m_valueList->next();
return true;
}
if (value->id == CSSValueNone) {
if (fill || shape || (valueListSize != 1 && !inShorthand()))
return false;
addProperty(CSSPropertyWebkitTextEmphasisStyle, cssValuePool().createIdentifierValue(CSSValueNone), important);
m_valueList->next();
return true;
}
if (value->id == CSSValueOpen || value->id == CSSValueFilled) {
if (fill)
return false;
fill = cssValuePool().createIdentifierValue(value->id);
} else if (value->id == CSSValueDot || value->id == CSSValueCircle || value->id == CSSValueDoubleCircle || value->id == CSSValueTriangle || value->id == CSSValueSesame) {
if (shape)
return false;
shape = cssValuePool().createIdentifierValue(value->id);
} else if (!inShorthand())
return false;
else
break;
}
if (fill && shape) {
RefPtrWillBeRawPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
parsedValues->append(fill.release());
parsedValues->append(shape.release());
addProperty(CSSPropertyWebkitTextEmphasisStyle, parsedValues.release(), important);
return true;
}
if (fill) {
addProperty(CSSPropertyWebkitTextEmphasisStyle, fill.release(), important);
return true;
}
if (shape) {
addProperty(CSSPropertyWebkitTextEmphasisStyle, shape.release(), important);
return true;
}
return false;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseTextIndent()
{
RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();
if (m_valueList->size() == 1) {
CSSParserValue* value = m_valueList->current();
if (!value->id && validUnit(value, FLength | FPercent)) {
list->append(createPrimitiveNumericValue(value));
m_valueList->next();
return list.release();
}
}
if (!RuntimeEnabledFeatures::css3TextEnabled())
return nullptr;
if (m_valueList->size() != 2)
return nullptr;
CSSParserValue* firstValue = m_valueList->current();
CSSParserValue* secondValue = m_valueList->next();
CSSParserValue* lengthOrPercentageValue = 0;
if (validUnit(firstValue, FLength | FPercent) && secondValue->id == CSSValueEachLine)
lengthOrPercentageValue = firstValue;
else if (firstValue->id == CSSValueEachLine && validUnit(secondValue, FLength | FPercent))
lengthOrPercentageValue = secondValue;
if (lengthOrPercentageValue) {
list->append(createPrimitiveNumericValue(lengthOrPercentageValue));
list->append(cssValuePool().createIdentifierValue(CSSValueEachLine));
m_valueList->next();
return list.release();
}
return nullptr;
}
bool CSSPropertyParser::parseLineBoxContain(bool important)
{
LineBoxContain lineBoxContain = LineBoxContainNone;
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
if (value->id == CSSValueBlock) {
if (lineBoxContain & LineBoxContainBlock)
return false;
lineBoxContain |= LineBoxContainBlock;
} else if (value->id == CSSValueInline) {
if (lineBoxContain & LineBoxContainInline)
return false;
lineBoxContain |= LineBoxContainInline;
} else if (value->id == CSSValueFont) {
if (lineBoxContain & LineBoxContainFont)
return false;
lineBoxContain |= LineBoxContainFont;
} else if (value->id == CSSValueGlyphs) {
if (lineBoxContain & LineBoxContainGlyphs)
return false;
lineBoxContain |= LineBoxContainGlyphs;
} else if (value->id == CSSValueReplaced) {
if (lineBoxContain & LineBoxContainReplaced)
return false;
lineBoxContain |= LineBoxContainReplaced;
} else if (value->id == CSSValueInlineBox) {
if (lineBoxContain & LineBoxContainInlineBox)
return false;
lineBoxContain |= LineBoxContainInlineBox;
} else
return false;
}
if (!lineBoxContain)
return false;
addProperty(CSSPropertyWebkitLineBoxContain, CSSLineBoxContainValue::create(lineBoxContain), important);
return true;
}
bool CSSPropertyParser::parseFontFeatureTag(CSSValueList* settings)
{
static const unsigned tagNameLength = 4;
CSSParserValue* value = m_valueList->current();
if (value->unit != CSSPrimitiveValue::CSS_STRING)
return false;
if (value->string.length() != tagNameLength)
return false;
for (unsigned i = 0; i < tagNameLength; ++i) {
UChar character = value->string[i];
if (character < 0x20 || character > 0x7E)
return false;
}
AtomicString tag = value->string;
int tagValue = 1;
value = m_valueList->next();
if (value) {
if (value->unit == CSSPrimitiveValue::CSS_NUMBER && value->isInt && value->fValue >= 0) {
tagValue = clampToInteger(value->fValue);
if (tagValue < 0)
return false;
m_valueList->next();
} else if (value->id == CSSValueOn || value->id == CSSValueOff) {
tagValue = value->id == CSSValueOn;
m_valueList->next();
}
}
settings->append(CSSFontFeatureValue::create(tag, tagValue));
return true;
}
bool CSSPropertyParser::parseFontFeatureSettings(bool important)
{
if (m_valueList->size() == 1 && m_valueList->current()->id == CSSValueNormal) {
RefPtrWillBeRawPtr<CSSPrimitiveValue> normalValue = cssValuePool().createIdentifierValue(CSSValueNormal);
m_valueList->next();
addProperty(CSSPropertyWebkitFontFeatureSettings, normalValue.release(), important);
return true;
}
RefPtrWillBeRawPtr<CSSValueList> settings = CSSValueList::createCommaSeparated();
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
if (!parseFontFeatureTag(settings.get()))
return false;
value = m_valueList->current();
if (value && !isComma(value))
return false;
}
if (settings->length()) {
addProperty(CSSPropertyWebkitFontFeatureSettings, settings.release(), important);
return true;
}
return false;
}
bool CSSPropertyParser::parseFontVariantLigatures(bool important)
{
RefPtrWillBeRawPtr<CSSValueList> ligatureValues = CSSValueList::createSpaceSeparated();
bool sawCommonLigaturesValue = false;
bool sawDiscretionaryLigaturesValue = false;
bool sawHistoricalLigaturesValue = false;
bool sawContextualLigaturesValue = false;
for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
if (value->unit != CSSPrimitiveValue::CSS_IDENT)
return false;
switch (value->id) {
case CSSValueNoCommonLigatures:
case CSSValueCommonLigatures:
if (sawCommonLigaturesValue)
return false;
sawCommonLigaturesValue = true;
ligatureValues->append(cssValuePool().createIdentifierValue(value->id));
break;
case CSSValueNoDiscretionaryLigatures:
case CSSValueDiscretionaryLigatures:
if (sawDiscretionaryLigaturesValue)
return false;
sawDiscretionaryLigaturesValue = true;
ligatureValues->append(cssValuePool().createIdentifierValue(value->id));
break;
case CSSValueNoHistoricalLigatures:
case CSSValueHistoricalLigatures:
if (sawHistoricalLigaturesValue)
return false;
sawHistoricalLigaturesValue = true;
ligatureValues->append(cssValuePool().createIdentifierValue(value->id));
break;
case CSSValueNoContextual:
case CSSValueContextual:
if (sawContextualLigaturesValue)
return false;
sawContextualLigaturesValue = true;
ligatureValues->append(cssValuePool().createIdentifierValue(value->id));
break;
default:
return false;
}
}
if (!ligatureValues->length())
return false;
addProperty(CSSPropertyFontVariantLigatures, ligatureValues.release(), important);
return true;
}
bool CSSPropertyParser::parseCalculation(CSSParserValue* value, ValueRange range)
{
ASSERT(isCalculation(value));
CSSParserValueList* args = value->function->args.get();
if (!args || !args->size())
return false;
ASSERT(!m_parsedCalculation);
m_parsedCalculation = CSSCalcValue::create(value->function->name, args, range);
if (!m_parsedCalculation)
return false;
return true;
}
bool CSSPropertyParser::parseViewportProperty(CSSPropertyID propId, bool important)
{
ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_context.mode()));
CSSParserValue* value = m_valueList->current();
if (!value)
return false;
CSSValueID id = value->id;
bool validPrimitive = false;
switch (propId) {
case CSSPropertyMinWidth:
case CSSPropertyMaxWidth:
case CSSPropertyMinHeight:
case CSSPropertyMaxHeight:
if (id == CSSValueAuto || id == CSSValueInternalExtendToZoom)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FLength | FPercent | FNonNeg));
break;
case CSSPropertyWidth:
return parseViewportShorthand(propId, CSSPropertyMinWidth, CSSPropertyMaxWidth, important);
case CSSPropertyHeight:
return parseViewportShorthand(propId, CSSPropertyMinHeight, CSSPropertyMaxHeight, important);
case CSSPropertyMinZoom:
case CSSPropertyMaxZoom:
case CSSPropertyZoom:
if (id == CSSValueAuto)
validPrimitive = true;
else
validPrimitive = (!id && validUnit(value, FNumber | FPercent | FNonNeg));
break;
case CSSPropertyUserZoom:
if (id == CSSValueZoom || id == CSSValueFixed)
validPrimitive = true;
break;
case CSSPropertyOrientation:
if (id == CSSValueAuto || id == CSSValuePortrait || id == CSSValueLandscape)
validPrimitive = true;
default:
break;
}
RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
if (validPrimitive) {
parsedValue = parseValidPrimitive(id, value);
m_valueList->next();
}
if (parsedValue) {
if (!m_valueList->current() || inShorthand()) {
addProperty(propId, parsedValue.release(), important);
return true;
}
}
return false;
}
bool CSSPropertyParser::parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPropertyID second, bool important)
{
ASSERT(RuntimeEnabledFeatures::cssViewportEnabled() || isUASheetBehavior(m_context.mode()));
unsigned numValues = m_valueList->size();
if (numValues > 2)
return false;
ShorthandScope scope(this, propId);
if (!parseViewportProperty(first, important))
return false;
if (numValues == 1)
m_valueList->previous();
return parseViewportProperty(second, important);
}
template <typename CharacterType>
static CSSPropertyID cssPropertyID(const CharacterType* propertyName, unsigned length)
{
char buffer[maxCSSPropertyNameLength + 1];
for (unsigned i = 0; i != length; ++i) {
CharacterType c = propertyName[i];
if (c == 0 || c >= 0x7F)
return CSSPropertyInvalid;
buffer[i] = toASCIILower(c);
}
buffer[length] = '\0';
const char* name = buffer;
const Property* hashTableEntry = findProperty(name, length);
return hashTableEntry ? static_cast<CSSPropertyID>(hashTableEntry->id) : CSSPropertyInvalid;
}
CSSPropertyID cssPropertyID(const String& string)
{
unsigned length = string.length();
if (!length)
return CSSPropertyInvalid;
if (length > maxCSSPropertyNameLength)
return CSSPropertyInvalid;
return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters16(), length);
}
CSSPropertyID cssPropertyID(const CSSParserString& string)
{
unsigned length = string.length();
if (!length)
return CSSPropertyInvalid;
if (length > maxCSSPropertyNameLength)
return CSSPropertyInvalid;
return string.is8Bit() ? cssPropertyID(string.characters8(), length) : cssPropertyID(string.characters16(), length);
}
template <typename CharacterType>
static CSSValueID cssValueKeywordID(const CharacterType* valueKeyword, unsigned length)
{
char buffer[maxCSSValueKeywordLength + 1];
for (unsigned i = 0; i != length; ++i) {
CharacterType c = valueKeyword[i];
if (c == 0 || c >= 0x7F)
return CSSValueInvalid;
buffer[i] = WTF::toASCIILower(c);
}
buffer[length] = '\0';
const Value* hashTableEntry = findValue(buffer, length);
return hashTableEntry ? static_cast<CSSValueID>(hashTableEntry->id) : CSSValueInvalid;
}
CSSValueID cssValueKeywordID(const CSSParserString& string)
{
unsigned length = string.length();
if (!length)
return CSSValueInvalid;
if (length > maxCSSValueKeywordLength)
return CSSValueInvalid;
return string.is8Bit() ? cssValueKeywordID(string.characters8(), length) : cssValueKeywordID(string.characters16(), length);
}
bool isValidNthToken(const CSSParserString& token)
{
return equalIgnoringCase(token, "odd") || equalIgnoringCase(token, "even")
|| equalIgnoringCase(token, "n") || equalIgnoringCase(token, "-n");
}
bool CSSPropertyParser::isSystemColor(int id)
{
return (id >= CSSValueActiveborder && id <= CSSValueWindowtext) || id == CSSValueMenu;
}
bool CSSPropertyParser::parseSVGValue(CSSPropertyID propId, bool important)
{
CSSParserValue* value = m_valueList->current();
if (!value)
return false;
CSSValueID id = value->id;
bool validPrimitive = false;
RefPtrWillBeRawPtr<CSSValue> parsedValue = nullptr;
switch (propId) {
case CSSPropertyAlignmentBaseline:
if (id == CSSValueAuto || id == CSSValueBaseline || id == CSSValueMiddle
|| (id >= CSSValueBeforeEdge && id <= CSSValueMathematical))
validPrimitive = true;
break;
case CSSPropertyBaselineShift:
if (id == CSSValueBaseline || id == CSSValueSub
|| id >= CSSValueSuper)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode);
break;
case CSSPropertyDominantBaseline:
if (id == CSSValueAuto || id == CSSValueMiddle
|| (id >= CSSValueUseScript && id <= CSSValueResetSize)
|| (id >= CSSValueCentral && id <= CSSValueMathematical))
validPrimitive = true;
break;
case CSSPropertyEnableBackground:
if (id == CSSValueAccumulate)
validPrimitive = true;
break;
case CSSPropertyMarkerStart:
case CSSPropertyMarkerMid:
case CSSPropertyMarkerEnd:
case CSSPropertyMask:
if (id == CSSValueNone) {
validPrimitive = true;
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSPrimitiveValue::create(value->string, CSSPrimitiveValue::CSS_URI);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyClipRule:
case CSSPropertyFillRule:
if (id == CSSValueNonzero || id == CSSValueEvenodd)
validPrimitive = true;
break;
case CSSPropertyStrokeMiterlimit:
validPrimitive = validUnit(value, FNumber | FNonNeg, SVGAttributeMode);
break;
case CSSPropertyStrokeLinejoin:
if (id == CSSValueMiter || id == CSSValueRound || id == CSSValueBevel)
validPrimitive = true;
break;
case CSSPropertyStrokeLinecap:
if (id == CSSValueButt || id == CSSValueRound || id == CSSValueSquare)
validPrimitive = true;
break;
case CSSPropertyStrokeOpacity:
case CSSPropertyFillOpacity:
case CSSPropertyStopOpacity:
case CSSPropertyFloodOpacity:
validPrimitive = (!id && validUnit(value, FNumber | FPercent, SVGAttributeMode));
break;
case CSSPropertyShapeRendering:
if (id == CSSValueAuto || id == CSSValueOptimizespeed
|| id == CSSValueCrispedges || id == CSSValueGeometricprecision)
validPrimitive = true;
break;
case CSSPropertyImageRendering:
case CSSPropertyColorRendering:
if (id == CSSValueAuto || id == CSSValueOptimizespeed
|| id == CSSValueOptimizequality)
validPrimitive = true;
break;
case CSSPropertyBufferedRendering:
if (id == CSSValueAuto || id == CSSValueDynamic || id == CSSValueStatic)
validPrimitive = true;
break;
case CSSPropertyColorProfile:
if (id == CSSValueAuto || id == CSSValueSrgb)
validPrimitive = true;
break;
case CSSPropertyColorInterpolation:
case CSSPropertyColorInterpolationFilters:
if (id == CSSValueAuto || id == CSSValueSrgb || id == CSSValueLinearrgb)
validPrimitive = true;
break;
case CSSPropertyTextAnchor:
if (id == CSSValueStart || id == CSSValueMiddle || id == CSSValueEnd)
validPrimitive = true;
break;
case CSSPropertyGlyphOrientationVertical:
if (id == CSSValueAuto) {
validPrimitive = true;
break;
}
case CSSPropertyGlyphOrientationHorizontal:
if (value->unit == CSSPrimitiveValue::CSS_DEG || value->unit == CSSPrimitiveValue::CSS_NUMBER) {
parsedValue = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_DEG);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyFill:
case CSSPropertyStroke:
{
if (id == CSSValueNone) {
parsedValue = SVGPaint::createNone();
} else if (id == CSSValueCurrentcolor) {
parsedValue = SVGPaint::createCurrentColor();
} else if (isSystemColor(id)) {
parsedValue = SVGPaint::createColor(RenderTheme::theme().systemColor(id));
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
RGBA32 c = Color::transparent;
if (m_valueList->next()) {
if (parseColorFromValue(m_valueList->current(), c))
parsedValue = SVGPaint::createURIAndColor(value->string, c);
else if (m_valueList->current()->id == CSSValueNone)
parsedValue = SVGPaint::createURIAndNone(value->string);
else if (m_valueList->current()->id == CSSValueCurrentcolor)
parsedValue = SVGPaint::createURIAndCurrentColor(value->string);
}
if (!parsedValue)
parsedValue = SVGPaint::createURI(value->string);
} else {
parsedValue = parseSVGPaint();
}
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyStopColor:
case CSSPropertyFloodColor:
case CSSPropertyLightingColor:
if (isSystemColor(id)) {
parsedValue = cssValuePool().createColorValue(RenderTheme::theme().systemColor(id).rgb());
} else if ((id >= CSSValueAqua && id <= CSSValueTransparent)
|| (id >= CSSValueAliceblue && id <= CSSValueYellowgreen) || id == CSSValueGrey) {
StyleColor styleColor = SVGPaint::colorFromRGBColorString(value->string);
ASSERT(!styleColor.isCurrentColor());
parsedValue = cssValuePool().createColorValue(styleColor.color().rgb());
} else if (id == CSSValueCurrentcolor) {
parsedValue = cssValuePool().createIdentifierValue(id);
} else {
parsedValue = parseColor();
}
if (parsedValue)
m_valueList->next();
break;
case CSSPropertyPaintOrder:
if (!RuntimeEnabledFeatures::svgPaintOrderEnabled())
return false;
if (m_valueList->size() == 1 && id == CSSValueNormal)
validPrimitive = true;
else if ((parsedValue = parsePaintOrder()))
m_valueList->next();
break;
case CSSPropertyVectorEffect:
if (id == CSSValueNone || id == CSSValueNonScalingStroke)
validPrimitive = true;
break;
case CSSPropertyWritingMode:
if (id == CSSValueLrTb || id == CSSValueRlTb || id == CSSValueTbRl || id == CSSValueLr || id == CSSValueRl || id == CSSValueTb)
validPrimitive = true;
break;
case CSSPropertyStrokeWidth:
case CSSPropertyStrokeDashoffset:
validPrimitive = validUnit(value, FLength | FPercent, SVGAttributeMode);
break;
case CSSPropertyStrokeDasharray:
if (id == CSSValueNone)
validPrimitive = true;
else
parsedValue = parseSVGStrokeDasharray();
break;
case CSSPropertyKerning:
if (id == CSSValueAuto || id == CSSValueNormal)
validPrimitive = true;
else
validPrimitive = validUnit(value, FLength, SVGAttributeMode);
break;
case CSSPropertyClipPath:
case CSSPropertyFilter:
if (id == CSSValueNone) {
validPrimitive = true;
} else if (value->unit == CSSPrimitiveValue::CSS_URI) {
parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
if (parsedValue)
m_valueList->next();
}
break;
case CSSPropertyMaskType:
if (id == CSSValueLuminance || id == CSSValueAlpha)
validPrimitive = true;
break;
case CSSPropertyMarker: {
ShorthandScope scope(this, propId);
CSSPropertyParser::ImplicitScope implicitScope(this, PropertyImplicit);
if (!parseValue(CSSPropertyMarkerStart, important))
return false;
if (m_valueList->current()) {
rollbackLastProperties(1);
return false;
}
CSSValue* value = m_parsedProperties.last().value();
addProperty(CSSPropertyMarkerMid, value, important);
addProperty(CSSPropertyMarkerEnd, value, important);
return true;
}
default:
ASSERT_WITH_MESSAGE(0, "unimplemented propertyID: %d", propId);
return false;
}
if (validPrimitive) {
if (id)
parsedValue = CSSPrimitiveValue::createIdentifier(id);
else if (value->unit == CSSPrimitiveValue::CSS_STRING)
parsedValue = CSSPrimitiveValue::create(value->string, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
parsedValue = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
else if (value->unit >= CSSParserValue::Q_EMS)
parsedValue = CSSPrimitiveValue::createAllowingMarginQuirk(value->fValue, CSSPrimitiveValue::CSS_EMS);
if (isCalculation(value)) {
m_parsedCalculation.release();
parsedValue = nullptr;
}
m_valueList->next();
}
if (!parsedValue || (m_valueList->current() && !inShorthand()))
return false;
addProperty(propId, parsedValue.release(), important);
return true;
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSVGStrokeDasharray()
{
RefPtrWillBeRawPtr<CSSValueList> ret = CSSValueList::createCommaSeparated();
CSSParserValue* value = m_valueList->current();
bool validPrimitive = true;
while (value) {
validPrimitive = validUnit(value, FLength | FPercent | FNonNeg, SVGAttributeMode);
if (!validPrimitive)
break;
if (value->id)
ret->append(CSSPrimitiveValue::createIdentifier(value->id));
else if (value->unit >= CSSPrimitiveValue::CSS_NUMBER && value->unit <= CSSPrimitiveValue::CSS_KHZ)
ret->append(CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit));
value = m_valueList->next();
if (value && value->unit == CSSParserValue::Operator && value->iValue == ',')
value = m_valueList->next();
}
if (!validPrimitive)
return nullptr;
return ret.release();
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSVGPaint()
{
RGBA32 c = Color::transparent;
if (!parseColorFromValue(m_valueList->current(), c))
return SVGPaint::createUnknown();
return SVGPaint::createColor(Color(c));
}
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parsePaintOrder() const
{
if (m_valueList->size() > 3)
return nullptr;
CSSParserValue* value = m_valueList->current();
if (!value)
return nullptr;
RefPtrWillBeRawPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSeparated();
bool seenFill = false, seenStroke = false, seenMarkers = false;
do {
switch (value->id) {
case CSSValueNormal:
return nullptr;
case CSSValueFill:
if (seenFill)
return nullptr;
seenFill = true;
break;
case CSSValueStroke:
if (seenStroke)
return nullptr;
seenStroke = true;
break;
case CSSValueMarkers:
if (seenMarkers)
return nullptr;
seenMarkers = true;
break;
default:
return nullptr;
}
parsedValues->append(CSSPrimitiveValue::createIdentifier(value->id));
} while ((value = m_valueList->next()));
if (!seenFill)
parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueFill));
if (!seenStroke)
parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueStroke));
if (!seenMarkers)
parsedValues->append(CSSPrimitiveValue::createIdentifier(CSSValueMarkers));
return parsedValues.release();
}
}