Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / layout / style / nsCSSStruct.cpp
bloba08ac29a57a73ed9ef20751a3c752e2529167796
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>
24 * Mats Palmgren <mats.palmgren@bredband.net>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * temporary (expanded) representation of the property-value pairs
42 * within a CSS declaration using during parsing and mutation, and
43 * representation of complex values for CSS properties
46 #include "nscore.h"
47 #include "nsCSSStruct.h"
48 #include "nsString.h"
49 #include "nsIAtom.h"
50 #include "nsUnicharUtils.h"
51 #include "nsCRT.h"
52 #include "nsCSSProps.h"
53 #include "nsFont.h"
55 #include "nsStyleConsts.h"
57 #include "nsCOMPtr.h"
58 #include "nsReadableUtils.h"
59 #include "nsPrintfCString.h"
61 // --- nsCSSFont -----------------
63 nsCSSFont::nsCSSFont(void)
65 MOZ_COUNT_CTOR(nsCSSFont);
68 nsCSSFont::~nsCSSFont(void)
70 MOZ_COUNT_DTOR(nsCSSFont);
73 // --- nsCSSValueList -----------------
75 nsCSSValueList::~nsCSSValueList()
77 MOZ_COUNT_DTOR(nsCSSValueList);
78 NS_CSS_DELETE_LIST_MEMBER(nsCSSValueList, this, mNext);
81 nsCSSValueList*
82 nsCSSValueList::Clone(PRBool aDeep) const
84 nsCSSValueList* result = new nsCSSValueList(*this);
85 if (NS_UNLIKELY(!result))
86 return result;
87 if (aDeep)
88 NS_CSS_CLONE_LIST_MEMBER(nsCSSValueList, this, mNext, result, (PR_FALSE));
89 return result;
92 /* static */ PRBool
93 nsCSSValueList::Equal(nsCSSValueList* aList1, nsCSSValueList* aList2)
95 if (aList1 == aList2)
96 return PR_TRUE;
98 nsCSSValueList *p1 = aList1, *p2 = aList2;
99 for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
100 if (p1->mValue != p2->mValue)
101 return PR_FALSE;
103 return !p1 && !p2; // true if same length, false otherwise
106 // --- nsCSSColor -----------------
108 nsCSSColor::nsCSSColor(void)
110 MOZ_COUNT_CTOR(nsCSSColor);
113 nsCSSColor::~nsCSSColor(void)
115 MOZ_COUNT_DTOR(nsCSSColor);
118 // --- nsCSSText -----------------
120 nsCSSText::nsCSSText(void)
121 : mTextShadow(nsnull)
123 MOZ_COUNT_CTOR(nsCSSText);
126 nsCSSText::~nsCSSText(void)
128 MOZ_COUNT_DTOR(nsCSSText);
129 delete mTextShadow;
132 // --- nsCSSRect -----------------
134 nsCSSRect::nsCSSRect(void)
136 MOZ_COUNT_CTOR(nsCSSRect);
139 nsCSSRect::nsCSSRect(const nsCSSRect& aCopy)
140 : mTop(aCopy.mTop),
141 mRight(aCopy.mRight),
142 mBottom(aCopy.mBottom),
143 mLeft(aCopy.mLeft)
145 MOZ_COUNT_CTOR(nsCSSRect);
148 nsCSSRect::~nsCSSRect()
150 MOZ_COUNT_DTOR(nsCSSRect);
153 void nsCSSRect::SetAllSidesTo(const nsCSSValue& aValue)
155 mTop = aValue;
156 mRight = aValue;
157 mBottom = aValue;
158 mLeft = aValue;
161 #if (NS_SIDE_TOP != 0) || (NS_SIDE_RIGHT != 1) || (NS_SIDE_BOTTOM != 2) || (NS_SIDE_LEFT != 3)
162 #error "Somebody changed the side constants."
163 #endif
165 /* static */ const nsCSSRect::side_type nsCSSRect::sides[4] = {
166 &nsCSSRect::mTop,
167 &nsCSSRect::mRight,
168 &nsCSSRect::mBottom,
169 &nsCSSRect::mLeft,
172 // --- nsCSSCornerSizes -----------------
174 nsCSSCornerSizes::nsCSSCornerSizes(void)
176 MOZ_COUNT_CTOR(nsCSSCornerSizes);
179 nsCSSCornerSizes::nsCSSCornerSizes(const nsCSSCornerSizes& aCopy)
180 : mTopLeft(aCopy.mTopLeft),
181 mTopRight(aCopy.mTopRight),
182 mBottomRight(aCopy.mBottomRight),
183 mBottomLeft(aCopy.mBottomLeft)
185 MOZ_COUNT_CTOR(nsCSSCornerSizes);
188 nsCSSCornerSizes::~nsCSSCornerSizes()
190 MOZ_COUNT_DTOR(nsCSSCornerSizes);
193 void
194 nsCSSCornerSizes::SetAllCornersTo(const nsCSSValue& aValue)
196 NS_FOR_CSS_FULL_CORNERS(corner) {
197 this->GetFullCorner(corner).SetBothValuesTo(aValue);
201 void
202 nsCSSCornerSizes::Reset()
204 NS_FOR_CSS_FULL_CORNERS(corner) {
205 this->GetFullCorner(corner).Reset();
209 #if NS_CORNER_TOP_LEFT != 0 || NS_CORNER_TOP_RIGHT != 1 || \
210 NS_CORNER_BOTTOM_RIGHT != 2 || NS_CORNER_BOTTOM_LEFT != 3
211 #error "Somebody changed the corner constants."
212 #endif
214 /* static */ const nsCSSCornerSizes::corner_type
215 nsCSSCornerSizes::corners[4] = {
216 &nsCSSCornerSizes::mTopLeft,
217 &nsCSSCornerSizes::mTopRight,
218 &nsCSSCornerSizes::mBottomRight,
219 &nsCSSCornerSizes::mBottomLeft,
222 // --- nsCSSValueListRect -----------------
224 nsCSSValueListRect::nsCSSValueListRect(void)
225 : mTop(nsnull),
226 mRight(nsnull),
227 mBottom(nsnull),
228 mLeft(nsnull)
230 MOZ_COUNT_CTOR(nsCSSValueListRect);
233 nsCSSValueListRect::nsCSSValueListRect(const nsCSSValueListRect& aCopy)
234 : mTop(aCopy.mTop),
235 mRight(aCopy.mRight),
236 mBottom(aCopy.mBottom),
237 mLeft(aCopy.mLeft)
239 MOZ_COUNT_CTOR(nsCSSValueListRect);
242 nsCSSValueListRect::~nsCSSValueListRect()
244 MOZ_COUNT_DTOR(nsCSSValueListRect);
247 /* static */ const nsCSSValueListRect::side_type
248 nsCSSValueListRect::sides[4] = {
249 &nsCSSValueListRect::mTop,
250 &nsCSSValueListRect::mRight,
251 &nsCSSValueListRect::mBottom,
252 &nsCSSValueListRect::mLeft,
255 // --- nsCSSDisplay -----------------
257 /* During allocation, null-out the transform list. */
258 nsCSSDisplay::nsCSSDisplay(void) : mTransform(nsnull)
260 MOZ_COUNT_CTOR(nsCSSDisplay);
263 nsCSSDisplay::~nsCSSDisplay(void)
265 MOZ_COUNT_DTOR(nsCSSDisplay);
268 // --- nsCSSMargin -----------------
270 nsCSSMargin::nsCSSMargin(void)
271 : mBoxShadow(nsnull)
273 MOZ_COUNT_CTOR(nsCSSMargin);
276 nsCSSMargin::~nsCSSMargin(void)
278 MOZ_COUNT_DTOR(nsCSSMargin);
279 delete mBoxShadow;
282 // --- nsCSSPosition -----------------
284 nsCSSPosition::nsCSSPosition(void)
286 MOZ_COUNT_CTOR(nsCSSPosition);
289 nsCSSPosition::~nsCSSPosition(void)
291 MOZ_COUNT_DTOR(nsCSSPosition);
294 // --- nsCSSList -----------------
296 nsCSSList::nsCSSList(void)
298 MOZ_COUNT_CTOR(nsCSSList);
301 nsCSSList::~nsCSSList(void)
303 MOZ_COUNT_DTOR(nsCSSList);
306 // --- nsCSSTable -----------------
308 nsCSSTable::nsCSSTable(void)
310 MOZ_COUNT_CTOR(nsCSSTable);
313 nsCSSTable::~nsCSSTable(void)
315 MOZ_COUNT_DTOR(nsCSSTable);
318 // --- nsCSSBreaks -----------------
320 nsCSSBreaks::nsCSSBreaks(void)
322 MOZ_COUNT_CTOR(nsCSSBreaks);
325 nsCSSBreaks::~nsCSSBreaks(void)
327 MOZ_COUNT_DTOR(nsCSSBreaks);
330 // --- nsCSSPage -----------------
332 nsCSSPage::nsCSSPage(void)
334 MOZ_COUNT_CTOR(nsCSSPage);
337 nsCSSPage::~nsCSSPage(void)
339 MOZ_COUNT_DTOR(nsCSSPage);
342 // --- nsCSSContent support -----------------
344 nsCSSValuePairList::~nsCSSValuePairList()
346 MOZ_COUNT_DTOR(nsCSSValuePairList);
347 NS_CSS_DELETE_LIST_MEMBER(nsCSSValuePairList, this, mNext);
350 nsCSSValuePairList*
351 nsCSSValuePairList::Clone(PRBool aDeep) const
353 nsCSSValuePairList* result = new nsCSSValuePairList(*this);
354 if (NS_UNLIKELY(!result))
355 return result;
356 if (aDeep)
357 NS_CSS_CLONE_LIST_MEMBER(nsCSSValuePairList, this, mNext, result,
358 (PR_FALSE));
359 return result;
362 /* static */ PRBool
363 nsCSSValuePairList::Equal(nsCSSValuePairList* aList1,
364 nsCSSValuePairList* aList2)
366 if (aList1 == aList2)
367 return PR_TRUE;
369 nsCSSValuePairList *p1 = aList1, *p2 = aList2;
370 for ( ; p1 && p2; p1 = p1->mNext, p2 = p2->mNext) {
371 if (p1->mXValue != p2->mXValue ||
372 p1->mYValue != p2->mYValue)
373 return PR_FALSE;
375 return !p1 && !p2; // true if same length, false otherwise
378 // --- nsCSSContent -----------------
380 nsCSSContent::nsCSSContent(void)
381 : mContent(nsnull),
382 mCounterIncrement(nsnull),
383 mCounterReset(nsnull),
384 mQuotes(nsnull)
386 MOZ_COUNT_CTOR(nsCSSContent);
389 nsCSSContent::~nsCSSContent(void)
391 MOZ_COUNT_DTOR(nsCSSContent);
392 delete mContent;
393 delete mCounterIncrement;
394 delete mCounterReset;
395 delete mQuotes;
398 // --- nsCSSUserInterface -----------------
400 nsCSSUserInterface::nsCSSUserInterface(void)
401 : mCursor(nsnull)
403 MOZ_COUNT_CTOR(nsCSSUserInterface);
406 nsCSSUserInterface::~nsCSSUserInterface(void)
408 MOZ_COUNT_DTOR(nsCSSUserInterface);
409 delete mCursor;
412 // --- nsCSSAural -----------------
414 nsCSSAural::nsCSSAural(void)
416 MOZ_COUNT_CTOR(nsCSSAural);
419 nsCSSAural::~nsCSSAural(void)
421 MOZ_COUNT_DTOR(nsCSSAural);
424 // --- nsCSSXUL -----------------
426 nsCSSXUL::nsCSSXUL(void)
428 MOZ_COUNT_CTOR(nsCSSXUL);
431 nsCSSXUL::~nsCSSXUL(void)
433 MOZ_COUNT_DTOR(nsCSSXUL);
436 // --- nsCSSColumn -----------------
438 nsCSSColumn::nsCSSColumn(void)
440 MOZ_COUNT_CTOR(nsCSSColumn);
443 nsCSSColumn::~nsCSSColumn(void)
445 MOZ_COUNT_DTOR(nsCSSColumn);
448 #ifdef MOZ_SVG
449 // --- nsCSSSVG -----------------
451 nsCSSSVG::nsCSSSVG(void) : mStrokeDasharray(nsnull)
453 MOZ_COUNT_CTOR(nsCSSSVG);
456 nsCSSSVG::~nsCSSSVG(void)
458 MOZ_COUNT_DTOR(nsCSSSVG);
459 delete mStrokeDasharray;
462 #endif // MOZ_SVG