File: CSSParserImpl.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (172 lines) | stat: -rw-r--r-- 7,015 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CSSParserImpl_h
#define CSSParserImpl_h

#include "core/CSSPropertyNames.h"
#include "core/css/CSSProperty.h"
#include "core/css/CSSPropertySourceData.h"
#include "core/css/StylePropertySet.h"
#include "core/css/parser/CSSParserTokenRange.h"
#include "platform/heap/Handle.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
#include <memory>

namespace blink {

class CSSLazyParsingState;
class CSSParserContext;
class CSSParserObserver;
class CSSParserObserverWrapper;
class StyleRule;
class StyleRuleBase;
class StyleRuleCharset;
class StyleRuleFontFace;
class StyleRuleImport;
class StyleRuleKeyframe;
class StyleRuleKeyframes;
class StyleRuleMedia;
class StyleRuleNamespace;
class StyleRulePage;
class StyleRuleSupports;
class StyleRuleViewport;
class StyleSheetContents;
class Element;

class CSSParserImpl {
  STACK_ALLOCATED();
  WTF_MAKE_NONCOPYABLE(CSSParserImpl);

 public:
  CSSParserImpl(const CSSParserContext*, StyleSheetContents* = nullptr);

  enum AllowedRulesType {
    // As per css-syntax, css-cascade and css-namespaces, @charset rules
    // must come first, followed by @import then @namespace.
    // AllowImportRules actually means we allow @import and any rules thay
    // may follow it, i.e. @namespace rules and regular rules.
    // AllowCharsetRules and AllowNamespaceRules behave similarly.
    AllowCharsetRules,
    AllowImportRules,
    AllowNamespaceRules,
    RegularRules,
    KeyframeRules,
    ApplyRules,  // For @apply inside style rules
    NoRules,     // For parsing at-rules inside declaration lists
  };

  static MutableStylePropertySet::SetResult parseValue(MutableStylePropertySet*,
                                                       CSSPropertyID,
                                                       const String&,
                                                       bool important,
                                                       const CSSParserContext*);
  static MutableStylePropertySet::SetResult parseVariableValue(
      MutableStylePropertySet*,
      const AtomicString& propertyName,
      const PropertyRegistry*,
      const String&,
      bool important,
      const CSSParserContext*,
      bool isAnimationTainted);
  static ImmutableStylePropertySet* parseInlineStyleDeclaration(const String&,
                                                                Element*);
  static bool parseDeclarationList(MutableStylePropertySet*,
                                   const String&,
                                   const CSSParserContext*);
  static StyleRuleBase* parseRule(const String&,
                                  const CSSParserContext*,
                                  StyleSheetContents*,
                                  AllowedRulesType);
  static void parseStyleSheet(const String&,
                              const CSSParserContext*,
                              StyleSheetContents*,
                              bool deferPropertyParsing = false);
  static CSSSelectorList parsePageSelector(CSSParserTokenRange,
                                           StyleSheetContents*);

  static ImmutableStylePropertySet* parseCustomPropertySet(CSSParserTokenRange);

  static std::unique_ptr<Vector<double>> parseKeyframeKeyList(const String&);

  bool supportsDeclaration(CSSParserTokenRange&);

  static void parseDeclarationListForInspector(const String&,
                                               const CSSParserContext*,
                                               CSSParserObserver&);
  static void parseStyleSheetForInspector(const String&,
                                          const CSSParserContext*,
                                          StyleSheetContents*,
                                          CSSParserObserver&);

  static StylePropertySet* parseDeclarationListForLazyStyle(
      CSSParserTokenRange block,
      const CSSParserContext*);

 private:
  enum RuleListType { TopLevelRuleList, RegularRuleList, KeyframesRuleList };

  // Returns whether the first encountered rule was valid
  template <typename T>
  bool consumeRuleList(CSSParserTokenRange, RuleListType, T callback);

  // These two functions update the range they're given
  StyleRuleBase* consumeAtRule(CSSParserTokenRange&, AllowedRulesType);
  StyleRuleBase* consumeQualifiedRule(CSSParserTokenRange&, AllowedRulesType);

  static StyleRuleCharset* consumeCharsetRule(CSSParserTokenRange prelude);
  StyleRuleImport* consumeImportRule(CSSParserTokenRange prelude);
  StyleRuleNamespace* consumeNamespaceRule(CSSParserTokenRange prelude);
  StyleRuleMedia* consumeMediaRule(CSSParserTokenRange prelude,
                                   CSSParserTokenRange block);
  StyleRuleSupports* consumeSupportsRule(CSSParserTokenRange prelude,
                                         CSSParserTokenRange block);
  StyleRuleViewport* consumeViewportRule(CSSParserTokenRange prelude,
                                         CSSParserTokenRange block);
  StyleRuleFontFace* consumeFontFaceRule(CSSParserTokenRange prelude,
                                         CSSParserTokenRange block);
  StyleRuleKeyframes* consumeKeyframesRule(bool webkitPrefixed,
                                           CSSParserTokenRange prelude,
                                           CSSParserTokenRange block);
  StyleRulePage* consumePageRule(CSSParserTokenRange prelude,
                                 CSSParserTokenRange block);
  // Updates m_parsedProperties
  void consumeApplyRule(CSSParserTokenRange prelude);

  StyleRuleKeyframe* consumeKeyframeStyleRule(CSSParserTokenRange prelude,
                                              CSSParserTokenRange block);
  StyleRule* consumeStyleRule(CSSParserTokenRange prelude,
                              CSSParserTokenRange block);

  void consumeDeclarationList(CSSParserTokenRange, StyleRule::RuleType);
  void consumeDeclaration(CSSParserTokenRange, StyleRule::RuleType);
  void consumeDeclarationValue(CSSParserTokenRange,
                               CSSPropertyID,
                               bool important,
                               StyleRule::RuleType);
  void consumeVariableValue(CSSParserTokenRange,
                            const AtomicString& propertyName,
                            bool important,
                            bool isAnimationTainted);

  static std::unique_ptr<Vector<double>> consumeKeyframeKeyList(
      CSSParserTokenRange);

  // FIXME: Can we build StylePropertySets directly?
  // FIXME: Investigate using a smaller inline buffer
  HeapVector<CSSProperty, 256> m_parsedProperties;

  Member<const CSSParserContext> m_context;
  Member<StyleSheetContents> m_styleSheet;

  // For the inspector
  CSSParserObserverWrapper* m_observerWrapper;

  Member<CSSLazyParsingState> m_lazyState;
};

}  // namespace blink

#endif  // CSSParserImpl_h