Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / layout / style / nsROCSSPrimitiveValue.h
blobc98aaf2286bc1f84a321f44da7272f35c649d734
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):
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"
44 #include "nsString.h"
45 #include "nsCoord.h"
46 #include "nsReadableUtils.h"
47 #include "nsIURI.h"
48 #include "nsIAtom.h"
49 #include "nsCSSKeywords.h"
51 #include "nsCOMPtr.h"
52 #include "nsDOMError.h"
53 #include "nsDOMCSSRect.h"
54 #include "nsDOMCSSRGBColor.h"
56 class nsROCSSPrimitiveValue : public nsIDOMCSSPrimitiveValue
58 public:
59 NS_DECL_ISUPPORTS
61 // nsIDOMCSSPrimitiveValue
62 NS_DECL_NSIDOMCSSPRIMITIVEVALUE
64 // nsIDOMCSSValue
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)
75 Reset();
76 mValue.mFloat = aValue;
77 mType = CSS_NUMBER;
80 void SetNumber(PRInt32 aValue)
82 Reset();
83 mValue.mFloat = float(aValue);
84 mType = CSS_NUMBER;
87 void SetNumber(PRUint32 aValue)
89 Reset();
90 mValue.mFloat = float(aValue);
91 mType = CSS_NUMBER;
94 void SetPercent(float aValue)
96 Reset();
97 mValue.mFloat = aValue;
98 mType = CSS_PERCENTAGE;
101 void SetAppUnits(nscoord aValue)
103 Reset();
104 mValue.mAppUnits = aValue;
105 mType = CSS_PX;
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");
116 Reset();
117 NS_ADDREF(mValue.mAtom = aAtom);
118 mType = CSS_IDENT;
121 // FIXME More callers should use this variant.
122 void SetIdent(nsCSSKeyword aKeyword)
124 SetIdent(nsCSSKeywords::GetStringValue(aKeyword));
127 void SetIdent(const nsACString& aString)
129 Reset();
130 mValue.mAtom = NS_NewAtom(aString);
131 if (mValue.mAtom) {
132 mType = CSS_IDENT;
133 } else {
134 // XXXcaa We should probably let the caller know we are out of memory
135 mType = CSS_UNKNOWN;
139 // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
140 void SetString(const nsACString& aString, PRUint16 aType = CSS_STRING)
142 Reset();
143 mValue.mString = ToNewUnicode(aString);
144 if (mValue.mString) {
145 mType = aType;
146 } else {
147 // XXXcaa We should probably let the caller know we are out of memory
148 mType = CSS_UNKNOWN;
152 // FIXME: CSS_STRING should imply a string with "" and a need for escaping.
153 void SetString(const nsAString& aString, PRUint16 aType = CSS_STRING)
155 Reset();
156 mValue.mString = ToNewUnicode(aString);
157 if (mValue.mString) {
158 mType = aType;
159 } else {
160 // XXXcaa We should probably let the caller know we are out of memory
161 mType = CSS_UNKNOWN;
165 void SetURI(nsIURI *aURI)
167 Reset();
168 mValue.mURI = aURI;
169 NS_IF_ADDREF(mValue.mURI);
170 mType = CSS_URI;
173 void SetColor(nsDOMCSSRGBColor* aColor)
175 NS_PRECONDITION(aColor, "Null RGBColor being set!");
176 Reset();
177 mValue.mColor = aColor;
178 if (mValue.mColor) {
179 NS_ADDREF(mValue.mColor);
180 mType = CSS_RGBCOLOR;
182 else {
183 mType = CSS_UNKNOWN;
187 void SetRect(nsIDOMRect* aRect)
189 NS_PRECONDITION(aRect, "Null rect being set!");
190 Reset();
191 mValue.mRect = aRect;
192 if (mValue.mRect) {
193 NS_ADDREF(mValue.mRect);
194 mType = CSS_RECT;
196 else {
197 mType = CSS_UNKNOWN;
201 void Reset(void)
203 switch (mType) {
204 case CSS_IDENT:
205 NS_ASSERTION(mValue.mAtom, "Null atom should never happen");
206 NS_RELEASE(mValue.mAtom);
207 break;
208 case CSS_STRING:
209 case CSS_ATTR:
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;
214 break;
215 case CSS_URI:
216 NS_IF_RELEASE(mValue.mURI);
217 break;
218 case CSS_RECT:
219 NS_ASSERTION(mValue.mRect, "Null Rect should never happen");
220 NS_RELEASE(mValue.mRect);
221 break;
222 case CSS_RGBCOLOR:
223 NS_ASSERTION(mValue.mColor, "Null RGBColor should never happen");
224 NS_RELEASE(mValue.mColor);
225 break;
229 private:
230 void GetEscapedURI(nsIURI *aURI, PRUnichar **aReturn);
232 PRUint16 mType;
234 union {
235 nscoord mAppUnits;
236 float mFloat;
237 nsDOMCSSRGBColor* mColor;
238 nsIDOMRect* mRect;
239 PRUnichar* mString;
240 nsIURI* mURI;
241 nsIAtom* mAtom; // FIXME use nsCSSKeyword instead
242 } mValue;
244 PRInt32 mAppUnitsPerInch;
247 #endif /* nsROCSSPrimitiveValue_h___ */