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 ***** */
39 * a list of the recomputation that needs to be done in response to a
43 #include "nsStyleChangeList.h"
44 #include "nsStyleConsts.h"
46 #include "nsIContent.h"
49 static const PRUint32 kGrowArrayBy
= 10;
51 nsStyleChangeList::nsStyleChangeList()
53 mArraySize(kStyleChangeBufferSize
),
56 MOZ_COUNT_CTOR(nsStyleChangeList
);
59 nsStyleChangeList::~nsStyleChangeList()
61 MOZ_COUNT_DTOR(nsStyleChangeList
);
66 nsStyleChangeList::ChangeAt(PRInt32 aIndex
, nsIFrame
*& aFrame
, nsIContent
*& aContent
,
67 nsChangeHint
& aHint
) const
69 if ((0 <= aIndex
) && (aIndex
< mCount
)) {
70 aFrame
= mArray
[aIndex
].mFrame
;
71 aContent
= mArray
[aIndex
].mContent
;
72 aHint
= mArray
[aIndex
].mHint
;
75 return NS_ERROR_ILLEGAL_VALUE
;
79 nsStyleChangeList::ChangeAt(PRInt32 aIndex
, const nsStyleChangeData
** aChangeData
) const
81 if ((0 <= aIndex
) && (aIndex
< mCount
)) {
82 *aChangeData
= &mArray
[aIndex
];
85 return NS_ERROR_ILLEGAL_VALUE
;
89 nsStyleChangeList::AppendChange(nsIFrame
* aFrame
, nsIContent
* aContent
, nsChangeHint aHint
)
91 NS_ASSERTION(aFrame
|| (aHint
& nsChangeHint_ReconstructFrame
),
93 NS_ASSERTION(aContent
|| !(aHint
& nsChangeHint_ReconstructFrame
),
95 NS_ASSERTION(!aContent
|| aContent
->IsNodeOfType(nsINode::eELEMENT
),
96 "Shouldn't be trying to restyle non-elements directly");
98 if ((0 < mCount
) && (aHint
& nsChangeHint_ReconstructFrame
)) { // filter out all other changes for same content
100 for (PRInt32 index
= mCount
- 1; index
>= 0; --index
) {
101 if (aContent
== mArray
[index
].mContent
) { // remove this change
104 if (index
< mCount
) { // move later changes down
105 ::memmove(&mArray
[index
], &mArray
[index
+ 1],
106 (mCount
- index
) * sizeof(nsStyleChangeData
));
113 PRInt32 last
= mCount
- 1;
114 if ((0 < mCount
) && aFrame
&& (aFrame
== mArray
[last
].mFrame
)) { // same as last frame
115 NS_UpdateHint(mArray
[last
].mHint
, aHint
);
118 if (mCount
== mArraySize
) {
119 PRInt32 newSize
= mArraySize
+ kGrowArrayBy
;
120 nsStyleChangeData
* newArray
= new nsStyleChangeData
[newSize
];
122 memcpy(newArray
, mArray
, mCount
* sizeof(nsStyleChangeData
));
123 if (mArray
!= mBuffer
) {
127 mArraySize
= newSize
;
130 return NS_ERROR_OUT_OF_MEMORY
;
133 mArray
[mCount
].mFrame
= aFrame
;
134 mArray
[mCount
].mContent
= aContent
;
138 mArray
[mCount
].mHint
= aHint
;
145 nsStyleChangeList::Clear()
147 for (PRInt32 index
= mCount
- 1; index
>= 0; --index
) {
148 nsIContent
* content
= mArray
[index
].mContent
;
153 if (mArray
!= mBuffer
) {
156 mArraySize
= kStyleChangeBufferSize
;