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
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.
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) */
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
;
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
75 nsCSSGroupRule(const nsCSSGroupRule
& aCopy
);
78 // implement part of nsIStyleRule and nsICSSRule
79 DECL_STYLE_RULE_INHERIT_NO_DOMRULE
81 // to help implement nsIStyleRule
83 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
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
);
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
,
109 nsresult
DeleteRule(PRUint32 aIndex
);
111 nsCOMArray
<nsICSSRule
> mRules
;
112 CSSGroupRuleRuleListImpl
* mRuleCollection
;
115 class nsCSSMediaRule
: public nsCSSGroupRule
,
116 public nsIDOMCSSMediaRule
120 nsCSSMediaRule(const nsCSSMediaRule
& aCopy
);
121 virtual ~nsCSSMediaRule();
123 NS_DECL_ISUPPORTS_INHERITED
125 // nsIStyleRule methods
127 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
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
)
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
);
154 nsRefPtr
<nsMediaList
> mMedia
;
157 class nsCSSDocumentRule
: public nsCSSGroupRule
,
158 public nsIDOMCSSMozDocumentRule
161 nsCSSDocumentRule(void);
162 nsCSSDocumentRule(const nsCSSDocumentRule
& aCopy
);
163 virtual ~nsCSSDocumentRule(void);
165 NS_DECL_ISUPPORTS_INHERITED
167 // nsIStyleRule methods
169 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
172 // nsICSSRule methods
173 NS_IMETHOD
GetType(PRInt32
& aType
) const;
174 NS_IMETHOD
Clone(nsICSSRule
*& aClone
) const;
175 nsIDOMCSSRule
* GetDOMRuleWeak(nsresult
*aResult
)
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
);
202 URL() : next(nsnull
) {}
203 URL(const URL
& aOther
)
206 , next(aOther
.next
? new URL(*aOther
.next
) : nsnull
)
209 ~URL() { delete next
; }
212 void SetURLs(URL
*aURLs
) { mURLs
= aURLs
; }
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
224 NS_DECL_NSIDOMCSSSTYLEDECLARATION
226 nsresult
GetPropertyValue(nsCSSFontDesc aFontDescID
,
227 nsAString
& aResult NS_OUTPARAM
) const;
230 friend class nsCSSFontFaceRule
;
236 nsCSSValue mUnicodeRange
;
238 static nsCSSValue
nsCSSFontFaceStyleDecl::* const Fields
[];
239 inline nsCSSFontFaceRule
* ContainingRule();
240 inline const nsCSSFontFaceRule
* ContainingRule() const;
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
,
251 public nsIDOMCSSFontFaceRule
254 NS_DECL_ISUPPORTS_INHERITED
256 // nsIStyleRule methods
258 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
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
);
277 friend class nsCSSFontFaceStyleDecl
;
278 nsCSSFontFaceStyleDecl mDecl
;
281 // nsFontFaceRuleContainer - used for associating sheet type with
282 // specific @font-face rules
283 struct nsFontFaceRuleContainer
{
284 nsRefPtr
<nsCSSFontFaceRule
> mRule
;
288 inline nsCSSFontFaceRule
*
289 nsCSSFontFaceStyleDecl::ContainingRule()
291 return reinterpret_cast<nsCSSFontFaceRule
*>
292 (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule
, mDecl
));
295 inline const nsCSSFontFaceRule
*
296 nsCSSFontFaceStyleDecl::ContainingRule() const
298 return reinterpret_cast<const nsCSSFontFaceRule
*>
299 (reinterpret_cast<const char*>(this) - offsetof(nsCSSFontFaceRule
, mDecl
));
302 #endif /* !defined(nsCSSRules_h_) */