Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / layout / style / nsCSSRules.h
blobb340c929b28b4b0562fe3dd9c2e36faf12e44ff5
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
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/
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.
16 * The Original Code is mozilla.org code.
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.
23 * Contributor(s):
24 * L. David Baron <dbaron@dbaron.org>
25 * Boris Zbarsky <bzbarsky@mit.edu>
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.
39 * ***** END LICENSE BLOCK ***** */
41 /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
43 #ifndef nsCSSRules_h_
44 #define nsCSSRules_h_
46 #include "nsCSSRule.h"
47 #include "nsICSSGroupRule.h"
48 #include "nsIDOMCSSMediaRule.h"
49 #include "nsIDOMCSSMozDocumentRule.h"
50 #include "nsIDOMCSSFontFaceRule.h"
51 #include "nsIDOMCSSStyleDeclaration.h"
52 #include "nsAutoPtr.h"
53 #include "nsCSSProperty.h"
54 #include "nsCSSValue.h"
56 class CSSGroupRuleRuleListImpl;
57 class nsMediaList;
59 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
60 NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
61 NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
62 NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
63 NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
65 #define DECL_STYLE_RULE_INHERIT \
66 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
67 nsIDOMCSSRule* GetDOMRuleWeak(nsresult* aResult);
69 // inherits from nsCSSRule and also implements methods on nsICSSGroupRule
70 // so they can be shared between nsCSSMediaRule and nsCSSDocumentRule
71 class nsCSSGroupRule : public nsCSSRule, public nsICSSGroupRule
73 protected:
74 nsCSSGroupRule();
75 nsCSSGroupRule(const nsCSSGroupRule& aCopy);
76 ~nsCSSGroupRule();
78 // implement part of nsIStyleRule and nsICSSRule
79 DECL_STYLE_RULE_INHERIT_NO_DOMRULE
81 // to help implement nsIStyleRule
82 #ifdef DEBUG
83 NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
84 #endif
86 public:
87 // implement nsICSSGroupRule
88 NS_IMETHOD AppendStyleRule(nsICSSRule* aRule);
89 NS_IMETHOD StyleRuleCount(PRInt32& aCount) const;
90 NS_IMETHOD GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const;
91 NS_IMETHOD_(PRBool) EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
92 NS_IMETHOD DeleteStyleRuleAt(PRUint32 aIndex);
93 NS_IMETHOD InsertStyleRulesAt(PRUint32 aIndex,
94 nsCOMArray<nsICSSRule>& aRules);
95 NS_IMETHOD ReplaceStyleRule(nsICSSRule *aOld, nsICSSRule *aNew);
97 protected:
98 // to help implement nsIDOMCSSRule
99 nsresult AppendRulesToCssText(nsAString& aCssText);
100 // to implement methods on nsIDOMCSSRule
101 nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
102 nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
104 // to implement common methods on nsIDOMCSSMediaRule and
105 // nsIDOMCSSMozDocumentRule
106 nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
107 nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
108 PRUint32* _retval);
109 nsresult DeleteRule(PRUint32 aIndex);
111 nsCOMArray<nsICSSRule> mRules;
112 CSSGroupRuleRuleListImpl* mRuleCollection;
115 class nsCSSMediaRule : public nsCSSGroupRule,
116 public nsIDOMCSSMediaRule
118 public:
119 nsCSSMediaRule();
120 nsCSSMediaRule(const nsCSSMediaRule& aCopy);
121 virtual ~nsCSSMediaRule();
123 NS_DECL_ISUPPORTS_INHERITED
125 // nsIStyleRule methods
126 #ifdef DEBUG
127 NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
128 #endif
130 // nsICSSRule methods
131 NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); //override nsCSSGroupRule
132 NS_IMETHOD GetType(PRInt32& aType) const;
133 NS_IMETHOD Clone(nsICSSRule*& aClone) const;
134 nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
136 *aResult = NS_OK;
137 return this;
140 // nsIDOMCSSRule interface
141 NS_DECL_NSIDOMCSSRULE
143 // nsIDOMCSSMediaRule interface
144 NS_DECL_NSIDOMCSSMEDIARULE
146 // rest of nsICSSGroupRule interface
147 NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext,
148 nsMediaQueryResultCacheKey& aKey);
150 // @media rule methods
151 nsresult SetMedia(nsMediaList* aMedia);
153 protected:
154 nsRefPtr<nsMediaList> mMedia;
157 class nsCSSDocumentRule : public nsCSSGroupRule,
158 public nsIDOMCSSMozDocumentRule
160 public:
161 nsCSSDocumentRule(void);
162 nsCSSDocumentRule(const nsCSSDocumentRule& aCopy);
163 virtual ~nsCSSDocumentRule(void);
165 NS_DECL_ISUPPORTS_INHERITED
167 // nsIStyleRule methods
168 #ifdef DEBUG
169 NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
170 #endif
172 // nsICSSRule methods
173 NS_IMETHOD GetType(PRInt32& aType) const;
174 NS_IMETHOD Clone(nsICSSRule*& aClone) const;
175 nsIDOMCSSRule* GetDOMRuleWeak(nsresult *aResult)
177 *aResult = NS_OK;
178 return this;
181 // nsIDOMCSSRule interface
182 NS_DECL_NSIDOMCSSRULE
184 // nsIDOMCSSMozDocumentRule interface
185 NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
187 // rest of nsICSSGroupRule interface
188 NS_IMETHOD_(PRBool) UseForPresentation(nsPresContext* aPresContext,
189 nsMediaQueryResultCacheKey& aKey);
191 enum Function {
192 eURL,
193 eURLPrefix,
194 eDomain
197 struct URL {
198 Function func;
199 nsCString url;
200 URL *next;
202 URL() : next(nsnull) {}
203 URL(const URL& aOther)
204 : func(aOther.func)
205 , url(aOther.url)
206 , next(aOther.next ? new URL(*aOther.next) : nsnull)
209 ~URL() { delete next; }
212 void SetURLs(URL *aURLs) { mURLs = aURLs; }
214 protected:
215 nsAutoPtr<URL> mURLs; // linked list of |struct URL| above.
218 // A nsCSSFontFaceStyleDecl is always embedded in a nsCSSFontFaceRule.
219 class nsCSSFontFaceRule;
220 class nsCSSFontFaceStyleDecl : public nsIDOMCSSStyleDeclaration
222 public:
223 NS_DECL_ISUPPORTS
224 NS_DECL_NSIDOMCSSSTYLEDECLARATION
226 nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
227 nsAString & aResult NS_OUTPARAM) const;
229 protected:
230 friend class nsCSSFontFaceRule;
231 nsCSSValue mFamily;
232 nsCSSValue mStyle;
233 nsCSSValue mWeight;
234 nsCSSValue mStretch;
235 nsCSSValue mSrc;
236 nsCSSValue mUnicodeRange;
238 static nsCSSValue nsCSSFontFaceStyleDecl::* const Fields[];
239 inline nsCSSFontFaceRule* ContainingRule();
240 inline const nsCSSFontFaceRule* ContainingRule() const;
242 private:
243 // NOT TO BE IMPLEMENTED
244 // This object cannot be allocated on its own, only as part of
245 // nsCSSFontFaceRule.
246 void* operator new(size_t size) CPP_THROW_NEW;
249 class nsCSSFontFaceRule : public nsCSSRule,
250 public nsICSSRule,
251 public nsIDOMCSSFontFaceRule
253 public:
254 NS_DECL_ISUPPORTS_INHERITED
256 // nsIStyleRule methods
257 #ifdef DEBUG
258 NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
259 #endif
261 // nsICSSRule methods
262 DECL_STYLE_RULE_INHERIT
264 NS_IMETHOD GetType(PRInt32& aType) const;
265 NS_IMETHOD Clone(nsICSSRule*& aClone) const;
267 // nsIDOMCSSRule interface
268 NS_DECL_NSIDOMCSSRULE
270 // nsIDOMCSSFontFaceRule interface
271 NS_DECL_NSIDOMCSSFONTFACERULE
273 void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue);
274 void GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue);
276 protected:
277 friend class nsCSSFontFaceStyleDecl;
278 nsCSSFontFaceStyleDecl mDecl;
281 inline nsCSSFontFaceRule*
282 nsCSSFontFaceStyleDecl::ContainingRule()
284 return reinterpret_cast<nsCSSFontFaceRule*>
285 (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
288 inline const nsCSSFontFaceRule*
289 nsCSSFontFaceStyleDecl::ContainingRule() const
291 return reinterpret_cast<const nsCSSFontFaceRule*>
292 (reinterpret_cast<const char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
295 #endif /* !defined(nsCSSRules_h_) */