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();
|
2020-08-25 21:25:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwner)
|
2014-04-12 01:26:29 +04:00
|
|
|
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)
|
2020-08-25 21:25:52 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwner)
|
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
|
|
|
|
|
2020-08-08 01:50:28 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMSVGLength, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMSVGLength, Release)
|
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)
|
2020-08-25 21:25:52 +03:00
|
|
|
: mOwner(aList),
|
2010-07-17 01:42:12 +04:00
|
|
|
mListIndex(aListIndex),
|
|
|
|
mAttrEnum(aAttrEnum),
|
|
|
|
mIsAnimValItem(aIsAnimValItem),
|
2020-08-25 21:25:52 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER) {
|
|
|
|
MOZ_ASSERT(aList, "bad arg");
|
|
|
|
MOZ_ASSERT(mAttrEnum == aAttrEnum, "bitfield too small");
|
|
|
|
MOZ_ASSERT(aListIndex <= MaxListIndex(), "list index too large");
|
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()
|
2020-08-25 21:25:52 +03:00
|
|
|
: mOwner(nullptr),
|
2010-07-17 01:42:12 +04:00
|
|
|
mListIndex(0),
|
|
|
|
mAttrEnum(0),
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimValItem(false),
|
2020-08-25 21:25:52 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER) {}
|
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)
|
2020-08-25 21:25:52 +03:00
|
|
|
: mOwner(aSVGElement),
|
2014-04-12 01:26:29 +04:00
|
|
|
mListIndex(0),
|
2020-08-25 21:25:52 +03:00
|
|
|
mAttrEnum(aVal->mAttrEnum),
|
2014-04-12 01:26:29 +04:00
|
|
|
mIsAnimValItem(aAnimVal),
|
2020-08-25 21:25:52 +03:00
|
|
|
mUnit(SVGLength_Binding::SVG_LENGTHTYPE_NUMBER) {
|
|
|
|
MOZ_ASSERT(aVal, "bad arg");
|
|
|
|
MOZ_ASSERT(mAttrEnum == aVal->mAttrEnum, "bitfield too small");
|
|
|
|
}
|
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.
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
MOZ_ASSERT(lengthList->mItems[mListIndex] == this,
|
2016-07-21 20:49:38 +03:00
|
|
|
"Clearing out the wrong list index...?");
|
2020-08-25 21:25:52 +03:00
|
|
|
lengthList->mItems[mListIndex] = nullptr;
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
|
|
|
|
2016-07-21 20:49:38 +03:00
|
|
|
// Similarly, we must update the tearoff table to remove its (non-owning)
|
|
|
|
// pointer to mVal.
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
2016-07-21 20:49:38 +03:00
|
|
|
auto& table = mIsAnimValItem ? sAnimSVGLengthTearOffTable
|
|
|
|
: sBaseSVGLengthTearOffTable;
|
2020-08-25 21:25:52 +03:00
|
|
|
table.RemoveTearoff(svg->GetAnimatedLength(mAttrEnum));
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
2020-08-25 21:25:52 +03:00
|
|
|
NS_ASSERTION(HasOwner(), "unexpected caller");
|
2014-08-06 03:15:00 +04:00
|
|
|
DOMSVGLength* copy = new DOMSVGLength();
|
|
|
|
uint16_t unit;
|
|
|
|
float value;
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
SVGAnimatedLength* length = svg->GetAnimatedLength(mAttrEnum);
|
|
|
|
unit = length->GetSpecifiedUnitType();
|
|
|
|
value = mIsAnimValItem ? length->GetAnimValInSpecifiedUnits()
|
|
|
|
: length->GetBaseValInSpecifiedUnits();
|
2014-08-06 03:15:00 +04:00
|
|
|
} else {
|
2020-08-25 21:25:52 +03:00
|
|
|
const SVGLength& length = InternalItem();
|
2014-08-06 03:15:00 +04:00
|
|
|
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() {
|
2020-08-25 21:25:52 +03:00
|
|
|
if (mIsAnimValItem) {
|
|
|
|
Element()->FlushAnimations();
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
return svg->GetAnimatedLength(mAttrEnum)->GetSpecifiedUnitType();
|
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) {
|
2020-08-25 21:25:52 +03:00
|
|
|
if (mIsAnimValItem) {
|
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
SVGAnimatedLength* length = svg->GetAnimatedLength(mAttrEnum);
|
|
|
|
return mIsAnimValItem ? length->GetAnimValue(svg)
|
|
|
|
: length->GetBaseValue(svg);
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
|
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
float value = InternalItem().GetValueInUserUnits(lengthList->Element(),
|
|
|
|
lengthList->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
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
aRv = svg->GetAnimatedLength(mAttrEnum)->SetBaseValue(aUserUnitValue, svg,
|
|
|
|
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.
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
SVGLength& internalItem = InternalItem();
|
|
|
|
if (internalItem.GetValueInUserUnits(
|
|
|
|
lengthList->Element(), lengthList->Axis()) == aUserUnitValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
float uuPerUnit = internalItem.GetUserUnitsPerUnit(lengthList->Element(),
|
|
|
|
lengthList->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)) {
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeLengthListNotifier notifier(this);
|
2020-08-25 21:25:52 +03:00
|
|
|
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() {
|
2020-08-25 21:25:52 +03:00
|
|
|
if (mIsAnimValItem) {
|
2011-10-17 18:59:28 +04:00
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
SVGAnimatedLength* length = svg->GetAnimatedLength(mAttrEnum);
|
|
|
|
return mIsAnimValItem ? length->GetAnimValInSpecifiedUnits()
|
|
|
|
: length->GetBaseValInSpecifiedUnits();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
svg->GetAnimatedLength(mAttrEnum)->SetBaseValueInSpecifiedUnits(aValue, svg,
|
|
|
|
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
|
|
|
|
|
|
|
if (HasOwner()) {
|
2020-08-25 21:25:52 +03:00
|
|
|
SVGLength& internalItem = InternalItem();
|
|
|
|
if (internalItem.GetValueInCurrentUnits() == aValue) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeLengthListNotifier notifier(this);
|
2020-08-25 21:25:52 +03: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;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
aRv = svg->GetAnimatedLength(mAttrEnum)->SetBaseValueString(aValue, svg,
|
|
|
|
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()) {
|
2020-08-25 21:25:52 +03:00
|
|
|
SVGLength& internalItem = InternalItem();
|
|
|
|
if (internalItem == value) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeLengthListNotifier notifier(this);
|
2020-08-25 21:25:52 +03: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) {
|
2020-08-25 21:25:52 +03:00
|
|
|
if (mIsAnimValItem) {
|
|
|
|
Element()->FlushAnimations(); // May make HasOwner() == false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
SVGAnimatedLength* length = svg->GetAnimatedLength(mAttrEnum);
|
2014-04-12 01:26:29 +04:00
|
|
|
if (mIsAnimValItem) {
|
2020-08-25 21:25:52 +03:00
|
|
|
length->GetAnimValueString(aValue);
|
2014-04-12 01:26:29 +04:00
|
|
|
} else {
|
2020-08-25 21:25:52 +03:00
|
|
|
length->GetBaseValueString(aValue);
|
2014-04-12 01:26:29 +04:00
|
|
|
}
|
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 (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
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
svg->GetAnimatedLength(mAttrEnum)->NewValueSpecifiedUnits(aUnit, aValue,
|
|
|
|
svg);
|
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
|
|
|
|
|
|
|
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()) {
|
2020-08-25 21:25:52 +03:00
|
|
|
SVGLength& internalItem = InternalItem();
|
|
|
|
if (internalItem == SVGLength(aValue, aUnit)) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeLengthListNotifier notifier(this);
|
2020-08-25 21:25:52 +03: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;
|
|
|
|
}
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
svg->GetAnimatedLength(mAttrEnum)->ConvertToSpecifiedUnits(aUnit, svg);
|
2014-04-12 01:26:29 +04:00
|
|
|
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
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
|
|
|
|
float val;
|
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
SVGLength& length = InternalItem();
|
|
|
|
if (length.GetUnit() == aUnit) {
|
2014-04-12 01:26:29 +04:00
|
|
|
return;
|
2012-02-16 03:40:45 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
val = length.GetValueInSpecifiedUnit(aUnit, lengthList->Element(),
|
|
|
|
lengthList->Axis());
|
|
|
|
} else {
|
|
|
|
val = SVGLength(mValue, mUnit).GetValueInSpecifiedUnit(aUnit, nullptr, 0);
|
|
|
|
}
|
|
|
|
if (IsFinite(val)) {
|
|
|
|
if (HasOwner()) {
|
2020-08-03 12:32:36 +03:00
|
|
|
AutoChangeLengthListNotifier notifier(this);
|
2013-12-25 02:09:22 +04:00
|
|
|
InternalItem().SetValueAndUnit(val, aUnit);
|
2020-08-25 21:25:52 +03:00
|
|
|
} else {
|
2013-12-25 02:09:22 +04:00
|
|
|
mValue = val;
|
2010-07-17 01:42:12 +04:00
|
|
|
mUnit = aUnit;
|
|
|
|
}
|
2020-08-25 21:25:52 +03: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");
|
|
|
|
|
2020-08-25 21:25:52 +03:00
|
|
|
mOwner = aList;
|
2010-07-17 01:42:12 +04:00
|
|
|
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();
|
2020-08-25 21:25:52 +03:00
|
|
|
mOwner = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimValItem = false;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGLength DOMSVGLength::ToSVGLength() {
|
2020-08-25 21:25:52 +03:00
|
|
|
if (nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner)) {
|
|
|
|
SVGAnimatedLength* length = svg->GetAnimatedLength(mAttrEnum);
|
|
|
|
return SVGLength(mIsAnimValItem ? length->GetAnimValInSpecifiedUnits()
|
|
|
|
: length->GetBaseValInSpecifiedUnits(),
|
|
|
|
length->GetSpecifiedUnitType());
|
|
|
|
}
|
|
|
|
return HasOwner() ? InternalItem() : SVGLength(mValue, mUnit);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DOMSVGLength::IsAnimating() const {
|
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
return lengthList->IsAnimating();
|
|
|
|
}
|
|
|
|
nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner);
|
|
|
|
return svg && svg->GetAnimatedLength(mAttrEnum)->IsAnimated();
|
|
|
|
}
|
|
|
|
|
|
|
|
SVGElement* DOMSVGLength::Element() {
|
|
|
|
if (nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner)) {
|
|
|
|
return lengthList->Element();
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
2020-08-25 21:25:52 +03:00
|
|
|
nsCOMPtr<SVGElement> svg = do_QueryInterface(mOwner);
|
|
|
|
return svg;
|
2010-07-17 01:42:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
SVGLength& DOMSVGLength::InternalItem() {
|
2020-08-25 21:25:52 +03:00
|
|
|
nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner);
|
|
|
|
SVGAnimatedLengthList* alist =
|
|
|
|
lengthList->Element()->GetAnimatedLengthList(mAttrEnum);
|
2010-07-17 01:42:12 +04:00
|
|
|
return mIsAnimValItem && alist->mAnimVal ? (*alist->mAnimVal)[mListIndex]
|
|
|
|
: alist->mBaseVal[mListIndex];
|
|
|
|
}
|
|
|
|
|
2010-12-03 19:40:23 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool DOMSVGLength::IndexIsValid() {
|
2020-08-25 21:25:52 +03:00
|
|
|
nsCOMPtr<DOMSVGLengthList> lengthList = do_QueryInterface(mOwner);
|
|
|
|
SVGAnimatedLengthList* alist =
|
|
|
|
lengthList->Element()->GetAnimatedLengthList(mAttrEnum);
|
2010-12-03 19:40:23 +03:00
|
|
|
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
|