2010-12-03 08:40:23 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2010-12-03 08:40:23 -08:00
|
|
|
|
|
|
|
#include "nsSVGElement.h"
|
|
|
|
#include "DOMSVGNumberList.h"
|
|
|
|
#include "DOMSVGNumber.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2010-12-03 08:40:23 -08:00
|
|
|
#include "SVGAnimatedNumberList.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-06-13 08:18:30 -07:00
|
|
|
#include "mozilla/dom/SVGNumberListBinding.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2010-12-03 08:40:23 -08:00
|
|
|
|
|
|
|
// See the comment in this file's header.
|
|
|
|
|
2011-02-15 23:54:04 -08:00
|
|
|
// local helper functions
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using mozilla::DOMSVGNumber;
|
|
|
|
|
2013-03-23 09:47:31 -07:00
|
|
|
void UpdateListIndicesFromIndex(FallibleTArray<DOMSVGNumber*>& aItemsArray,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aStartingIndex)
|
2011-02-15 23:54:04 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length = aItemsArray.Length();
|
2011-02-15 23:54:04 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = aStartingIndex; i < length; ++i) {
|
2011-02-15 23:54:04 -08:00
|
|
|
if (aItemsArray[i]) {
|
|
|
|
aItemsArray[i]->UpdateListIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-11-17 07:59:45 -08:00
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
// We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
|
2010-12-03 08:40:23 -08:00
|
|
|
// 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
|
|
|
|
// the cycle, as NS_SVG_VAL_IMPL_CYCLE_COLLECTION does.)
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGNumberList)
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGNumberList)
|
2012-07-18 15:44:22 -07:00
|
|
|
if (tmp->mAList) {
|
|
|
|
if (tmp->IsAnimValList()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mAList->mAnimVal = nullptr;
|
2012-07-18 15:44:22 -07:00
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
tmp->mAList->mBaseVal = nullptr;
|
2012-07-18 15:44:22 -07:00
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAList)
|
2012-07-18 15:44:22 -07:00
|
|
|
}
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2010-12-03 08:40:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGNumberList)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAList)
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2010-12-03 08:40:23 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGNumberList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2010-12-03 08:40:23 -08:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGNumberList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGNumberList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGNumberList)
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-12-03 08:40:23 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2011-08-22 02:14:13 -07:00
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
DOMSVGNumberList::WrapObject(JSContext *cx)
|
2011-08-22 02:14:13 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return mozilla::dom::SVGNumberListBinding::Wrap(cx, this);
|
2011-04-07 15:44:03 -07:00
|
|
|
}
|
|
|
|
|
2013-12-24 14:09:22 -08:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeNumberListNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeNumberList and
|
|
|
|
// DidChangeNumberList.
|
|
|
|
class MOZ_STACK_CLASS AutoChangeNumberListNotifier
|
|
|
|
{
|
|
|
|
public:
|
2014-08-31 18:08:04 -07:00
|
|
|
explicit AutoChangeNumberListNotifier(DOMSVGNumberList* aNumberList MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-24 14:09:22 -08:00
|
|
|
: mNumberList(aNumberList)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 00:33:48 -08:00
|
|
|
MOZ_ASSERT(mNumberList, "Expecting non-null numberList");
|
2013-12-24 14:09:22 -08:00
|
|
|
mEmptyOrOldValue =
|
|
|
|
mNumberList->Element()->WillChangeNumberList(mNumberList->AttrEnum());
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeNumberListNotifier()
|
|
|
|
{
|
|
|
|
mNumberList->Element()->DidChangeNumberList(mNumberList->AttrEnum(),
|
|
|
|
mEmptyOrOldValue);
|
|
|
|
if (mNumberList->IsAnimating()) {
|
|
|
|
mNumberList->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 00:33:48 -08:00
|
|
|
DOMSVGNumberList* const mNumberList;
|
2013-12-24 14:09:22 -08:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
DOMSVGNumberList::InternalListLengthWillChange(uint32_t aNewLength)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t oldLength = mItems.Length();
|
2010-12-03 08:40:23 -08:00
|
|
|
|
2011-02-08 05:43:34 -08:00
|
|
|
if (aNewLength > DOMSVGNumber::MaxListIndex()) {
|
|
|
|
// It's safe to get out of sync with our internal list as long as we have
|
|
|
|
// FEWER items than it does.
|
|
|
|
aNewLength = DOMSVGNumber::MaxListIndex();
|
|
|
|
}
|
|
|
|
|
2011-03-29 08:47:53 -07:00
|
|
|
nsRefPtr<DOMSVGNumberList> kungFuDeathGrip;
|
2011-07-07 08:48:10 -07:00
|
|
|
if (aNewLength < oldLength) {
|
2011-03-29 08:47:53 -07:00
|
|
|
// RemovingFromList() might clear last reference to |this|.
|
|
|
|
// Retain a temporary reference to keep from dying before returning.
|
|
|
|
kungFuDeathGrip = this;
|
|
|
|
}
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
// If our length will decrease, notify the items that will be removed:
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = aNewLength; i < oldLength; ++i) {
|
2010-12-03 08:40:23 -08:00
|
|
|
if (mItems[i]) {
|
|
|
|
mItems[i]->RemovingFromList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mItems.SetLength(aNewLength)) {
|
|
|
|
// We silently ignore SetLength OOM failure since being out of sync is safe
|
|
|
|
// so long as we have *fewer* items than our internal list.
|
|
|
|
mItems.Clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our length has increased, null out the new pointers:
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = oldLength; i < aNewLength; ++i) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mItems[i] = nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGNumberList&
|
2011-11-26 02:22:15 -08:00
|
|
|
DOMSVGNumberList::InternalList() const
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
SVGAnimatedNumberList *alist = Element()->GetAnimatedNumberList(AttrEnum());
|
|
|
|
return IsAnimValList() && alist->mAnimVal ? *alist->mAnimVal : alist->mBaseVal;
|
|
|
|
}
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
void
|
|
|
|
DOMSVGNumberList::Clear(ErrorResult& error)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2012-09-05 07:52:57 -07:00
|
|
|
if (LengthNoFlush() > 0) {
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangeNumberListNotifier notifier(this);
|
2010-12-03 08:40:23 -08:00
|
|
|
// Notify any existing DOM items of removal *before* truncating the lists
|
|
|
|
// so that they can find their SVGNumber internal counterparts and copy
|
2011-02-15 23:54:26 -08:00
|
|
|
// their values. This also notifies the animVal list:
|
2010-12-03 08:40:23 -08:00
|
|
|
mAList->InternalBaseValListWillChangeTo(SVGNumberList());
|
|
|
|
|
|
|
|
mItems.Clear();
|
|
|
|
InternalList().Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
|
|
|
DOMSVGNumberList::Initialize(DOMSVGNumber& aItem,
|
2012-09-05 13:49:53 -07:00
|
|
|
ErrorResult& error)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If newItem is already in a list we should insert a clone of newItem, and
|
|
|
|
// for consistency, this should happen even if *this* is the list that
|
|
|
|
// newItem is currently in. Note that in the case of newItem being in this
|
|
|
|
// list, the Clear() call before the InsertItemBefore() call would remove it
|
|
|
|
// from this list, and so the InsertItemBefore() call would not insert a
|
|
|
|
// clone of newItem, it would actually insert newItem. To prevent that from
|
|
|
|
// happening we have to do the clone here, if necessary.
|
2014-05-30 00:36:52 -07:00
|
|
|
nsRefPtr<DOMSVGNumber> domItem = aItem.HasOwner() ? aItem.Clone() : &aItem;
|
2010-12-03 08:40:23 -08:00
|
|
|
|
2012-12-22 20:54:25 -08:00
|
|
|
Clear(error);
|
|
|
|
MOZ_ASSERT(!error.Failed());
|
2014-05-30 00:36:52 -07:00
|
|
|
return InsertItemBefore(*domItem, 0, error);
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
2013-07-12 03:25:26 -07:00
|
|
|
DOMSVGNumberList::GetItem(uint32_t index, ErrorResult& error)
|
|
|
|
{
|
|
|
|
bool found;
|
2014-05-30 00:36:52 -07:00
|
|
|
nsRefPtr<DOMSVGNumber> item = IndexedGetter(index, found, error);
|
2013-07-12 03:25:26 -07:00
|
|
|
if (!found) {
|
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
}
|
|
|
|
return item.forget();
|
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
2012-09-05 13:49:53 -07:00
|
|
|
DOMSVGNumberList::IndexedGetter(uint32_t index, bool& found, ErrorResult& error)
|
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
|
|
|
Element()->FlushAnimations();
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
2012-09-05 13:49:53 -07:00
|
|
|
found = index < LengthNoFlush();
|
|
|
|
if (found) {
|
2013-07-12 03:25:26 -07:00
|
|
|
return GetItemAt(index);
|
2012-09-05 13:49:53 -07:00
|
|
|
}
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
|
|
|
DOMSVGNumberList::InsertItemBefore(DOMSVGNumber& aItem,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index,
|
2012-09-05 13:49:53 -07:00
|
|
|
ErrorResult& error)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2013-01-15 04:22:03 -08:00
|
|
|
index = std::min(index, LengthNoFlush());
|
2011-02-08 05:43:34 -08:00
|
|
|
if (index >= DOMSVGNumber::MaxListIndex()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2011-02-08 05:43:34 -08:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
// must do this before changing anything!
|
|
|
|
nsRefPtr<DOMSVGNumber> domItem = aItem.HasOwner() ? aItem.Clone() : &aItem;
|
2011-02-06 01:11:26 -08:00
|
|
|
|
|
|
|
// Ensure we have enough memory so we can avoid complex error handling below:
|
|
|
|
if (!mItems.SetCapacity(mItems.Length() + 1) ||
|
|
|
|
!InternalList().SetCapacity(InternalList().Length() + 1)) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangeNumberListNotifier notifier(this);
|
2011-02-15 23:54:26 -08:00
|
|
|
// Now that we know we're inserting, keep animVal list in sync as necessary.
|
|
|
|
MaybeInsertNullInAnimValListAt(index);
|
|
|
|
|
2011-02-06 01:11:26 -08:00
|
|
|
InternalList().InsertItem(index, domItem->ToSVGNumber());
|
2014-05-30 00:36:52 -07:00
|
|
|
mItems.InsertElementAt(index, domItem);
|
2011-02-06 01:11:26 -08:00
|
|
|
|
|
|
|
// This MUST come after the insertion into InternalList(), or else under the
|
|
|
|
// insertion into InternalList() the values read from domItem would be bad
|
|
|
|
// data from InternalList() itself!:
|
2010-12-03 08:40:23 -08:00
|
|
|
domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList());
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2011-02-15 23:54:04 -08:00
|
|
|
UpdateListIndicesFromIndex(mItems, index + 1);
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
return domItem.forget();
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
|
|
|
DOMSVGNumberList::ReplaceItem(DOMSVGNumber& aItem,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index,
|
2012-09-05 13:49:53 -07:00
|
|
|
ErrorResult& error)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2012-09-05 07:52:57 -07:00
|
|
|
if (index >= LengthNoFlush()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
2014-05-30 00:36:52 -07:00
|
|
|
|
|
|
|
// must do this before changing anything!
|
|
|
|
nsRefPtr<DOMSVGNumber> domItem = aItem.HasOwner() ? aItem.Clone() : &aItem;
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangeNumberListNotifier notifier(this);
|
2010-12-03 08:40:23 -08:00
|
|
|
if (mItems[index]) {
|
|
|
|
// Notify any existing DOM item of removal *before* modifying the lists so
|
|
|
|
// that the DOM item can copy the *old* value at its index:
|
|
|
|
mItems[index]->RemovingFromList();
|
|
|
|
}
|
2011-02-06 01:11:26 -08:00
|
|
|
|
|
|
|
InternalList()[index] = domItem->ToSVGNumber();
|
2010-12-03 08:40:23 -08:00
|
|
|
mItems[index] = domItem;
|
|
|
|
|
2011-02-06 01:11:26 -08:00
|
|
|
// This MUST come after the ToSVGPoint() call, otherwise that call
|
|
|
|
// would end up reading bad data from InternalList()!
|
|
|
|
domItem->InsertingIntoList(this, AttrEnum(), index, IsAnimValList());
|
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
return domItem.forget();
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
2012-08-22 08:56:38 -07:00
|
|
|
DOMSVGNumberList::RemoveItem(uint32_t index,
|
2012-09-05 13:49:53 -07:00
|
|
|
ErrorResult& error)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
|
|
|
if (IsAnimValList()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
|
|
|
|
2012-09-05 07:52:57 -07:00
|
|
|
if (index >= LengthNoFlush()) {
|
2012-09-05 13:49:53 -07:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
2011-02-15 23:54:26 -08:00
|
|
|
|
|
|
|
// Now that we know we're removing, keep animVal list in sync as necessary.
|
|
|
|
// Do this *before* touching InternalList() so the removed item can get its
|
|
|
|
// internal value.
|
|
|
|
MaybeRemoveItemFromAnimValListAt(index);
|
|
|
|
|
2013-07-12 03:25:26 -07:00
|
|
|
// We have to return the removed item, so get it, creating it if necessary:
|
2014-05-30 00:36:52 -07:00
|
|
|
nsRefPtr<DOMSVGNumber> result = GetItemAt(index);
|
2010-12-03 08:40:23 -08:00
|
|
|
|
2013-12-24 14:09:22 -08:00
|
|
|
AutoChangeNumberListNotifier notifier(this);
|
2010-12-03 08:40:23 -08:00
|
|
|
// Notify the DOM item of removal *before* modifying the lists so that the
|
|
|
|
// DOM item can copy its *old* value:
|
|
|
|
mItems[index]->RemovingFromList();
|
|
|
|
|
|
|
|
InternalList().RemoveItem(index);
|
|
|
|
mItems.RemoveElementAt(index);
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2011-02-15 23:54:04 -08:00
|
|
|
UpdateListIndicesFromIndex(mItems, index);
|
2011-02-06 01:11:26 -08:00
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2014-05-30 00:36:52 -07:00
|
|
|
already_AddRefed<DOMSVGNumber>
|
2013-07-12 03:25:26 -07:00
|
|
|
DOMSVGNumberList::GetItemAt(uint32_t aIndex)
|
2010-12-03 08:40:23 -08:00
|
|
|
{
|
2013-07-12 03:25:26 -07:00
|
|
|
MOZ_ASSERT(aIndex < mItems.Length());
|
|
|
|
|
2010-12-03 08:40:23 -08:00
|
|
|
if (!mItems[aIndex]) {
|
|
|
|
mItems[aIndex] = new DOMSVGNumber(this, AttrEnum(), aIndex, IsAnimValList());
|
|
|
|
}
|
2014-05-30 00:36:52 -07:00
|
|
|
nsRefPtr<DOMSVGNumber> result = mItems[aIndex];
|
2013-07-12 03:25:26 -07:00
|
|
|
return result.forget();
|
2010-12-03 08:40:23 -08:00
|
|
|
}
|
2011-02-15 23:53:43 -08:00
|
|
|
|
2011-02-15 23:54:26 -08:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
DOMSVGNumberList::MaybeInsertNullInAnimValListAt(uint32_t aIndex)
|
2011-02-15 23:54:26 -08:00
|
|
|
{
|
2015-02-06 15:04:32 -08:00
|
|
|
NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal");
|
2011-02-15 23:54:26 -08:00
|
|
|
|
|
|
|
DOMSVGNumberList* animVal = mAList->mAnimVal;
|
|
|
|
|
|
|
|
if (!animVal || mAList->IsAnimating()) {
|
|
|
|
// No animVal list wrapper, or animVal not a clone of baseVal
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:04:32 -08:00
|
|
|
NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(),
|
|
|
|
"animVal list not in sync!");
|
2011-02-15 23:54:26 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
animVal->mItems.InsertElementAt(aIndex, static_cast<DOMSVGNumber*>(nullptr));
|
2011-02-15 23:54:26 -08:00
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
DOMSVGNumberList::MaybeRemoveItemFromAnimValListAt(uint32_t aIndex)
|
2011-02-15 23:54:26 -08:00
|
|
|
{
|
2015-02-06 15:04:32 -08:00
|
|
|
NS_ABORT_IF_FALSE(!IsAnimValList(), "call from baseVal to animVal");
|
2011-02-15 23:54:26 -08:00
|
|
|
|
2011-03-29 08:47:53 -07:00
|
|
|
// This needs to be a strong reference; otherwise, the RemovingFromList call
|
|
|
|
// below might drop the last reference to animVal before we're done with it.
|
|
|
|
nsRefPtr<DOMSVGNumberList> animVal = mAList->mAnimVal;
|
2011-02-15 23:54:26 -08:00
|
|
|
|
|
|
|
if (!animVal || mAList->IsAnimating()) {
|
|
|
|
// No animVal list wrapper, or animVal not a clone of baseVal
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:04:32 -08:00
|
|
|
NS_ABORT_IF_FALSE(animVal->mItems.Length() == mItems.Length(),
|
|
|
|
"animVal list not in sync!");
|
2011-02-15 23:54:26 -08:00
|
|
|
|
|
|
|
if (animVal->mItems[aIndex]) {
|
|
|
|
animVal->mItems[aIndex]->RemovingFromList();
|
|
|
|
}
|
|
|
|
animVal->mItems.RemoveElementAt(aIndex);
|
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex);
|
|
|
|
}
|
|
|
|
|
2011-02-15 23:53:43 -08:00
|
|
|
} // namespace mozilla
|