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