1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : // vim:cindent:ts=2:et:sw=2:
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1999
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * L. David Baron <dbaron@dbaron.org>
25 : * Boris Zbarsky <bzbarsky@mit.edu>
26 : *
27 : * Alternatively, the contents of this file may be used under the terms of
28 : * either of the GNU General Public License Version 2 or later (the "GPL"),
29 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 : * in which case the provisions of the GPL or the LGPL are applicable instead
31 : * of those above. If you wish to allow use of your version of this file only
32 : * under the terms of either the GPL or the LGPL, and not to allow others to
33 : * use your version of this file under the terms of the MPL, indicate your
34 : * decision by deleting the provisions above and replace them with the notice
35 : * and other provisions required by the GPL or the LGPL. If you do not delete
36 : * the provisions above, a recipient may use your version of this file under
37 : * the terms of any one of the MPL, the GPL or the LGPL.
38 : *
39 : * ***** END LICENSE BLOCK ***** */
40 :
41 : /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
42 :
43 : #ifndef nsCSSRules_h_
44 : #define nsCSSRules_h_
45 :
46 : #include "mozilla/Attributes.h"
47 :
48 : #include "mozilla/css/GroupRule.h"
49 : #include "nsIDOMCSSMediaRule.h"
50 : #include "nsIDOMCSSMozDocumentRule.h"
51 : #include "nsIDOMCSSFontFaceRule.h"
52 : #include "nsIDOMMozCSSKeyframeRule.h"
53 : #include "nsIDOMMozCSSKeyframesRule.h"
54 : #include "nsIDOMCSSStyleDeclaration.h"
55 : #include "nsICSSRuleList.h"
56 : #include "nsAutoPtr.h"
57 : #include "nsCSSProperty.h"
58 : #include "nsCSSValue.h"
59 : #include "nsIDOMCSSCharsetRule.h"
60 : #include "nsTArray.h"
61 : #include "nsDOMCSSDeclaration.h"
62 : #include "Declaration.h"
63 :
64 : namespace mozilla {
65 : namespace css {
66 : class StyleRule;
67 : }
68 : }
69 :
70 : class nsMediaList;
71 :
72 : namespace mozilla {
73 : namespace css {
74 :
75 : class MediaRule MOZ_FINAL : public GroupRule,
76 : public nsIDOMCSSMediaRule
77 : {
78 : public:
79 : MediaRule();
80 : private:
81 : MediaRule(const MediaRule& aCopy);
82 : ~MediaRule();
83 : public:
84 :
85 : NS_DECL_ISUPPORTS_INHERITED
86 :
87 : // nsIStyleRule methods
88 : #ifdef DEBUG
89 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
90 : #endif
91 :
92 : // Rule methods
93 : virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); //override GroupRule
94 : virtual PRInt32 GetType() const;
95 : virtual already_AddRefed<Rule> Clone() const;
96 0 : virtual nsIDOMCSSRule* GetDOMRule()
97 : {
98 0 : return this;
99 : }
100 :
101 : // nsIDOMCSSRule interface
102 : NS_DECL_NSIDOMCSSRULE
103 :
104 : // nsIDOMCSSMediaRule interface
105 : NS_DECL_NSIDOMCSSMEDIARULE
106 :
107 : // rest of GroupRule
108 : virtual bool UseForPresentation(nsPresContext* aPresContext,
109 : nsMediaQueryResultCacheKey& aKey);
110 :
111 : // @media rule methods
112 : nsresult SetMedia(nsMediaList* aMedia);
113 :
114 : virtual NS_MUST_OVERRIDE size_t
115 : SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
116 :
117 : protected:
118 : nsRefPtr<nsMediaList> mMedia;
119 : };
120 :
121 : class DocumentRule MOZ_FINAL : public GroupRule,
122 : public nsIDOMCSSMozDocumentRule
123 : {
124 : public:
125 : DocumentRule();
126 : private:
127 : DocumentRule(const DocumentRule& aCopy);
128 : ~DocumentRule();
129 : public:
130 :
131 : NS_DECL_ISUPPORTS_INHERITED
132 :
133 : // nsIStyleRule methods
134 : #ifdef DEBUG
135 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
136 : #endif
137 :
138 : // Rule methods
139 : virtual PRInt32 GetType() const;
140 : virtual already_AddRefed<Rule> Clone() const;
141 0 : virtual nsIDOMCSSRule* GetDOMRule()
142 : {
143 0 : return this;
144 : }
145 :
146 : // nsIDOMCSSRule interface
147 : NS_DECL_NSIDOMCSSRULE
148 :
149 : // nsIDOMCSSMozDocumentRule interface
150 : NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
151 :
152 : // rest of GroupRule
153 : virtual bool UseForPresentation(nsPresContext* aPresContext,
154 : nsMediaQueryResultCacheKey& aKey);
155 :
156 : enum Function {
157 : eURL,
158 : eURLPrefix,
159 : eDomain,
160 : eRegExp
161 : };
162 :
163 : struct URL {
164 : Function func;
165 : nsCString url;
166 : URL *next;
167 :
168 0 : URL() : next(nsnull) {}
169 0 : URL(const URL& aOther)
170 : : func(aOther.func)
171 : , url(aOther.url)
172 0 : , next(aOther.next ? new URL(*aOther.next) : nsnull)
173 : {
174 0 : }
175 : ~URL();
176 : };
177 :
178 0 : void SetURLs(URL *aURLs) { mURLs = aURLs; }
179 :
180 : virtual NS_MUST_OVERRIDE size_t
181 : SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
182 :
183 : protected:
184 : nsAutoPtr<URL> mURLs; // linked list of |struct URL| above.
185 : };
186 :
187 : } // namespace css
188 : } // namespace mozilla
189 :
190 : // A nsCSSFontFaceStyleDecl is always embedded in a nsCSSFontFaceRule.
191 : class nsCSSFontFaceRule;
192 : class nsCSSFontFaceStyleDecl : public nsIDOMCSSStyleDeclaration
193 0 : {
194 : public:
195 : NS_DECL_ISUPPORTS
196 : NS_DECL_NSIDOMCSSSTYLEDECLARATION
197 :
198 : nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
199 : nsAString & aResult NS_OUTPARAM) const;
200 :
201 : protected:
202 : friend class nsCSSFontFaceRule;
203 : #define CSS_FONT_DESC(name_, method_) nsCSSValue m##method_;
204 : #include "nsCSSFontDescList.h"
205 : #undef CSS_FONT_DESC
206 :
207 : static nsCSSValue nsCSSFontFaceStyleDecl::* const Fields[];
208 : inline nsCSSFontFaceRule* ContainingRule();
209 : inline const nsCSSFontFaceRule* ContainingRule() const;
210 :
211 : private:
212 : // NOT TO BE IMPLEMENTED
213 : // This object cannot be allocated on its own, only as part of
214 : // nsCSSFontFaceRule.
215 : void* operator new(size_t size) CPP_THROW_NEW;
216 : };
217 :
218 : class nsCSSFontFaceRule MOZ_FINAL : public mozilla::css::Rule,
219 : public nsIDOMCSSFontFaceRule
220 0 : {
221 : public:
222 0 : nsCSSFontFaceRule() {}
223 :
224 0 : nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy)
225 : // copy everything except our reference count
226 0 : : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {}
227 :
228 : NS_DECL_ISUPPORTS_INHERITED
229 :
230 : // nsIStyleRule methods
231 : #ifdef DEBUG
232 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
233 : #endif
234 :
235 : // Rule methods
236 : DECL_STYLE_RULE_INHERIT
237 :
238 : virtual PRInt32 GetType() const;
239 : virtual already_AddRefed<mozilla::css::Rule> Clone() const;
240 :
241 : // nsIDOMCSSRule interface
242 : NS_DECL_NSIDOMCSSRULE
243 :
244 : // nsIDOMCSSFontFaceRule interface
245 : NS_DECL_NSIDOMCSSFONTFACERULE
246 :
247 : void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue);
248 : void GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue);
249 :
250 : virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
251 :
252 : protected:
253 : friend class nsCSSFontFaceStyleDecl;
254 : nsCSSFontFaceStyleDecl mDecl;
255 : };
256 :
257 : // nsFontFaceRuleContainer - used for associating sheet type with
258 : // specific @font-face rules
259 0 : struct nsFontFaceRuleContainer {
260 : nsRefPtr<nsCSSFontFaceRule> mRule;
261 : PRUint8 mSheetType;
262 : };
263 :
264 : inline nsCSSFontFaceRule*
265 0 : nsCSSFontFaceStyleDecl::ContainingRule()
266 : {
267 : return reinterpret_cast<nsCSSFontFaceRule*>
268 0 : (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
269 : }
270 :
271 : inline const nsCSSFontFaceRule*
272 : nsCSSFontFaceStyleDecl::ContainingRule() const
273 : {
274 : return reinterpret_cast<const nsCSSFontFaceRule*>
275 : (reinterpret_cast<const char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
276 : }
277 :
278 : namespace mozilla {
279 : namespace css {
280 :
281 : class CharsetRule MOZ_FINAL : public Rule,
282 : public nsIDOMCSSCharsetRule
283 : {
284 : public:
285 : CharsetRule(const nsAString& aEncoding);
286 : private:
287 : // For |Clone|
288 : CharsetRule(const CharsetRule& aCopy);
289 0 : ~CharsetRule() {}
290 :
291 : public:
292 : NS_DECL_ISUPPORTS_INHERITED
293 :
294 : DECL_STYLE_RULE_INHERIT
295 :
296 : // nsIStyleRule methods
297 : #ifdef DEBUG
298 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
299 : #endif
300 :
301 : // Rule methods
302 : virtual PRInt32 GetType() const;
303 : virtual already_AddRefed<Rule> Clone() const;
304 :
305 : // nsIDOMCSSRule interface
306 : NS_DECL_NSIDOMCSSRULE
307 :
308 : // nsIDOMCSSCharsetRule methods
309 : NS_IMETHOD GetEncoding(nsAString& aEncoding);
310 : NS_IMETHOD SetEncoding(const nsAString& aEncoding);
311 :
312 : virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
313 :
314 : private:
315 : nsString mEncoding;
316 : };
317 :
318 : } // namespace css
319 : } // namespace mozilla
320 :
321 : class nsCSSKeyframeRule;
322 :
323 : class nsCSSKeyframeStyleDeclaration MOZ_FINAL : public nsDOMCSSDeclaration
324 : {
325 : public:
326 : nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule);
327 : virtual ~nsCSSKeyframeStyleDeclaration();
328 :
329 : NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
330 0 : void DropReference() { mRule = nsnull; }
331 : virtual mozilla::css::Declaration* GetCSSDeclaration(bool aAllocate);
332 : virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl);
333 : virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
334 : virtual nsIDocument* DocToUpdate();
335 :
336 : NS_IMETHOD_(nsrefcnt) AddRef();
337 : NS_IMETHOD_(nsrefcnt) Release();
338 :
339 0 : virtual nsINode *GetParentObject()
340 : {
341 0 : return nsnull;
342 : }
343 :
344 : protected:
345 : nsAutoRefCnt mRefCnt;
346 : NS_DECL_OWNINGTHREAD
347 :
348 : // This reference is not reference-counted. The rule object tells us
349 : // when it's about to go away.
350 : nsCSSKeyframeRule *mRule;
351 : };
352 :
353 : class nsCSSKeyframeRule MOZ_FINAL : public mozilla::css::Rule,
354 : public nsIDOMMozCSSKeyframeRule
355 : {
356 : public:
357 : // WARNING: Steals the contents of aKeys *and* aDeclaration
358 0 : nsCSSKeyframeRule(nsTArray<float> aKeys,
359 : nsAutoPtr<mozilla::css::Declaration> aDeclaration)
360 0 : : mDeclaration(aDeclaration)
361 : {
362 0 : mKeys.SwapElements(aKeys);
363 0 : }
364 : private:
365 : nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy);
366 : ~nsCSSKeyframeRule();
367 : public:
368 : NS_DECL_ISUPPORTS_INHERITED
369 :
370 : // nsIStyleRule methods
371 : #ifdef DEBUG
372 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
373 : #endif
374 :
375 : // Rule methods
376 : DECL_STYLE_RULE_INHERIT
377 : virtual PRInt32 GetType() const;
378 : virtual already_AddRefed<mozilla::css::Rule> Clone() const;
379 :
380 : // nsIDOMCSSRule interface
381 : NS_DECL_NSIDOMCSSRULE
382 :
383 : // nsIDOMMozCSSKeyframeRule interface
384 : NS_DECL_NSIDOMMOZCSSKEYFRAMERULE
385 :
386 0 : const nsTArray<float>& GetKeys() const { return mKeys; }
387 0 : mozilla::css::Declaration* Declaration() { return mDeclaration; }
388 :
389 : void ChangeDeclaration(mozilla::css::Declaration* aDeclaration);
390 :
391 : virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
392 :
393 : private:
394 : nsAutoTArray<float, 1> mKeys;
395 : nsAutoPtr<mozilla::css::Declaration> mDeclaration;
396 : // lazily created when needed:
397 : nsRefPtr<nsCSSKeyframeStyleDeclaration> mDOMDeclaration;
398 : };
399 :
400 : class nsCSSKeyframesRule MOZ_FINAL : public mozilla::css::GroupRule,
401 : public nsIDOMMozCSSKeyframesRule
402 : {
403 : public:
404 0 : nsCSSKeyframesRule(const nsSubstring& aName)
405 0 : : mName(aName)
406 : {
407 0 : }
408 : private:
409 : nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy);
410 : ~nsCSSKeyframesRule();
411 : public:
412 : NS_DECL_ISUPPORTS_INHERITED
413 :
414 : // nsIStyleRule methods
415 : #ifdef DEBUG
416 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
417 : #endif
418 :
419 : // Rule methods
420 : virtual PRInt32 GetType() const;
421 : virtual already_AddRefed<mozilla::css::Rule> Clone() const;
422 0 : virtual nsIDOMCSSRule* GetDOMRule()
423 : {
424 0 : return this;
425 : }
426 :
427 : // nsIDOMCSSRule interface
428 : NS_DECL_NSIDOMCSSRULE
429 :
430 : // nsIDOMMozCSSKeyframesRule interface
431 : NS_DECL_NSIDOMMOZCSSKEYFRAMESRULE
432 :
433 : // rest of GroupRule
434 : virtual bool UseForPresentation(nsPresContext* aPresContext,
435 : nsMediaQueryResultCacheKey& aKey);
436 :
437 0 : const nsString& GetName() { return mName; }
438 :
439 : virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
440 :
441 : private:
442 : PRUint32 FindRuleIndexForKey(const nsAString& aKey);
443 :
444 : nsString mName;
445 : };
446 :
447 : #endif /* !defined(nsCSSRules_h_) */
|