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 \
60 NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const; \
61 NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet); \
62 NS_IMETHOD SetParentRule(nsICSSGroupRule* aRule); \
63 NS_IMETHOD GetDOMRule(nsIDOMCSSRule** aDOMRule); \
64 NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
66 // inherits from nsCSSRule and also implements methods on nsICSSGroupRule
67 // so they can be shared between nsCSSMediaRule and nsCSSDocumentRule
68 class nsCSSGroupRule
: public nsCSSRule
, public nsICSSGroupRule
72 nsCSSGroupRule(const nsCSSGroupRule
& aCopy
);
75 // implement part of nsIStyleRule and nsICSSRule
76 DECL_STYLE_RULE_INHERIT
78 // to help implement nsIStyleRule
80 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
84 // implement nsICSSGroupRule
85 NS_IMETHOD
AppendStyleRule(nsICSSRule
* aRule
);
86 NS_IMETHOD
StyleRuleCount(PRInt32
& aCount
) const;
87 NS_IMETHOD
GetStyleRuleAt(PRInt32 aIndex
, nsICSSRule
*& aRule
) const;
88 NS_IMETHOD_(PRBool
) EnumerateRulesForwards(RuleEnumFunc aFunc
, void * aData
) const;
89 NS_IMETHOD
DeleteStyleRuleAt(PRUint32 aIndex
);
90 NS_IMETHOD
InsertStyleRulesAt(PRUint32 aIndex
,
91 nsCOMArray
<nsICSSRule
>& aRules
);
92 NS_IMETHOD
ReplaceStyleRule(nsICSSRule
*aOld
, nsICSSRule
*aNew
);
95 // to help implement nsIDOMCSSRule
96 nsresult
AppendRulesToCssText(nsAString
& aCssText
);
97 // to implement methods on nsIDOMCSSRule
98 nsresult
GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
);
99 nsresult
GetParentRule(nsIDOMCSSRule
** aParentRule
);
101 // to implement common methods on nsIDOMCSSMediaRule and
102 // nsIDOMCSSMozDocumentRule
103 nsresult
GetCssRules(nsIDOMCSSRuleList
* *aRuleList
);
104 nsresult
InsertRule(const nsAString
& aRule
, PRUint32 aIndex
,
106 nsresult
DeleteRule(PRUint32 aIndex
);
108 nsCOMArray
<nsICSSRule
> mRules
;
109 CSSGroupRuleRuleListImpl
* mRuleCollection
;
112 class nsCSSMediaRule
: public nsCSSGroupRule
,
113 public nsIDOMCSSMediaRule
117 nsCSSMediaRule(const nsCSSMediaRule
& aCopy
);
118 virtual ~nsCSSMediaRule();
120 NS_DECL_ISUPPORTS_INHERITED
122 // nsIStyleRule methods
124 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
127 // nsICSSRule methods
128 NS_IMETHOD
SetStyleSheet(nsICSSStyleSheet
* aSheet
); //override nsCSSGroupRule
129 NS_IMETHOD
GetType(PRInt32
& aType
) const;
130 NS_IMETHOD
Clone(nsICSSRule
*& aClone
) const;
132 // nsIDOMCSSRule interface
133 NS_DECL_NSIDOMCSSRULE
135 // nsIDOMCSSMediaRule interface
136 NS_DECL_NSIDOMCSSMEDIARULE
138 // rest of nsICSSGroupRule interface
139 NS_IMETHOD_(PRBool
) UseForPresentation(nsPresContext
* aPresContext
,
140 nsMediaQueryResultCacheKey
& aKey
);
142 // @media rule methods
143 nsresult
SetMedia(nsMediaList
* aMedia
);
146 nsRefPtr
<nsMediaList
> mMedia
;
149 class nsCSSDocumentRule
: public nsCSSGroupRule
,
150 public nsIDOMCSSMozDocumentRule
153 nsCSSDocumentRule(void);
154 nsCSSDocumentRule(const nsCSSDocumentRule
& aCopy
);
155 virtual ~nsCSSDocumentRule(void);
157 NS_DECL_ISUPPORTS_INHERITED
159 // nsIStyleRule methods
161 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
164 // nsICSSRule methods
165 NS_IMETHOD
GetType(PRInt32
& aType
) const;
166 NS_IMETHOD
Clone(nsICSSRule
*& aClone
) const;
168 // nsIDOMCSSRule interface
169 NS_DECL_NSIDOMCSSRULE
171 // nsIDOMCSSMozDocumentRule interface
172 NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
174 // rest of nsICSSGroupRule interface
175 NS_IMETHOD_(PRBool
) UseForPresentation(nsPresContext
* aPresContext
,
176 nsMediaQueryResultCacheKey
& aKey
);
189 URL() : next(nsnull
) {}
190 URL(const URL
& aOther
)
193 , next(aOther
.next
? new URL(*aOther
.next
) : nsnull
)
196 ~URL() { delete next
; }
199 void SetURLs(URL
*aURLs
) { mURLs
= aURLs
; }
202 nsAutoPtr
<URL
> mURLs
; // linked list of |struct URL| above.
205 // A nsCSSFontFaceStyleDecl is always embedded in a nsCSSFontFaceRule.
206 class nsCSSFontFaceRule
;
207 class nsCSSFontFaceStyleDecl
: public nsIDOMCSSStyleDeclaration
211 NS_DECL_NSIDOMCSSSTYLEDECLARATION
213 nsresult
GetPropertyValue(nsCSSFontDesc aFontDescID
,
214 nsAString
& aResult NS_OUTPARAM
) const;
217 friend class nsCSSFontFaceRule
;
223 nsCSSValue mUnicodeRange
;
225 static nsCSSValue
nsCSSFontFaceStyleDecl::* const Fields
[];
226 inline nsCSSFontFaceRule
* ContainingRule();
227 inline const nsCSSFontFaceRule
* ContainingRule() const;
230 // NOT TO BE IMPLEMENTED
231 // This object cannot be allocated on its own, only as part of
232 // nsCSSFontFaceRule.
233 void* operator new(size_t size
) CPP_THROW_NEW
;
236 class nsCSSFontFaceRule
: public nsCSSRule
,
238 public nsIDOMCSSFontFaceRule
241 NS_DECL_ISUPPORTS_INHERITED
243 // nsIStyleRule methods
245 NS_IMETHOD
List(FILE* out
= stdout
, PRInt32 aIndent
= 0) const;
248 // nsICSSRule methods
249 DECL_STYLE_RULE_INHERIT
251 NS_IMETHOD
GetType(PRInt32
& aType
) const;
252 NS_IMETHOD
Clone(nsICSSRule
*& aClone
) const;
254 // nsIDOMCSSRule interface
255 NS_DECL_NSIDOMCSSRULE
257 // nsIDOMCSSFontFaceRule interface
258 NS_DECL_NSIDOMCSSFONTFACERULE
260 void SetDesc(nsCSSFontDesc aDescID
, nsCSSValue
const & aValue
);
261 void GetDesc(nsCSSFontDesc aDescID
, nsCSSValue
& aValue
);
264 friend class nsCSSFontFaceStyleDecl
;
265 nsCSSFontFaceStyleDecl mDecl
;
268 inline nsCSSFontFaceRule
*
269 nsCSSFontFaceStyleDecl::ContainingRule()
271 return reinterpret_cast<nsCSSFontFaceRule
*>
272 (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule
, mDecl
));
275 inline const nsCSSFontFaceRule
*
276 nsCSSFontFaceStyleDecl::ContainingRule() const
278 return reinterpret_cast<const nsCSSFontFaceRule
*>
279 (reinterpret_cast<const char*>(this) - offsetof(nsCSSFontFaceRule
, mDecl
));
282 #endif /* !defined(nsCSSRules_h_) */