2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2016 Apple Inc. All rights reserved.
4 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 - 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
25 #include "CSSParserTokenRange.h"
26 #include "StyleRule.h"
27 #include <wtf/text/StringView.h>
33 class StylePropertyShorthand;
34 class StyleSheetContents;
36 // Inputs: PropertyID, isImportant bool, CSSParserTokenRange.
37 // Outputs: Vector of CSSProperties
39 class CSSPropertyParser {
40 WTF_MAKE_NONCOPYABLE(CSSPropertyParser);
42 static bool parseValue(CSSPropertyID, bool important,
43 const CSSParserTokenRange&, const CSSParserContext&, StyleSheetContents*,
44 Vector<CSSProperty, 256>&, StyleRule::Type);
46 // Parses a non-shorthand CSS property
47 static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const CSSParserTokenRange&, const CSSParserContext&, StyleSheetContents*);
50 CSSPropertyParser(const CSSParserTokenRange&, const CSSParserContext&, StyleSheetContents*, Vector<CSSProperty, 256>*);
52 // FIXME: Rename once the CSSParserValue-based parseValue is removed
53 bool parseValueStart(CSSPropertyID, bool important);
54 bool consumeCSSWideKeyword(CSSPropertyID, bool important);
55 RefPtr<CSSValue> parseSingleValue(CSSPropertyID, CSSPropertyID = CSSPropertyInvalid);
57 bool inQuirksMode() const { return m_context.mode == HTMLQuirksMode; }
59 bool parseViewportDescriptor(CSSPropertyID propId, bool important);
60 bool parseFontFaceDescriptor(CSSPropertyID);
62 void addProperty(CSSPropertyID, CSSPropertyID, Ref<CSSValue>&&, bool important, bool implicit = false);
63 void addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&&, bool);
65 bool consumeBorder(bool important);
67 bool parseShorthand(CSSPropertyID, bool important);
68 bool consumeShorthandGreedily(const StylePropertyShorthand&, bool important);
69 bool consume4Values(const StylePropertyShorthand&, bool important);
71 // Legacy parsing allows <string>s for animation-name
72 bool consumeAnimationShorthand(const StylePropertyShorthand&, bool important);
73 bool consumeBackgroundShorthand(const StylePropertyShorthand&, bool important);
75 bool consumeColumns(bool important);
77 bool consumeGridItemPositionShorthand(CSSPropertyID, bool important);
78 bool consumeGridTemplateRowsAndAreasAndColumns(CSSPropertyID, bool important);
79 bool consumeGridTemplateShorthand(CSSPropertyID, bool important);
80 bool consumeGridShorthand(bool important);
81 bool consumeGridAreaShorthand(bool important);
83 bool consumePlaceContentShorthand(bool important);
84 bool consumePlaceItemsShorthand(bool important);
86 bool consumeFont(bool important);
87 bool consumeFontVariantShorthand(bool important);
88 bool consumeSystemFont(bool important);
90 bool consumeBorderSpacing(bool important);
92 // CSS3 Parsing Routines (for properties specific to CSS3)
93 bool consumeBorderImage(CSSPropertyID, bool important);
95 bool consumeFlex(bool important);
97 bool consumeLegacyBreakProperty(CSSPropertyID, bool important);
99 bool consumeTransformOrigin(bool important);
100 bool consumePerspectiveOrigin(bool important);
104 CSSParserTokenRange m_range;
105 const CSSParserContext& m_context;
106 StyleSheetContents* m_styleSheetContents;
109 Vector<CSSProperty, 256>* m_parsedProperties;
112 CSSPropertyID cssPropertyID(StringView);
113 CSSValueID cssValueKeywordID(StringView);
114 bool isCustomPropertyName(const String&);
117 void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyNameAlias, unsigned& newLength);
120 } // namespace WebCore