Bug 632143 patch 0: Add helper-method 'UpdateListIndicesFromIndex' to DOMSVGxxxList classes. r=roc a=blocking-final+

This commit is contained in:
Daniel Holbert 2011-02-15 23:54:04 -08:00
Родитель 1919c3a4a0
Коммит ddfe7e24f9
5 изменённых файлов: 86 добавлений и 42 удалений

Просмотреть файл

@ -43,6 +43,25 @@
// See the comment in this file's header.
// local helper functions
namespace {
using mozilla::DOMSVGLength;
void UpdateListIndicesFromIndex(nsTArray<DOMSVGLength*>& aItemsArray,
PRUint32 aStartingIndex)
{
PRUint32 length = aItemsArray.Length();
for (PRUint32 i = aStartingIndex; i < length; ++i) {
if (aItemsArray[i]) {
aItemsArray[i]->UpdateListIndex(i);
}
}
}
} // namespace
namespace mozilla {
// We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
@ -235,11 +254,7 @@ DOMSVGLengthList::InsertItemBefore(nsIDOMSVGLength *newItem,
// data from InternalList() itself!:
domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList());
for (PRUint32 i = index + 1; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, index + 1);
Element()->DidChangeLengthList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL
@ -318,11 +333,7 @@ DOMSVGLengthList::RemoveItem(PRUint32 index,
InternalList().RemoveItem(index);
mItems.RemoveElementAt(index);
for (PRUint32 i = index; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, index);
Element()->DidChangeLengthList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL

Просмотреть файл

@ -45,6 +45,25 @@
namespace mozilla {
// local helper functions
namespace {
using mozilla::DOMSVGNumber;
void UpdateListIndicesFromIndex(nsTArray<DOMSVGNumber*>& aItemsArray,
PRUint32 aStartingIndex)
{
PRUint32 length = aItemsArray.Length();
for (PRUint32 i = aStartingIndex; i < length; ++i) {
if (aItemsArray[i]) {
aItemsArray[i]->UpdateListIndex(i);
}
}
}
} // namespace
// We could use NS_IMPL_CYCLE_COLLECTION_1, except that in Unlink() we need to
// clear our DOMSVGAnimatedNumberList's weak ref to us to be safe. (The other
// option would be to not unlink and rely on the breaking of the other edges in
@ -235,11 +254,7 @@ DOMSVGNumberList::InsertItemBefore(nsIDOMSVGNumber *newItem,
// data from InternalList() itself!:
domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList());
for (PRUint32 i = index + 1; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, index + 1);
Element()->DidChangeNumberList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL
@ -318,11 +333,7 @@ DOMSVGNumberList::RemoveItem(PRUint32 index,
InternalList().RemoveItem(index);
mItems.RemoveElementAt(index);
for (PRUint32 i = index; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, index);
Element()->DidChangeNumberList(AttrEnum(), PR_TRUE);
#ifdef MOZ_SMIL

Просмотреть файл

@ -360,12 +360,7 @@ DOMSVGPathSegList::InsertItemBefore(nsIDOMSVGPathSeg *aNewItem,
// data from InternalList() itself!:
domItem->InsertingIntoList(this, aIndex, IsAnimValList());
for (PRUint32 i = aIndex + 1; i < Length(); ++i) {
mItems[i].mInternalDataIndex += 1 + argCount;
if (ItemAt(i)) {
ItemAt(i)->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(aIndex + 1, argCount + 1);
Element()->DidChangePathSegList(PR_TRUE);
#ifdef MOZ_SMIL
@ -470,12 +465,7 @@ DOMSVGPathSegList::RemoveItem(PRUint32 aIndex,
InternalList().mData.RemoveElementsAt(internalIndex, 1 + argCount);
mItems.RemoveElementAt(aIndex);
for (PRUint32 i = aIndex; i < Length(); ++i) {
mItems[i].mInternalDataIndex -= 1 + argCount;
if (ItemAt(i)) {
ItemAt(i)->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(aIndex, -(argCount + 1));
Element()->DidChangePathSegList(PR_TRUE);
#ifdef MOZ_SMIL
@ -501,4 +491,18 @@ DOMSVGPathSegList::EnsureItemAt(PRUint32 aIndex)
}
}
void
DOMSVGPathSegList::UpdateListIndicesFromIndex(PRUint32 aStartingIndex,
PRInt32 aInternalDataIndexDelta)
{
PRUint32 length = Length();
for (PRUint32 i = aStartingIndex; i < length; ++i) {
mItems[i].mInternalDataIndex += aInternalDataIndexDelta;
if (ItemAt(i)) {
ItemAt(i)->UpdateListIndex(i);
}
}
}
} // namespace mozilla

Просмотреть файл

@ -190,6 +190,12 @@ private:
// aIndex, if it doesn't already exist.
void EnsureItemAt(PRUint32 aIndex);
// Calls UpdateListIndex on all elements in |mItems| that satisfy ItemAt(),
// from |aStartingIndex| to the end of |mItems|. Also adjusts
// |mItems.mInternalDataIndex| by the requested amount.
void UpdateListIndicesFromIndex(PRUint32 aStartingIndex,
PRInt32 aInternalDataIndexDelta);
DOMSVGPathSeg*& ItemAt(PRUint32 aIndex) {
return mItems[aIndex].mItem;
}

Просмотреть файл

@ -44,6 +44,26 @@
// See the comment in this file's header.
// local helper functions
namespace {
using mozilla::DOMSVGPoint;
void
UpdateListIndicesFromIndex(nsTArray<DOMSVGPoint*>& aItemsArray,
PRUint32 aStartingIndex)
{
PRUint32 length = aItemsArray.Length();
for (PRUint32 i = aStartingIndex; i < length; ++i) {
if (aItemsArray[i]) {
aItemsArray[i]->UpdateListIndex(i);
}
}
}
} // namespace
namespace mozilla {
static nsSVGAttrTearoffTable<void, DOMSVGPointList>
@ -285,11 +305,7 @@ DOMSVGPointList::InsertItemBefore(nsIDOMSVGPoint *aNewItem,
// data from InternalList() itself!:
domItem->InsertingIntoList(this, aIndex, IsAnimValList());
for (PRUint32 i = aIndex + 1; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, aIndex + 1);
Element()->DidChangePointList(PR_TRUE);
#ifdef MOZ_SMIL
@ -368,11 +384,7 @@ DOMSVGPointList::RemoveItem(PRUint32 aIndex,
InternalList().RemoveItem(aIndex);
mItems.RemoveElementAt(aIndex);
for (PRUint32 i = aIndex; i < Length(); ++i) {
if (mItems[i]) {
mItems[i]->UpdateListIndex(i);
}
}
UpdateListIndicesFromIndex(mItems, aIndex);
Element()->DidChangePointList(PR_TRUE);
#ifdef MOZ_SMIL