| 1 | /* |
| 2 | * Copyright (C) 2003 Lars Knoll (knoll@kde.org) |
| 3 | * Copyright (C) 2004-2010, 2015 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 "CSSParserContext.h" |
| 26 | #include "CSSRegisteredCustomProperty.h" |
| 27 | #include "CSSValue.h" |
| 28 | #include "WritingMode.h" |
| 29 | #include <wtf/text/WTFString.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | struct ApplyCascadedPropertyState; |
| 34 | class CSSParserObserver; |
| 35 | class CSSSelectorList; |
| 36 | class Color; |
| 37 | class Element; |
| 38 | class ImmutableStyleProperties; |
| 39 | class MutableStyleProperties; |
| 40 | class StyleRuleBase; |
| 41 | class StyleRuleKeyframe; |
| 42 | class StyleSheetContents; |
| 43 | class RenderStyle; |
| 44 | |
| 45 | class CSSParser { |
| 46 | public: |
| 47 | enum class ParseResult { |
| 48 | Changed, |
| 49 | Unchanged, |
| 50 | Error |
| 51 | }; |
| 52 | |
| 53 | WEBCORE_EXPORT explicit CSSParser(const CSSParserContext&); |
| 54 | WEBCORE_EXPORT ~CSSParser(); |
| 55 | |
| 56 | enum class RuleParsing { Normal, Deferred }; |
| 57 | void parseSheet(StyleSheetContents*, const String&, RuleParsing = RuleParsing::Normal); |
| 58 | |
| 59 | static RefPtr<StyleRuleBase> parseRule(const CSSParserContext&, StyleSheetContents*, const String&); |
| 60 | |
| 61 | RefPtr<StyleRuleKeyframe> parseKeyframeRule(const String&); |
| 62 | static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&); |
| 63 | |
| 64 | bool parseSupportsCondition(const String&); |
| 65 | |
| 66 | static void parseSheetForInspector(const CSSParserContext&, StyleSheetContents*, const String&, CSSParserObserver&); |
| 67 | static void parseDeclarationForInspector(const CSSParserContext&, const String&, CSSParserObserver&); |
| 68 | |
| 69 | static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&); |
| 70 | static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&); |
| 71 | |
| 72 | static RefPtr<CSSValue> parseFontFaceDescriptor(CSSPropertyID, const String&, const CSSParserContext&); |
| 73 | |
| 74 | static RefPtr<CSSValue> parseSingleValue(CSSPropertyID, const String&, const CSSParserContext& = strictCSSParserContext()); |
| 75 | |
| 76 | WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&); |
| 77 | static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, const Element*); |
| 78 | |
| 79 | void parseSelector(const String&, CSSSelectorList&); |
| 80 | |
| 81 | RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, ApplyCascadedPropertyState&); |
| 82 | |
| 83 | static Color parseColor(const String&, bool strict = false); |
| 84 | static Color parseSystemColor(const String&, const CSSParserContext*); |
| 85 | |
| 86 | private: |
| 87 | ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important); |
| 88 | |
| 89 | CSSParserContext m_context; |
| 90 | }; |
| 91 | |
| 92 | } // namespace WebCore |
| 93 | |