/webview/native/Source/WebCore/css/CSSParser.cpp
C++ | 10081 lines | 8704 code | 919 blank | 458 comment | 3195 complexity | 80fbb512e7a4d7e468ae0655bce3d67d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- /*
- * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
- * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
- * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
- * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
- * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
- * Copyright (C) 2012 Adobe Systems Incorporated. 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.
- */
- #include "config.h"
- #include "CSSParser.h"
- #include "CSSAspectRatioValue.h"
- #include "CSSBorderImage.h"
- #include "CSSCanvasValue.h"
- #include "CSSCrossfadeValue.h"
- #include "CSSCursorImageValue.h"
- #include "CSSFontFaceRule.h"
- #include "CSSFontFaceSrcValue.h"
- #include "CSSFunctionValue.h"
- #include "CSSGradientValue.h"
- #include "CSSImageValue.h"
- #include "CSSInheritedValue.h"
- #include "CSSInitialValue.h"
- #include "CSSLineBoxContainValue.h"
- #include "CSSMediaRule.h"
- #include "CSSPageRule.h"
- #include "CSSPrimitiveValue.h"
- #include "CSSProperty.h"
- #include "CSSPropertySourceData.h"
- #include "CSSReflectValue.h"
- #include "CSSSelector.h"
- #include "CSSTimingFunctionValue.h"
- #include "CSSUnicodeRangeValue.h"
- #include "CSSValueKeywords.h"
- #include "CSSValueList.h"
- #include "CSSValuePool.h"
- #if ENABLE(CSS_VARIABLES)
- #include "CSSVariableValue.h"
- #endif
- #include "CSSWrapShapes.h"
- #include "Counter.h"
- #include "Document.h"
- #include "FloatConversion.h"
- #include "FontFeatureValue.h"
- #include "FontValue.h"
- #include "HTMLParserIdioms.h"
- #include "HashTools.h"
- #include "MediaList.h"
- #include "MediaQueryExp.h"
- #include "Page.h"
- #include "Pair.h"
- #include "Rect.h"
- #include "RenderTheme.h"
- #include "RuntimeEnabledFeatures.h"
- #include "SVGParserUtilities.h"
- #include "Settings.h"
- #include "ShadowValue.h"
- #include "StylePropertySet.h"
- #include "StylePropertyShorthand.h"
- #include "StyleRule.h"
- #include "StyleRuleImport.h"
- #include "StyleSheetContents.h"
- #include "TextEncoding.h"
- #include "WebKitCSSKeyframeRule.h"
- #include "WebKitCSSKeyframesRule.h"
- #include "WebKitCSSRegionRule.h"
- #include "WebKitCSSTransformValue.h"
- #include <limits.h>
- #include <wtf/BitArray.h>
- #include <wtf/HexNumber.h>
- #include <wtf/dtoa.h>
- #include <wtf/text/StringBuffer.h>
- #include <wtf/text/StringBuilder.h>
- #if ENABLE(CSS_IMAGE_SET)
- #include "CSSImageSetValue.h"
- #endif
- #if ENABLE(CSS_FILTERS)
- #include "WebKitCSSFilterValue.h"
- #if ENABLE(SVG)
- #include "WebKitCSSSVGDocumentValue.h"
- #endif
- #endif
- #if ENABLE(CSS_SHADERS)
- #include "WebKitCSSShaderValue.h"
- #endif
- #if ENABLE(DASHBOARD_SUPPORT)
- #include "DashboardRegion.h"
- #endif
- #define YYDEBUG 0
- #if YYDEBUG > 0
- extern int cssyydebug;
- #endif
- extern int cssyyparse(WebCore::CSSParser*);
- using namespace std;
- using namespace WTF;
- namespace {
- enum PropertyType {
- PropertyExplicit,
- PropertyImplicit
- };
- class ImplicitScope {
- WTF_MAKE_NONCOPYABLE(ImplicitScope);
- public:
- ImplicitScope(WebCore::CSSParser* parser, PropertyType propertyType)
- : m_parser(parser)
- {
- m_parser->m_implicitShorthand = propertyType == PropertyImplicit;
- }
- ~ImplicitScope()
- {
- m_parser->m_implicitShorthand = false;
- }
- private:
- WebCore::CSSParser* m_parser;
- };
- } // namespace
- namespace WebCore {
- static const unsigned INVALID_NUM_PARSED_PROPERTIES = UINT_MAX;
- static const double MAX_SCALE = 1000000;
- static bool equal(const CSSParserString& a, const char* b)
- {
- for (int i = 0; i < a.length; ++i) {
- if (!b[i])
- return false;
- if (a.characters[i] != b[i])
- return false;
- }
- return !b[a.length];
- }
- static bool equalIgnoringCase(const CSSParserString& a, const char* b)
- {
- for (int i = 0; i < a.length; ++i) {
- if (!b[i])
- return false;
- ASSERT(!isASCIIUpper(b[i]));
- if (toASCIILower(a.characters[i]) != b[i])
- return false;
- }
- return !b[a.length];
- }
- static bool hasPrefix(const char* string, unsigned length, const char* prefix)
- {
- for (unsigned i = 0; i < length; ++i) {
- if (!prefix[i])
- return true;
- if (string[i] != prefix[i])
- return false;
- }
- return false;
- }
-
- const CSSParserContext& strictCSSParserContext()
- {
- DEFINE_STATIC_LOCAL(CSSParserContext, strictContext, (CSSStrictMode));
- return strictContext;
- }
- CSSParserContext::CSSParserContext(CSSParserMode mode, const KURL& baseURL)
- : baseURL(baseURL)
- , mode(mode)
- , isHTMLDocument(false)
- , isCSSCustomFilterEnabled(false)
- , isCSSRegionsEnabled(false)
- , isCSSGridLayoutEnabled(false)
- #if ENABLE(CSS_VARIABLES)
- , isCSSVariablesEnabled(false)
- #endif
- , needsSiteSpecificQuirks(false)
- , enforcesCSSMIMETypeInNoQuirksMode(true)
- {
- }
- CSSParserContext::CSSParserContext(Document* document, const KURL& baseURL, const String& charset)
- : baseURL(baseURL.isNull() ? document->baseURL() : baseURL)
- , charset(charset)
- , mode(document->inQuirksMode() ? CSSQuirksMode : CSSStrictMode)
- , isHTMLDocument(document->isHTMLDocument())
- , isCSSCustomFilterEnabled(document->settings() ? document->settings()->isCSSCustomFilterEnabled() : false)
- , isCSSRegionsEnabled(document->cssRegionsEnabled())
- , isCSSGridLayoutEnabled(document->cssGridLayoutEnabled())
- #if ENABLE(CSS_VARIABLES)
- , isCSSVariablesEnabled(document->settings() ? document->settings()->cssVariablesEnabled() : false)
- #endif
- , needsSiteSpecificQuirks(document->settings() ? document->settings()->needsSiteSpecificQuirks() : false)
- , enforcesCSSMIMETypeInNoQuirksMode(!document->settings() || document->settings()->enforceCSSMIMETypeInNoQuirksMode())
- {
- }
- bool operator==(const CSSParserContext& a, const CSSParserContext& b)
- {
- return a.baseURL == b.baseURL
- && a.charset == b.charset
- && a.mode == b.mode
- && a.isHTMLDocument == b.isHTMLDocument
- && a.isCSSCustomFilterEnabled == b.isCSSCustomFilterEnabled
- && a.isCSSRegionsEnabled == b.isCSSRegionsEnabled
- && a.isCSSGridLayoutEnabled == b.isCSSGridLayoutEnabled
- #if ENABLE(CSS_VARIABLES)
- && a.isCSSVariablesEnabled == b.isCSSVariablesEnabled
- #endif
- && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
- && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode;
- }
- CSSParser::CSSParser(const CSSParserContext& context)
- : m_context(context)
- , m_important(false)
- , m_id(CSSPropertyInvalid)
- , m_styleSheet(0)
- , m_selectorListForParseSelector(0)
- , m_numParsedPropertiesBeforeMarginBox(INVALID_NUM_PARSED_PROPERTIES)
- , m_inParseShorthand(0)
- , m_currentShorthand(CSSPropertyInvalid)
- , m_implicitShorthand(false)
- , m_hasFontFaceOnlyValues(false)
- , m_hadSyntacticallyValidCSSRule(false)
- , m_defaultNamespace(starAtom)
- , m_parsedTextPrefixLength(0)
- , m_propertyRange(UINT_MAX, UINT_MAX)
- , m_ruleSourceDataResult(0)
- , m_parsingMode(NormalMode)
- , m_currentCharacter(0)
- , m_tokenStart(0)
- , m_token(0)
- , m_lineNumber(0)
- , m_lastSelectorLineNumber(0)
- , m_allowImportRules(true)
- , m_allowNamespaceDeclarations(true)
- {
- #if YYDEBUG > 0
- cssyydebug = 1;
- #endif
- CSSPropertySourceData::init();
- }
- CSSParser::~CSSParser()
- {
- clearProperties();
- fastDeleteAllValues(m_floatingSelectors);
- deleteAllValues(m_floatingSelectorVectors);
- deleteAllValues(m_floatingValueLists);
- deleteAllValues(m_floatingFunctions);
- }
- void CSSParserString::lower()
- {
- // FIXME: If we need Unicode lowercasing here, then we probably want the real kind
- // that can potentially change the length of the string rather than the character
- // by character kind. If we don't need Unicode lowercasing, it would be good to
- // simplify this function.
- if (charactersAreAllASCII(characters, length)) {
- // Fast case for all-ASCII.
- for (int i = 0; i < length; i++)
- characters[i] = toASCIILower(characters[i]);
- } else {
- for (int i = 0; i < length; i++)
- characters[i] = Unicode::toLower(characters[i]);
- }
- }
- void CSSParser::setupParser(const char* prefix, const String& string, const char* suffix)
- {
- m_parsedTextPrefixLength = strlen(prefix);
- int length = string.length() + m_parsedTextPrefixLength + strlen(suffix) + 1;
- m_dataStart = adoptArrayPtr(new UChar[length]);
- for (unsigned i = 0; i < m_parsedTextPrefixLength; i++)
- m_dataStart[i] = prefix[i];
- memcpy(m_dataStart.get() + m_parsedTextPrefixLength, string.characters(), string.length() * sizeof(UChar));
- unsigned start = m_parsedTextPrefixLength + string.length();
- unsigned end = start + strlen(suffix);
- for (unsigned i = start; i < end; i++)
- m_dataStart[i] = suffix[i - start];
- m_dataStart[length - 1] = 0;
- m_currentCharacter = m_tokenStart = m_dataStart.get();
- }
- void CSSParser::parseSheet(StyleSheetContents* sheet, const String& string, int startLineNumber, RuleSourceDataList* ruleSourceDataResult)
- {
- setStyleSheet(sheet);
- m_defaultNamespace = starAtom; // Reset the default namespace.
- if (ruleSourceDataResult)
- m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
- m_ruleSourceDataResult = ruleSourceDataResult;
- m_lineNumber = startLineNumber;
- setupParser("", string, "");
- cssyyparse(this);
- m_currentRuleDataStack.clear();
- m_ruleSourceDataResult = 0;
- m_rule = 0;
- }
- PassRefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
- {
- setStyleSheet(sheet);
- m_allowNamespaceDeclarations = false;
- setupParser("@-webkit-rule{", string, "} ");
- cssyyparse(this);
- return m_rule.release();
- }
- PassRefPtr<StyleKeyframe> CSSParser::parseKeyframeRule(StyleSheetContents* sheet, const String& string)
- {
- setStyleSheet(sheet);
- setupParser("@-webkit-keyframe-rule{ ", string, "} ");
- cssyyparse(this);
- return m_keyframe.release();
- }
- static inline bool isColorPropertyID(CSSPropertyID propertyId)
- {
- switch (propertyId) {
- case CSSPropertyColor:
- case CSSPropertyBackgroundColor:
- case CSSPropertyBorderBottomColor:
- case CSSPropertyBorderLeftColor:
- case CSSPropertyBorderRightColor:
- case CSSPropertyBorderTopColor:
- case CSSPropertyOutlineColor:
- case CSSPropertyTextLineThroughColor:
- case CSSPropertyTextOverlineColor:
- case CSSPropertyTextUnderlineColor:
- case CSSPropertyWebkitBorderAfterColor:
- case CSSPropertyWebkitBorderBeforeColor:
- case CSSPropertyWebkitBorderEndColor:
- case CSSPropertyWebkitBorderStartColor:
- case CSSPropertyWebkitColumnRuleColor:
- case CSSPropertyWebkitTextEmphasisColor:
- case CSSPropertyWebkitTextFillColor:
- case CSSPropertyWebkitTextStrokeColor:
- return true;
- default:
- return false;
- }
- }
- static bool parseColorValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
- {
- ASSERT(!string.isEmpty());
- bool strict = isStrictParserMode(cssParserMode);
- if (!isColorPropertyID(propertyId))
- return false;
- CSSParserString cssString;
- cssString.characters = const_cast<UChar*>(string.characters());
- cssString.length = string.length();
- int valueID = cssValueKeywordID(cssString);
- bool validPrimitive = false;
- if (valueID == CSSValueWebkitText)
- validPrimitive = true;
- else if (valueID == CSSValueCurrentcolor)
- validPrimitive = true;
- else if ((valueID >= CSSValueAqua && valueID <= CSSValueWindowtext) || valueID == CSSValueMenu
- || (valueID >= CSSValueWebkitFocusRingColor && valueID < CSSValueWebkitText && !strict)) {
- validPrimitive = true;
- }
- if (validPrimitive) {
- RefPtr<CSSValue> value = cssValuePool().createIdentifierValue(valueID);
- declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
- return true;
- }
- RGBA32 color;
- if (!CSSParser::fastParseColor(color, string, strict && string[0] != '#'))
- return false;
- RefPtr<CSSValue> value = cssValuePool().createColorValue(color);
- declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
- return true;
- }
- static inline bool isSimpleLengthPropertyID(CSSPropertyID propertyId, bool& acceptsNegativeNumbers)
- {
- switch (propertyId) {
- case CSSPropertyFontSize:
- case CSSPropertyHeight:
- case CSSPropertyWidth:
- case CSSPropertyMinHeight:
- case CSSPropertyMinWidth:
- case CSSPropertyPaddingBottom:
- case CSSPropertyPaddingLeft:
- case CSSPropertyPaddingRight:
- case CSSPropertyPaddingTop:
- case CSSPropertyWebkitLogicalWidth:
- case CSSPropertyWebkitLogicalHeight:
- case CSSPropertyWebkitMinLogicalWidth:
- case CSSPropertyWebkitMinLogicalHeight:
- case CSSPropertyWebkitPaddingAfter:
- case CSSPropertyWebkitPaddingBefore:
- case CSSPropertyWebkitPaddingEnd:
- case CSSPropertyWebkitPaddingStart:
- acceptsNegativeNumbers = false;
- return true;
- #if ENABLE(CSS_EXCLUSIONS)
- case CSSPropertyWebkitWrapMargin:
- case CSSPropertyWebkitWrapPadding:
- acceptsNegativeNumbers = false;
- return RuntimeEnabledFeatures::cssExclusionsEnabled();
- #endif
- case CSSPropertyBottom:
- case CSSPropertyLeft:
- case CSSPropertyMarginBottom:
- case CSSPropertyMarginLeft:
- case CSSPropertyMarginRight:
- case CSSPropertyMarginTop:
- case CSSPropertyRight:
- case CSSPropertyTextIndent:
- case CSSPropertyTop:
- case CSSPropertyWebkitMarginAfter:
- case CSSPropertyWebkitMarginBefore:
- case CSSPropertyWebkitMarginEnd:
- case CSSPropertyWebkitMarginStart:
- acceptsNegativeNumbers = true;
- return true;
- default:
- return false;
- }
- }
- template <typename CharType>
- static inline bool parseSimpleLength(const CharType* characters, unsigned& length, CSSPrimitiveValue::UnitTypes& unit, double& number)
- {
- if (length > 2 && (characters[length - 2] | 0x20) == 'p' && (characters[length - 1] | 0x20) == 'x') {
- length -= 2;
- unit = CSSPrimitiveValue::CSS_PX;
- } else if (length > 1 && characters[length - 1] == '%') {
- length -= 1;
- unit = CSSPrimitiveValue::CSS_PERCENTAGE;
- }
- // We rely on charactersToDouble for validation as well. The function
- // will set "ok" to "false" if the entire passed-in character range does
- // not represent a double.
- bool ok;
- number = charactersToDouble(characters, length, &ok);
- return ok;
- }
- static bool parseSimpleLengthValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, CSSParserMode cssParserMode)
- {
- ASSERT(!string.isEmpty());
- bool acceptsNegativeNumbers;
- if (!isSimpleLengthPropertyID(propertyId, acceptsNegativeNumbers))
- return false;
- unsigned length = string.length();
- double number;
- CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
- if (string.is8Bit()) {
- if (!parseSimpleLength(string.characters8(), length, unit, number))
- return false;
- } else {
- if (!parseSimpleLength(string.characters16(), length, unit, number))
- return false;
- }
- if (unit == CSSPrimitiveValue::CSS_NUMBER) {
- if (number && isStrictParserMode(cssParserMode))
- return false;
- unit = CSSPrimitiveValue::CSS_PX;
- }
- if (number < 0 && !acceptsNegativeNumbers)
- return false;
- RefPtr<CSSValue> value = cssValuePool().createValue(number, unit);
- declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
- return true;
- }
- static inline bool isValidKeywordPropertyAndValue(CSSPropertyID propertyId, int valueID, const CSSParserContext& parserContext)
- {
- if (!valueID)
- return false;
- switch (propertyId) {
- case CSSPropertyBorderCollapse: // collapse | separate | inherit
- if (valueID == CSSValueCollapse || valueID == CSSValueSeparate)
- return true;
- break;
- case CSSPropertyBorderTopStyle: // <border-style> | inherit
- case CSSPropertyBorderRightStyle: // Defined as: none | hidden | dotted | dashed |
- case CSSPropertyBorderBottomStyle: // solid | double | groove | ridge | inset | outset
- case CSSPropertyBorderLeftStyle:
- case CSSPropertyWebkitBorderAfterStyle:
- case CSSPropertyWebkitBorderBeforeStyle:
- case CSSPropertyWebkitBorderEndStyle:
- case CSSPropertyWebkitBorderStartStyle:
- case CSSPropertyWebkitColumnRuleStyle:
- if (valueID >= CSSValueNone && valueID <= CSSValueDouble)
- return true;
- break;
- case CSSPropertyBoxSizing:
- if (valueID == CSSValueBorderBox || valueID == CSSValueContentBox)
- return true;
- break;
- case CSSPropertyCaptionSide: // top | bottom | left | right | inherit
- if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueTop || valueID == CSSValueBottom)
- return true;
- break;
- case CSSPropertyClear: // none | left | right | both | inherit
- if (valueID == CSSValueNone || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueBoth)
- return true;
- break;
- case CSSPropertyDirection: // ltr | rtl | inherit
- if (valueID == CSSValueLtr || valueID == CSSValueRtl)
- return true;
- break;
- case CSSPropertyDisplay:
- // inline | block | list-item | run-in | inline-block | table |
- // inline-table | table-row-group | table-header-group | table-footer-group | table-row |
- // table-column-group | table-column | table-cell | table-caption | -webkit-box | -webkit-inline-box | none | inherit
- // -webkit-flex | -webkit-inline-flex | -webkit-grid | -webkit-inline-grid
- if ((valueID >= CSSValueInline && valueID <= CSSValueWebkitInlineBox) || valueID == CSSValueNone)
- return true;
- #if ENABLE(CSS3_FLEXBOX)
- if (valueID == CSSValueWebkitFlex || valueID == CSSValueWebkitInlineFlex)
- return true;
- #endif
- if (parserContext.isCSSGridLayoutEnabled && (valueID == CSSValueWebkitGrid || valueID == CSSValueWebkitInlineGrid))
- return true;
- break;
- case CSSPropertyEmptyCells: // show | hide | inherit
- if (valueID == CSSValueShow || valueID == CSSValueHide)
- return true;
- break;
- case CSSPropertyFloat: // left | right | none | center (for buggy CSS, maps to none)
- if (valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueNone || valueID == CSSValueCenter)
- return true;
- break;
- case CSSPropertyFontStyle: // normal | italic | oblique | inherit
- if (valueID == CSSValueNormal || valueID == CSSValueItalic || valueID == CSSValueOblique)
- return true;
- break;
- case CSSPropertyImageRendering: // auto | optimizeContrast
- if (valueID == CSSValueAuto || valueID == CSSValueWebkitOptimizeContrast)
- return true;
- break;
- case CSSPropertyListStylePosition: // inside | outside | inherit
- if (valueID == CSSValueInside || valueID == CSSValueOutside)
- return true;
- break;
- case CSSPropertyListStyleType:
- // See section CSS_PROP_LIST_STYLE_TYPE of file CSSValueKeywords.in
- // for the list of supported list-style-types.
- if ((valueID >= CSSValueDisc && valueID <= CSSValueKatakanaIroha) || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyOutlineStyle: // (<border-style> except hidden) | auto | inherit
- if (valueID == CSSValueAuto || valueID == CSSValueNone || (valueID >= CSSValueInset && valueID <= CSSValueDouble))
- return true;
- break;
- case CSSPropertyOverflowX:
- case CSSPropertyOverflowY: // visible | hidden | scroll | auto | marquee | overlay | inherit
- if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueScroll || valueID == CSSValueAuto || valueID == CSSValueOverlay || valueID == CSSValueWebkitMarquee)
- return true;
- break;
- case CSSPropertyPageBreakAfter: // auto | always | avoid | left | right | inherit
- case CSSPropertyPageBreakBefore:
- case CSSPropertyWebkitColumnBreakAfter:
- case CSSPropertyWebkitColumnBreakBefore:
- if (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight)
- return true;
- break;
- case CSSPropertyPageBreakInside: // avoid | auto | inherit
- case CSSPropertyWebkitColumnBreakInside:
- if (valueID == CSSValueAuto || valueID == CSSValueAvoid)
- return true;
- break;
- case CSSPropertyPointerEvents:
- // none | visiblePainted | visibleFill | visibleStroke | visible |
- // painted | fill | stroke | auto | all | inherit
- if (valueID == CSSValueVisible || valueID == CSSValueNone || valueID == CSSValueAll || valueID == CSSValueAuto || (valueID >= CSSValueVisiblepainted && valueID <= CSSValueStroke))
- return true;
- break;
- case CSSPropertyPosition: // static | relative | absolute | fixed | inherit
- if (valueID == CSSValueStatic || valueID == CSSValueRelative || valueID == CSSValueAbsolute || valueID == CSSValueFixed)
- return true;
- break;
- case CSSPropertyResize: // none | both | horizontal | vertical | auto
- if (valueID == CSSValueNone || valueID == CSSValueBoth || valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueAuto)
- return true;
- break;
- case CSSPropertySpeak: // none | normal | spell-out | digits | literal-punctuation | no-punctuation | inherit
- if (valueID == CSSValueNone || valueID == CSSValueNormal || valueID == CSSValueSpellOut || valueID == CSSValueDigits || valueID == CSSValueLiteralPunctuation || valueID == CSSValueNoPunctuation)
- return true;
- break;
- case CSSPropertyTableLayout: // auto | fixed | inherit
- if (valueID == CSSValueAuto || valueID == CSSValueFixed)
- return true;
- break;
- case CSSPropertyTextLineThroughMode:
- case CSSPropertyTextOverlineMode:
- case CSSPropertyTextUnderlineMode:
- if (valueID == CSSValueContinuous || valueID == CSSValueSkipWhiteSpace)
- return true;
- break;
- case CSSPropertyTextLineThroughStyle:
- case CSSPropertyTextOverlineStyle:
- case CSSPropertyTextUnderlineStyle:
- if (valueID == CSSValueNone || valueID == CSSValueSolid || valueID == CSSValueDouble || valueID == CSSValueDashed || valueID == CSSValueDotDash || valueID == CSSValueDotDotDash || valueID == CSSValueWave)
- return true;
- break;
- case CSSPropertyTextOverflow: // clip | ellipsis
- if (valueID == CSSValueClip || valueID == CSSValueEllipsis)
- return true;
- break;
- case CSSPropertyTextRendering: // auto | optimizeSpeed | optimizeLegibility | geometricPrecision
- if (valueID == CSSValueAuto || valueID == CSSValueOptimizespeed || valueID == CSSValueOptimizelegibility || valueID == CSSValueGeometricprecision)
- return true;
- break;
- case CSSPropertyTextTransform: // capitalize | uppercase | lowercase | none | inherit
- if ((valueID >= CSSValueCapitalize && valueID <= CSSValueLowercase) || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyVisibility: // visible | hidden | collapse | inherit
- if (valueID == CSSValueVisible || valueID == CSSValueHidden || valueID == CSSValueCollapse)
- return true;
- break;
- case CSSPropertyWebkitAppearance:
- if ((valueID >= CSSValueCheckbox && valueID <= CSSValueTextarea) || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyWebkitBackfaceVisibility:
- if (valueID == CSSValueVisible || valueID == CSSValueHidden)
- return true;
- break;
- case CSSPropertyWebkitBorderFit:
- if (valueID == CSSValueBorder || valueID == CSSValueLines)
- return true;
- break;
- case CSSPropertyWebkitBoxAlign:
- if (valueID == CSSValueStretch || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline)
- return true;
- break;
- #if ENABLE(CSS_BOX_DECORATION_BREAK)
- case CSSPropertyWebkitBoxDecorationBreak:
- if (valueID == CSSValueClone || valueID == CSSValueSlice)
- return true;
- break;
- #endif
- case CSSPropertyWebkitBoxDirection:
- if (valueID == CSSValueNormal || valueID == CSSValueReverse)
- return true;
- break;
- case CSSPropertyWebkitBoxLines:
- if (valueID == CSSValueSingle || valueID == CSSValueMultiple)
- return true;
- break;
- case CSSPropertyWebkitBoxOrient:
- if (valueID == CSSValueHorizontal || valueID == CSSValueVertical || valueID == CSSValueInlineAxis || valueID == CSSValueBlockAxis)
- return true;
- break;
- case CSSPropertyWebkitBoxPack:
- if (valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueCenter || valueID == CSSValueJustify)
- return true;
- break;
- case CSSPropertyWebkitColorCorrection:
- if (valueID == CSSValueSrgb || valueID == CSSValueDefault)
- return true;
- break;
- #if ENABLE(CSS3_FLEXBOX)
- case CSSPropertyWebkitAlignContent:
- if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround || valueID == CSSValueStretch)
- return true;
- break;
- case CSSPropertyWebkitAlignItems:
- if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
- return true;
- break;
- case CSSPropertyWebkitAlignSelf:
- if (valueID == CSSValueAuto || valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueBaseline || valueID == CSSValueStretch)
- return true;
- break;
- case CSSPropertyWebkitFlexDirection:
- if (valueID == CSSValueRow || valueID == CSSValueRowReverse || valueID == CSSValueColumn || valueID == CSSValueColumnReverse)
- return true;
- break;
- case CSSPropertyWebkitFlexWrap:
- if (valueID == CSSValueNone || valueID == CSSValueWrap || valueID == CSSValueWrapReverse)
- return true;
- break;
- case CSSPropertyWebkitJustifyContent:
- if (valueID == CSSValueFlexStart || valueID == CSSValueFlexEnd || valueID == CSSValueCenter || valueID == CSSValueSpaceBetween || valueID == CSSValueSpaceAround)
- return true;
- break;
- #endif
- case CSSPropertyWebkitFontKerning:
- if (valueID == CSSValueAuto || valueID == CSSValueNormal || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyWebkitFontSmoothing:
- if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueAntialiased || valueID == CSSValueSubpixelAntialiased)
- return true;
- break;
- case CSSPropertyWebkitHyphens:
- if (valueID == CSSValueNone || valueID == CSSValueManual || valueID == CSSValueAuto)
- return true;
- break;
- case CSSPropertyWebkitLineAlign:
- if (valueID == CSSValueNone || valueID == CSSValueEdges)
- return true;
- break;
- case CSSPropertyWebkitLineBreak: // normal | after-white-space
- if (valueID == CSSValueNormal || valueID == CSSValueAfterWhiteSpace)
- return true;
- break;
- case CSSPropertyWebkitLineSnap:
- if (valueID == CSSValueNone || valueID == CSSValueBaseline || valueID == CSSValueContain)
- return true;
- break;
- case CSSPropertyWebkitMarginAfterCollapse:
- case CSSPropertyWebkitMarginBeforeCollapse:
- case CSSPropertyWebkitMarginBottomCollapse:
- case CSSPropertyWebkitMarginTopCollapse:
- if (valueID == CSSValueCollapse || valueID == CSSValueSeparate || valueID == CSSValueDiscard)
- return true;
- break;
- case CSSPropertyWebkitMarqueeDirection:
- if (valueID == CSSValueForwards || valueID == CSSValueBackwards || valueID == CSSValueAhead || valueID == CSSValueReverse || valueID == CSSValueLeft || valueID == CSSValueRight || valueID == CSSValueDown
- || valueID == CSSValueUp || valueID == CSSValueAuto)
- return true;
- break;
- case CSSPropertyWebkitMarqueeStyle:
- if (valueID == CSSValueNone || valueID == CSSValueSlide || valueID == CSSValueScroll || valueID == CSSValueAlternate)
- return true;
- break;
- case CSSPropertyWebkitNbspMode: // normal | space
- if (valueID == CSSValueNormal || valueID == CSSValueSpace)
- return true;
- break;
- #if ENABLE(OVERFLOW_SCROLLING)
- case CSSPropertyWebkitOverflowScrolling:
- if (valueID == CSSValueAuto || valueID == CSSValueTouch)
- return true;
- break;
- #endif
- case CSSPropertyWebkitPrintColorAdjust:
- if (valueID == CSSValueExact || valueID == CSSValueEconomy)
- return true;
- break;
- #if ENABLE(CSS_REGIONS)
- case CSSPropertyWebkitRegionBreakAfter:
- case CSSPropertyWebkitRegionBreakBefore:
- if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAlways || valueID == CSSValueAvoid || valueID == CSSValueLeft || valueID == CSSValueRight))
- return true;
- break;
- case CSSPropertyWebkitRegionBreakInside:
- if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueAvoid))
- return true;
- break;
- case CSSPropertyWebkitRegionOverflow:
- if (parserContext.isCSSRegionsEnabled && (valueID == CSSValueAuto || valueID == CSSValueBreak))
- return true;
- break;
- #endif
- case CSSPropertyWebkitRtlOrdering:
- if (valueID == CSSValueLogical || valueID == CSSValueVisual)
- return true;
- break;
- case CSSPropertyWebkitTextCombine:
- if (valueID == CSSValueNone || valueID == CSSValueHorizontal)
- return true;
- break;
- case CSSPropertyWebkitTextEmphasisPosition:
- if (valueID == CSSValueOver || valueID == CSSValueUnder)
- return true;
- break;
- case CSSPropertyWebkitTextSecurity:
- // disc | circle | square | none | inherit
- if (valueID == CSSValueDisc || valueID == CSSValueCircle || valueID == CSSValueSquare || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyWebkitTextSizeAdjust:
- if (valueID == CSSValueAuto || valueID == CSSValueNone)
- return true;
- break;
- case CSSPropertyWebkitTransformStyle:
- if (valueID == CSSValueFlat || valueID == CSSValuePreserve3d)
- return true;
- break;
- case CSSPropertyWebkitUserDrag: // auto | none | element
- if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueElement)
- return true;
- break;
- case CSSPropertyWebkitUserModify: // read-only | read-write
- if (valueID == CSSValueReadOnly || valueID == CSSValueReadWrite || valueID == CSSValueReadWritePlaintextOnly)
- return true;
- break;
- case CSSPropertyWebkitUserSelect: // auto | none | text
- if (valueID == CSSValueAuto || valueID == CSSValueNone || valueID == CSSValueText)
- return true;
- break;
- #if ENABLE(CSS_EXCLUSIONS)
- case CSSPropertyWebkitWrapFlow:
- if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
- return false;
- if (valueID == CSSValueAuto || valueID == CSSValueBoth || valueID == CSSValueStart || valueID == CSSValueEnd || valueID == CSSValueMaximum || valueID == CSSValueClear)
- return true;
- break;
- case CSSPropertyWebkitWrapThrough:
- if (!RuntimeEnabledFeatures::cssExclusionsEnabled())
- return false;
- if (valueID == CSSValueWrap || valueID == CSSValueNone)
- return true;
- break;
- #endif
- case CSSPropertyWebkitWritingMode:
- if (valueID >= CSSValueHorizontalTb && valueID <= CSSValueHorizontalBt)
- return true;
- break;
- case CSSPropertyWhiteSpace: // normal | pre | nowrap | inherit
- if (valueID == CSSValueNormal || valueID == CSSValuePre || valueID == CSSValuePreWrap || valueID == CSSValuePreLine || valueID == CSSValueNowrap)
- return true;
- break;
- case CSSPropertyWordBreak: // normal | break-all | break-word (this is a custom extension)
- if (valueID == CSSValueNormal || valueID == CSSValueBreakAll || valueID == CSSValueBreakWord)
- return true;
- break;
- case CSSPropertyWordWrap: // normal | break-word
- if (valueID == CSSValueNormal || valueID == CSSValueBreakWord)
- return true;
- break;
- default:
- ASSERT_NOT_REACHED();
- return false;
- }
- return false;
- }
- static inline bool isKeywordPropertyID(CSSPropertyID propertyId)
- {
- switch (propertyId) {
- 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 CSSPropertyOutlineStyle:
- case CSSPropertyOverflowX:
- case CSSPropertyOverflowY:
- case CSSPropertyPageBreakAfter:
- case CSSPropertyPageBreakBefore:
- case CSSPropertyPageBreakInside:
- case CSSPropertyPointerEvents:
- case CSSPropertyPosition:
- case CSSPropertyResize:
- case CSSPropertySpeak:
- case CSSPropertyTableLayout:
- case CSSPropertyTextLineThroughMode:
- case CSSPropertyTextLineThroughStyle:
- case CSSPropertyTextOverflow:
- case CSSPropertyTextOverlineMode:
- case CSSPropertyTextOverlineStyle:
- case CSSPropertyTextRendering:
- case CSSPropertyTextTransform:
- case CSSPropertyTextUnderlineMode:
- case CSSPropertyTextUnderlineStyle:
- case CSSPropertyVisibility:
- case CSSPropertyWebkitAppearance:
- case CSSPropertyWebkitBackfaceVisibility:
- case CSSPropertyWebkitBorderAfterStyle:
- case CSSPropertyWebkitBorderBeforeStyle:
- case CSSPropertyWebkitBorderEndStyle:
- case CSSPropertyWebkitBorderFit:
- case CSSPropertyWebkitBorderStartStyle:
- case CSSPropertyWebkitBoxAlign:
- #if ENABLE(CSS_BOX_DECORATION_BREAK)
- case CSSPropertyWebkitBoxDecorationBreak:
- #endif
- case CSSPropertyWebkitBoxDirection:
- case CSSPropertyWebkitBoxLines:
- case CSSPropertyWebkitBoxOrient:
- case CSSPropertyWebkitBoxPack:
- case CSSPropertyWebkitColorCorrection:
- case CSSPropertyWebkitColumnBreakAfter:
- case CSSPropertyWebkitColumnBreakBefore:
- case CSSPropertyWebkitColumnBreakInside:
- case CSSPropertyWebkitColumnRuleStyle:
- #if ENABLE(CSS3_FLEXBOX)
- case CSSPropertyWebkitAlignContent:
- case CSSPropertyWebkitAlignItems:
- case CSSPropertyWebkitAlignSelf:
- case CSSPropertyWebkitFlexDirection:
- case CSSPropertyWebkitFlexWrap:
- case CSSPropertyWebkitJustifyContent:
- #endif
- case CSSPropertyWebkitFontKerning:
- case CSSPropertyWebkitFontSmoothing:
- case CSSPropertyWebkitHyphens:
- case CSSPropertyWebkitLineAlign:
- case CSSPropertyWebkitLineBreak:
- case CSSPropertyWebkitLineSnap:
- case CSSPropertyWebkitMarginAfterCollapse:
- case CSSPropertyWebkitMarginBeforeCollapse:
- case CSSPropertyWebkitMarginBottomCollapse:
- case CSSPropertyWebkitMarginTopCollapse:
- case CSSPropertyWebkitMarqueeDirection:
- case CSSPropertyWebkitMarqueeStyle:
- case CSSPropertyWebkitNbspMode:
- #if ENABLE(OVERFLOW_SCROLLING)
- case CSSPropertyWebkitOverflowScrolling:
- #endif
- case CSSPropertyWebkitPrintColorAdjust:
- #if ENABLE(CSS_REGIONS)
- case CSSPropertyWebkitRegionBreakAfter:
- case CSSPropertyWebkitRegionBreakBefore:
- case CSSPropertyWebkitRegionBreakInside:
- case CSSPropertyWebkitRegionOverflow:
- #endif
- case CSSPropertyWebkitRtlOrdering:
- case CSSPropertyWebkitTextCombine:
- case CSSPropertyWebkitTextEmphasisPosition:
- case CSSPropertyWebkitTextSecurity:
- case CSSPropertyWebkitTextSizeAdjust:
- case CSSPropertyWebkitTransformStyle:
- case CSSPropertyWebkitUserDrag:
- case CSSPropertyWebkitUserModify:
- case CSSPropertyWebkitUserSelect:
- #if ENABLE(CSS_EXCLUSIONS)
- case CSSPropertyWebkitWrapFlow:
- case CSSPropertyWebkitWrapThrough:
- #endif
- case CSSPropertyWebkitWritingMode:
- case CSSPropertyWhiteSpace:
- case CSSPropertyWordBreak:
- case CSSPropertyWordWrap:
- return true;
- default:
- return false;
- }
- }
- static bool parseKeywordValue(StylePropertySet* declaration, CSSPropertyID propertyId, const String& string, bool important, const CSSParserContext& parserContext)
- {
- ASSERT(!string.isEmpty());
- if (!isKeywordPropertyID(propertyId))
- return false;
- CSSParserString cssString;
- cssString.characters = const_cast<UChar*>(string.characters());
- cssString.length = string.length();
- int valueID = cssValueKeywordID(cssString);
- if (!valueID)
- return false;
- RefPtr<CSSValue> value;
- if (valueID == CSSValueInherit)
- value = cssValuePool().createInheritedValue();
- else if (valueID == CSSValueInitial)
- value = cssValuePool().createExplicitInitialValue();
- else if (isValidKeywordPropertyAndValue(propertyId, valueID, parserContext))
- value = cssValuePool().createIdentifierValue(valueID);
- else
- return false;
- declaration->addParsedProperty(CSSProperty(propertyId, value.release(), important));
- return true;
- }
- template <typename CharType>
- static bool parseTransformArguments(WebKitCSSTransformValue* transformValue, CharType* characters, unsigned length, unsigned start, unsigned expectedCount)
- {
- while (expectedCount) {
- size_t end = WTF::find(characters, length, expectedCount == 1 ? ')' : ',', start);
- if (end == notFound || (expectedCount == 1 && end != length - 1))
- return false;
- unsigned argumentLength = end - start;
- CSSPrimitiveValue::UnitTypes unit = CSSPrimitiveValue::CSS_NUMBER;
- double number;
- if (!parseSimpleLength(characters + start, argumentLength, unit, number))
- return false;
- if (unit != CSSPrimitiveValue::CSS_PX && (number || unit != CSSPrimitiveValue::CSS_NUMBER))
- return false;
- transformValue->append(cssValuePool().createValue(number, unit));
- start = end + 1;
- --expectedCount;
- }
- return true;
- }
- static bool parseTransformValue(StylePropertySet* properties, CSSPropertyID propertyID, const String& string, bool important)
- {
- if (propertyID != CSSPropertyWebkitTransform)
- return false;
- static const unsigned shortestValidTransformStringLength = 12;
- static const unsigned likelyMultipartTransformStringLengthCutoff = 32;
- if (string.length() < shortestValidTransformStringLength || string.length() > likelyMultipartTransformStringLengthCutoff)
- return false;
- if (!string.startsWith("translate", false))
- return false;
- UChar c9 = toASCIILower(string[9]);
- UChar c10 = toASCIILower(string[10]);
- WebKitCSSTransformValue::TransformOperationType transformType;
- unsigned expectedArgumentCount = 1;
- unsigned argumentStart = 11;
- if (c9 == 'x' && c10 == '(')
- transformType = WebKitCSSTransformValue::TranslateXTransformOperation;
- else if (c9 == 'y' && c10 == '(')
- transformType = WebKitCSSTransformValue::TranslateYTransformOperation;
- else if (c9 == 'z' && c10 == '(')
- transformType = WebKitCSSTransformValue::TranslateZTransformOperation;
- else if (c9 == '(') {
- transformType = WebKitCSSTransformValue::TranslateTransformOperation;
- expectedArgumentCount = 2;
- argumentStart = 10;
- } else if (c9 == '3' && c10 == 'd' && string[11] == '(') {
- transformType = WebKitCSSTransformValue::Translate3DTransformOperation;
- expectedArgumentCount = 3;
- argumentStart = 12;
- } else
- return false;
- RefPtr<WebKitCSSTransformValue> transformValue = WebKitCSSTransformValue::create(transformType);
- bool success;
- if (string.is8Bit())
- success = parseTransformArguments(transformValue.get(), string.characters8(), string.length(), argumentStart, expectedArgumentCount);
- else
- success = parseTransformArguments(transformValue.get(), string.characters16(), string.length(), argumentStart, expectedArgumentCount);
- if (!success)
- return false;
- RefPtr<CSSValueList> result = CSSValueList::createSpaceSeparated();
- result->append(transformValue.release());
- properties->addParsedProperty(CSSProperty(CSSPropertyWebkitTransform, result.release(), important));
- return true;
- }
- PassRefPtr<CSSValueList> CSSParser::parseFontFaceValue(const AtomicString& string)
- {
- if (string.isEmpty())
- return 0;
- RefPtr<StylePropertySet> dummyStyle = StylePropertySet::create();
- if (!parseValue(dummyStyle.get(), CSSPropertyFontFamily, string, false, CSSQuirksMode, 0))
- return 0;
- return static_pointer_cast<CSSValueList>(dummyStyle->getPropertyCSSValue(CSSPropertyFontFamily));
- }
- #if ENABLE(CSS_VARIABLES)
- bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, Document* document)
- {
- ASSERT(!string.isEmpty());
- CSSParserContext context(document);
- if (parseSimpleLengthValue(declaration, propertyID, string, important, context.mode))
- return true;
- if (parseColorValue(declaration, propertyID, string, important, context.mode))
- return true;
- if (parseKeywordValue(declaration, propertyID, string, important, context))
- return true;
- CSSParser parser(context);
- return parser.parseValue(declaration, propertyID, string, important, static_cast<StyleSheetContents*>(0));
- }
- #endif
- bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, CSSParserMode cssParserMode, StyleSheetContents* contextStyleSheet)
- {
- ASSERT(!string.isEmpty());
- if (parseSimpleLengthValue(declaration, propertyID, string, important, cssParserMode))
- return true;
- if (parseColorValue(declaration, propertyID, string, important, cssParserMode))
- return true;
- if (parseKeywordValue(declaration, propertyID, string, important, contextStyleSheet->parserContext()))
- return true;
- if (parseTransformValue(declaration, propertyID, string, important))
- return true;
- CSSParserContext context(cssParserMode);
- if (contextStyleSheet) {
- context = contextStyleSheet->parserContext();
- context.mode = cssParserMode;
- }
- CSSParser parser(context);
- return parser.parseValue(declaration, propertyID, string, important, contextStyleSheet);
- }
- bool CSSParser::parseValue(StylePropertySet* declaration, CSSPropertyID propertyID, const String& string, bool important, StyleSheetContents* contextStyleSheet)
- {
- setStyleSheet(contextStyleSheet);
- setupParser("@-webkit-value{", string, "} ");
- m_id = propertyID;
- m_important = important;
- cssyyparse(this);
- m_rule = 0;
- bool ok = false;
- if (m_hasFontFaceOnlyValues)
- deleteFontFaceOnlyValues();
- if (!m_parsedProperties.isEmpty()) {
- ok = true;
- declaration->addParsedProperties(m_parsedProperties);
- clearProperties();
- }
- return ok;
- }
- // The color will only be changed when string contains a valid CSS color, so callers
- // can set it to a default color and ignore the boolean result.
- bool CSSParser::parseColor(RGBA32& color, const String& string, bool strict)
- {
- // First try creating a color specified by name, rgba(), rgb() or "#" syntax.
- if (fastParseColor(color, string, strict))
- return true;
- CSSParser parser(CSSStrictMode);
- // In case the fast-path parser didn't understand the color, try the full parser.
- if (!parser.parseColor(string))
- return false;
- CSSValue* value = parser.m_parsedProperties.first().value();
- if (!value->isPrimitiveValue())
- return false;
- CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
- if (!primitiveValue->isRGBColor())
- return false;
- color = primitiveValue->getRGBA32Value();
- return true;
- }
- bool CSSParser::parseColor(const String& string)
- {
- setupParser("@-webkit-decls{color:", string, "} ");
- cssyyparse(this);
- m_rule = 0;
- return !m_parsedProperties.isEmpty() && m_parsedProperties.first().id() == CSSPropertyColor;
- }
- bool CSSParser::parseSystemColor(RGBA32& color, const String& string, Document* document)
- {
- if (!document || !document->page())
- return false;
- CSSParserString cssColor;
- cssColor.characters = const_cast<UChar*>(string.characters());
- cssColor.length = string.length();
- int id = cssValueKeywordID(cssColor);
- if (id <= 0)
- return false;
- color = document->page()->theme()->systemColor(id).rgb();
- return true;
- }
- void CSSParser::parseSelector(const String& string, CSSSelectorList& selectorList)
- {
- m_selectorListForParseSelector = &selectorList;
- setupParser("@-webkit-selector{", string, "}");
- cssyyparse(this);
- m_selectorListForParseSelector = 0;
- }
- bool CSSParser::parseDeclaration(StylePropertySet* declaration, const String& string, PassRefPtr<CSSRuleSourceData> prpRuleSourceData, StyleSheetContents* contextStyleSheet)
- {
- // Length of the "@-webkit-decls{" prefix.
- static const unsigned prefixLength = 15;
- setStyleSheet(contextStyleSheet);
- RefPtr<CSSRuleSourceData> ruleSourceData = prpRuleSourceData;
- if (ruleSourceData) {
- m_currentRuleDataStack = adoptPtr(new RuleSourceDataList());
- m_currentRuleDataStack->append(ruleSourceData);
- }
- setupParser("@-webkit-decls{", string, "} ");
- cssyyparse(this);
- m_rule = 0;
- bool ok = false;
- if (m_hasFontFaceOnlyValues)
- deleteFontFaceOnlyValues();
- if (!m_parsedProperties.isEmpty()) {
- ok = true;
- declaration->addParsedProperties(m_parsedProperties);
- clearProperties();
- }
- if (ruleSourceData) {
- ASSERT(m_currentRuleDataStack->size() == 1);
- ruleSourceData->ruleBodyRange.start = 0;
- ruleSourceData->ruleBodyRange.end = string.length();
- for (size_t i = 0, size = ruleSourceData->styleSourceData->propertyData.size(); i < size; ++i) {
- CSSPropertySourceData& propertyData = ruleSourceData->styleSourceData->propertyData.at(i);
- propertyData.range.start -= prefixLength;
- propertyData.range.end -= prefixLength;
- }
- fixUnparsedPropertyRanges(ruleSourceData.get());
- m_currentRuleDataStack.clear();
- }
- return ok;
- }
- PassOwnPtr<MediaQuery> CSSParser::parseMediaQuery(const String& string)
- {
- if (string.isEmpty())
- return nullptr;
- ASSERT(!m_mediaQuery);
- // can't use { because tokenizer state switches from mediaquery to initial state when it sees { token.
- // instead insert one " " (which is WHITESPACE in CSSGrammar.y)
- setupParser("@-webkit-mediaquery ", string, "} ");
- cssyyparse(this);
- return m_mediaQuery.release();
- }
- #if ENABLE(CSS_VARIABLES)
- static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties, HashSet<AtomicString>& seenVariables)
- #else
- static inline void filterProperties(bool important, const CSSParser::ParsedPropertyVector& input, Vector<CSSProperty, 256>& output, size_t& unusedEntries, BitArray<numCSSProperties>& seenProperties)
- #endif
- {
- // Add properties in reverse order so that highest priority definitions are reached first. Duplicate definitions can then be ignored when found.
- for (int i = input.size() - 1; i >= 0; --i) {
- const CSSProperty& property = input[i];
- if (property.isImportant() != important)
- continue;
- #if ENABLE(CSS_VARIABLES)
- if (property.id() == CSSPropertyVariable) {
- const AtomicString& name = static_cast<CSSVariableValue*>(property.value())->name();
- if (seenVariables.contains(name))
- continue;
- seenVariables.add(name);
- output[--unusedEntries] = property;
- continue;
- }
- #endif
- const unsigned propertyIDIndex = property.id() - firstCSSProperty;
- if (seenProperties.get(propertyIDIndex))
- continue;
- …
Large files files are truncated, but you can click here to view the full file