Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * a list of the recomputation that needs to be done in response to a |
michael@0 | 8 | * style change |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include "nsStyleChangeList.h" |
michael@0 | 12 | #include "nsIContent.h" |
michael@0 | 13 | |
michael@0 | 14 | static const uint32_t kGrowArrayBy = 10; |
michael@0 | 15 | |
michael@0 | 16 | nsStyleChangeList::nsStyleChangeList() |
michael@0 | 17 | : mArray(mBuffer), |
michael@0 | 18 | mArraySize(kStyleChangeBufferSize), |
michael@0 | 19 | mCount(0) |
michael@0 | 20 | { |
michael@0 | 21 | MOZ_COUNT_CTOR(nsStyleChangeList); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | nsStyleChangeList::~nsStyleChangeList() |
michael@0 | 25 | { |
michael@0 | 26 | MOZ_COUNT_DTOR(nsStyleChangeList); |
michael@0 | 27 | Clear(); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | nsresult |
michael@0 | 31 | nsStyleChangeList::ChangeAt(int32_t aIndex, nsIFrame*& aFrame, nsIContent*& aContent, |
michael@0 | 32 | nsChangeHint& aHint) const |
michael@0 | 33 | { |
michael@0 | 34 | if ((0 <= aIndex) && (aIndex < mCount)) { |
michael@0 | 35 | aFrame = mArray[aIndex].mFrame; |
michael@0 | 36 | aContent = mArray[aIndex].mContent; |
michael@0 | 37 | aHint = mArray[aIndex].mHint; |
michael@0 | 38 | return NS_OK; |
michael@0 | 39 | } |
michael@0 | 40 | return NS_ERROR_ILLEGAL_VALUE; |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | nsresult |
michael@0 | 44 | nsStyleChangeList::ChangeAt(int32_t aIndex, const nsStyleChangeData** aChangeData) const |
michael@0 | 45 | { |
michael@0 | 46 | if ((0 <= aIndex) && (aIndex < mCount)) { |
michael@0 | 47 | *aChangeData = &mArray[aIndex]; |
michael@0 | 48 | return NS_OK; |
michael@0 | 49 | } |
michael@0 | 50 | return NS_ERROR_ILLEGAL_VALUE; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | nsresult |
michael@0 | 54 | nsStyleChangeList::AppendChange(nsIFrame* aFrame, nsIContent* aContent, nsChangeHint aHint) |
michael@0 | 55 | { |
michael@0 | 56 | NS_ASSERTION(aFrame || (aHint & nsChangeHint_ReconstructFrame), |
michael@0 | 57 | "must have frame"); |
michael@0 | 58 | NS_ASSERTION(aContent || !(aHint & nsChangeHint_ReconstructFrame), |
michael@0 | 59 | "must have content"); |
michael@0 | 60 | // XXXbz we should make this take Element instead of nsIContent |
michael@0 | 61 | NS_ASSERTION(!aContent || aContent->IsElement(), |
michael@0 | 62 | "Shouldn't be trying to restyle non-elements directly"); |
michael@0 | 63 | NS_ASSERTION(!(aHint & nsChangeHint_AllReflowHints) || |
michael@0 | 64 | (aHint & nsChangeHint_NeedReflow), |
michael@0 | 65 | "Reflow hint bits set without actually asking for a reflow"); |
michael@0 | 66 | |
michael@0 | 67 | if ((0 < mCount) && (aHint & nsChangeHint_ReconstructFrame)) { // filter out all other changes for same content |
michael@0 | 68 | if (aContent) { |
michael@0 | 69 | for (int32_t index = mCount - 1; index >= 0; --index) { |
michael@0 | 70 | if (aContent == mArray[index].mContent) { // remove this change |
michael@0 | 71 | aContent->Release(); |
michael@0 | 72 | mCount--; |
michael@0 | 73 | if (index < mCount) { // move later changes down |
michael@0 | 74 | ::memmove(&mArray[index], &mArray[index + 1], |
michael@0 | 75 | (mCount - index) * sizeof(nsStyleChangeData)); |
michael@0 | 76 | } |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | int32_t last = mCount - 1; |
michael@0 | 83 | if ((0 < mCount) && aFrame && (aFrame == mArray[last].mFrame)) { // same as last frame |
michael@0 | 84 | NS_UpdateHint(mArray[last].mHint, aHint); |
michael@0 | 85 | } |
michael@0 | 86 | else { |
michael@0 | 87 | if (mCount == mArraySize) { |
michael@0 | 88 | int32_t newSize = mArraySize + kGrowArrayBy; |
michael@0 | 89 | nsStyleChangeData* newArray = new nsStyleChangeData[newSize]; |
michael@0 | 90 | if (newArray) { |
michael@0 | 91 | memcpy(newArray, mArray, mCount * sizeof(nsStyleChangeData)); |
michael@0 | 92 | if (mArray != mBuffer) { |
michael@0 | 93 | delete [] mArray; |
michael@0 | 94 | } |
michael@0 | 95 | mArray = newArray; |
michael@0 | 96 | mArraySize = newSize; |
michael@0 | 97 | } |
michael@0 | 98 | else { |
michael@0 | 99 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 100 | } |
michael@0 | 101 | } |
michael@0 | 102 | mArray[mCount].mFrame = aFrame; |
michael@0 | 103 | mArray[mCount].mContent = aContent; |
michael@0 | 104 | if (aContent) { |
michael@0 | 105 | aContent->AddRef(); |
michael@0 | 106 | } |
michael@0 | 107 | mArray[mCount].mHint = aHint; |
michael@0 | 108 | mCount++; |
michael@0 | 109 | } |
michael@0 | 110 | return NS_OK; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void |
michael@0 | 114 | nsStyleChangeList::Clear() |
michael@0 | 115 | { |
michael@0 | 116 | for (int32_t index = mCount - 1; index >= 0; --index) { |
michael@0 | 117 | nsIContent* content = mArray[index].mContent; |
michael@0 | 118 | if (content) { |
michael@0 | 119 | content->Release(); |
michael@0 | 120 | } |
michael@0 | 121 | } |
michael@0 | 122 | if (mArray != mBuffer) { |
michael@0 | 123 | delete [] mArray; |
michael@0 | 124 | mArray = mBuffer; |
michael@0 | 125 | mArraySize = kStyleChangeBufferSize; |
michael@0 | 126 | } |
michael@0 | 127 | mCount = 0; |
michael@0 | 128 | } |
michael@0 | 129 |