1/*
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.
6 *
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.
11 *
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.
16 *
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.
21 */
22
23#pragma once
24
25#include "CSSParserTokenRange.h"
26#include "StyleRule.h"
27#include <wtf/text/StringView.h>
28
29namespace WebCore {
30
31class CSSProperty;
32class CSSValue;
33class StylePropertyShorthand;
34class StyleSheetContents;
35class StyleResolver;
36
37// Inputs: PropertyID, isImportant bool, CSSParserTokenRange.
38// Outputs: Vector of CSSProperties
39
40class CSSPropertyParser {
41 WTF_MAKE_NONCOPYABLE(CSSPropertyParser);
42public:
43 static bool parseValue(CSSPropertyID, bool important,
44 const CSSParserTokenRange&, const CSSParserContext&,
45 Vector<CSSProperty, 256>&, StyleRule::Type);
46
47 // Parses a non-shorthand CSS property
48 static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const CSSParserTokenRange&, const CSSParserContext&);
49 static bool canParseTypedCustomPropertyValue(const String& syntax, const CSSParserTokenRange&, const CSSParserContext&);
50 static RefPtr<CSSCustomPropertyValue> parseTypedCustomPropertyValue(const String& name, const String& syntax, const CSSParserTokenRange&, const StyleResolver&, const CSSParserContext&);
51 static void collectParsedCustomPropertyValueDependencies(const String& syntax, bool isRoot, HashSet<CSSPropertyID>& dependencies, const CSSParserTokenRange&, const CSSParserContext&);
52
53private:
54 CSSPropertyParser(const CSSParserTokenRange&, const CSSParserContext&, Vector<CSSProperty, 256>*, bool consumeWhitespace = true);
55
56 // FIXME: Rename once the CSSParserValue-based parseValue is removed
57 bool parseValueStart(CSSPropertyID, bool important);
58 bool consumeCSSWideKeyword(CSSPropertyID, bool important);
59 RefPtr<CSSValue> parseSingleValue(CSSPropertyID, CSSPropertyID = CSSPropertyInvalid);
60 bool canParseTypedCustomPropertyValue(const String& syntax);
61 RefPtr<CSSCustomPropertyValue> parseTypedCustomPropertyValue(const String& name, const String& syntax, const StyleResolver&);
62 void collectParsedCustomPropertyValueDependencies(const String& syntax, bool isRoot, HashSet<CSSPropertyID>& dependencies);
63
64 bool inQuirksMode() const { return m_context.mode == HTMLQuirksMode; }
65
66 bool parseViewportDescriptor(CSSPropertyID propId, bool important);
67 bool parseFontFaceDescriptor(CSSPropertyID);
68
69 void addProperty(CSSPropertyID, CSSPropertyID, Ref<CSSValue>&&, bool important, bool implicit = false);
70 void addExpandedPropertyForValue(CSSPropertyID propId, Ref<CSSValue>&&, bool);
71
72 bool consumeBorder(RefPtr<CSSValue>& width, RefPtr<CSSValue>& style, RefPtr<CSSValue>& color);
73
74 bool parseShorthand(CSSPropertyID, bool important);
75 bool consumeShorthandGreedily(const StylePropertyShorthand&, bool important);
76 bool consume2ValueShorthand(const StylePropertyShorthand&, bool important);
77 bool consume4ValueShorthand(const StylePropertyShorthand&, bool important);
78
79 // Legacy parsing allows <string>s for animation-name
80 bool consumeAnimationShorthand(const StylePropertyShorthand&, bool important);
81 bool consumeBackgroundShorthand(const StylePropertyShorthand&, bool important);
82
83 bool consumeColumns(bool important);
84
85 bool consumeGridItemPositionShorthand(CSSPropertyID, bool important);
86 bool consumeGridTemplateRowsAndAreasAndColumns(CSSPropertyID, bool important);
87 bool consumeGridTemplateShorthand(CSSPropertyID, bool important);
88 bool consumeGridShorthand(bool important);
89 bool consumeGridAreaShorthand(bool important);
90
91 bool consumePlaceContentShorthand(bool important);
92 bool consumePlaceItemsShorthand(bool important);
93 bool consumePlaceSelfShorthand(bool important);
94
95 bool consumeFont(bool important);
96 bool consumeFontVariantShorthand(bool important);
97 bool consumeSystemFont(bool important);
98
99 bool consumeBorderSpacing(bool important);
100
101 // CSS3 Parsing Routines (for properties specific to CSS3)
102 bool consumeBorderImage(CSSPropertyID, bool important);
103
104 bool consumeFlex(bool important);
105
106 bool consumeLegacyBreakProperty(CSSPropertyID, bool important);
107
108 bool consumeTransformOrigin(bool important);
109 bool consumePerspectiveOrigin(bool important);
110
111private:
112 // Inputs:
113 CSSParserTokenRange m_range;
114 const CSSParserContext& m_context;
115
116 // Outputs:
117 Vector<CSSProperty, 256>* m_parsedProperties;
118};
119
120CSSPropertyID cssPropertyID(StringView);
121CSSValueID cssValueKeywordID(StringView);
122bool isCustomPropertyName(const String&);
123
124#if PLATFORM(IOS_FAMILY)
125void cssPropertyNameIOSAliasing(const char* propertyName, const char*& propertyNameAlias, unsigned& newLength);
126#endif
127
128} // namespace WebCore
129