2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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-08 15:15:53 +03:00
|
|
|
|
|
|
|
#include "DOMSVGPointList.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "DOMSVGPoint.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-12-08 15:15:53 +03:00
|
|
|
#include "SVGAnimatedPointList.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SVGAttrTearoffTable.h"
|
2018-12-22 20:04:05 +03:00
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2012-06-13 19:18:30 +04:00
|
|
|
#include "mozilla/dom/SVGPointListBinding.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2018-12-22 20:04:05 +03:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
// See the comment in this file's header.
|
|
|
|
|
2011-02-16 10:54:04 +03:00
|
|
|
// local helper functions
|
|
|
|
namespace {
|
|
|
|
|
2013-03-23 20:47:31 +04:00
|
|
|
void UpdateListIndicesFromIndex(
|
|
|
|
FallibleTArray<mozilla::nsISVGPoint*>& aItemsArray,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStartingIndex) {
|
|
|
|
uint32_t length = aItemsArray.Length();
|
2011-02-16 10:54:04 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = aStartingIndex; i < length; ++i) {
|
2011-02-16 10:54:04 +03:00
|
|
|
if (aItemsArray[i]) {
|
|
|
|
aItemsArray[i]->UpdateListIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2011-02-16 10:53:43 +03:00
|
|
|
namespace mozilla {
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2019-01-24 00:48:00 +03:00
|
|
|
static inline SVGAttrTearoffTable<void, DOMSVGPointList>&
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGPointListTearoffTable() {
|
2019-01-24 00:48:00 +03:00
|
|
|
static SVGAttrTearoffTable<void, DOMSVGPointList> sSVGPointListTearoffTable;
|
2013-05-31 02:34:53 +04:00
|
|
|
return sSVGPointListTearoffTable;
|
|
|
|
}
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGPointList)
|
|
|
|
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGPointList)
|
|
|
|
// No unlinking of mElement, we'd need to null out the value pointer (the
|
|
|
|
// object it points to is held by the element) and null-check it everywhere.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGPointList)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGPointList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2013-12-22 21:56:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGPointList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGPointList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGPointList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangePointListNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangePointList and
|
|
|
|
// DidChangePointList.
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII AutoChangePointListNotifier {
|
2013-12-25 02:09:22 +04:00
|
|
|
public:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit AutoChangePointListNotifier(
|
|
|
|
DOMSVGPointList* aPointList MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-25 02:09:22 +04:00
|
|
|
: mPointList(aPointList) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 12:33:48 +04:00
|
|
|
MOZ_ASSERT(mPointList, "Expecting non-null pointList");
|
2013-12-25 02:09:22 +04:00
|
|
|
mEmptyOrOldValue = mPointList->Element()->WillChangePointList();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangePointListNotifier() {
|
|
|
|
mPointList->Element()->DidChangePointList(mEmptyOrOldValue);
|
|
|
|
if (mPointList->AttrIsAnimating()) {
|
|
|
|
mPointList->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 12:33:48 +04:00
|
|
|
DOMSVGPointList* const mPointList;
|
2013-12-25 02:09:22 +04:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
/* static */ already_AddRefed<DOMSVGPointList> DOMSVGPointList::GetDOMWrapper(
|
2018-12-21 11:58:14 +03:00
|
|
|
void* aList, SVGElement* aElement, bool aIsAnimValList) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGPointList> wrapper =
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGPointListTearoffTable().GetTearoff(aList);
|
2010-12-08 15:15:53 +03:00
|
|
|
if (!wrapper) {
|
|
|
|
wrapper = new DOMSVGPointList(aElement, aIsAnimValList);
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGPointListTearoffTable().AddTearoff(aList, wrapper);
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2012-08-23 10:24:41 +04:00
|
|
|
return wrapper.forget();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ DOMSVGPointList* DOMSVGPointList::GetDOMWrapperIfExists(
|
|
|
|
void* aList) {
|
2013-05-31 02:34:53 +04:00
|
|
|
return SVGPointListTearoffTable().GetTearoff(aList);
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGPointList::~DOMSVGPointList() {
|
2011-02-06 12:11:26 +03:00
|
|
|
// There are now no longer any references to us held by script or list items.
|
|
|
|
// Note we must use GetAnimValKey/GetBaseValKey here, NOT InternalList()!
|
2010-12-08 15:15:53 +03:00
|
|
|
void* key = mIsAnimValList ? InternalAList().GetAnimValKey()
|
|
|
|
: InternalAList().GetBaseValKey();
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGPointListTearoffTable().RemoveTearoff(key);
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* DOMSVGPointList::WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return mozilla::dom::SVGPointList_Binding::Wrap(cx, this, aGivenProto);
|
2011-04-08 02:44:03 +04:00
|
|
|
}
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
void DOMSVGPointList::InternalListWillChangeTo(const SVGPointList& aNewValue) {
|
|
|
|
// When the number of items in our internal counterpart changes, we MUST stay
|
|
|
|
// in sync. Everything in the scary comment in
|
|
|
|
// DOMSVGLengthList::InternalBaseValListWillChangeTo applies here too!
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldLength = mItems.Length();
|
2011-02-08 16:43:34 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t newLength = aNewValue.Length();
|
2013-01-17 05:35:24 +04:00
|
|
|
if (newLength > nsISVGPoint::MaxListIndex()) {
|
2011-02-08 16:43:34 +03:00
|
|
|
// It's safe to get out of sync with our internal list as long as we have
|
|
|
|
// FEWER items than it does.
|
2013-01-17 05:35:24 +04:00
|
|
|
newLength = nsISVGPoint::MaxListIndex();
|
2011-02-08 16:43:34 +03:00
|
|
|
}
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGPointList> kungFuDeathGrip;
|
2011-07-07 19:48:10 +04:00
|
|
|
if (newLength < oldLength) {
|
2011-03-29 19:47:53 +04:00
|
|
|
// RemovingFromList() might clear last reference to |this|.
|
|
|
|
// Retain a temporary reference to keep from dying before returning.
|
|
|
|
kungFuDeathGrip = this;
|
|
|
|
}
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
// If our length will decrease, notify the items that will be removed:
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = newLength; i < oldLength; ++i) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (mItems[i]) {
|
|
|
|
mItems[i]->RemovingFromList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!mItems.SetLength(newLength, fallible)) {
|
2010-12-08 15:15:53 +03:00
|
|
|
// 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 19:56:38 +04:00
|
|
|
for (uint32_t i = oldLength; i < newLength; ++i) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mItems[i] = nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DOMSVGPointList::AttrIsAnimating() const {
|
2011-11-26 14:22:15 +04:00
|
|
|
return InternalAList().IsAnimating();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
bool DOMSVGPointList::AnimListMirrorsBaseList() const {
|
|
|
|
return GetDOMWrapperIfExists(InternalAList().GetAnimValKey()) &&
|
|
|
|
!AttrIsAnimating();
|
|
|
|
}
|
|
|
|
|
2011-11-26 14:22:15 +04:00
|
|
|
SVGPointList& DOMSVGPointList::InternalList() const {
|
2010-12-08 15:15:53 +03:00
|
|
|
SVGAnimatedPointList* alist = mElement->GetAnimatedPointList();
|
|
|
|
return mIsAnimValList && alist->IsAnimating() ? *alist->mAnimVal
|
|
|
|
: alist->mBaseVal;
|
|
|
|
}
|
|
|
|
|
2011-11-26 14:22:15 +04:00
|
|
|
SVGAnimatedPointList& DOMSVGPointList::InternalAList() const {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mElement->GetAnimatedPointList(), "Internal error");
|
2010-12-08 15:15:53 +03:00
|
|
|
return *mElement->GetAnimatedPointList();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// nsIDOMSVGPointList implementation:
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
void DOMSVGPointList::Clear(ErrorResult& aError) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (LengthNoFlush() > 0) {
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointListNotifier notifier(this);
|
2010-12-08 15:15:53 +03:00
|
|
|
// DOM list items that are to be removed must be removed before we change
|
|
|
|
// the internal list, otherwise they wouldn't be able to copy their
|
|
|
|
// internal counterparts' values!
|
|
|
|
|
|
|
|
InternalListWillChangeTo(SVGPointList()); // clears mItems
|
|
|
|
|
|
|
|
if (!AttrIsAnimating()) {
|
|
|
|
// The anim val list is in sync with the base val list
|
|
|
|
DOMSVGPointList* animList =
|
|
|
|
GetDOMWrapperIfExists(InternalAList().GetAnimValKey());
|
|
|
|
if (animList) {
|
|
|
|
animList->InternalListWillChangeTo(
|
|
|
|
SVGPointList()); // clears its mItems
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalList().Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::Initialize(nsISVGPoint& aNewItem,
|
|
|
|
ErrorResult& aError) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If aNewItem is already in a list we should insert a clone of aNewItem,
|
|
|
|
// and for consistency, this should happen even if *this* is the list that
|
|
|
|
// aNewItem is currently in. Note that in the case of aNewItem 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 aNewItem, it would actually insert aNewItem. To prevent that
|
|
|
|
// from happening we have to do the clone here, if necessary.
|
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> domItem = &aNewItem;
|
2014-08-06 17:58:57 +04:00
|
|
|
if (domItem->HasOwner() || domItem->IsReadonly() ||
|
|
|
|
domItem->IsTranslatePoint()) {
|
|
|
|
domItem = domItem->Copy(); // must do this before changing anything!
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
ErrorResult rv;
|
2012-12-23 08:54:21 +04:00
|
|
|
Clear(rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
|
|
|
return InsertItemBefore(*domItem, 0, aError);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
|
2013-07-12 14:25:27 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::GetItem(uint32_t index,
|
|
|
|
ErrorResult& error) {
|
|
|
|
bool found;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsISVGPoint> item = IndexedGetter(index, found, error);
|
2013-07-12 14:25:27 +04:00
|
|
|
if (!found) {
|
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
}
|
|
|
|
return item.forget();
|
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::IndexedGetter(
|
|
|
|
uint32_t aIndex, bool& aFound, ErrorResult& aError) {
|
|
|
|
if (IsAnimValList()) {
|
|
|
|
Element()->FlushAnimations();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2012-09-06 00:49:53 +04:00
|
|
|
aFound = aIndex < LengthNoFlush();
|
|
|
|
if (aFound) {
|
2013-07-12 14:25:27 +04:00
|
|
|
return GetItemAt(aIndex);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::InsertItemBefore(
|
|
|
|
nsISVGPoint& aNewItem, uint32_t aIndex, ErrorResult& aError) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
aIndex = std::min(aIndex, LengthNoFlush());
|
2013-01-17 05:35:24 +04:00
|
|
|
if (aIndex >= nsISVGPoint::MaxListIndex()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2011-02-08 16:43:34 +03:00
|
|
|
}
|
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> domItem = &aNewItem;
|
2014-08-06 17:58:57 +04:00
|
|
|
if (domItem->HasOwner() || domItem->IsReadonly() ||
|
|
|
|
domItem->IsTranslatePoint()) {
|
|
|
|
domItem = domItem->Copy(); // must do this before changing anything!
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure we have enough memory so we can avoid complex error handling below:
|
2015-05-18 23:50:34 +03:00
|
|
|
if (!mItems.SetCapacity(mItems.Length() + 1, fallible) ||
|
2010-12-08 15:15:53 +03:00
|
|
|
!InternalList().SetCapacity(InternalList().Length() + 1)) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2015-11-05 09:32:29 +03:00
|
|
|
if (AnimListMirrorsBaseList()) {
|
|
|
|
DOMSVGPointList* animVal =
|
|
|
|
GetDOMWrapperIfExists(InternalAList().GetAnimValKey());
|
2015-12-03 05:18:00 +03:00
|
|
|
MOZ_ASSERT(animVal, "animVal must be a valid pointer");
|
2015-11-05 09:32:29 +03:00
|
|
|
if (!animVal->mItems.SetCapacity(animVal->mItems.Length() + 1, fallible)) {
|
|
|
|
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointListNotifier notifier(this);
|
2011-02-16 10:54:37 +03:00
|
|
|
// Now that we know we're inserting, keep animVal list in sync as necessary.
|
|
|
|
MaybeInsertNullInAnimValListAt(aIndex);
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
InternalList().InsertItem(aIndex, domItem->ToSVGPoint());
|
2015-05-28 21:07:43 +03:00
|
|
|
MOZ_ALWAYS_TRUE(mItems.InsertElementAt(aIndex, domItem, fallible));
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2011-02-06 12:11:26 +03: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-08 15:15:53 +03:00
|
|
|
domItem->InsertingIntoList(this, aIndex, IsAnimValList());
|
|
|
|
|
2011-02-16 10:54:04 +03:00
|
|
|
UpdateListIndicesFromIndex(mItems, aIndex + 1);
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return domItem.forget();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::ReplaceItem(
|
|
|
|
nsISVGPoint& aNewItem, uint32_t aIndex, ErrorResult& aError) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (aIndex >= LengthNoFlush()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2012-12-23 08:54:19 +04:00
|
|
|
|
2013-01-17 05:35:24 +04:00
|
|
|
nsCOMPtr<nsISVGPoint> domItem = &aNewItem;
|
2014-08-06 17:58:57 +04:00
|
|
|
if (domItem->HasOwner() || domItem->IsReadonly() ||
|
|
|
|
domItem->IsTranslatePoint()) {
|
|
|
|
domItem = domItem->Copy(); // must do this before changing anything!
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointListNotifier notifier(this);
|
2010-12-08 15:15:53 +03:00
|
|
|
if (mItems[aIndex]) {
|
|
|
|
// 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[aIndex]->RemovingFromList();
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalList()[aIndex] = domItem->ToSVGPoint();
|
|
|
|
mItems[aIndex] = domItem;
|
|
|
|
|
2011-02-06 12:11:26 +03:00
|
|
|
// This MUST come after the ToSVGPoint() call, otherwise that call
|
2010-12-08 15:15:53 +03:00
|
|
|
// would end up reading bad data from InternalList()!
|
|
|
|
domItem->InsertingIntoList(this, aIndex, IsAnimValList());
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return domItem.forget();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::RemoveItem(uint32_t aIndex,
|
|
|
|
ErrorResult& aError) {
|
2010-12-08 15:15:53 +03:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (aIndex >= LengthNoFlush()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
2011-02-16 10:54:37 +03:00
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangePointListNotifier notifier(this);
|
2011-02-16 10:54:37 +03: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(aIndex);
|
|
|
|
|
2013-07-12 14:25:27 +04:00
|
|
|
// We have to return the removed item, so get it, creating it if necessary:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsISVGPoint> result = GetItemAt(aIndex);
|
2010-12-08 15:15:53 +03:00
|
|
|
|
|
|
|
// Notify the DOM item of removal *before* modifying the lists so that the
|
|
|
|
// DOM item can copy its *old* value:
|
|
|
|
mItems[aIndex]->RemovingFromList();
|
|
|
|
|
|
|
|
InternalList().RemoveItem(aIndex);
|
|
|
|
mItems.RemoveElementAt(aIndex);
|
|
|
|
|
2011-02-16 10:54:04 +03:00
|
|
|
UpdateListIndicesFromIndex(mItems, aIndex);
|
2010-12-08 15:15:53 +03:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2013-07-12 14:25:27 +04:00
|
|
|
already_AddRefed<nsISVGPoint> DOMSVGPointList::GetItemAt(uint32_t aIndex) {
|
|
|
|
MOZ_ASSERT(aIndex < mItems.Length());
|
|
|
|
|
2010-12-08 15:15:53 +03:00
|
|
|
if (!mItems[aIndex]) {
|
|
|
|
mItems[aIndex] = new DOMSVGPoint(this, aIndex, IsAnimValList());
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsISVGPoint> result = mItems[aIndex];
|
2013-07-12 14:25:27 +04:00
|
|
|
return result.forget();
|
2010-12-08 15:15:53 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void DOMSVGPointList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal");
|
2011-02-16 10:54:37 +03:00
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
if (!AnimListMirrorsBaseList()) {
|
2011-02-16 10:54:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The anim val list is in sync with the base val list
|
|
|
|
DOMSVGPointList* animVal =
|
|
|
|
GetDOMWrapperIfExists(InternalAList().GetAnimValKey());
|
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
MOZ_ASSERT(animVal, "AnimListMirrorsBaseList() promised a non-null animVal");
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(),
|
|
|
|
"animVal list not in sync!");
|
2015-05-28 21:07:43 +03:00
|
|
|
MOZ_ALWAYS_TRUE(animVal->mItems.InsertElementAt(aIndex, nullptr, fallible));
|
2011-02-16 10:54:37 +03:00
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void DOMSVGPointList::MaybeRemoveItemFromAnimValListAt(uint32_t aIndex) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal");
|
2011-02-16 10:54:37 +03:00
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
if (!AnimListMirrorsBaseList()) {
|
2011-02-16 10:54:37 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:47:53 +04: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.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGPointList> animVal =
|
2011-02-16 10:54:37 +03:00
|
|
|
GetDOMWrapperIfExists(InternalAList().GetAnimValKey());
|
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
MOZ_ASSERT(animVal, "AnimListMirrorsBaseList() promised a non-null animVal");
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(animVal->mItems.Length() == mItems.Length(),
|
|
|
|
"animVal list not in sync!");
|
2011-02-16 10:54:37 +03:00
|
|
|
|
|
|
|
if (animVal->mItems[aIndex]) {
|
|
|
|
animVal->mItems[aIndex]->RemovingFromList();
|
|
|
|
}
|
|
|
|
animVal->mItems.RemoveElementAt(aIndex);
|
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex);
|
|
|
|
}
|
|
|
|
|
2011-02-16 10:53:43 +03:00
|
|
|
} // namespace mozilla
|