#ifndef CSSPropertyParser_h
#define CSSPropertyParser_h
#include "CSSPropertyNames.h"
#include "CSSValueKeywords.h"
#include "core/css/CSSCalculationValue.h"
#include "core/css/CSSFilterValue.h"
#include "core/css/CSSGradientValue.h"
#include "core/css/CSSGridTemplateAreasValue.h"
#include "core/css/CSSParserMode.h"
#include "core/css/CSSParserValues.h"
#include "core/css/CSSProperty.h"
#include "core/css/CSSPropertySourceData.h"
#include "core/css/CSSSelector.h"
#include "platform/graphics/Color.h"
#include "wtf/OwnPtr.h"
#include "wtf/Vector.h"
namespace WebCore {
class AnimationParseContext;
class CSSArrayFunctionValue;
class CSSBorderImageSliceValue;
class CSSPrimitiveValue;
class CSSSelectorList;
class CSSValue;
class CSSValueList;
class CSSBasicShape;
class CSSBasicShapeInset;
class CSSGridLineNamesValue;
class Document;
class Element;
class ImmutableStylePropertySet;
class StyleKeyframe;
class StylePropertyShorthand;
class StyleKeyframe;
class UseCounter;
class CSSPropertyParser {
STACK_ALLOCATED();
public:
CSSPropertyParser(OwnPtr<CSSParserValueList>&,
const CSSParserContext&, bool inViewport, bool savedImportant,
WillBeHeapVector<CSSProperty, 256>&, bool& hasFontFaceOnlyValues);
~CSSPropertyParser();
template<typename StringType>
static bool fastParseColor(RGBA32&, const StringType&, bool strict);
bool parseValue(CSSPropertyID, bool important);
static bool isSystemColor(int id);
private:
bool inShorthand() const { return m_inParseShorthand; }
bool inQuirksMode() const { return isQuirksModeBehavior(m_context.mode()); }
bool inViewport() const { return m_inViewport; }
bool parseViewportProperty(CSSPropertyID propId, bool important);
bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPropertyID second, bool important);
KURL completeURL(const String& url) const;
void addPropertyWithPrefixingVariant(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool important, bool implicit = false);
void addProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool important, bool implicit = false);
void rollbackLastProperties(int num);
bool hasProperties() const { return !m_parsedProperties.isEmpty(); }
void addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtrWillBeRawPtr<CSSValue>, bool);
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, CSSParserValue*);
bool parseShorthand(CSSPropertyID, const StylePropertyShorthand&, bool important);
bool parse4Values(CSSPropertyID, const CSSPropertyID* properties, bool important);
bool parseContent(CSSPropertyID, bool important);
bool parseQuotes(CSSPropertyID, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseAttr(CSSParserValueList* args);
PassRefPtrWillBeRawPtr<CSSValue> parseBackgroundColor();
bool parseFillImage(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&);
enum FillPositionFlag { InvalidFillPosition = 0, AmbiguousFillPosition = 1, XFillPosition = 2, YFillPosition = 4 };
enum FillPositionParsingMode { ResolveValuesAsPercent = 0, ResolveValuesAsKeyword = 1 };
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseFillPositionComponent(CSSParserValueList*, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode = ResolveValuesAsPercent);
PassRefPtrWillBeRawPtr<CSSValue> parseFillPositionX(CSSParserValueList*);
PassRefPtrWillBeRawPtr<CSSValue> parseFillPositionY(CSSParserValueList*);
void parse2ValuesFillPosition(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
bool isPotentialPositionValue(CSSParserValue*);
void parseFillPosition(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
void parse3ValuesFillPosition(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&, PassRefPtrWillBeRawPtr<CSSPrimitiveValue>, PassRefPtrWillBeRawPtr<CSSPrimitiveValue>);
void parse4ValuesFillPosition(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&, PassRefPtrWillBeRawPtr<CSSPrimitiveValue>, PassRefPtrWillBeRawPtr<CSSPrimitiveValue>);
void parseFillRepeat(RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
PassRefPtrWillBeRawPtr<CSSValue> parseFillSize(CSSPropertyID, bool &allowComma);
bool parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
bool parseFillShorthand(CSSPropertyID, const CSSPropertyID* properties, int numProperties, bool important);
void addFillValue(RefPtrWillBeRawPtr<CSSValue>& lval, PassRefPtrWillBeRawPtr<CSSValue> rval);
void addAnimationValue(RefPtrWillBeRawPtr<CSSValue>& lval, PassRefPtrWillBeRawPtr<CSSValue> rval);
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationDelay();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationDirection();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationDuration();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationFillMode();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationIterationCount();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationName();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationPlayState();
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationProperty(AnimationParseContext&);
PassRefPtrWillBeRawPtr<CSSValue> parseAnimationTimingFunction();
bool parseWebkitTransformOriginShorthand(RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
bool parseCubicBezierTimingFunctionValue(CSSParserValueList*& args, double& result);
bool parseAnimationProperty(CSSPropertyID, RefPtrWillBeRawPtr<CSSValue>&, AnimationParseContext&);
bool parseTransitionShorthand(CSSPropertyID, bool important);
bool parseAnimationShorthand(CSSPropertyID, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseColumnWidth();
PassRefPtrWillBeRawPtr<CSSValue> parseColumnCount();
bool parseColumnsShorthand(bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseGridPosition();
bool parseIntegerOrStringFromGridPosition(RefPtrWillBeRawPtr<CSSPrimitiveValue>& numericValue, RefPtrWillBeRawPtr<CSSPrimitiveValue>& gridLineName);
bool parseGridItemPositionShorthand(CSSPropertyID, bool important);
bool parseGridTemplateRowsAndAreas(PassRefPtrWillBeRawPtr<CSSValue>, bool important);
bool parseGridTemplateShorthand(bool important);
bool parseGridAreaShorthand(bool important);
bool parseSingleGridAreaLonghand(RefPtrWillBeRawPtr<CSSValue>&);
PassRefPtrWillBeRawPtr<CSSValue> parseGridTrackList(bool important);
bool parseGridTrackRepeatFunction(CSSValueList&);
PassRefPtrWillBeRawPtr<CSSValue> parseGridTrackSize(CSSParserValueList& inputList);
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseGridBreadth(CSSParserValue*);
bool parseGridTemplateAreasRow(NamedGridAreaMap&, const size_t, size_t&);
PassRefPtrWillBeRawPtr<CSSValue> parseGridTemplateAreas();
void parseGridLineNames(CSSParserValueList&, CSSValueList&, CSSGridLineNamesValue* = 0);
bool parseClipShape(CSSPropertyID, bool important);
bool parseItemPositionOverflowPosition(CSSPropertyID, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseShapeProperty(CSSPropertyID propId);
PassRefPtrWillBeRawPtr<CSSValue> parseBasicShapeAndOrBox();
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseBasicShape();
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseShapeRadius(CSSParserValue*);
PassRefPtrWillBeRawPtr<CSSBasicShape> parseBasicShapeCircle(CSSParserValueList* args);
PassRefPtrWillBeRawPtr<CSSBasicShape> parseBasicShapeEllipse(CSSParserValueList* args);
PassRefPtrWillBeRawPtr<CSSBasicShape> parseBasicShapePolygon(CSSParserValueList* args);
PassRefPtrWillBeRawPtr<CSSBasicShape> parseBasicShapeInset(CSSParserValueList* args);
bool parseFont(bool important);
PassRefPtrWillBeRawPtr<CSSValueList> parseFontFamily();
bool parseCounter(CSSPropertyID, int defaultValue, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseCounterContent(CSSParserValueList* args, bool counters);
bool parseColorParameters(CSSParserValue*, int* colorValues, bool parseAlpha);
bool parseHSLParameters(CSSParserValue*, double* colorValues, bool parseAlpha);
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseColor(CSSParserValue* = 0);
bool parseColorFromValue(CSSParserValue*, RGBA32&);
bool parseLineHeight(bool important);
bool parseFontSize(bool important);
bool parseFontVariant(bool important);
bool parseFontWeight(bool important);
bool parseFontFaceSrc();
bool parseFontFaceUnicodeRange();
bool parseSVGValue(CSSPropertyID propId, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseSVGPaint();
PassRefPtrWillBeRawPtr<CSSValue> parseSVGStrokeDasharray();
PassRefPtrWillBeRawPtr<CSSValue> parsePaintOrder() const;
PassRefPtrWillBeRawPtr<CSSValueList> parseShadow(CSSParserValueList*, CSSPropertyID);
bool parseBorderImageShorthand(CSSPropertyID, bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseBorderImage(CSSPropertyID);
bool parseBorderImageRepeat(RefPtrWillBeRawPtr<CSSValue>&);
bool parseBorderImageSlice(CSSPropertyID, RefPtrWillBeRawPtr<CSSBorderImageSliceValue>&);
bool parseBorderImageWidth(RefPtrWillBeRawPtr<CSSPrimitiveValue>&);
bool parseBorderImageOutset(RefPtrWillBeRawPtr<CSSPrimitiveValue>&);
bool parseBorderRadius(CSSPropertyID, bool important);
bool parseAspectRatio(bool important);
bool parseReflect(CSSPropertyID, bool important);
bool parseFlex(CSSParserValueList* args, bool important);
bool parseObjectPosition(bool important);
bool parseCanvas(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&);
bool parseDeprecatedGradient(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&);
bool parseDeprecatedLinearGradient(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, CSSGradientRepeat repeating);
bool parseDeprecatedRadialGradient(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, CSSGradientRepeat repeating);
bool parseLinearGradient(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, CSSGradientRepeat repeating);
bool parseRadialGradient(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&, CSSGradientRepeat repeating);
bool parseGradientColorStops(CSSParserValueList*, CSSGradientValue*, bool expectComma);
bool parseCrossfade(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&);
PassRefPtrWillBeRawPtr<CSSValue> parseImageSet(CSSParserValueList*);
bool parseWillChange(bool important);
PassRefPtrWillBeRawPtr<CSSValueList> parseFilter();
PassRefPtrWillBeRawPtr<CSSFilterValue> parseBuiltinFilterArguments(CSSParserValueList*, CSSFilterValue::FilterOperationType);
static bool isBlendMode(CSSValueID);
static bool isCompositeOperator(CSSValueID);
PassRefPtrWillBeRawPtr<CSSValueList> parseTransformOrigin();
PassRefPtrWillBeRawPtr<CSSValueList> parseTransform(CSSPropertyID);
PassRefPtrWillBeRawPtr<CSSValue> parseTransformValue(CSSPropertyID, CSSParserValue*);
bool parseWebkitTransformOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, CSSPropertyID& propId3, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
bool parseWebkitPerspectiveOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtrWillBeRawPtr<CSSValue>&, RefPtrWillBeRawPtr<CSSValue>&);
bool parseTextEmphasisStyle(bool important);
bool parseTouchAction(bool important);
void addTextDecorationProperty(CSSPropertyID, PassRefPtrWillBeRawPtr<CSSValue>, bool important);
bool parseTextDecoration(CSSPropertyID propId, bool important);
bool parseTextUnderlinePosition(bool important);
PassRefPtrWillBeRawPtr<CSSValue> parseTextIndent();
bool parseLineBoxContain(bool important);
bool parseCalculation(CSSParserValue*, ValueRange);
bool parseFontFeatureTag(CSSValueList*);
bool parseFontFeatureSettings(bool important);
bool parseFontVariantLigatures(bool important);
bool parseGeneratedImage(CSSParserValueList*, RefPtrWillBeRawPtr<CSSValue>&);
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createPrimitiveNumericValue(CSSParserValue*);
PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createPrimitiveStringValue(CSSParserValue*);
bool validWidthOrHeight(CSSParserValue*);
PassRefPtrWillBeRawPtr<CSSBasicShape> parseInsetRoundedCorners(PassRefPtrWillBeRawPtr<CSSBasicShapeInset>, CSSParserValueList*);
enum SizeParameterType {
None,
Auto,
Length,
PageSize,
Orientation,
};
bool parsePage(CSSPropertyID propId, bool important);
bool parseSize(CSSPropertyID propId, bool important);
SizeParameterType parseSizeParameter(CSSValueList* parsedValues, CSSParserValue*, SizeParameterType prevParamType);
bool parseFontFaceSrcURI(CSSValueList*);
bool parseFontFaceSrcLocal(CSSValueList*);
enum PropertyType {
PropertyExplicit,
PropertyImplicit
};
class ImplicitScope {
STACK_ALLOCATED();
WTF_MAKE_NONCOPYABLE(ImplicitScope);
public:
ImplicitScope(CSSPropertyParser* parser, PropertyType propertyType)
: m_parser(parser)
{
m_parser->m_implicitShorthand = propertyType == CSSPropertyParser::PropertyImplicit;
}
~ImplicitScope()
{
m_parser->m_implicitShorthand = false;
}
private:
CSSPropertyParser* m_parser;
};
class ShorthandScope {
STACK_ALLOCATED();
public:
ShorthandScope(CSSPropertyParser* parser, CSSPropertyID propId) : m_parser(parser)
{
if (!(m_parser->m_inParseShorthand++))
m_parser->m_currentShorthand = propId;
}
~ShorthandScope()
{
if (!(--m_parser->m_inParseShorthand))
m_parser->m_currentShorthand = CSSPropertyInvalid;
}
private:
CSSPropertyParser* m_parser;
};
enum ReleaseParsedCalcValueCondition {
ReleaseParsedCalcValue,
DoNotReleaseParsedCalcValue
};
enum Units {
FUnknown = 0x0000,
FInteger = 0x0001,
FNumber = 0x0002,
FPercent = 0x0004,
FLength = 0x0008,
FAngle = 0x0010,
FTime = 0x0020,
FFrequency = 0x0040,
FPositiveInteger = 0x0080,
FRelative = 0x0100,
FResolution = 0x0200,
FNonNeg = 0x0400
};
friend inline Units operator|(Units a, Units b)
{
return static_cast<Units>(static_cast<unsigned>(a) | static_cast<unsigned>(b));
}
bool validCalculationUnit(CSSParserValue*, Units, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
bool shouldAcceptUnitLessValues(CSSParserValue*, Units, CSSParserMode);
inline bool validUnit(CSSParserValue* value, Units unitflags, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue) { return validUnit(value, unitflags, m_context.mode(), releaseCalc); }
bool validUnit(CSSParserValue*, Units, CSSParserMode, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
bool parseBorderImageQuad(Units, RefPtrWillBeRawPtr<CSSPrimitiveValue>&);
int colorIntFromValue(CSSParserValue*);
double parsedDouble(CSSParserValue*, ReleaseParsedCalcValueCondition releaseCalc = DoNotReleaseParsedCalcValue);
bool isCalculation(CSSParserValue*);
private:
const OwnPtr<CSSParserValueList>& m_valueList;
const CSSParserContext& m_context;
const bool m_inViewport;
const bool m_important;
WillBeHeapVector<CSSProperty, 256>& m_parsedProperties;
bool m_hasFontFaceOnlyValues;
int m_inParseShorthand;
CSSPropertyID m_currentShorthand;
bool m_implicitShorthand;
RefPtrWillBeMember<CSSCalcValue> m_parsedCalculation;
friend class ShadowParseContext;
friend class BorderImageParseContext;
friend class BorderImageSliceParseContext;
friend class BorderImageQuadParseContext;
friend class TransformOperationInfo;
friend bool parseDeprecatedGradientColorStop(CSSPropertyParser*, CSSParserValue*, CSSGradientColorStop&);
friend PassRefPtrWillBeRawPtr<CSSPrimitiveValue> parseGradientColorOrKeyword(CSSPropertyParser*, CSSParserValue*);
};
CSSPropertyID cssPropertyID(const CSSParserString&);
CSSPropertyID cssPropertyID(const String&);
CSSValueID cssValueKeywordID(const CSSParserString&);
bool isKeywordPropertyID(CSSPropertyID);
bool isValidKeywordPropertyAndValue(CSSPropertyID, int valueID, const CSSParserContext&);
}
#endif