Bug 867089 - Validate the playbackRate before using it. r=ehsan
[gecko.git] / layout / style / nsCSSParser.h
blob8d4e1bc0302d6c9193b5dcce14a4a1c82a8506fe
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
8 #ifndef nsCSSParser_h___
9 #define nsCSSParser_h___
11 #include "mozilla/Attributes.h"
13 #include "nsCSSProperty.h"
14 #include "nsCOMPtr.h"
15 #include "nsStringFwd.h"
16 #include "nsTArrayForwardDeclare.h"
18 class nsCSSStyleSheet;
19 class nsIPrincipal;
20 class nsIURI;
21 struct nsCSSSelectorList;
22 class nsMediaList;
23 class nsCSSKeyframeRule;
24 class nsCSSValue;
26 namespace mozilla {
27 namespace css {
28 class Rule;
29 class Declaration;
30 class Loader;
31 class StyleRule;
35 // Interface to the css parser.
37 class MOZ_STACK_CLASS nsCSSParser {
38 public:
39 nsCSSParser(mozilla::css::Loader* aLoader = nullptr,
40 nsCSSStyleSheet* aSheet = nullptr);
41 ~nsCSSParser();
43 static void Shutdown();
45 private:
46 nsCSSParser(nsCSSParser const&) MOZ_DELETE;
47 nsCSSParser& operator=(nsCSSParser const&) MOZ_DELETE;
49 public:
50 // Set a style sheet for the parser to fill in. The style sheet must
51 // implement the nsCSSStyleSheet interface. Null can be passed in to clear
52 // out an existing stylesheet reference.
53 nsresult SetStyleSheet(nsCSSStyleSheet* aSheet);
55 // Set whether or not to emulate Nav quirks
56 nsresult SetQuirkMode(bool aQuirkMode);
58 // Set loader to use for child sheets
59 nsresult SetChildLoader(mozilla::css::Loader* aChildLoader);
61 /**
62 * Parse aInput into the stylesheet that was previously set by calling
63 * SetStyleSheet. Calling this method without calling SetStyleSheet first is
64 * an error.
66 * @param aInput the data to parse
67 * @param aSheetURL the URI to use as the sheet URI (for error reporting).
68 * This must match the URI of the sheet passed to
69 * SetStyleSheet.
70 * @param aBaseURI the URI to use for relative URI resolution
71 * @param aSheetPrincipal the principal of the stylesheet. This must match
72 * the principal of the sheet passed to SetStyleSheet.
73 * @param aLineNumber the line number of the first line of the sheet.
74 * @param aAllowUnsafeRules see aEnableUnsafeRules in
75 * mozilla::css::Loader::LoadSheetSync
77 nsresult ParseSheet(const nsAString& aInput,
78 nsIURI* aSheetURL,
79 nsIURI* aBaseURI,
80 nsIPrincipal* aSheetPrincipal,
81 uint32_t aLineNumber,
82 bool aAllowUnsafeRules);
84 // Parse HTML style attribute or its equivalent in other markup
85 // languages. aBaseURL is the base url to use for relative links in
86 // the declaration.
87 nsresult ParseStyleAttribute(const nsAString& aAttributeValue,
88 nsIURI* aDocURL,
89 nsIURI* aBaseURL,
90 nsIPrincipal* aNodePrincipal,
91 mozilla::css::StyleRule** aResult);
93 // Parse the body of a declaration block. Very similar to
94 // ParseStyleAttribute, but used under different circumstances.
95 // The contents of aDeclaration will be erased and replaced with the
96 // results of parsing; aChanged will be set true if the aDeclaration
97 // argument was modified.
98 nsresult ParseDeclarations(const nsAString& aBuffer,
99 nsIURI* aSheetURL,
100 nsIURI* aBaseURL,
101 nsIPrincipal* aSheetPrincipal,
102 mozilla::css::Declaration* aDeclaration,
103 bool* aChanged);
105 nsresult ParseRule(const nsAString& aRule,
106 nsIURI* aSheetURL,
107 nsIURI* aBaseURL,
108 nsIPrincipal* aSheetPrincipal,
109 mozilla::css::Rule** aResult);
111 // Parse the value of a single CSS property, and add or replace that
112 // property in aDeclaration.
114 // SVG "mapped attributes" (which correspond directly to CSS
115 // properties) are parsed slightly differently from regular CSS; in
116 // particular, units may be omitted from <length>. The 'aIsSVGMode'
117 // argument controls this quirk. Note that this *only* applies to
118 // mapped attributes, not inline styles or full style sheets in SVG.
119 nsresult ParseProperty(const nsCSSProperty aPropID,
120 const nsAString& aPropValue,
121 nsIURI* aSheetURL,
122 nsIURI* aBaseURL,
123 nsIPrincipal* aSheetPrincipal,
124 mozilla::css::Declaration* aDeclaration,
125 bool* aChanged,
126 bool aIsImportant,
127 bool aIsSVGMode = false);
130 * Parse aBuffer into a media list |aMediaList|, which must be
131 * non-null, replacing its current contents. If aHTMLMode is true,
132 * parse according to HTML rules, with commas as the most important
133 * delimiter. Otherwise, parse according to CSS rules, with
134 * parentheses and strings more important than commas. |aURL| and
135 * |aLineNumber| are used for error reporting.
137 nsresult ParseMediaList(const nsSubstring& aBuffer,
138 nsIURI* aURL,
139 uint32_t aLineNumber,
140 nsMediaList* aMediaList,
141 bool aHTMLMode);
144 * Parse aBuffer into a nsCSSValue |aValue|. Will return false
145 * if aBuffer is not a valid CSS color specification.
146 * One can use nsRuleNode::ComputeColor to compute an nscolor from
147 * the returned nsCSSValue.
149 bool ParseColorString(const nsSubstring& aBuffer,
150 nsIURI* aURL,
151 uint32_t aLineNumber,
152 nsCSSValue& aValue);
155 * Parse aBuffer into a selector list. On success, caller must
156 * delete *aSelectorList when done with it.
158 nsresult ParseSelectorString(const nsSubstring& aSelectorString,
159 nsIURI* aURL,
160 uint32_t aLineNumber,
161 nsCSSSelectorList** aSelectorList);
164 * Parse a keyframe rule (which goes inside an @keyframes rule).
165 * Return it if the parse was successful.
167 already_AddRefed<nsCSSKeyframeRule>
168 ParseKeyframeRule(const nsSubstring& aBuffer,
169 nsIURI* aURL,
170 uint32_t aLineNumber);
173 * Parse a selector list for a keyframe rule. Return whether
174 * the parse succeeded.
176 bool ParseKeyframeSelectorString(const nsSubstring& aSelectorString,
177 nsIURI* aURL,
178 uint32_t aLineNumber,
179 InfallibleTArray<float>& aSelectorList);
182 * Parse a property and value and return whether the property/value pair
183 * is supported.
185 bool EvaluateSupportsDeclaration(const nsAString& aProperty,
186 const nsAString& aValue,
187 nsIURI* aDocURL,
188 nsIURI* aBaseURL,
189 nsIPrincipal* aDocPrincipal);
192 * Parse an @supports condition and returns the result of evaluating the
193 * condition.
195 bool EvaluateSupportsCondition(const nsAString& aCondition,
196 nsIURI* aDocURL,
197 nsIURI* aBaseURL,
198 nsIPrincipal* aDocPrincipal);
200 protected:
201 // This is a CSSParserImpl*, but if we expose that type name in this
202 // header, we can't put the type definition (in nsCSSParser.cpp) in
203 // the anonymous namespace.
204 void* mImpl;
207 #endif /* nsCSSParser_h___ */