1 | /*
|
---|
2 | * Copyright (C) 2003 Lars Knoll ([email protected])
|
---|
3 | * Copyright (C) 2004-2022 Apple Inc. All rights reserved.
|
---|
4 | * Copyright (C) 2008 Eric Seidel <[email protected]>
|
---|
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 "CSSParserContext.h"
|
---|
26 | #include "CSSRegisteredCustomProperty.h"
|
---|
27 | #include "CSSValue.h"
|
---|
28 | #include "ColorTypes.h"
|
---|
29 | #include "WritingMode.h"
|
---|
30 | #include <wtf/text/WTFString.h>
|
---|
31 |
|
---|
32 | namespace WebCore {
|
---|
33 |
|
---|
34 | class CSSParserObserver;
|
---|
35 | class CSSSelectorList;
|
---|
36 | class CSSValueList;
|
---|
37 | class CSSValuePool;
|
---|
38 | class Color;
|
---|
39 | class Element;
|
---|
40 | class ImmutableStyleProperties;
|
---|
41 | class MutableStyleProperties;
|
---|
42 | class StyleRuleBase;
|
---|
43 | class StyleRuleKeyframe;
|
---|
44 | class StyleSheetContents;
|
---|
45 | class RenderStyle;
|
---|
46 |
|
---|
47 | namespace CSSPropertyParserHelpers {
|
---|
48 | struct FontRaw;
|
---|
49 | }
|
---|
50 |
|
---|
51 | namespace Style {
|
---|
52 | class BuilderState;
|
---|
53 | }
|
---|
54 |
|
---|
55 | class CSSParser {
|
---|
56 | public:
|
---|
57 | enum class ParseResult {
|
---|
58 | Changed,
|
---|
59 | Unchanged,
|
---|
60 | Error
|
---|
61 | };
|
---|
62 |
|
---|
63 | WEBCORE_EXPORT explicit CSSParser(const CSSParserContext&);
|
---|
64 | WEBCORE_EXPORT ~CSSParser();
|
---|
65 |
|
---|
66 | void parseSheet(StyleSheetContents&, const String&);
|
---|
67 |
|
---|
68 | static RefPtr<StyleRuleBase> parseRule(const CSSParserContext&, StyleSheetContents*, const String&);
|
---|
69 |
|
---|
70 | RefPtr<StyleRuleKeyframe> parseKeyframeRule(const String&);
|
---|
71 | static Vector<double> parseKeyframeKeyList(const String&);
|
---|
72 |
|
---|
73 | bool parseSupportsCondition(const String&);
|
---|
74 |
|
---|
75 | static void parseSheetForInspector(const CSSParserContext&, StyleSheetContents*, const String&, CSSParserObserver&);
|
---|
76 | static void parseDeclarationForInspector(const CSSParserContext&, const String&, CSSParserObserver&);
|
---|
77 |
|
---|
78 | static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&);
|
---|
79 | static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomString& propertyName, const String&, bool important, const CSSParserContext&);
|
---|
80 |
|
---|
81 | static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const String&, const CSSParserContext& = strictCSSParserContext());
|
---|
82 |
|
---|
83 | WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&);
|
---|
84 | static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, const Element*);
|
---|
85 |
|
---|
86 | std::optional<CSSSelectorList> parseSelector(const String&);
|
---|
87 |
|
---|
88 | RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, Style::BuilderState&);
|
---|
89 |
|
---|
90 | WEBCORE_EXPORT static Color parseColor(const String&, const CSSParserContext&);
|
---|
91 | // FIXME: All callers are not getting the right Settings for parsing due to lack of CSSParserContext and should switch to the parseColor function above.
|
---|
92 | WEBCORE_EXPORT static Color parseColorWithoutContext(const String&, bool strict = false);
|
---|
93 | static Color parseSystemColor(StringView);
|
---|
94 | static std::optional<SRGBA<uint8_t>> parseNamedColor(StringView);
|
---|
95 | static std::optional<SRGBA<uint8_t>> parseHexColor(StringView);
|
---|
96 |
|
---|
97 | private:
|
---|
98 | ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important);
|
---|
99 |
|
---|
100 | CSSParserContext m_context;
|
---|
101 | };
|
---|
102 |
|
---|
103 | } // namespace WebCore
|
---|