2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-03-25 06:35:59 +00:00
|
|
|
|
2006-03-30 05:56:38 +00:00
|
|
|
/*
|
|
|
|
* a list of the recomputation that needs to be done in response to a
|
|
|
|
* style change
|
|
|
|
*/
|
|
|
|
|
1999-03-25 06:35:59 +00:00
|
|
|
#include "nsStyleChangeList.h"
|
1999-09-21 07:49:55 +00:00
|
|
|
#include "nsIContent.h"
|
1999-03-25 06:35:59 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static const uint32_t kGrowArrayBy = 10;
|
1999-03-25 06:35:59 +00:00
|
|
|
|
2008-03-15 09:01:18 +00:00
|
|
|
nsStyleChangeList::nsStyleChangeList()
|
1999-03-25 06:35:59 +00:00
|
|
|
: mArray(mBuffer),
|
|
|
|
mArraySize(kStyleChangeBufferSize),
|
|
|
|
mCount(0)
|
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_CTOR(nsStyleChangeList);
|
1999-03-25 06:35:59 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 09:01:18 +00:00
|
|
|
nsStyleChangeList::~nsStyleChangeList()
|
1999-03-25 06:35:59 +00:00
|
|
|
{
|
1999-10-08 20:41:19 +00:00
|
|
|
MOZ_COUNT_DTOR(nsStyleChangeList);
|
1999-03-25 06:35:59 +00:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsStyleChangeList::ChangeAt(int32_t aIndex, nsIFrame*& aFrame, nsIContent*& aContent,
|
2002-08-24 14:41:28 +00:00
|
|
|
nsChangeHint& aHint) const
|
1999-03-25 06:35:59 +00:00
|
|
|
{
|
|
|
|
if ((0 <= aIndex) && (aIndex < mCount)) {
|
|
|
|
aFrame = mArray[aIndex].mFrame;
|
1999-10-02 04:26:53 +00:00
|
|
|
aContent = mArray[aIndex].mContent;
|
1999-03-25 06:35:59 +00:00
|
|
|
aHint = mArray[aIndex].mHint;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2003-01-20 01:07:03 +00:00
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsStyleChangeList::ChangeAt(int32_t aIndex, const nsStyleChangeData** aChangeData) const
|
2003-01-20 01:07:03 +00:00
|
|
|
{
|
|
|
|
if ((0 <= aIndex) && (aIndex < mCount)) {
|
|
|
|
*aChangeData = &mArray[aIndex];
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
1999-03-25 06:35:59 +00:00
|
|
|
nsresult
|
2002-08-24 14:41:28 +00:00
|
|
|
nsStyleChangeList::AppendChange(nsIFrame* aFrame, nsIContent* aContent, nsChangeHint aHint)
|
1999-03-25 06:35:59 +00:00
|
|
|
{
|
2004-01-15 03:32:06 +00:00
|
|
|
NS_ASSERTION(aFrame || (aHint & nsChangeHint_ReconstructFrame),
|
2002-08-24 14:41:28 +00:00
|
|
|
"must have frame");
|
2004-01-15 03:32:06 +00:00
|
|
|
NS_ASSERTION(aContent || !(aHint & nsChangeHint_ReconstructFrame),
|
2002-08-24 14:41:28 +00:00
|
|
|
"must have content");
|
2010-04-30 13:12:06 +00:00
|
|
|
// XXXbz we should make this take Element instead of nsIContent
|
|
|
|
NS_ASSERTION(!aContent || aContent->IsElement(),
|
2007-02-28 22:32:00 +00:00
|
|
|
"Shouldn't be trying to restyle non-elements directly");
|
2012-09-07 22:57:06 +00:00
|
|
|
NS_ASSERTION(!(aHint & nsChangeHint_AllReflowHints) ||
|
2009-08-10 14:54:21 +00:00
|
|
|
(aHint & nsChangeHint_NeedReflow),
|
|
|
|
"Reflow hint bits set without actually asking for a reflow");
|
1999-09-21 07:49:55 +00:00
|
|
|
|
2002-08-24 14:41:28 +00:00
|
|
|
if ((0 < mCount) && (aHint & nsChangeHint_ReconstructFrame)) { // filter out all other changes for same content
|
1999-10-02 04:26:53 +00:00
|
|
|
if (aContent) {
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t index = mCount - 1; index >= 0; --index) {
|
1999-10-02 04:26:53 +00:00
|
|
|
if (aContent == mArray[index].mContent) { // remove this change
|
2008-03-15 09:01:18 +00:00
|
|
|
aContent->Release();
|
1999-09-21 07:49:55 +00:00
|
|
|
mCount--;
|
|
|
|
if (index < mCount) { // move later changes down
|
2006-06-03 14:19:21 +00:00
|
|
|
::memmove(&mArray[index], &mArray[index + 1],
|
|
|
|
(mCount - index) * sizeof(nsStyleChangeData));
|
1999-09-21 07:49:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t last = mCount - 1;
|
1999-10-12 00:22:18 +00:00
|
|
|
if ((0 < mCount) && aFrame && (aFrame == mArray[last].mFrame)) { // same as last frame
|
2002-08-24 14:41:28 +00:00
|
|
|
NS_UpdateHint(mArray[last].mHint, aHint);
|
1999-03-25 06:35:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (mCount == mArraySize) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t newSize = mArraySize + kGrowArrayBy;
|
1999-03-25 06:35:59 +00:00
|
|
|
nsStyleChangeData* newArray = new nsStyleChangeData[newSize];
|
|
|
|
if (newArray) {
|
2002-01-12 03:18:55 +00:00
|
|
|
memcpy(newArray, mArray, mCount * sizeof(nsStyleChangeData));
|
1999-03-25 06:35:59 +00:00
|
|
|
if (mArray != mBuffer) {
|
|
|
|
delete [] mArray;
|
|
|
|
}
|
|
|
|
mArray = newArray;
|
|
|
|
mArraySize = newSize;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mArray[mCount].mFrame = aFrame;
|
1999-10-02 04:26:53 +00:00
|
|
|
mArray[mCount].mContent = aContent;
|
2008-03-15 09:01:18 +00:00
|
|
|
if (aContent) {
|
|
|
|
aContent->AddRef();
|
|
|
|
}
|
1999-03-25 06:35:59 +00:00
|
|
|
mArray[mCount].mHint = aHint;
|
|
|
|
mCount++;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-16 19:28:36 +00:00
|
|
|
void
|
|
|
|
nsStyleChangeList::Clear()
|
1999-03-25 06:35:59 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t index = mCount - 1; index >= 0; --index) {
|
2008-03-15 09:01:18 +00:00
|
|
|
nsIContent* content = mArray[index].mContent;
|
|
|
|
if (content) {
|
|
|
|
content->Release();
|
|
|
|
}
|
|
|
|
}
|
1999-03-25 06:35:59 +00:00
|
|
|
if (mArray != mBuffer) {
|
|
|
|
delete [] mArray;
|
|
|
|
mArray = mBuffer;
|
|
|
|
mArraySize = kStyleChangeBufferSize;
|
|
|
|
}
|
|
|
|
mCount = 0;
|
|
|
|
}
|
|
|
|
|