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-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
#include "DOMSVGStringList.h"
|
2013-04-21 10:42:00 +04:00
|
|
|
|
|
|
|
#include "mozilla/dom/SVGStringListBinding.h"
|
2013-03-02 10:08:42 +04:00
|
|
|
#include "mozilla/dom/SVGTests.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2011-12-31 13:44:03 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
// See the architecture comment in this file's header.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
using namespace dom;
|
|
|
|
|
2013-05-31 02:34:53 +04:00
|
|
|
static inline
|
|
|
|
nsSVGAttrTearoffTable<SVGStringList, DOMSVGStringList>&
|
|
|
|
SVGStringListTearoffTable()
|
|
|
|
{
|
|
|
|
static nsSVGAttrTearoffTable<SVGStringList, DOMSVGStringList>
|
|
|
|
sSVGStringListTearoffTable;
|
|
|
|
return sSVGStringListTearoffTable;
|
|
|
|
}
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
NS_SVG_VAL_IMPL_CYCLE_COLLECTION_WRAPPERCACHED(DOMSVGStringList, mElement)
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2013-12-22 21:56:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGStringList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGStringList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGStringList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeStringListNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeStringListList and
|
|
|
|
// DidChangeStringListList.
|
|
|
|
class MOZ_STACK_CLASS AutoChangeStringListNotifier
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit AutoChangeStringListNotifier(DOMSVGStringList* aStringList MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-25 02:09:22 +04:00
|
|
|
: mStringList(aStringList)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 12:33:48 +04:00
|
|
|
MOZ_ASSERT(mStringList, "Expecting non-null stringList");
|
2013-12-25 02:09:22 +04:00
|
|
|
mEmptyOrOldValue =
|
|
|
|
mStringList->mElement->WillChangeStringList(mStringList->mIsConditionalProcessingAttribute,
|
|
|
|
mStringList->mAttrEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeStringListNotifier()
|
|
|
|
{
|
|
|
|
mStringList->mElement->DidChangeStringList(mStringList->mIsConditionalProcessingAttribute,
|
|
|
|
mStringList->mAttrEnum, mEmptyOrOldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 12:33:48 +04:00
|
|
|
DOMSVGStringList* const mStringList;
|
2013-12-25 02:09:22 +04:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2011-12-31 13:44:03 +04:00
|
|
|
/* static */ already_AddRefed<DOMSVGStringList>
|
|
|
|
DOMSVGStringList::GetDOMWrapper(SVGStringList *aList,
|
|
|
|
nsSVGElement *aElement,
|
|
|
|
bool aIsConditionalProcessingAttribute,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aAttrEnum)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2012-08-23 10:24:41 +04:00
|
|
|
nsRefPtr<DOMSVGStringList> wrapper =
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGStringListTearoffTable().GetTearoff(aList);
|
2011-12-31 13:44:03 +04:00
|
|
|
if (!wrapper) {
|
|
|
|
wrapper = new DOMSVGStringList(aElement,
|
|
|
|
aIsConditionalProcessingAttribute,
|
|
|
|
aAttrEnum);
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGStringListTearoffTable().AddTearoff(aList, wrapper);
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
2012-08-23 10:24:41 +04:00
|
|
|
return wrapper.forget();
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGStringList::~DOMSVGStringList()
|
|
|
|
{
|
|
|
|
// Script no longer has any references to us.
|
2013-05-31 02:34:53 +04:00
|
|
|
SVGStringListTearoffTable().RemoveTearoff(&InternalList());
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
/* virtual */ JSObject*
|
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
|
|
|
DOMSVGStringList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-04-21 10:42:00 +04: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
|
|
|
return SVGStringListBinding::Wrap(aCx, this, aGivenProto);
|
2013-04-21 10:42:00 +04:00
|
|
|
}
|
|
|
|
|
2011-12-31 13:44:03 +04:00
|
|
|
// ----------------------------------------------------------------------------
|
2013-04-21 10:42:00 +04:00
|
|
|
// SVGStringList implementation:
|
2011-12-31 13:44:03 +04:00
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
uint32_t
|
|
|
|
DOMSVGStringList::NumberOfItems() const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
return InternalList().Length();
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
uint32_t
|
|
|
|
DOMSVGStringList::Length() const
|
2012-01-28 14:43:34 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
return NumberOfItems();
|
2012-01-28 14:43:34 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
2011-12-31 13:44:03 +04:00
|
|
|
DOMSVGStringList::Clear()
|
|
|
|
{
|
|
|
|
if (InternalList().IsExplicitlySet()) {
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeStringListNotifier notifier(this);
|
2011-12-31 13:44:03 +04:00
|
|
|
InternalList().Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::Initialize(const nsAString& aNewItem, nsAString& aRetval,
|
|
|
|
ErrorResult& aRv)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
|
|
|
if (InternalList().IsExplicitlySet()) {
|
|
|
|
InternalList().Clear();
|
|
|
|
}
|
2013-04-21 10:42:00 +04:00
|
|
|
InsertItemBefore(aNewItem, 0, aRetval, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGStringList::GetItem(uint32_t aIndex, nsAString& aRetval, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
IndexedGetter(aIndex, found, aRetval);
|
|
|
|
if (!found) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
}
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::IndexedGetter(uint32_t aIndex, bool& aFound,
|
|
|
|
nsAString& aRetval)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
aFound = aIndex < InternalList().Length();
|
|
|
|
if (aFound) {
|
|
|
|
aRetval = InternalList()[aIndex];
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::InsertItemBefore(const nsAString& aNewItem, uint32_t aIndex,
|
|
|
|
nsAString& aRetval, ErrorResult& aRv)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
if (aNewItem.IsEmpty()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return;
|
2012-02-09 00:09:01 +04:00
|
|
|
}
|
2013-04-21 10:42:00 +04:00
|
|
|
aIndex = std::min(aIndex, InternalList().Length());
|
2011-12-31 13:44:03 +04:00
|
|
|
|
|
|
|
// Ensure we have enough memory so we can avoid complex error handling below:
|
|
|
|
if (!InternalList().SetCapacity(InternalList().Length() + 1)) {
|
2013-04-21 10:42:00 +04:00
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeStringListNotifier notifier(this);
|
2013-04-21 10:42:00 +04:00
|
|
|
InternalList().InsertItem(aIndex, aNewItem);
|
|
|
|
aRetval = aNewItem;
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::ReplaceItem(const nsAString& aNewItem, uint32_t aIndex,
|
|
|
|
nsAString& aRetval, ErrorResult& aRv)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
if (aNewItem.IsEmpty()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return;
|
2012-02-09 00:09:01 +04:00
|
|
|
}
|
2013-04-21 10:42:00 +04:00
|
|
|
if (aIndex >= InternalList().Length()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
aRetval = InternalList()[aIndex];
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeStringListNotifier notifier(this);
|
2013-04-21 10:42:00 +04:00
|
|
|
InternalList().ReplaceItem(aIndex, aNewItem);
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::RemoveItem(uint32_t aIndex, nsAString& aRetval,
|
|
|
|
ErrorResult& aRv)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
if (aIndex >= InternalList().Length()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeStringListNotifier notifier(this);
|
2013-04-21 10:42:00 +04:00
|
|
|
InternalList().RemoveItem(aIndex);
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 10:42:00 +04:00
|
|
|
void
|
|
|
|
DOMSVGStringList::AppendItem(const nsAString& aNewItem, nsAString& aRetval,
|
|
|
|
ErrorResult& aRv)
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
2013-04-21 10:42:00 +04:00
|
|
|
InsertItemBefore(aNewItem, InternalList().Length(), aRetval, aRv);
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGStringList &
|
2013-04-21 10:42:00 +04:00
|
|
|
DOMSVGStringList::InternalList() const
|
2011-12-31 13:44:03 +04:00
|
|
|
{
|
|
|
|
if (mIsConditionalProcessingAttribute) {
|
2013-04-21 10:42:00 +04:00
|
|
|
nsCOMPtr<dom::SVGTests> tests = do_QueryObject(mElement.get());
|
2012-09-05 01:53:04 +04:00
|
|
|
return tests->mStringListAttributes[mAttrEnum];
|
2011-12-31 13:44:03 +04:00
|
|
|
}
|
|
|
|
return mElement->GetStringListInfo().mStringLists[mAttrEnum];
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mozilla
|