Bug 451040 ? Passwords Manager Empty after convert to MozStorage. r=gavin
[wine-gecko.git] / layout / style / nsStyleCoord.cpp
blobb4f9d6deb10951ce51f8cb96f58b0e973d167dde
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 /* representation of length values in computed style data */
40 #include "nsStyleCoord.h"
41 #include "nsString.h"
42 #include "nsCRT.h"
44 nsStyleCoord::nsStyleCoord(nsStyleUnit aUnit)
45 : mUnit(aUnit)
47 NS_ASSERTION(aUnit < eStyleUnit_Percent, "not a valueless unit");
48 if (aUnit >= eStyleUnit_Percent) {
49 mUnit = eStyleUnit_Null;
51 mValue.mInt = 0;
54 nsStyleCoord::nsStyleCoord(nscoord aValue)
55 : mUnit(eStyleUnit_Coord)
57 mValue.mInt = aValue;
60 nsStyleCoord::nsStyleCoord(PRInt32 aValue, nsStyleUnit aUnit)
61 : mUnit(aUnit)
63 //if you want to pass in eStyleUnit_Coord, don't. instead, use the
64 //constructor just above this one... MMP
65 NS_ASSERTION((aUnit == eStyleUnit_Enumerated) ||
66 (aUnit == eStyleUnit_Integer), "not an int value");
67 if ((aUnit == eStyleUnit_Enumerated) ||
68 (aUnit == eStyleUnit_Integer)) {
69 mValue.mInt = aValue;
71 else {
72 mUnit = eStyleUnit_Null;
73 mValue.mInt = 0;
77 nsStyleCoord::nsStyleCoord(float aValue, nsStyleUnit aUnit)
78 : mUnit(aUnit)
80 NS_ASSERTION((aUnit == eStyleUnit_Percent) ||
81 (aUnit == eStyleUnit_Factor), "not a float value");
82 if ((aUnit == eStyleUnit_Percent) ||
83 (aUnit == eStyleUnit_Factor)) {
84 mValue.mFloat = aValue;
86 else {
87 mUnit = eStyleUnit_Null;
88 mValue.mInt = 0;
92 nsStyleCoord& nsStyleCoord::operator=(const nsStyleCoord& aCopy)
94 mUnit = aCopy.mUnit;
95 if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
96 mValue.mFloat = aCopy.mValue.mFloat;
98 else {
99 mValue.mInt = aCopy.mValue.mInt;
101 return *this;
104 PRBool nsStyleCoord::operator==(const nsStyleCoord& aOther) const
106 if (mUnit == aOther.mUnit) {
107 if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
108 return PRBool(mValue.mFloat == aOther.mValue.mFloat);
110 else {
111 return PRBool(mValue.mInt == aOther.mValue.mInt);
114 return PR_FALSE;
117 void nsStyleCoord::Reset(void)
119 mUnit = eStyleUnit_Null;
120 mValue.mInt = 0;
123 void nsStyleCoord::SetCoordValue(nscoord aValue)
125 mUnit = eStyleUnit_Coord;
126 mValue.mInt = aValue;
129 void nsStyleCoord::SetIntValue(PRInt32 aValue, nsStyleUnit aUnit)
131 NS_ASSERTION((aUnit == eStyleUnit_Enumerated) ||
132 (aUnit == eStyleUnit_Integer), "not an int value");
133 if ((aUnit == eStyleUnit_Enumerated) ||
134 (aUnit == eStyleUnit_Integer)) {
135 mUnit = aUnit;
136 mValue.mInt = aValue;
138 else {
139 Reset();
143 void nsStyleCoord::SetPercentValue(float aValue)
145 mUnit = eStyleUnit_Percent;
146 mValue.mFloat = aValue;
149 void nsStyleCoord::SetFactorValue(float aValue)
151 mUnit = eStyleUnit_Factor;
152 mValue.mFloat = aValue;
155 void nsStyleCoord::SetNormalValue(void)
157 mUnit = eStyleUnit_Normal;
158 mValue.mInt = 0;
161 void nsStyleCoord::SetAutoValue(void)
163 mUnit = eStyleUnit_Auto;
164 mValue.mInt = 0;
167 void nsStyleCoord::SetNoneValue(void)
169 mUnit = eStyleUnit_None;
170 mValue.mInt = 0;
173 void nsStyleCoord::AppendToString(nsString& aBuffer) const
175 if ((eStyleUnit_Percent <= mUnit) && (mUnit < eStyleUnit_Coord)) {
176 aBuffer.AppendFloat(mValue.mFloat);
178 else if ((eStyleUnit_Coord == mUnit) ||
179 (eStyleUnit_Enumerated == mUnit) ||
180 (eStyleUnit_Integer == mUnit)) {
181 aBuffer.AppendInt(mValue.mInt, 10);
182 aBuffer.AppendLiteral("[0x");
183 aBuffer.AppendInt(mValue.mInt, 16);
184 aBuffer.Append(PRUnichar(']'));
187 switch (mUnit) {
188 case eStyleUnit_Null: aBuffer.AppendLiteral("Null"); break;
189 case eStyleUnit_Coord: aBuffer.AppendLiteral("tw"); break;
190 case eStyleUnit_Percent: aBuffer.AppendLiteral("%"); break;
191 case eStyleUnit_Factor: aBuffer.AppendLiteral("f"); break;
192 case eStyleUnit_Normal: aBuffer.AppendLiteral("Normal"); break;
193 case eStyleUnit_Auto: aBuffer.AppendLiteral("Auto"); break;
194 case eStyleUnit_None: aBuffer.AppendLiteral("None"); break;
195 case eStyleUnit_Enumerated: aBuffer.AppendLiteral("enum"); break;
196 case eStyleUnit_Integer: aBuffer.AppendLiteral("int"); break;
198 aBuffer.Append(PRUnichar(' '));
201 void nsStyleCoord::ToString(nsString& aBuffer) const
203 aBuffer.Truncate();
204 AppendToString(aBuffer);
210 nsStyleSides::nsStyleSides(void)
212 memset(this, 0x00, sizeof(nsStyleSides));
215 #define COMPARE_SIDE(side) \
216 if ((eStyleUnit_Percent <= mUnits[side]) && \
217 (mUnits[side] < eStyleUnit_Coord)) { \
218 if (mValues[side].mFloat != aOther.mValues[side].mFloat) \
219 return PR_FALSE; \
221 else { \
222 if (mValues[side].mInt != aOther.mValues[side].mInt) \
223 return PR_FALSE; \
226 PRBool nsStyleSides::operator==(const nsStyleSides& aOther) const
228 if ((mUnits[NS_SIDE_LEFT] == aOther.mUnits[NS_SIDE_LEFT]) &&
229 (mUnits[NS_SIDE_TOP] == aOther.mUnits[NS_SIDE_TOP]) &&
230 (mUnits[NS_SIDE_RIGHT] == aOther.mUnits[NS_SIDE_RIGHT]) &&
231 (mUnits[NS_SIDE_BOTTOM] == aOther.mUnits[NS_SIDE_BOTTOM])) {
232 COMPARE_SIDE(NS_SIDE_LEFT);
233 COMPARE_SIDE(NS_SIDE_TOP);
234 COMPARE_SIDE(NS_SIDE_RIGHT);
235 COMPARE_SIDE(NS_SIDE_BOTTOM);
236 return PR_TRUE;
238 return PR_FALSE;
241 void nsStyleSides::Reset(void)
243 memset(this, 0x00, sizeof(nsStyleSides));
246 void nsStyleSides::AppendToString(nsString& aBuffer) const
248 aBuffer.AppendLiteral("left: ");
249 GetLeft().AppendToString(aBuffer);
251 aBuffer.AppendLiteral("top: ");
252 GetTop().AppendToString(aBuffer);
254 aBuffer.AppendLiteral("right: ");
255 GetRight().AppendToString(aBuffer);
257 aBuffer.AppendLiteral("bottom: ");
258 GetBottom().AppendToString(aBuffer);
261 void nsStyleSides::ToString(nsString& aBuffer) const
263 aBuffer.Truncate();
264 AppendToString(aBuffer);