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-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
#include "DOMSVGLength.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
#include "DOMSVGLengthList.h"
|
|
|
|
#include "DOMSVGAnimatedLengthList.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2011-08-01 21:43:23 +04:00
|
|
|
#include "nsMathUtils.h"
|
2019-04-09 23:04:33 +03:00
|
|
|
#include "SVGAnimatedLength.h"
|
2019-01-24 00:48:00 +03:00
|
|
|
#include "SVGAnimatedLengthList.h"
|
|
|
|
#include "SVGAttrTearoffTable.h"
|
|
|
|
#include "SVGLength.h"
|
|
|
|
#include "mozilla/dom/SVGElement.h"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "mozilla/dom/SVGLengthBinding.h"
|
2014-10-01 13:26:00 +04:00
|
|
|
#include "mozilla/FloatingPoint.h"
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
// See the architecture comment in DOMSVGAnimatedLengthList.h.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2018-12-28 16:42:46 +03:00
|
|
|
namespace dom {
|
2018-02-02 16:21:33 +03:00
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
static SVGAttrTearoffTable<SVGAnimatedLength, DOMSVGLength>
|
2014-04-12 01:26:29 +04:00
|
|
|
sBaseSVGLengthTearOffTable, sAnimSVGLengthTearOffTable;
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
// We could use NS_IMPL_CYCLE_COLLECTION(, except that in Unlink() we need to
|
2010-07-17 01:42:12 +04: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(DOMSVGLength)
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(DOMSVGLength)
|
2016-07-21 21:11:37 +03:00
|
|
|
tmp->CleanupWeakRefs();
|
|
|
|
tmp->mVal = nullptr; // (owned by mSVGElement, which we drop our ref to here)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mList)
|
2014-04-12 01:26:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSVGElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2014-04-12 01:26:29 +04:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(DOMSVGLength)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mList)
|
2014-04-12 01:26:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSVGElement)
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(DOMSVGLength)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(DOMSVGLength)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(DOMSVGLength)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGLength)
|
2014-04-12 01:26:29 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2018-12-28 16:42:46 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(DOMSVGLength) // pseudo-interface
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-12-25 02:09:22 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Helper class: AutoChangeLengthNotifier
|
|
|
|
// Stack-based helper class to pair calls to WillChangeLengthList and
|
|
|
|
// DidChangeLengthList.
|
2015-09-03 19:15:23 +03:00
|
|
|
class MOZ_RAII AutoChangeLengthNotifier {
|
2013-12-25 02:09:22 +04:00
|
|
|
public:
|
2014-09-01 05:08:04 +04:00
|
|
|
explicit AutoChangeLengthNotifier(
|
|
|
|
DOMSVGLength* aLength MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
|
2013-12-25 02:09:22 +04:00
|
|
|
: mLength(aLength) {
|
|
|
|
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
|
2013-12-25 12:33:48 +04:00
|
|
|
MOZ_ASSERT(mLength, "Expecting non-null length");
|
2013-12-25 02:09:22 +04:00
|
|
|
MOZ_ASSERT(mLength->HasOwner(),
|
|
|
|
"Expecting list to have an owner for notification");
|
|
|
|
mEmptyOrOldValue =
|
|
|
|
mLength->Element()->WillChangeLengthList(mLength->mAttrEnum);
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoChangeLengthNotifier() {
|
|
|
|
mLength->Element()->DidChangeLengthList(mLength->mAttrEnum,
|
|
|
|
mEmptyOrOldValue);
|
2018-11-20 10:01:49 +03:00
|
|
|
// Null check mLength->mList, since DidChangeLengthList can run script,
|
|
|
|
// potentially removing mLength from its list.
|
|
|
|
if (mLength->mList && mLength->mList->IsAnimating()) {
|
2013-12-25 02:09:22 +04:00
|
|
|
mLength->Element()->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-12-25 12:33:48 +04:00
|
|
|
DOMSVGLength* const mLength;
|
2013-12-25 02:09:22 +04:00
|
|
|
nsAttrValue mEmptyOrOldValue;
|
|
|
|
MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
|
|
|
|
};
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
DOMSVGLength::DOMSVGLength(DOMSVGLengthList* aList, uint8_t aAttrEnum,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aListIndex, bool aIsAnimValItem)
|
2010-07-17 01:42:12 +04:00
|
|
|
: mList(aList),
|
|
|
|
mListIndex(aListIndex),
|
|
|
|
mAttrEnum(aAttrEnum),
|
|
|
|
mIsAnimValItem(aIsAnimValItem),
|
2018-06-26 00:20:54 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER),
|
2010-07-17 01:42:12 +04:00
|
|
|
mValue(0.0f),
|
2014-04-12 01:26:29 +04:00
|
|
|
mVal(nullptr) {
|
2010-12-03 19:40:23 +03:00
|
|
|
// 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-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DOMSVGLength::DOMSVGLength()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mList(nullptr),
|
2010-07-17 01:42:12 +04:00
|
|
|
mListIndex(0),
|
|
|
|
mAttrEnum(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimValItem(false),
|
2018-06-26 00:20:54 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER),
|
2010-07-17 01:42:12 +04:00
|
|
|
mValue(0.0f),
|
2014-04-12 01:26:29 +04:00
|
|
|
mVal(nullptr) {}
|
2014-04-11 19:24:06 +04:00
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
DOMSVGLength::DOMSVGLength(SVGAnimatedLength* aVal, SVGElement* aSVGElement,
|
2014-04-12 01:26:29 +04:00
|
|
|
bool aAnimVal)
|
|
|
|
: mList(nullptr),
|
|
|
|
mListIndex(0),
|
|
|
|
mAttrEnum(0),
|
|
|
|
mIsAnimValItem(aAnimVal),
|
2018-06-26 00:20:54 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER),
|
2014-04-12 01:26:29 +04:00
|
|
|
mValue(0.0f),
|
|
|
|
mVal(aVal),
|
|
|
|
mSVGElement(aSVGElement) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
void DOMSVGLength::CleanupWeakRefs() {
|
|
|
|
// Our mList's weak ref to us must be nulled out when we die (or when we're
|
|
|
|
// cycle collected), so we that don't leave behind a pointer to
|
|
|
|
// free / soon-to-be-free memory.
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mList) {
|
2016-07-21 20:49:38 +03:00
|
|
|
MOZ_ASSERT(mList->mItems[mListIndex] == this,
|
|
|
|
"Clearing out the wrong list index...?");
|
2014-04-12 01:26:29 +04:00
|
|
|
mList->mItems[mListIndex] = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
// Similarly, we must update the tearoff table to remove its (non-owning)
|
|
|
|
// pointer to mVal.
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mVal) {
|
2016-07-21 20:49:38 +03:00
|
|
|
auto& table = mIsAnimValItem ? sAnimSVGLengthTearOffTable
|
|
|
|
: sBaseSVGLengthTearOffTable;
|
2014-04-12 01:26:29 +04:00
|
|
|
table.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
DOMSVGLength::~DOMSVGLength() { CleanupWeakRefs(); }
|
|
|
|
|
2019-04-09 23:04:33 +03:00
|
|
|
already_AddRefed<DOMSVGLength> DOMSVGLength::GetTearOff(SVGAnimatedLength* aVal,
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* aSVGElement,
|
|
|
|
bool aAnimVal) {
|
2014-04-12 01:26:29 +04:00
|
|
|
auto& table =
|
|
|
|
aAnimVal ? sAnimSVGLengthTearOffTable : sBaseSVGLengthTearOffTable;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMSVGLength> domLength = table.GetTearoff(aVal);
|
2014-04-12 01:26:29 +04:00
|
|
|
if (!domLength) {
|
|
|
|
domLength = new DOMSVGLength(aVal, aSVGElement, aAnimVal);
|
|
|
|
table.AddTearoff(aVal, domLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
return domLength.forget();
|
|
|
|
}
|
|
|
|
|
2014-08-06 03:15:00 +04:00
|
|
|
DOMSVGLength* DOMSVGLength::Copy() {
|
|
|
|
NS_ASSERTION(HasOwner() || IsReflectingAttribute(), "unexpected caller");
|
|
|
|
DOMSVGLength* copy = new DOMSVGLength();
|
|
|
|
uint16_t unit;
|
|
|
|
float value;
|
|
|
|
if (mVal) {
|
|
|
|
unit = mVal->mSpecifiedUnitType;
|
|
|
|
value = mIsAnimValItem ? mVal->mAnimVal : mVal->mBaseVal;
|
|
|
|
} else {
|
|
|
|
SVGLength& length = InternalItem();
|
|
|
|
unit = length.GetUnit();
|
|
|
|
value = length.GetValueInCurrentUnits();
|
|
|
|
}
|
2018-02-02 16:21:32 +03:00
|
|
|
copy->NewValueSpecifiedUnits(unit, value, IgnoreErrors());
|
2014-08-06 03:15:00 +04:00
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
uint16_t DOMSVGLength::UnitType() {
|
|
|
|
if (mVal) {
|
|
|
|
if (mIsAnimValItem) {
|
|
|
|
mSVGElement->FlushAnimations();
|
|
|
|
}
|
|
|
|
return mVal->mSpecifiedUnitType;
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2014-04-12 01:26:29 +04:00
|
|
|
return HasOwner() ? InternalItem().GetUnit() : mUnit;
|
2014-04-11 19:24:06 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
float DOMSVGLength::GetValue(ErrorResult& aRv) {
|
|
|
|
if (mVal) {
|
|
|
|
if (mIsAnimValItem) {
|
|
|
|
mSVGElement->FlushAnimations();
|
|
|
|
return mVal->GetAnimValue(mSVGElement);
|
|
|
|
}
|
|
|
|
return mVal->GetBaseValue(mSVGElement);
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
if (HasOwner()) {
|
2014-04-12 01:26:29 +04:00
|
|
|
float value = InternalItem().GetValueInUserUnits(Element(), Axis());
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(value)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2014-04-12 01:26:29 +04:00
|
|
|
return value;
|
2019-04-20 13:26:19 +03:00
|
|
|
}
|
2019-06-23 15:51:05 +03:00
|
|
|
|
|
|
|
float unitToPx;
|
|
|
|
if (UserSpaceMetrics::ResolveAbsoluteUnit(mUnit, unitToPx)) {
|
|
|
|
return mValue * unitToPx;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2019-06-23 15:51:05 +03:00
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
// else [SVGWG issue] Can't convert this length's value to user units
|
|
|
|
// ReportToConsole
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return 0.0f;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
void DOMSVGLength::SetValue(float aUserUnitValue, ErrorResult& aRv) {
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mVal) {
|
2017-12-30 20:07:27 +03:00
|
|
|
aRv = mVal->SetBaseValue(aUserUnitValue, mSVGElement, true);
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2011-08-11 17:29:50 +04:00
|
|
|
}
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
// Although the value passed in is in user units, this method does not turn
|
|
|
|
// this length into a user unit length. Instead it converts the user unit
|
|
|
|
// value to this length's current unit and sets that, leaving this length's
|
|
|
|
// unit as it is.
|
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (InternalItem().GetValueInUserUnits(Element(), Axis()) ==
|
|
|
|
aUserUnitValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
float uuPerUnit = InternalItem().GetUserUnitsPerUnit(Element(), Axis());
|
2013-12-25 12:33:48 +04:00
|
|
|
if (uuPerUnit > 0) {
|
|
|
|
float newValue = aUserUnitValue / uuPerUnit;
|
2014-10-01 13:26:00 +04:00
|
|
|
if (IsFinite(newValue)) {
|
2013-12-25 12:33:48 +04:00
|
|
|
AutoChangeLengthNotifier notifier(this);
|
|
|
|
InternalItem().SetValueAndUnit(newValue, InternalItem().GetUnit());
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2013-12-25 12:33:48 +04:00
|
|
|
}
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2018-06-26 00:20:54 +03:00
|
|
|
} else if (mUnit == SVGLength_Binding::SVG_LENGTHTYPE_NUMBER ||
|
|
|
|
mUnit == SVGLength_Binding::SVG_LENGTHTYPE_PX) {
|
2010-07-17 01:42:12 +04:00
|
|
|
mValue = aUserUnitValue;
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
// else [SVGWG issue] Can't convert user unit value to this length's unit
|
|
|
|
// ReportToConsole
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
float DOMSVGLength::ValueInSpecifiedUnits() {
|
|
|
|
if (mVal) {
|
|
|
|
if (mIsAnimValItem) {
|
|
|
|
mSVGElement->FlushAnimations();
|
|
|
|
return mVal->mAnimVal;
|
|
|
|
}
|
|
|
|
return mVal->mBaseVal;
|
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2014-04-12 01:26:29 +04:00
|
|
|
return HasOwner() ? InternalItem().GetValueInCurrentUnits() : mValue;
|
2014-04-11 19:24:06 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
void DOMSVGLength::SetValueInSpecifiedUnits(float aValue, ErrorResult& aRv) {
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mVal) {
|
|
|
|
mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement, true);
|
|
|
|
return;
|
2011-08-11 17:29:50 +04:00
|
|
|
}
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (InternalItem().GetValueInCurrentUnits() == aValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeLengthNotifier notifier(this);
|
2010-07-17 01:42:12 +04:00
|
|
|
InternalItem().SetValueInCurrentUnits(aValue);
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
mValue = aValue;
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
void DOMSVGLength::SetValueAsString(const nsAString& aValue, ErrorResult& aRv) {
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVal) {
|
2015-04-28 11:21:52 +03:00
|
|
|
aRv = mVal->SetBaseValueString(aValue, mSVGElement, true);
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGLength value;
|
|
|
|
if (!value.SetValueFromString(aValue)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (InternalItem() == value) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeLengthNotifier notifier(this);
|
2010-07-17 01:42:12 +04:00
|
|
|
InternalItem() = value;
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
mValue = value.GetValueInCurrentUnits();
|
|
|
|
mUnit = value.GetUnit();
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
void DOMSVGLength::GetValueAsString(nsAString& aValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mVal) {
|
|
|
|
if (mIsAnimValItem) {
|
|
|
|
mSVGElement->FlushAnimations();
|
|
|
|
mVal->GetAnimValueString(aValue);
|
|
|
|
} else {
|
|
|
|
mVal->GetBaseValueString(aValue);
|
|
|
|
}
|
2018-02-02 16:21:32 +03:00
|
|
|
return;
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem && HasOwner()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
if (HasOwner()) {
|
|
|
|
InternalItem().GetValueAsString(aValue);
|
2018-02-02 16:21:32 +03:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
SVGLength(mValue, mUnit).GetValueAsString(aValue);
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
void DOMSVGLength::NewValueSpecifiedUnits(uint16_t aUnit, float aValue,
|
|
|
|
ErrorResult& aRv) {
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mVal) {
|
|
|
|
mVal->NewValueSpecifiedUnits(aUnit, aValue, mSVGElement);
|
|
|
|
return;
|
2011-08-11 17:29:50 +04:00
|
|
|
}
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
if (!SVGLength::IsValidUnitType(aUnit)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (InternalItem().GetUnit() == aUnit &&
|
|
|
|
InternalItem().GetValueInCurrentUnits() == aValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeLengthNotifier notifier(this);
|
2012-08-22 19:56:38 +04:00
|
|
|
InternalItem().SetValueAndUnit(aValue, uint8_t(aUnit));
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
mUnit = uint8_t(aUnit);
|
2010-07-17 01:42:12 +04:00
|
|
|
mValue = aValue;
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
void DOMSVGLength::ConvertToSpecifiedUnits(uint16_t aUnit, ErrorResult& aRv) {
|
2010-07-17 01:42:12 +04:00
|
|
|
if (mIsAnimValItem) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVal) {
|
|
|
|
mVal->ConvertToSpecifiedUnits(aUnit, mSVGElement);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!SVGLength::IsValidUnitType(aUnit)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
if (HasOwner()) {
|
2012-02-16 03:40:45 +04:00
|
|
|
if (InternalItem().GetUnit() == aUnit) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2013-12-25 02:09:22 +04:00
|
|
|
float val =
|
|
|
|
InternalItem().GetValueInSpecifiedUnit(aUnit, Element(), Axis());
|
2014-10-01 13:26:00 +04:00
|
|
|
if (IsFinite(val)) {
|
2013-12-25 02:09:22 +04:00
|
|
|
AutoChangeLengthNotifier notifier(this);
|
|
|
|
InternalItem().SetValueAndUnit(val, aUnit);
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SVGLength len(mValue, mUnit);
|
2013-12-25 02:09:22 +04:00
|
|
|
float val = len.GetValueInSpecifiedUnit(aUnit, nullptr, 0);
|
2014-10-01 13:26:00 +04:00
|
|
|
if (IsFinite(val)) {
|
2013-12-25 02:09:22 +04:00
|
|
|
mValue = val;
|
2010-07-17 01:42:12 +04:00
|
|
|
mUnit = aUnit;
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// else [SVGWG issue] Can't convert unit
|
|
|
|
// ReportToConsole
|
2014-04-12 01:26:29 +04:00
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
}
|
|
|
|
|
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* DOMSVGLength::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return SVGLength_Binding::Wrap(aCx, this, aGivenProto);
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DOMSVGLength::InsertingIntoList(DOMSVGLengthList* aList, uint8_t aAttrEnum,
|
2012-09-23 04:48:27 +04:00
|
|
|
uint32_t aListIndex, bool aIsAnimValItem) {
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_ASSERTION(!HasOwner(), "Inserting item that is already in a list");
|
|
|
|
|
|
|
|
mList = aList;
|
|
|
|
mAttrEnum = aAttrEnum;
|
|
|
|
mListIndex = aListIndex;
|
|
|
|
mIsAnimValItem = aIsAnimValItem;
|
2010-12-03 19:40:23 +03:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGLength!");
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DOMSVGLength::RemovingFromList() {
|
|
|
|
mValue = InternalItem().GetValueInCurrentUnits();
|
|
|
|
mUnit = InternalItem().GetUnit();
|
2012-07-30 18:20:58 +04:00
|
|
|
mList = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimValItem = false;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGLength DOMSVGLength::ToSVGLength() {
|
|
|
|
if (HasOwner()) {
|
|
|
|
return SVGLength(InternalItem().GetValueInCurrentUnits(),
|
|
|
|
InternalItem().GetUnit());
|
|
|
|
}
|
|
|
|
return SVGLength(mValue, mUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGLength& DOMSVGLength::InternalItem() {
|
|
|
|
SVGAnimatedLengthList* alist = Element()->GetAnimatedLengthList(mAttrEnum);
|
|
|
|
return mIsAnimValItem && alist->mAnimVal ? (*alist->mAnimVal)[mListIndex]
|
|
|
|
: alist->mBaseVal[mListIndex];
|
|
|
|
}
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool DOMSVGLength::IndexIsValid() {
|
|
|
|
SVGAnimatedLengthList* alist = Element()->GetAnimatedLengthList(mAttrEnum);
|
|
|
|
return (mIsAnimValItem && mListIndex < alist->GetAnimValue().Length()) ||
|
|
|
|
(!mIsAnimValItem && mListIndex < alist->GetBaseValue().Length());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-28 16:42:46 +03:00
|
|
|
} // namespace dom
|
2010-07-17 01:42:12 +04:00
|
|
|
} // namespace mozilla
|