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
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.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* DOM object representing values in DOM computed style */
40 #ifndef nsROCSSPrimitiveValue_h___
41 #define nsROCSSPrimitiveValue_h___
43 #include "nsIDOMCSSPrimitiveValue.h"
46 #include "nsReadableUtils.h"
49 #include "nsCSSKeywords.h"
52 #include "nsDOMError.h"
53 #include "nsDOMCSSRect.h"
54 #include "nsDOMCSSRGBColor.h"
56 class nsROCSSPrimitiveValue
: public nsIDOMCSSPrimitiveValue
61 // nsIDOMCSSPrimitiveValue
62 NS_DECL_NSIDOMCSSPRIMITIVEVALUE
65 NS_DECL_NSIDOMCSSVALUE
67 // nsROCSSPrimitiveValue
68 nsROCSSPrimitiveValue(PRInt32 aAppUnitsPerInch
);
69 virtual ~nsROCSSPrimitiveValue();
71 // FIXME Many of these methods should be out-of-line.
73 void SetNumber(float aValue
)
76 mValue
.mFloat
= aValue
;
80 void SetNumber(PRInt32 aValue
)
83 mValue
.mFloat
= float(aValue
);
87 void SetNumber(PRUint32 aValue
)
90 mValue
.mFloat
= float(aValue
);
94 void SetPercent(float aValue
)
97 mValue
.mFloat
= aValue
;
98 mType
= CSS_PERCENTAGE
;
101 void SetAppUnits(nscoord aValue
)
104 mValue
.mAppUnits
= aValue
;
108 void SetAppUnits(float aValue
)
110 SetAppUnits(NSToCoordRound(aValue
));
113 void SetIdent(nsIAtom
* aAtom
)
115 NS_PRECONDITION(aAtom
, "Don't pass in a null atom");
117 NS_ADDREF(mValue
.mAtom
= aAtom
);
121 // FIXME More callers should use this variant.
122 void SetIdent(nsCSSKeyword aKeyword
)
124 SetIdent(nsCSSKeywords::GetStringValue(aKeyword
));
127 void SetIdent(const nsACString
& aString
)
130 mValue
.mAtom
= NS_NewAtom(aString
);
134 // XXXcaa We should probably let the caller know we are out of memory
139 // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
140 void SetString(const nsACString
& aString
, PRUint16 aType
= CSS_STRING
)
143 mValue
.mString
= ToNewUnicode(aString
);
144 if (mValue
.mString
) {
147 // XXXcaa We should probably let the caller know we are out of memory
152 // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
153 void SetString(const nsAString
& aString
, PRUint16 aType
= CSS_STRING
)
156 mValue
.mString
= ToNewUnicode(aString
);
157 if (mValue
.mString
) {
160 // XXXcaa We should probably let the caller know we are out of memory
165 void SetURI(nsIURI
*aURI
)
169 NS_IF_ADDREF(mValue
.mURI
);
173 void SetColor(nsDOMCSSRGBColor
* aColor
)
175 NS_PRECONDITION(aColor
, "Null RGBColor being set!");
177 mValue
.mColor
= aColor
;
179 NS_ADDREF(mValue
.mColor
);
180 mType
= CSS_RGBCOLOR
;
187 void SetRect(nsIDOMRect
* aRect
)
189 NS_PRECONDITION(aRect
, "Null rect being set!");
191 mValue
.mRect
= aRect
;
193 NS_ADDREF(mValue
.mRect
);
205 NS_ASSERTION(mValue
.mAtom
, "Null atom should never happen");
206 NS_RELEASE(mValue
.mAtom
);
210 case CSS_COUNTER
: // FIXME: Counter should use an object
211 NS_ASSERTION(mValue
.mString
, "Null string should never happen");
212 nsMemory::Free(mValue
.mString
);
213 mValue
.mString
= nsnull
;
216 NS_IF_RELEASE(mValue
.mURI
);
219 NS_ASSERTION(mValue
.mRect
, "Null Rect should never happen");
220 NS_RELEASE(mValue
.mRect
);
223 NS_ASSERTION(mValue
.mColor
, "Null RGBColor should never happen");
224 NS_RELEASE(mValue
.mColor
);
230 void GetEscapedURI(nsIURI
*aURI
, PRUnichar
**aReturn
);
237 nsDOMCSSRGBColor
* mColor
;
241 nsIAtom
* mAtom
; // FIXME use nsCSSKeyword instead
244 PRInt32 mAppUnitsPerInch
;
247 #endif /* nsROCSSPrimitiveValue_h___ */