1 /*
2  * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Apple Inc. All rights
4  * reserved.
5  * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6  * Copyright (C) 2009 - 2010  Torch Mobile (Beijing) Co. Ltd. All rights
7  * reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PARSER_CSS_PROPERTY_PARSER_H_
26 #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PARSER_CSS_PROPERTY_PARSER_H_
27 
28 #include "base/macros.h"
29 #include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
30 #include "third_party/blink/renderer/core/css/parser/css_parser_mode.h"
31 #include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
32 #include "third_party/blink/renderer/core/css/style_rule.h"
33 #include "third_party/blink/renderer/platform/wtf/text/string_view.h"
34 
35 namespace blink {
36 
37 class CSSPropertyValue;
38 class CSSValue;
39 class ExecutionContext;
40 
41 // Inputs: PropertyID, isImportant bool, CSSParserTokenRange.
42 // Outputs: Vector of CSSProperties
43 
44 class CORE_EXPORT CSSPropertyParser {
45   STACK_ALLOCATED();
46 
47  public:
48   static bool ParseValue(CSSPropertyID,
49                          bool important,
50                          const CSSParserTokenRange&,
51                          const CSSParserContext*,
52                          HeapVector<CSSPropertyValue, 256>&,
53                          StyleRule::RuleType);
54 
55   // Parses a non-shorthand CSS property
56   static const CSSValue* ParseSingleValue(CSSPropertyID,
57                                           const CSSParserTokenRange&,
58                                           const CSSParserContext*);
59 
60  private:
61   CSSPropertyParser(const CSSParserTokenRange&,
62                     const CSSParserContext*,
63                     HeapVector<CSSPropertyValue, 256>*);
64 
65   // TODO(timloh): Rename once the CSSParserValue-based parseValue is removed
66   bool ParseValueStart(CSSPropertyID unresolved_property, bool important);
67   bool ConsumeCSSWideKeyword(CSSPropertyID unresolved_property, bool important);
68 
69   bool ParseViewportDescriptor(CSSPropertyID prop_id, bool important);
70   bool ParseFontFaceDescriptor(CSSPropertyID);
71 
72  private:
73   // Inputs:
74   CSSParserTokenRange range_;
75   const CSSParserContext* context_;
76   // Outputs:
77   HeapVector<CSSPropertyValue, 256>* parsed_properties_;
78   DISALLOW_COPY_AND_ASSIGN(CSSPropertyParser);
79 };
80 
81 CSSPropertyID UnresolvedCSSPropertyID(const ExecutionContext*,
82                                       StringView,
83                                       CSSParserMode mode = kHTMLStandardMode);
84 CSSValueID CssValueKeywordID(StringView);
85 
86 }  // namespace blink
87 
88 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PARSER_CSS_PROPERTY_PARSER_H_
89