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/. */
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
#include "DOMSVGTransformList.h"
|
2018-12-27 20:30:38 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2013-01-12 00:30:21 +04:00
|
|
|
#include "mozilla/dom/SVGMatrix.h"
|
2012-06-13 19:18:30 +04:00
|
|
|
#include "mozilla/dom/SVGTransformListBinding.h"
|
2019-03-19 03:01:03 +03:00
|
|
|
#include "DOMSVGTransform.h"
|
2018-12-27 20:30:38 +03:00
|
|
|
#include "SVGAnimatedTransformList.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
// local helper functions
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void UpdateListIndicesFromIndex(
|
2018-12-28 20:20:15 +03:00
|
|
|
FallibleTArray<mozilla::dom::DOMSVGTransform*>& aItemsArray,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aStartingIndex) {
|
|
|
|
uint32_t length = aItemsArray.Length();
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = aStartingIndex; i < length; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (aItemsArray[i]) {
|
|
|
|
aItemsArray[i]->UpdateListIndex(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2019-09-21 17:38:56 +03:00
|
|
|
namespace dom {
|
2013-04-02 23:17:41 +04:00
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
// We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
|
2013-04-15 02:56:34 +04:00
|
|
|
// clear our SVGAnimatedTransformList's weak ref to us to be safe. (The other
|
2011-09-26 01:04:31 +04:00
|
|
|
// 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-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGTransformList)
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGTransformList)
|
2012-07-19 02:44:22 +04:00
|
|
|
if (tmp->mAList) {
|
|
|
|
if (tmp->IsAnimValList()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
tmp->mAList->mAnimVal = nullptr;
|
2012-07-19 02:44:22 +04:00
|
|
|
} else {
|
2012-07-30 18:20:58 +04:00
|
|
|
tmp->mAList->mBaseVal = nullptr;
|
2012-07-19 02:44:22 +04:00
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAList)
|
2012-07-19 02:44:22 +04:00
|
|
|
}
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2011-09-26 01:04:31 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGTransformList)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAList)
|
2011-09-26 01:04:31 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGTransformList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-12-22 21:56:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGTransformList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGTransformList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGTransformList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// DOMSVGTransformList methods:
|
|
|
|
|
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* DOMSVGTransformList::WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return mozilla::dom::SVGTransformList_Binding::Wrap(cx, this, aGivenProto);
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeTransformListNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeTransformList and
|
|
|
|
// DidChangeTransformList.
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII AutoChangeTransformListNotifier {
|
2013-12-25 02:09:22 +04:00
|
|
|
public:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit AutoChangeTransformListNotifier(
|
|
|
|
DOMSVGTransformList* aTransformList MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-25 02:09:22 +04:00
|
|
|
: mTransformList(aTransformList) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 12:33:48 +04:00
|
|
|
MOZ_ASSERT(mTransformList, "Expecting non-null transformList");
|
2013-12-25 02:09:22 +04:00
|
|
|
mEmptyOrOldValue = mTransformList->Element()->WillChangeTransformList();
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeTransformListNotifier() {
|
|
|
|
mTransformList->Element()->DidChangeTransformList(mEmptyOrOldValue);
|
|
|
|
if (mTransformList->IsAnimating()) {
|
|
|
|
mTransformList->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 12:33:48 +04:00
|
|
|
DOMSVGTransformList* const mTransformList;
|
2013-12-25 02:09:22 +04:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void DOMSVGTransformList::InternalListLengthWillChange(uint32_t aNewLength) {
|
|
|
|
uint32_t oldLength = mItems.Length();
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
if (aNewLength > DOMSVGTransform::MaxListIndex()) {
|
2011-09-26 01:04:31 +04:00
|
|
|
// It's safe to get out of sync with our internal list as long as we have
|
|
|
|
// FEWER items than it does.
|
2018-12-28 20:20:15 +03:00
|
|
|
aNewLength = DOMSVGTransform::MaxListIndex();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGTransformList> kungFuDeathGrip;
|
2011-09-26 01:04:31 +04:00
|
|
|
if (aNewLength < oldLength) {
|
|
|
|
// RemovingFromList() might clear last reference to |this|.
|
|
|
|
// Retain a temporary reference to keep from dying before returning.
|
|
|
|
kungFuDeathGrip = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If our length will decrease, notify the items that will be removed:
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = aNewLength; i < oldLength; ++i) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (mItems[i]) {
|
|
|
|
mItems[i]->RemovingFromList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 23:50:35 +03:00
|
|
|
if (!mItems.SetLength(aNewLength, fallible)) {
|
2011-09-26 01:04:31 +04: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 < aNewLength; ++i) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mItems[i] = nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-26 14:22:15 +04:00
|
|
|
SVGTransformList& DOMSVGTransformList::InternalList() const {
|
2018-12-27 02:46:38 +03:00
|
|
|
SVGAnimatedTransformList* alist = Element()->GetAnimatedTransformList();
|
2011-09-26 01:04:31 +04:00
|
|
|
return IsAnimValList() && alist->mAnimVal ? *alist->mAnimVal
|
|
|
|
: alist->mBaseVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2012-09-06 00:49:53 +04:00
|
|
|
void DOMSVGTransformList::Clear(ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (LengthNoFlush() > 0) {
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeTransformListNotifier notifier(this);
|
2011-09-26 01:04:31 +04:00
|
|
|
// Notify any existing DOM items of removal *before* truncating the lists
|
2018-12-28 20:20:15 +03:00
|
|
|
// so that they can find their DOMSVGTransform internal counterparts and
|
|
|
|
// copy their values. This also notifies the animVal list:
|
2011-09-26 01:04:31 +04:00
|
|
|
mAList->InternalBaseValListWillChangeLengthTo(0);
|
|
|
|
|
|
|
|
mItems.Clear();
|
|
|
|
InternalList().Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::Initialize(
|
|
|
|
DOMSVGTransform& newItem, ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04: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.
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> domItem = &newItem;
|
2011-09-26 01:04:31 +04:00
|
|
|
if (domItem->HasOwner()) {
|
2012-12-23 08:54:20 +04:00
|
|
|
domItem = newItem.Clone();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
Clear(error);
|
|
|
|
MOZ_ASSERT(!error.Failed(), "How could this fail?");
|
2012-12-23 08:54:20 +04:00
|
|
|
return InsertItemBefore(*domItem, 0, error);
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::GetItem(
|
2013-07-12 14:25:25 +04:00
|
|
|
uint32_t index, ErrorResult& error) {
|
|
|
|
bool found;
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> item = IndexedGetter(index, found, error);
|
2013-07-12 14:25:25 +04:00
|
|
|
if (!found) {
|
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
}
|
|
|
|
return item.forget();
|
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::IndexedGetter(
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t index, bool& found, ErrorResult& error) {
|
|
|
|
if (IsAnimValList()) {
|
|
|
|
Element()->FlushAnimations();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
2012-09-06 00:49:53 +04:00
|
|
|
found = index < LengthNoFlush();
|
|
|
|
if (found) {
|
2013-07-12 14:25:25 +04:00
|
|
|
return GetItemAt(index);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::InsertItemBefore(
|
|
|
|
DOMSVGTransform& newItem, uint32_t index, ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
index = std::min(index, LengthNoFlush());
|
2018-12-28 20:20:15 +03:00
|
|
|
if (index >= DOMSVGTransform::MaxListIndex()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> domItem = &newItem;
|
2012-12-23 08:54:20 +04:00
|
|
|
if (newItem.HasOwner()) {
|
|
|
|
domItem = newItem.Clone(); // must do this before changing anything!
|
2011-09-26 01:04:31 +04: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) ||
|
2011-09-26 01:04:31 +04:00
|
|
|
!InternalList().SetCapacity(InternalList().Length() + 1)) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
2015-11-05 09:32:29 +03:00
|
|
|
if (AnimListMirrorsBaseList()) {
|
|
|
|
if (!mAList->mAnimVal->mItems.SetCapacity(
|
|
|
|
mAList->mAnimVal->mItems.Length() + 1, fallible)) {
|
|
|
|
error.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeTransformListNotifier notifier(this);
|
2011-09-26 01:04:31 +04:00
|
|
|
// Now that we know we're inserting, keep animVal list in sync as necessary.
|
|
|
|
MaybeInsertNullInAnimValListAt(index);
|
|
|
|
|
|
|
|
InternalList().InsertItem(index, domItem->ToSVGTransform());
|
2015-05-28 21:07:43 +03:00
|
|
|
MOZ_ALWAYS_TRUE(mItems.InsertElementAt(index, domItem.get(), fallible));
|
2011-09-26 01:04:31 +04: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!:
|
|
|
|
domItem->InsertingIntoList(this, index, IsAnimValList());
|
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(mItems, index + 1);
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return domItem.forget();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::ReplaceItem(
|
|
|
|
DOMSVGTransform& newItem, uint32_t index, ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (index >= LengthNoFlush()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
2012-12-23 08:54:20 +04:00
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> domItem = &newItem;
|
2012-12-23 08:54:20 +04:00
|
|
|
if (newItem.HasOwner()) {
|
|
|
|
domItem = newItem.Clone(); // must do this before changing anything!
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeTransformListNotifier notifier(this);
|
2011-09-26 01:04:31 +04: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();
|
|
|
|
}
|
|
|
|
|
|
|
|
InternalList()[index] = domItem->ToSVGTransform();
|
|
|
|
mItems[index] = domItem;
|
|
|
|
|
|
|
|
// This MUST come after the ToSVGPoint() call, otherwise that call
|
|
|
|
// would end up reading bad data from InternalList()!
|
|
|
|
domItem->InsertingIntoList(this, index, IsAnimValList());
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return domItem.forget();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::RemoveItem(
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t index, ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-09-05 18:52:57 +04:00
|
|
|
if (index >= LengthNoFlush()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeTransformListNotifier notifier(this);
|
2011-09-26 01:04:31 +04: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 14:25:25 +04:00
|
|
|
// We have to return the removed item, so get it, creating it if necessary:
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> result = GetItemAt(index);
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
// Notify the DOM item of removal *before* modifying the lists so that the
|
|
|
|
// DOM item can copy its *old* value:
|
2013-07-12 14:25:25 +04:00
|
|
|
result->RemovingFromList();
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
InternalList().RemoveItem(index);
|
|
|
|
mItems.RemoveElementAt(index);
|
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(mItems, index);
|
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform>
|
2013-01-12 00:30:21 +04:00
|
|
|
DOMSVGTransformList::CreateSVGTransformFromMatrix(dom::SVGMatrix& matrix) {
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> result = new DOMSVGTransform(matrix.GetMatrix());
|
2012-09-06 00:49:53 +04:00
|
|
|
return result.forget();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::Consolidate(
|
2012-09-06 00:49:53 +04:00
|
|
|
ErrorResult& error) {
|
2011-09-26 01:04:31 +04:00
|
|
|
if (IsAnimValList()) {
|
2012-09-06 00:49:53 +04:00
|
|
|
error.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-12-23 08:54:20 +04:00
|
|
|
if (LengthNoFlush() == 0) {
|
2012-09-06 00:49:53 +04:00
|
|
|
return nullptr;
|
2012-12-23 08:54:20 +04:00
|
|
|
}
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
// Note that SVG 1.1 says, "The consolidation operation creates new
|
|
|
|
// SVGTransform object as the first and only item in the list" hence, even if
|
2012-09-05 18:52:57 +04:00
|
|
|
// LengthNoFlush() == 1 we can't return that one item (after making it a
|
|
|
|
// matrix type). We must orphan the existing item and then make a new one.
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
// First calculate our matrix
|
|
|
|
gfxMatrix mx = InternalList().GetConsolidationMatrix();
|
|
|
|
|
|
|
|
// Then orphan the existing items
|
2012-09-06 00:49:53 +04:00
|
|
|
Clear(error);
|
|
|
|
MOZ_ASSERT(!error.Failed(), "How could this fail?");
|
2011-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
// And append the new transform
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> transform = new DOMSVGTransform(mx);
|
2012-12-23 08:54:20 +04:00
|
|
|
return InsertItemBefore(*transform, LengthNoFlush(), error);
|
2012-09-06 00:49:53 +04:00
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers:
|
|
|
|
|
2018-12-28 20:20:15 +03:00
|
|
|
already_AddRefed<DOMSVGTransform> DOMSVGTransformList::GetItemAt(
|
|
|
|
uint32_t aIndex) {
|
2013-07-12 14:25:25 +04:00
|
|
|
MOZ_ASSERT(aIndex < mItems.Length());
|
|
|
|
|
2011-09-26 01:04:31 +04:00
|
|
|
if (!mItems[aIndex]) {
|
2018-12-28 20:20:15 +03:00
|
|
|
mItems[aIndex] = new DOMSVGTransform(this, aIndex, IsAnimValList());
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
2018-12-28 20:20:15 +03:00
|
|
|
RefPtr<DOMSVGTransform> result = mItems[aIndex];
|
2013-07-12 14:25:25 +04:00
|
|
|
return result.forget();
|
2011-09-26 01:04:31 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void DOMSVGTransformList::MaybeInsertNullInAnimValListAt(uint32_t aIndex) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal");
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
if (!AnimListMirrorsBaseList()) {
|
2011-09-26 01:04:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
DOMSVGTransformList* animVal = mAList->mAnimVal;
|
|
|
|
|
|
|
|
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-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex + 1);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void DOMSVGTransformList::MaybeRemoveItemFromAnimValListAt(uint32_t aIndex) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!IsAnimValList(), "call from baseVal to animVal");
|
2011-09-26 01:04:31 +04:00
|
|
|
|
2015-11-04 08:42:41 +03:00
|
|
|
if (!AnimListMirrorsBaseList()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-26 01:04:31 +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<DOMSVGTransformList> animVal = mAList->mAnimVal;
|
2011-09-26 01:04:31 +04:00
|
|
|
|
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-09-26 01:04:31 +04:00
|
|
|
|
|
|
|
if (animVal->mItems[aIndex]) {
|
|
|
|
animVal->mItems[aIndex]->RemovingFromList();
|
|
|
|
}
|
|
|
|
animVal->mItems.RemoveElementAt(aIndex);
|
|
|
|
|
|
|
|
UpdateListIndicesFromIndex(animVal->mItems, aIndex);
|
|
|
|
}
|
|
|
|
|
2019-09-21 17:38:56 +03:00
|
|
|
} // namespace dom
|
2011-09-26 01:04:31 +04:00
|
|
|
} // namespace mozilla
|