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"
|
|
|
|
#include "DOMSVGLengthList.h"
|
|
|
|
#include "DOMSVGAnimatedLengthList.h"
|
|
|
|
#include "SVGLength.h"
|
|
|
|
#include "SVGAnimatedLengthList.h"
|
|
|
|
#include "nsSVGElement.h"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "nsSVGLength2.h"
|
2010-07-17 01:42:12 +04:00
|
|
|
#include "nsIDOMSVGLength.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2011-08-01 21:43:23 +04:00
|
|
|
#include "nsMathUtils.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"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
2010-07-17 01:42:12 +04:00
|
|
|
|
|
|
|
// See the architecture comment in DOMSVGAnimatedLengthList.h.
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGLength2, DOMSVGLength>
|
|
|
|
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)
|
|
|
|
// 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-07-17 01:42:12 +04:00
|
|
|
}
|
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)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
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
|
2010-07-26 04:25:38 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::DOMSVGLength) // pseudo-interface
|
2010-07-17 01:42:12 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGLength)
|
|
|
|
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);
|
|
|
|
if (mLength->mList->IsAnimating()) {
|
|
|
|
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,
|
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-07-17 01:42:12 +04:00
|
|
|
: mList(aList)
|
|
|
|
, mListIndex(aListIndex)
|
|
|
|
, mAttrEnum(aAttrEnum)
|
|
|
|
, mIsAnimValItem(aIsAnimValItem)
|
|
|
|
, mUnit(nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER)
|
|
|
|
, mValue(0.0f)
|
2014-04-12 01:26:29 +04:00
|
|
|
, mVal(nullptr)
|
2010-07-17 01:42:12 +04:00
|
|
|
{
|
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)
|
2010-07-17 01:42:12 +04:00
|
|
|
, mUnit(nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER)
|
|
|
|
, mValue(0.0f)
|
2014-04-12 01:26:29 +04:00
|
|
|
, mVal(nullptr)
|
2014-04-11 19:24:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::DOMSVGLength(nsSVGLength2* aVal, nsSVGElement* aSVGElement,
|
|
|
|
bool aAnimVal)
|
|
|
|
: mList(nullptr)
|
|
|
|
, mListIndex(0)
|
|
|
|
, mAttrEnum(0)
|
|
|
|
, mIsAnimValItem(aAnimVal)
|
|
|
|
, mUnit(nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER)
|
|
|
|
, mValue(0.0f)
|
|
|
|
, mVal(aVal)
|
|
|
|
, mSVGElement(aSVGElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
void
|
|
|
|
DOMSVGLength::CleanupWeakRefs()
|
2014-04-12 01:26:29 +04:00
|
|
|
{
|
2016-07-21 20:49:38 +03:00
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
already_AddRefed<DOMSVGLength>
|
|
|
|
DOMSVGLength::GetTearOff(nsSVGLength2* aVal, nsSVGElement* aSVGElement,
|
|
|
|
bool aAnimVal)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
copy->NewValueSpecifiedUnits(unit, value);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2014-04-12 01:26:29 +04:00
|
|
|
uint16_t
|
|
|
|
DOMSVGLength::UnitType()
|
2010-07-17 01:42:12 +04:00
|
|
|
{
|
2014-04-12 01:26:29 +04:00
|
|
|
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-11 20:07:42 +04:00
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::GetUnitType(uint16_t* aUnit)
|
|
|
|
{
|
|
|
|
*aUnit = UnitType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
DOMSVGLength::GetValue(ErrorResult& aRv)
|
2010-07-17 01:42:12 +04:00
|
|
|
{
|
2014-04-12 01:26:29 +04:00
|
|
|
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;
|
2010-07-17 01:42:12 +04:00
|
|
|
} else if (mUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER ||
|
|
|
|
mUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_PX) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return mValue;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::GetValue(float* aValue)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aValue = GetValue(rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
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) {
|
|
|
|
mVal->SetBaseValue(aUserUnitValue, mSVGElement, true);
|
|
|
|
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
|
|
|
}
|
|
|
|
} else if (mUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER ||
|
|
|
|
mUnit == nsIDOMSVGLength::SVG_LENGTHTYPE_PX) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::SetValue(float aUserUnitValue)
|
2014-04-11 19:24:06 +04:00
|
|
|
{
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(aUserUnitValue)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
SetValue(aUserUnitValue, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
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-11 20:07:42 +04:00
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::GetValueInSpecifiedUnits(float* aValue)
|
|
|
|
{
|
|
|
|
*aValue = ValueInSpecifiedUnits();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::SetValueInSpecifiedUnits(float aValue)
|
|
|
|
{
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(aValue)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
SetValueInSpecifiedUnits(aValue, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGLength::SetValueAsString(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
SetValueAsString(aValue, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
SVGLength(mValue, mUnit).GetValueAsString(aValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-04-12 01:26:29 +04:00
|
|
|
DOMSVGLength::NewValueSpecifiedUnits(uint16_t aUnit, float aValue)
|
|
|
|
{
|
2014-10-01 13:26:00 +04:00
|
|
|
if (!IsFinite(aValue)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
NewValueSpecifiedUnits(aUnit, aValue, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DOMSVGLength::ConvertToSpecifiedUnits(uint16_t aUnit)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
ConvertToSpecifiedUnits(aUnit, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2014-04-12 01:26:29 +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
|
|
|
DOMSVGLength::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-04-12 01:26:29 +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::SVGLengthBinding::Wrap(aCx, this, aGivenProto);
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
DOMSVGLength::InsertingIntoList(DOMSVGLengthList *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-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
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-12-03 19:40:23 +03:00
|
|
|
DOMSVGLength::IndexIsValid()
|
|
|
|
{
|
|
|
|
SVGAnimatedLengthList *alist = Element()->GetAnimatedLengthList(mAttrEnum);
|
|
|
|
return (mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetAnimValue().Length()) ||
|
|
|
|
(!mIsAnimValItem &&
|
|
|
|
mListIndex < alist->GetBaseValue().Length());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-17 01:42:12 +04:00
|
|
|
} // namespace mozilla
|