2010-12-03 16:40:23 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 16:40:23 +00:00
|
|
|
|
|
|
|
#include "DOMSVGNumber.h"
|
|
|
|
#include "DOMSVGNumberList.h"
|
|
|
|
#include "DOMSVGAnimatedNumberList.h"
|
|
|
|
#include "SVGAnimatedNumberList.h"
|
|
|
|
#include "nsSVGElement.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2013-08-14 06:56:21 +00:00
|
|
|
#include "nsContentUtils.h" // for NS_ENSURE_FINITE
|
2014-05-30 07:36:52 +00:00
|
|
|
#include "mozilla/dom/SVGNumberBinding.h"
|
2010-12-03 16:40:23 +00:00
|
|
|
|
|
|
|
// See the architecture comment in DOMSVGAnimatedNumberList.h.
|
|
|
|
|
2013-12-25 08:33:48 +00:00
|
|
|
namespace mozilla {
|
2010-12-03 16:40:23 +00:00
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
// We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
|
2010-12-03 16:40:23 +00:00
|
|
|
// clear our list'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-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(DOMSVGNumber)
|
|
|
|
|
2010-12-03 16:40:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGNumber)
|
|
|
|
// We may not belong to a list, so we must null check tmp->mList.
|
|
|
|
if (tmp->mList) {
|
2012-07-30 14:20:58 +00:00
|
|
|
tmp->mList->mItems[tmp->mListIndex] = nullptr;
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
2014-05-30 07:36:52 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent)
|
2010-12-03 16:40:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGNumber)
|
2014-05-30 07:36:52 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2010-12-03 16:40:23 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2014-05-30 07:36:52 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGNumber)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2010-12-03 16:40:23 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGNumber)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGNumber)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGNumber)
|
2014-05-30 07:36:52 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2010-12-03 16:40:23 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-12-24 22:09:22 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeNumberNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeNumberList and
|
|
|
|
// DidChangeNumberList.
|
|
|
|
class MOZ_STACK_CLASS AutoChangeNumberNotifier
|
|
|
|
{
|
|
|
|
public:
|
2014-09-01 01:08:04 +00:00
|
|
|
explicit AutoChangeNumberNotifier(DOMSVGNumber* aNumber MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-24 22:09:22 +00:00
|
|
|
: mNumber(aNumber)
|
|
|
|
{
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 08:33:48 +00:00
|
|
|
MOZ_ASSERT(mNumber, "Expecting non-null number");
|
2013-12-24 22:09:22 +00:00
|
|
|
MOZ_ASSERT(mNumber->HasOwner(),
|
|
|
|
"Expecting list to have an owner for notification");
|
|
|
|
mEmptyOrOldValue =
|
|
|
|
mNumber->Element()->WillChangeNumberList(mNumber->mAttrEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeNumberNotifier()
|
|
|
|
{
|
|
|
|
mNumber->Element()->DidChangeNumberList(mNumber->mAttrEnum,
|
|
|
|
mEmptyOrOldValue);
|
|
|
|
if (mNumber->mList->IsAnimating()) {
|
|
|
|
mNumber->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 08:33:48 +00:00
|
|
|
DOMSVGNumber* const mNumber;
|
2013-12-24 22:09:22 +00:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-12-03 16:40:23 +00:00
|
|
|
DOMSVGNumber::DOMSVGNumber(DOMSVGNumberList *aList,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aAttrEnum,
|
|
|
|
uint32_t aListIndex,
|
2012-09-23 00:48:27 +00:00
|
|
|
bool aIsAnimValItem)
|
2010-12-03 16:40:23 +00:00
|
|
|
: mList(aList)
|
2014-05-30 07:36:52 +00:00
|
|
|
, mParent(aList)
|
2010-12-03 16:40:23 +00:00
|
|
|
, mListIndex(aListIndex)
|
|
|
|
, mAttrEnum(aAttrEnum)
|
|
|
|
, mIsAnimValItem(aIsAnimValItem)
|
|
|
|
, mValue(0.0f)
|
|
|
|
{
|
|
|
|
// These shifts are in sync with the members in the header.
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(aList &&
|
|
|
|
aAttrEnum < (1 << 4) &&
|
|
|
|
aListIndex <= MaxListIndex(),
|
|
|
|
"bad arg");
|
2010-12-03 16:40:23 +00:00
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGNumber!");
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 07:36:52 +00:00
|
|
|
DOMSVGNumber::DOMSVGNumber(nsISupports* aParent)
|
2012-07-30 14:20:58 +00:00
|
|
|
: mList(nullptr)
|
2014-05-30 07:36:52 +00:00
|
|
|
, mParent(aParent)
|
2010-12-03 16:40:23 +00:00
|
|
|
, mListIndex(0)
|
|
|
|
, mAttrEnum(0)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mIsAnimValItem(false)
|
2010-12-03 16:40:23 +00:00
|
|
|
, mValue(0.0f)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-05-30 07:36:52 +00:00
|
|
|
/* static */ already_AddRefed<DOMSVGNumber>
|
|
|
|
DOMSVGNumber::Constructor(const dom::GlobalObject& aGlobal, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMSVGNumber> number = new DOMSVGNumber(window);
|
|
|
|
return number.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed<DOMSVGNumber>
|
|
|
|
DOMSVGNumber::Constructor(const dom::GlobalObject& aGlobal, float aValue,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
|
|
|
if (!window) {
|
|
|
|
aRv.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<DOMSVGNumber> number = new DOMSVGNumber(window);
|
|
|
|
number->SetValue(aValue, aRv);
|
|
|
|
return number.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
DOMSVGNumber::Value()
|
2010-12-03 16:40:23 +00:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
2014-05-30 07:36:52 +00:00
|
|
|
return HasOwner() ? InternalItem() : mValue;
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-30 07:36:52 +00:00
|
|
|
void
|
|
|
|
DOMSVGNumber::SetValue(float aValue, ErrorResult& aRv)
|
2010-12-03 16:40:23 +00:00
|
|
|
{
|
|
|
|
if (mIsAnimValItem) {
|
2014-05-30 07:36:52 +00:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-15 23:40:46 +00:00
|
|
|
if (InternalItem() == aValue) {
|
2014-05-30 07:36:52 +00:00
|
|
|
return;
|
2012-02-15 23:40:46 +00:00
|
|
|
}
|
2013-12-24 22:09:22 +00:00
|
|
|
AutoChangeNumberNotifier notifier(this);
|
2010-12-03 16:40:23 +00:00
|
|
|
InternalItem() = aValue;
|
2014-05-30 07:36:52 +00:00
|
|
|
return;
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
2014-05-30 07:36:52 +00:00
|
|
|
|
2010-12-03 16:40:23 +00:00
|
|
|
mValue = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGNumber::InsertingIntoList(DOMSVGNumberList *aList,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t aAttrEnum,
|
|
|
|
uint32_t aListIndex,
|
2012-09-23 00:48:27 +00:00
|
|
|
bool aIsAnimValItem)
|
2010-12-03 16:40:23 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!HasOwner(), "Inserting item that is already in a list");
|
|
|
|
|
|
|
|
mList = aList;
|
|
|
|
mAttrEnum = aAttrEnum;
|
|
|
|
mListIndex = aListIndex;
|
|
|
|
mIsAnimValItem = aIsAnimValItem;
|
|
|
|
|
2015-02-09 22:34:50 +00:00
|
|
|
MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGNumber!");
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGNumber::RemovingFromList()
|
|
|
|
{
|
|
|
|
mValue = InternalItem();
|
2012-07-30 14:20:58 +00:00
|
|
|
mList = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsAnimValItem = false;
|
2010-12-03 16:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
DOMSVGNumber::ToSVGNumber()
|
|
|
|
{
|
|
|
|
return HasOwner() ? InternalItem() : mValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float&
|
|
|
|
DOMSVGNumber::InternalItem()
|
|
|
|
{
|
|
|
|
SVGAnimatedNumberList *alist = Element()->GetAnimatedNumberList(mAttrEnum);
|
|
|
|
return mIsAnimValItem && alist->mAnimVal ?
|
|
|
|
(*alist->mAnimVal)[mListIndex] :
|
|
|
|
alist->mBaseVal[mListIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-12-03 16:40:23 +00:00
|
|
|
DOMSVGNumber::IndexIsValid()
|
|
|
|
{
|
|
|
|
SVGAnimatedNumberList *alist = Element()->GetAnimatedNumberList(mAttrEnum);
|
|
|
|
return (mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetAnimValue().Length()) ||
|
|
|
|
(!mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetBaseValue().Length());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-05-30 07:36:52 +00:00
|
|
|
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 14:13:33 +00:00
|
|
|
DOMSVGNumber::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-05-30 07:36:52 +00: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 14:13:33 +00:00
|
|
|
return dom::SVGNumberBinding::Wrap(aCx, this, aGivenProto);
|
2014-05-30 07:36:52 +00:00
|
|
|
}
|
|
|
|
|
2013-12-25 08:33:48 +00:00
|
|
|
} // namespace mozilla
|