Bug 454376 add -lCrun -lCstd for Solaris OS_LIBS, r=bsmedberg
[wine-gecko.git] / layout / style / nsCSSDeclaration.h
blobcbb5f5cc2b449bc5397deefb0b7c51c7f2418d7c
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Daniel Glazman <glazman@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * representation of a declaration block (or style attribute) in a CSS
41 * stylesheet
44 #ifndef nsCSSDeclaration_h___
45 #define nsCSSDeclaration_h___
47 #include "nsISupports.h"
48 #include "nsColor.h"
49 #include <stdio.h>
50 #include "nsString.h"
51 #include "nsCoord.h"
52 #include "nsCSSValue.h"
53 #include "nsCSSProps.h"
54 #include "nsTArray.h"
55 #include "nsCSSDataBlock.h"
56 #include "nsCSSStruct.h"
58 class nsCSSDeclaration {
59 public:
60 /**
61 * Construct an |nsCSSDeclaration| that is in an invalid state (null
62 * |mData|) and cannot be used until its |CompressFrom| method or
63 * |InitializeEmpty| method is called.
65 nsCSSDeclaration();
67 nsCSSDeclaration(const nsCSSDeclaration& aCopy);
69 /**
70 * |ValueAppended| must be called to maintain this declaration's
71 * |mOrder| whenever a property is parsed into an expanded data block
72 * for this declaration.
74 nsresult ValueAppended(nsCSSProperty aProperty);
76 nsresult AppendComment(const nsAString& aComment);
77 nsresult RemoveProperty(nsCSSProperty aProperty);
79 nsresult GetValue(nsCSSProperty aProperty, nsAString& aValue) const;
80 nsresult GetValue(const nsAString& aProperty, nsAString& aValue) const;
82 PRBool HasImportantData() const { return mImportantData != nsnull; }
83 PRBool GetValueIsImportant(nsCSSProperty aProperty) const;
84 PRBool GetValueIsImportant(const nsAString& aProperty) const;
86 PRUint32 Count() const {
87 return mOrder.Length();
89 nsresult GetNthProperty(PRUint32 aIndex, nsAString& aReturn) const;
91 nsresult ToString(nsAString& aString) const;
93 nsCSSDeclaration* Clone() const;
95 nsresult MapRuleInfoInto(nsRuleData *aRuleData) const {
96 return mData->MapRuleInfoInto(aRuleData);
99 nsresult MapImportantRuleInfoInto(nsRuleData *aRuleData) const {
100 return mImportantData->MapRuleInfoInto(aRuleData);
104 * Initialize this declaration as holding no data. Return false on
105 * out-of-memory.
107 PRBool InitializeEmpty();
110 * Transfer all of the state from |aExpandedData| into this declaration.
111 * After calling, |aExpandedData| should be in its initial state.
113 void CompressFrom(nsCSSExpandedDataBlock *aExpandedData) {
114 NS_ASSERTION(!mData, "oops");
115 NS_ASSERTION(!mImportantData, "oops");
116 aExpandedData->Compress(&mData, &mImportantData);
120 * Transfer all of the state from this declaration into
121 * |aExpandedData| and put this declaration temporarily into an
122 * invalid state (ended by |CompressFrom| or |InitializeEmpty|) that
123 * should last only during parsing. During this time only
124 * |ValueAppended| should be called.
126 void ExpandTo(nsCSSExpandedDataBlock *aExpandedData) {
127 aExpandedData->AssertInitialState();
129 NS_ASSERTION(mData, "oops");
130 aExpandedData->Expand(&mData, &mImportantData);
131 NS_ASSERTION(!mData && !mImportantData,
132 "Expand didn't null things out");
136 * Clear the data, in preparation for its replacement with entirely
137 * new data by a call to |CompressFrom|.
139 void ClearData() {
140 mData->Destroy();
141 mData = nsnull;
142 if (mImportantData) {
143 mImportantData->Destroy();
144 mImportantData = nsnull;
146 mOrder.Clear();
149 #ifdef DEBUG
150 void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
151 #endif
153 // return whether there was a value in |aValue| (i.e., it had a non-null unit)
154 static PRBool AppendCSSValueToString(nsCSSProperty aProperty,
155 const nsCSSValue& aValue,
156 nsAString& aResult);
158 private:
159 // Not implemented, and not supported.
160 nsCSSDeclaration& operator=(const nsCSSDeclaration& aCopy);
161 PRBool operator==(const nsCSSDeclaration& aCopy) const;
163 static void AppendImportanceToString(PRBool aIsImportant, nsAString& aString);
164 // return whether there was a value in |aValue| (i.e., it had a non-null unit)
165 PRBool AppendValueToString(nsCSSProperty aProperty, nsAString& aResult) const;
166 // May be called only for properties whose type is eCSSType_Value.
167 nsresult GetValueOrImportantValue(nsCSSProperty aProperty, nsCSSValue& aValue) const;
169 void PropertyIsSet(PRInt32 & aPropertyIndex, PRInt32 aIndex, PRUint32 & aSet, PRUint32 aValue) const;
170 PRBool TryBorderShorthand(nsAString & aString, PRUint32 aPropertiesSet,
171 PRInt32 aBorderTopWidth,
172 PRInt32 aBorderTopStyle,
173 PRInt32 aBorderTopColor,
174 PRInt32 aBorderBottomWidth,
175 PRInt32 aBorderBottomStyle,
176 PRInt32 aBorderBottomColor,
177 PRInt32 aBorderLeftWidth,
178 PRInt32 aBorderLeftStyle,
179 PRInt32 aBorderLeftColor,
180 PRInt32 aBorderRightWidth,
181 PRInt32 aBorderRightStyle,
182 PRInt32 aBorderRightColor) const;
183 PRBool TryBorderSideShorthand(nsAString & aString,
184 nsCSSProperty aShorthand,
185 PRInt32 aBorderWidth,
186 PRInt32 aBorderStyle,
187 PRInt32 aBorderColor) const;
188 PRBool TryFourSidesShorthand(nsAString & aString,
189 nsCSSProperty aShorthand,
190 PRInt32 & aTop,
191 PRInt32 & aBottom,
192 PRInt32 & aLeft,
193 PRInt32 & aRight,
194 PRBool aClearIndexes) const;
195 void TryBackgroundShorthand(nsAString & aString,
196 PRInt32 & aBgColor, PRInt32 & aBgImage,
197 PRInt32 & aBgRepeat, PRInt32 & aBgAttachment,
198 PRInt32 & aBgPosition) const;
199 void TryOverflowShorthand(nsAString & aString,
200 PRInt32 & aOverflowX, PRInt32 & aOverflowY) const;
201 #ifdef MOZ_SVG
202 void TryMarkerShorthand(nsAString & aString,
203 PRInt32 & aMarkerEnd,
204 PRInt32 & aMarkerMid,
205 PRInt32 & aMarkerStart) const;
206 #endif
208 PRBool AllPropertiesSameImportance(PRInt32 aFirst, PRInt32 aSecond,
209 PRInt32 aThird, PRInt32 aFourth,
210 PRInt32 aFifth,
211 PRBool & aImportance) const;
212 PRBool AllPropertiesSameValue(PRInt32 aFirst, PRInt32 aSecond,
213 PRInt32 aThird, PRInt32 aFourth) const;
214 void AppendPropertyAndValueToString(nsCSSProperty aProperty,
215 nsAString& aResult) const
217 AppendPropertyAndValueToString(aProperty, aProperty, aResult);
219 void AppendPropertyAndValueToString(nsCSSProperty aProperty,
220 nsCSSProperty aPropertyName,
221 nsAString& aResult) const;
223 private:
225 // Specialized ref counting.
226 // We do not want everyone to ref count us, only the rules which hold
227 // onto us (our well defined lifetime is when the last rule releases
228 // us).
229 // It's worth a comment here that the main nsCSSDeclaration is refcounted,
230 // but it's |mImportant| is not refcounted, but just owned by the
231 // non-important declaration.
233 friend class CSSStyleRuleImpl;
234 void AddRef(void) {
235 ++mRefCnt;
237 void Release(void) {
238 NS_ASSERTION(0 < mRefCnt, "bad Release");
239 if (0 == --mRefCnt) {
240 delete this;
243 public:
244 void RuleAbort(void) {
245 NS_ASSERTION(0 == mRefCnt, "bad RuleAbort");
246 delete this;
248 private:
249 // Block everyone, except us or a derivative, from deleting us.
250 ~nsCSSDeclaration(void);
252 nsCSSProperty OrderValueAt(PRUint32 aValue) const {
253 return nsCSSProperty(mOrder.ElementAt(aValue));
256 private:
257 nsAutoTArray<PRUint8, 8> mOrder;
258 nsAutoRefCnt mRefCnt;
259 nsCSSCompressedDataBlock *mData; // never null, except while expanded
260 nsCSSCompressedDataBlock *mImportantData; // may be null
263 #endif /* nsCSSDeclaration_h___ */