/* * Copyright (C) 2003 Lars Knoll (knoll@kde.org) * Copyright (C) 2004-2010, 2015 Apple Inc. All rights reserved. * Copyright (C) 2008 Eric Seidel * Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef CSSParser_h #define CSSParser_h #include "CSSCalculationValue.h" #include "CSSGradientValue.h" #include "CSSParserMode.h" #include "CSSParserValues.h" #include "CSSProperty.h" #include "CSSPropertyNames.h" #include "CSSPropertySourceData.h" #include "CSSValueKeywords.h" #include "Color.h" #include "MediaQuery.h" #include "SourceSizeList.h" #include "WebKitCSSFilterValue.h" #include #include #include #include #include #include #if ENABLE(CSS_GRID_LAYOUT) #include "GridCoordinate.h" #endif namespace WebCore { class AnimationParseContext; class CSSBorderImageSliceValue; class CSSPrimitiveValue; class CSSSelectorList; class CSSValue; class CSSValueList; class CSSBasicShape; class CSSBasicShapeInset; class CSSGridLineNamesValue; class CSSVariableDependentValue; class Document; class Element; class ImmutableStyleProperties; class MediaQueryExp; class MediaQuerySet; class MutableStyleProperties; class StyleKeyframe; class StylePropertyShorthand; class StyleRuleBase; class StyleRuleKeyframes; class StyleKeyframe; class StyleSheetContents; class StyledElement; class CSSParser { friend inline int cssyylex(void*, CSSParser*); public: struct Location; enum SyntaxErrorType { PropertyDeclarationError, GeneralSyntaxError }; enum class ParseResult { Changed, Unchanged, Error }; using ParsedPropertyVector = Vector; class ValueWithCalculation { public: explicit ValueWithCalculation(CSSParserValue& value) : m_value(value) { } CSSParserValue& value() const { return m_value; } operator CSSParserValue&() { return m_value; } RefPtr calculation() const { return m_calculation; } void setCalculation(RefPtr&& calculation) { ASSERT(isCalculation(m_value)); m_calculation = calculation; } private: CSSParserValue& m_value; RefPtr m_calculation; }; WEBCORE_EXPORT CSSParser(const CSSParserContext&); WEBCORE_EXPORT ~CSSParser(); void parseSheet(StyleSheetContents*, const String&, const TextPosition&, RuleSourceDataList*, bool logErrors); RefPtr parseRule(StyleSheetContents*, const String&); RefPtr parseKeyframeRule(StyleSheetContents*, const String&); bool parseSupportsCondition(const String&); static ParseResult parseValue(MutableStyleProperties*, CSSPropertyID, const String&, bool important, CSSParserMode, StyleSheetContents*); static ParseResult parseCustomPropertyValue(MutableStyleProperties*, const AtomicString& propertyName, const String&, bool important, CSSParserMode, StyleSheetContents* contextStyleSheet); static bool parseColor(RGBA32& color, const String&, bool strict = false); static bool isValidSystemColorValue(CSSValueID); static bool parseSystemColor(RGBA32& color, const String&, Document*); static RefPtr parseFontFaceValue(const AtomicString&); RefPtr parseValidPrimitive(CSSValueID ident, ValueWithCalculation&); WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties*, const String&, PassRefPtr, StyleSheetContents* contextStyleSheet); static Ref parseInlineStyleDeclaration(const String&, Element*); std::unique_ptr parseMediaQuery(const String&); void addPropertyWithPrefixingVariant(CSSPropertyID, PassRefPtr, bool important, bool implicit = false); void addProperty(CSSPropertyID, PassRefPtr, bool important, bool implicit = false); void rollbackLastProperties(int num); bool hasProperties() const { return !m_parsedProperties.isEmpty(); } void addExpandedPropertyForValue(CSSPropertyID propId, PassRefPtr, bool); bool parseValue(CSSPropertyID, bool important); 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); bool parseAlt(CSSPropertyID, bool important); bool parseCustomPropertyDeclaration(bool important, CSSValueID); RefPtr parseAttr(CSSParserValueList& args); RefPtr parseBackgroundColor(); struct SourceSize { std::unique_ptr expression; RefPtr length; SourceSize(SourceSize&&); SourceSize(std::unique_ptr&&, RefPtr); }; Vector parseSizesAttribute(StringView); SourceSize sourceSize(std::unique_ptr&&, CSSParserValue&); bool parseFillImage(CSSParserValueList&, RefPtr&); enum FillPositionFlag { InvalidFillPosition = 0, AmbiguousFillPosition = 1, XFillPosition = 2, YFillPosition = 4 }; enum FillPositionParsingMode { ResolveValuesAsPercent = 0, ResolveValuesAsKeyword = 1 }; RefPtr parseFillPositionComponent(CSSParserValueList&, unsigned& cumulativeFlags, FillPositionFlag& individualFlag, FillPositionParsingMode = ResolveValuesAsPercent); RefPtr parsePositionX(CSSParserValueList&); RefPtr parsePositionY(CSSParserValueList&); void parse2ValuesFillPosition(CSSParserValueList&, RefPtr&, RefPtr&); bool isPotentialPositionValue(CSSParserValue&); void parseFillPosition(CSSParserValueList&, RefPtr&, RefPtr&); void parse3ValuesFillPosition(CSSParserValueList&, RefPtr&, RefPtr&, RefPtr&&, RefPtr&&); void parse4ValuesFillPosition(CSSParserValueList&, RefPtr&, RefPtr&, RefPtr&&, RefPtr&&); void parseFillRepeat(RefPtr&, RefPtr&); RefPtr parseFillSize(CSSPropertyID, bool &allowComma); bool parseFillProperty(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtr&, RefPtr&); bool parseFillShorthand(CSSPropertyID, const CSSPropertyID* properties, int numProperties, bool important); void addFillValue(RefPtr& lval, Ref&& rval); void addAnimationValue(RefPtr& lval, Ref&& rval); RefPtr parseAnimationDelay(); RefPtr parseAnimationDirection(); RefPtr parseAnimationDuration(); RefPtr parseAnimationFillMode(); RefPtr parseAnimationIterationCount(); RefPtr parseAnimationName(); RefPtr parseAnimationPlayState(); RefPtr parseAnimationProperty(AnimationParseContext&); RefPtr parseAnimationTimingFunction(); #if ENABLE(CSS_ANIMATIONS_LEVEL_2) RefPtr parseAnimationTrigger(); #endif static Vector parseKeyframeSelector(const String&); bool parseTransformOriginShorthand(RefPtr&, RefPtr&, RefPtr&); bool parseCubicBezierTimingFunctionValue(CSSParserValueList& args, double& result); bool parseAnimationProperty(CSSPropertyID, RefPtr&, AnimationParseContext&); bool parseTransitionShorthand(CSSPropertyID, bool important); bool parseAnimationShorthand(CSSPropertyID, bool important); RefPtr parseColumnWidth(); RefPtr parseColumnCount(); bool parseColumnsShorthand(bool important); #if ENABLE(CSS_GRID_LAYOUT) RefPtr parseGridPosition(); bool parseGridItemPositionShorthand(CSSPropertyID, bool important); bool parseGridTemplateRowsAndAreas(PassRefPtr, bool important); bool parseGridTemplateShorthand(bool important); bool parseGridShorthand(bool important); bool parseGridAreaShorthand(bool important); bool parseGridGapShorthand(bool important); bool parseSingleGridAreaLonghand(RefPtr&); RefPtr parseGridTrackList(); bool parseGridTrackRepeatFunction(CSSValueList&); RefPtr parseGridTrackSize(CSSParserValueList& inputList); RefPtr parseGridBreadth(CSSParserValue&); bool parseGridTemplateAreasRow(NamedGridAreaMap&, const unsigned, unsigned&); RefPtr parseGridTemplateAreas(); bool parseGridLineNames(CSSParserValueList&, CSSValueList&, CSSGridLineNamesValue* = nullptr); RefPtr parseGridAutoFlow(CSSParserValueList&); #endif bool parseDashboardRegions(CSSPropertyID, bool important); bool parseClipShape(CSSPropertyID, bool important); bool parseLegacyPosition(CSSPropertyID, bool important); bool parseItemPositionOverflowPosition(CSSPropertyID, bool important); RefPtr parseContentDistributionOverflowPosition(); #if ENABLE(CSS_SHAPES) RefPtr parseShapeProperty(CSSPropertyID); #endif RefPtr parseBasicShapeAndOrBox(CSSPropertyID propId); RefPtr parseBasicShape(); RefPtr parseShapeRadius(CSSParserValue&); RefPtr parseBasicShapeCircle(CSSParserValueList&); RefPtr parseBasicShapeEllipse(CSSParserValueList&); RefPtr parseBasicShapePolygon(CSSParserValueList&); RefPtr parseBasicShapePath(CSSParserValueList&); RefPtr parseBasicShapeInset(CSSParserValueList&); bool parseFont(bool important); void parseSystemFont(bool important); RefPtr parseFontFamily(); bool parseCounter(CSSPropertyID, int defaultValue, bool important); RefPtr parseCounterContent(CSSParserValueList& args, bool counters); bool parseColorParameters(CSSParserValue&, int* colorValues, bool parseAlpha); bool parseHSLParameters(CSSParserValue&, double* colorValues, bool parseAlpha); RefPtr parseColor(CSSParserValue* = nullptr); bool parseColorFromValue(CSSParserValue&, RGBA32&); void parseSelector(const String&, CSSSelectorList&); template static bool fastParseColor(RGBA32&, const StringType&, bool strict); bool parseLineHeight(bool important); bool parseFontSize(bool important); bool parseFontWeight(bool important); bool parseFontSynthesis(bool important); bool parseFontFaceSrc(); bool parseFontFaceUnicodeRange(); bool parseSVGValue(CSSPropertyID propId, bool important); RefPtr parseSVGPaint(); RefPtr parseSVGColor(); RefPtr parseSVGStrokeDasharray(); RefPtr parsePaintOrder(); // CSS3 Parsing Routines (for properties specific to CSS3) RefPtr parseShadow(CSSParserValueList&, CSSPropertyID); bool parseBorderImage(CSSPropertyID, RefPtr&, bool important = false); bool parseBorderImageRepeat(RefPtr&); bool parseBorderImageSlice(CSSPropertyID, RefPtr&); bool parseBorderImageWidth(RefPtr&); bool parseBorderImageOutset(RefPtr&); bool parseBorderRadius(CSSPropertyID, bool important); bool parseAspectRatio(bool important); bool parseReflect(CSSPropertyID, bool important); bool parseFlex(CSSParserValueList& args, bool important); // Image generators bool parseCanvas(CSSParserValueList&, RefPtr&); bool parseNamedImage(CSSParserValueList&, RefPtr&); bool parseDeprecatedGradient(CSSParserValueList&, RefPtr&); bool parseDeprecatedLinearGradient(CSSParserValueList&, RefPtr&, CSSGradientRepeat repeating); bool parseDeprecatedRadialGradient(CSSParserValueList&, RefPtr&, CSSGradientRepeat repeating); bool parseLinearGradient(CSSParserValueList&, RefPtr&, CSSGradientRepeat repeating); bool parseRadialGradient(CSSParserValueList&, RefPtr&, CSSGradientRepeat repeating); bool parseGradientColorStops(CSSParserValueList&, CSSGradientValue&, bool expectComma); bool parseCrossfade(CSSParserValueList&, RefPtr&); #if ENABLE(CSS_IMAGE_RESOLUTION) RefPtr parseImageResolution(); #endif #if ENABLE(CSS_IMAGE_SET) RefPtr parseImageSet(); #endif bool parseFilterImage(CSSParserValueList&, RefPtr&); bool parseFilter(CSSParserValueList&, RefPtr&); RefPtr parseBuiltinFilterArguments(CSSParserValueList&, WebKitCSSFilterValue::FilterOperationType); RefPtr parseClipPath(); static bool isBlendMode(CSSValueID); static bool isCompositeOperator(CSSValueID); RefPtr parseTransform(); RefPtr parseTransformValue(CSSParserValue&); bool parseTransformOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, CSSPropertyID& propId3, RefPtr&, RefPtr&, RefPtr&); bool parsePerspectiveOrigin(CSSPropertyID propId, CSSPropertyID& propId1, CSSPropertyID& propId2, RefPtr&, RefPtr&); bool parseTextEmphasisStyle(bool important); bool parseTextEmphasisPosition(bool important); void addTextDecorationProperty(CSSPropertyID, PassRefPtr, bool important); bool parseTextDecoration(CSSPropertyID propId, bool important); bool parseTextDecorationSkip(bool important); bool parseTextUnderlinePosition(bool important); RefPtr parseTextIndent(); bool parseHangingPunctuation(bool important); bool parseLineBoxContain(bool important); RefPtr parseCalculation(CSSParserValue&, CalculationPermittedValueRange); bool parseFontFeatureTag(CSSValueList&); bool parseFontFeatureSettings(bool important); bool cssRegionsEnabled() const; bool cssCompositingEnabled() const; bool parseFlowThread(CSSPropertyID, bool important); bool parseRegionThread(CSSPropertyID, bool important); bool parseFontVariantLigatures(bool important, bool unknownIsFailure, bool implicit); bool parseFontVariantNumeric(bool important, bool unknownIsFailure, bool implicit); bool parseFontVariantEastAsian(bool important, bool unknownIsFailure, bool implicit); bool parseFontVariant(bool important); bool parseWillChange(bool important); // Faster than doing a new/delete each time since it keeps one vector. std::unique_ptr>> createSelectorVector(); void recycleSelectorVector(std::unique_ptr>>); RefPtr createImportRule(const CSSParserString&, PassRefPtr); RefPtr createKeyframe(CSSParserValueList&); RefPtr createKeyframesRule(const String&, std::unique_ptr>>); typedef Vector> RuleList; RefPtr createMediaRule(PassRefPtr, RuleList*); RefPtr createEmptyMediaRule(RuleList*); RefPtr createStyleRule(Vector>* selectors); RefPtr createFontFaceRule(); RefPtr createPageRule(std::unique_ptr pageSelector); RefPtr createRegionRule(Vector>* regionSelector, RuleList* rules); void createMarginAtRule(CSSSelector::MarginBoxType); RefPtr createSupportsRule(bool conditionIsSupported, RuleList*); void markSupportsRuleHeaderStart(); void markSupportsRuleHeaderEnd(); RefPtr popSupportsRuleData(); void startDeclarationsForMarginBox(); void endDeclarationsForMarginBox(); void addNamespace(const AtomicString& prefix, const AtomicString& uri); QualifiedName determineNameInNamespace(const AtomicString& prefix, const AtomicString& localName); void rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector&, bool isNamespacePlaceholder = false); void rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector&); std::unique_ptr rewriteSpecifiers(std::unique_ptr, std::unique_ptr); void invalidBlockHit(); void updateLastSelectorLineAndPosition(); void updateLastMediaLine(MediaQuerySet*); void clearProperties(); Ref createStyleProperties(); CSSParserContext m_context; bool m_important; CSSPropertyID m_id; AtomicString m_customPropertyName; StyleSheetContents* m_styleSheet; RefPtr m_rule; RefPtr m_keyframe; std::unique_ptr m_mediaQuery; std::unique_ptr> m_sourceSizeList; std::unique_ptr m_valueList; bool m_supportsCondition; ParsedPropertyVector m_parsedProperties; CSSSelectorList* m_selectorListForParseSelector; unsigned m_numParsedPropertiesBeforeMarginBox; int m_inParseShorthand; CSSPropertyID m_currentShorthand; bool m_implicitShorthand; bool m_hadSyntacticallyValidCSSRule; bool m_logErrors; bool m_ignoreErrorsInDeclaration; AtomicString m_defaultNamespace; // tokenizer methods and data size_t m_parsedTextPrefixLength; unsigned m_nestedSelectorLevel; SourceRange m_selectorRange; SourceRange m_propertyRange; std::unique_ptr m_currentRuleDataStack; RefPtr m_currentRuleData; RuleSourceDataList* m_ruleSourceDataResult; void fixUnparsedPropertyRanges(CSSRuleSourceData*); void markRuleHeaderStart(CSSRuleSourceData::Type); void markRuleHeaderEnd(); void startNestedSelectorList() { ++m_nestedSelectorLevel; } void endNestedSelectorList() { --m_nestedSelectorLevel; } void markSelectorStart(); void markSelectorEnd(); void markRuleBodyStart(); void markRuleBodyEnd(); void markPropertyStart(); void markPropertyEnd(bool isImportantFound, bool isPropertyParsed); void processAndAddNewRuleToSourceTreeIfNeeded(); void addNewRuleToSourceTree(PassRefPtr); PassRefPtr popRuleData(); void resetPropertyRange() { m_propertyRange.start = m_propertyRange.end = UINT_MAX; } bool isExtractingSourceData() const { return !!m_currentRuleDataStack; } void syntaxError(const Location&, SyntaxErrorType = GeneralSyntaxError); inline int lex(void* yylval) { return (this->*m_lexFunc)(yylval); } int token() { return m_token; } #if ENABLE(CSS_DEVICE_ADAPTATION) void markViewportRuleBodyStart() { m_inViewport = true; } void markViewportRuleBodyEnd() { m_inViewport = false; } PassRefPtr createViewportRule(); #endif Ref createPrimitiveNumericValue(ValueWithCalculation&); Ref createPrimitiveStringValue(CSSParserValue&); static URL completeURL(const CSSParserContext&, const String& url); Location currentLocation(); static bool isCalculation(CSSParserValue&); void setCustomPropertyName(const AtomicString& propertyName) { m_customPropertyName = propertyName; } RefPtr parseVariableDependentValue(CSSPropertyID, const CSSVariableDependentValue&, const CustomPropertyValueMap& customProperties); private: bool is8BitSource() { return m_is8BitSource; } template int realLex(void* yylval); UChar*& currentCharacter16(); template inline CharacterType*& currentCharacter(); template inline CharacterType* tokenStart(); template inline void setTokenStart(CharacterType*); inline unsigned tokenStartOffset(); inline UChar tokenStartChar(); inline unsigned currentCharacterOffset(); template inline bool isIdentifierStart(); template unsigned parseEscape(CharacterType*&); template inline void UnicodeToChars(DestCharacterType*&, unsigned); template inline bool parseIdentifierInternal(SrcCharacterType*&, DestCharacterType*&, bool&); template inline void parseIdentifier(CharacterType*&, CSSParserString&, bool&); template inline bool parseStringInternal(SrcCharacterType*&, DestCharacterType*&, UChar); template inline void parseString(CharacterType*&, CSSParserString& resultString, UChar); template inline bool findURI(CharacterType*& start, CharacterType*& end, UChar& quote); template inline bool parseURIInternal(SrcCharacterType*&, DestCharacterType*&, UChar quote); template inline void parseURI(CSSParserString&); template inline bool parseUnicodeRange(); template bool parseNthChild(); template bool parseNthChildExtra(); template inline bool detectFunctionTypeToken(int); template inline void detectMediaQueryToken(int); template inline void detectNumberToken(CharacterType*, int); template inline void detectDashToken(int); template inline void detectAtToken(int, bool); template inline void detectSupportsToken(int); template inline void setRuleHeaderEnd(const CharacterType*); void setStyleSheet(StyleSheetContents* styleSheet) { m_styleSheet = styleSheet; } inline bool inStrictMode() const { return m_context.mode == CSSStrictMode || m_context.mode == SVGAttributeMode; } inline bool inQuirksMode() const { return m_context.mode == CSSQuirksMode; } URL completeURL(const String& url) const; void recheckAtKeyword(const UChar* str, int len); template void setupParser(const char (&prefix)[prefixLength], StringView string, const char (&suffix)[suffixLength]) { setupParser(prefix, prefixLength - 1, string, suffix, suffixLength - 1); } void setupParser(const char* prefix, unsigned prefixLength, StringView, const char* suffix, unsigned suffixLength); bool inShorthand() const { return m_inParseShorthand; } bool isValidSize(ValueWithCalculation&); bool isGeneratedImageValue(CSSParserValue&) const; bool parseGeneratedImage(CSSParserValueList&, RefPtr&); ParseResult parseValue(MutableStyleProperties*, CSSPropertyID, const String&, bool important, StyleSheetContents* contextStyleSheet); Ref parseDeclaration(const String&, StyleSheetContents* contextStyleSheet); RefPtr parseInsetRoundedCorners(PassRefPtr, 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); #if ENABLE(CSS_SCROLL_SNAP) bool parseNonElementSnapPoints(CSSPropertyID propId, bool important); bool parseScrollSnapDestination(CSSPropertyID propId, bool important); bool parseScrollSnapCoordinate(CSSPropertyID propId, bool important); bool parseScrollSnapPositions(RefPtr& cssValueX, RefPtr& cssValueY); #endif bool parseFontFaceSrcURI(CSSValueList&); bool parseFontFaceSrcLocal(CSSValueList&); bool parseColor(const String&); #if ENABLE(CSS_GRID_LAYOUT) bool parseIntegerOrCustomIdentFromGridPosition(RefPtr& numericValue, RefPtr& gridLineName); #endif enum ParsingMode { NormalMode, MediaQueryMode, SupportsMode, NthChildMode }; ParsingMode m_parsingMode; bool m_is8BitSource; std::unique_ptr m_dataStart8; std::unique_ptr m_dataStart16; LChar* m_currentCharacter8; UChar* m_currentCharacter16; union { LChar* ptr8; UChar* ptr16; } m_tokenStart; unsigned m_length; int m_token; int m_lineNumber; int m_tokenStartLineNumber; int m_tokenStartColumnNumber; int m_lastSelectorLineNumber; int m_columnOffsetForLine; int m_sheetStartLineNumber; int m_sheetStartColumnNumber; bool m_allowImportRules; bool m_allowNamespaceDeclarations; #if ENABLE(CSS_DEVICE_ADAPTATION) bool parseViewportProperty(CSSPropertyID propId, bool important); bool parseViewportShorthand(CSSPropertyID propId, CSSPropertyID first, CSSPropertyID second, bool important); bool inViewport() const { return m_inViewport; } bool m_inViewport; #endif bool useLegacyBackgroundSizeShorthandBehavior() const; int (CSSParser::*m_lexFunc)(void*); std::unique_ptr>> m_recycledSelectorVector; std::unique_ptr m_supportsRuleDataStack; // defines units allowed for a certain property, used in parseUnit enum Units { FUnknown = 0x0000, FInteger = 0x0001, FNumber = 0x0002, // Real Numbers FPercent = 0x0004, FLength = 0x0008, FAngle = 0x0010, FTime = 0x0020, FFrequency = 0x0040, FPositiveInteger = 0x0080, FRelative = 0x0100, #if ENABLE(CSS_IMAGE_RESOLUTION) || ENABLE(RESOLUTION_MEDIA_QUERY) FResolution = 0x0200, #endif FNonNeg = 0x0400 }; friend inline Units operator|(Units a, Units b) { return static_cast(static_cast(a) | static_cast(b)); } enum ReleaseParsedCalcValueCondition { ReleaseParsedCalcValue, DoNotReleaseParsedCalcValue }; bool isLoggingErrors(); void logError(const String& message, int lineNumber, int columnNumber); bool validateCalculationUnit(ValueWithCalculation&, Units); bool shouldAcceptUnitLessValues(CSSParserValue&, Units, CSSParserMode); inline bool validateUnit(ValueWithCalculation& value, Units unitFlags) { return validateUnit(value, unitFlags, m_context.mode); } bool validateUnit(ValueWithCalculation&, Units, CSSParserMode); bool parseBorderImageQuad(Units, RefPtr&); int colorIntFromValue(ValueWithCalculation&); double parsedDouble(ValueWithCalculation&); friend class TransformOperationInfo; friend class FilterOperationInfo; }; CSSPropertyID cssPropertyID(const CSSParserString&); CSSPropertyID cssPropertyID(const String&); CSSValueID cssValueKeywordID(const CSSParserString&); #if PLATFORM(IOS) void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyNameAlias, unsigned& newLength); #endif class ShorthandScope { WTF_MAKE_FAST_ALLOCATED; public: ShorthandScope(CSSParser* 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: CSSParser* m_parser; }; struct CSSParser::Location { int lineNumber; int columnNumber; CSSParserString token; }; String quoteCSSString(const String&); String quoteCSSStringIfNeeded(const String&); String quoteCSSURLIfNeeded(const String&); bool isValidNthToken(const CSSParserString&); template <> inline void CSSParser::setTokenStart(LChar* tokenStart) { m_tokenStart.ptr8 = tokenStart; } template <> inline void CSSParser::setTokenStart(UChar* tokenStart) { m_tokenStart.ptr16 = tokenStart; } inline unsigned CSSParser::tokenStartOffset() { if (is8BitSource()) return m_tokenStart.ptr8 - m_dataStart8.get(); return m_tokenStart.ptr16 - m_dataStart16.get(); } unsigned CSSParser::currentCharacterOffset() { if (is8BitSource()) return m_currentCharacter8 - m_dataStart8.get(); return m_currentCharacter16 - m_dataStart16.get(); } inline UChar CSSParser::tokenStartChar() { if (is8BitSource()) return *m_tokenStart.ptr8; return *m_tokenStart.ptr16; } inline bool isCustomPropertyName(const String& propertyName) { return propertyName.length() > 2 && propertyName.characterAt(0) == '-' && propertyName.characterAt(1) == '-'; } inline int cssyylex(void* yylval, CSSParser* parser) { return parser->lex(yylval); } } // namespace WebCore #endif // CSSParser_h