2006-04-14 19:09:39 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
#include "nsSVGLength2.h"
|
2013-09-17 16:52:39 +04:00
|
|
|
#include "mozilla/dom/SVGAnimatedLength.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h" // NS_ENSURE_FINITE
|
2013-09-17 16:52:39 +04:00
|
|
|
#include "nsIFrame.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsSMILFloatType.h"
|
2013-09-17 16:52:39 +04:00
|
|
|
#include "nsSMILValue.h"
|
|
|
|
#include "nsSVGAttrTearoffTable.h"
|
|
|
|
#include "nsSVGIntegrationUtils.h"
|
|
|
|
#include "nsTextFormatter.h"
|
2014-04-12 01:26:29 +04:00
|
|
|
#include "DOMSVGLength.h"
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2013-01-10 03:02:45 +04:00
|
|
|
using namespace mozilla::dom;
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2007-10-03 13:02:19 +04:00
|
|
|
static nsIAtom** const unitMap[] =
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, /* SVG_LENGTHTYPE_UNKNOWN */
|
|
|
|
nullptr, /* SVG_LENGTHTYPE_NUMBER */
|
2007-10-03 13:02:19 +04:00
|
|
|
&nsGkAtoms::percentage,
|
|
|
|
&nsGkAtoms::em,
|
|
|
|
&nsGkAtoms::ex,
|
|
|
|
&nsGkAtoms::px,
|
|
|
|
&nsGkAtoms::cm,
|
|
|
|
&nsGkAtoms::mm,
|
|
|
|
&nsGkAtoms::in,
|
|
|
|
&nsGkAtoms::pt,
|
|
|
|
&nsGkAtoms::pc
|
|
|
|
};
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
static nsSVGAttrTearoffTable<nsSVGLength2, SVGAnimatedLength>
|
2009-08-27 08:30:51 +04:00
|
|
|
sSVGAnimatedLengthTearoffTable;
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
/* Helper functions */
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2012-08-22 19:56:38 +04:00
|
|
|
IsValidUnitType(uint16_t unit)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
|
|
|
if (unit > nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN &&
|
|
|
|
unit <= nsIDOMSVGLength::SVG_LENGTHTYPE_PC)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
GetUnitString(nsAString& unit, uint16_t unitType)
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
|
|
|
if (IsValidUnitType(unitType)) {
|
|
|
|
if (unitMap[unitType]) {
|
|
|
|
(*unitMap[unitType])->ToString(unit);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint16_t
|
2012-08-24 11:29:09 +04:00
|
|
|
GetUnitTypeForString(const nsAString& unitStr)
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
2012-08-24 11:29:09 +04:00
|
|
|
if (unitStr.IsEmpty())
|
2007-10-03 13:02:19 +04:00
|
|
|
return nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER;
|
|
|
|
|
2012-08-24 11:29:09 +04:00
|
|
|
nsIAtom *unitAtom = NS_GetStaticAtom(unitStr);
|
|
|
|
if (unitAtom) {
|
|
|
|
for (uint32_t i = 0 ; i < ArrayLength(unitMap) ; i++) {
|
|
|
|
if (unitMap[i] && *unitMap[i] == unitAtom) {
|
|
|
|
return i;
|
|
|
|
}
|
2007-10-03 13:02:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsIDOMSVGLength::SVG_LENGTHTYPE_UNKNOWN;
|
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2007-10-03 13:02:19 +04:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
GetValueString(nsAString &aValueAsString, float aValue, uint16_t aUnitType)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t buf[24];
|
|
|
|
nsTextFormatter::snprintf(buf, sizeof(buf)/sizeof(char16_t),
|
2013-12-13 05:50:01 +04:00
|
|
|
MOZ_UTF16("%g"),
|
2006-04-14 19:09:39 +04:00
|
|
|
(double)aValue);
|
|
|
|
aValueAsString.Assign(buf);
|
|
|
|
|
|
|
|
nsAutoString unitString;
|
2007-10-03 13:02:19 +04:00
|
|
|
GetUnitString(unitString, aUnitType);
|
2006-04-14 19:09:39 +04:00
|
|
|
aValueAsString.Append(unitString);
|
|
|
|
}
|
|
|
|
|
2013-10-01 11:50:40 +04:00
|
|
|
static bool
|
2013-10-29 21:15:39 +04:00
|
|
|
GetValueFromString(const nsAString& aString,
|
2013-10-01 11:50:40 +04:00
|
|
|
float& aValue,
|
|
|
|
uint16_t* aUnitType)
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
RangedPtr<const char16_t> iter =
|
2013-10-29 21:15:39 +04:00
|
|
|
SVGContentUtils::GetStartRangedPtr(aString);
|
2014-01-04 19:02:17 +04:00
|
|
|
const RangedPtr<const char16_t> end =
|
2013-10-29 21:15:39 +04:00
|
|
|
SVGContentUtils::GetEndRangedPtr(aString);
|
|
|
|
|
|
|
|
if (!SVGContentUtils::ParseNumber(iter, end, aValue)) {
|
2013-10-01 11:50:40 +04:00
|
|
|
return false;
|
2007-10-03 13:02:19 +04:00
|
|
|
}
|
2013-10-29 21:15:39 +04:00
|
|
|
const nsAString& units = Substring(iter.get(), end.get());
|
2013-10-01 11:50:40 +04:00
|
|
|
*aUnitType = GetUnitTypeForString(units);
|
|
|
|
return IsValidUnitType(*aUnitType);
|
2007-10-03 13:02:19 +04:00
|
|
|
}
|
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
static float GetMMPerPixel() { return MM_PER_INCH_FLOAT / 96; }
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
static float
|
|
|
|
FixAxisLength(float aLength)
|
|
|
|
{
|
|
|
|
if (aLength == 0.0f) {
|
|
|
|
NS_WARNING("zero axis length");
|
|
|
|
return 1e-20f;
|
|
|
|
}
|
|
|
|
return aLength;
|
|
|
|
}
|
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
SVGElementMetrics::SVGElementMetrics(nsSVGElement* aSVGElement,
|
|
|
|
SVGSVGElement* aCtx)
|
|
|
|
: mSVGElement(aSVGElement)
|
|
|
|
, mCtx(aCtx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
SVGElementMetrics::GetEmLength() const
|
|
|
|
{
|
|
|
|
return SVGContentUtils::GetFontSize(mSVGElement);
|
|
|
|
}
|
|
|
|
|
2007-03-09 19:27:01 +03:00
|
|
|
float
|
2014-09-15 14:12:50 +04:00
|
|
|
SVGElementMetrics::GetExLength() const
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-09-15 14:12:50 +04:00
|
|
|
return SVGContentUtils::GetFontXHeight(mSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
SVGElementMetrics::GetAxisLength(uint8_t aCtxType) const
|
|
|
|
{
|
|
|
|
if (!EnsureCtx()) {
|
2006-04-14 19:09:39 +04:00
|
|
|
return 1;
|
2014-09-15 14:12:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return FixAxisLength(mCtx->GetLength(aCtxType));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SVGElementMetrics::EnsureCtx() const
|
|
|
|
{
|
|
|
|
if (!mCtx && mSVGElement) {
|
|
|
|
mCtx = mSVGElement->GetCtx();
|
|
|
|
}
|
|
|
|
return mCtx != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
NonSVGFrameUserSpaceMetrics::NonSVGFrameUserSpaceMetrics(nsIFrame* aFrame)
|
|
|
|
: mFrame(aFrame)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
NonSVGFrameUserSpaceMetrics::GetEmLength() const
|
|
|
|
{
|
|
|
|
return SVGContentUtils::GetFontSize(mFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
NonSVGFrameUserSpaceMetrics::GetExLength() const
|
|
|
|
{
|
|
|
|
return SVGContentUtils::GetFontXHeight(mFrame);
|
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
gfx::Size
|
|
|
|
NonSVGFrameUserSpaceMetrics::GetSize() const
|
|
|
|
{
|
|
|
|
return nsSVGIntegrationUtils::GetSVGCoordContextForNonSVGFrame(mFrame);
|
2008-09-11 04:24:16 +04:00
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
float
|
2014-09-15 14:12:50 +04:00
|
|
|
UserSpaceMetricsWithSize::GetAxisLength(uint8_t aCtxType) const
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
2014-09-15 14:12:50 +04:00
|
|
|
gfx::Size size = GetSize();
|
2008-09-11 04:24:16 +04:00
|
|
|
float length;
|
2014-09-15 14:12:50 +04:00
|
|
|
switch (aCtxType) {
|
2012-09-22 23:26:05 +04:00
|
|
|
case SVGContentUtils::X:
|
|
|
|
length = size.width;
|
|
|
|
break;
|
|
|
|
case SVGContentUtils::Y:
|
|
|
|
length = size.height;
|
|
|
|
break;
|
|
|
|
case SVGContentUtils::XY:
|
|
|
|
length = SVGContentUtils::ComputeNormalizedHypotenuse(size.width, size.height);
|
2008-09-11 04:24:16 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown axis type");
|
|
|
|
length = 1;
|
|
|
|
break;
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
return FixAxisLength(length);
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2009-01-22 04:00:27 +03:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(nsSVGElement *aSVGElement,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aUnitType) const
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-09-15 14:12:50 +04:00
|
|
|
return GetUnitScaleFactor(SVGElementMetrics(aSVGElement), aUnitType);
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
2013-01-10 03:02:45 +04:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(SVGSVGElement *aCtx, uint8_t aUnitType) const
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-09-15 14:12:50 +04:00
|
|
|
return GetUnitScaleFactor(SVGElementMetrics(aCtx, aCtx), aUnitType);
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
2008-09-11 04:24:16 +04:00
|
|
|
float
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLength2::GetUnitScaleFactor(nsIFrame *aFrame, uint8_t aUnitType) const
|
2008-09-11 04:24:16 +04:00
|
|
|
{
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsSVGElement()) {
|
2014-09-15 14:12:50 +04:00
|
|
|
return GetUnitScaleFactor(SVGElementMetrics(static_cast<nsSVGElement*>(content)), aUnitType);
|
|
|
|
}
|
|
|
|
return GetUnitScaleFactor(NonSVGFrameUserSpaceMetrics(aFrame), aUnitType);
|
|
|
|
}
|
2008-09-11 04:24:16 +04:00
|
|
|
|
2014-09-15 14:12:50 +04:00
|
|
|
float
|
|
|
|
nsSVGLength2::GetUnitScaleFactor(const UserSpaceMetrics& aMetrics, uint8_t aUnitType) const
|
|
|
|
{
|
2009-01-22 04:00:27 +03:00
|
|
|
switch (aUnitType) {
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_NUMBER:
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PX:
|
|
|
|
return 1;
|
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_MM:
|
2010-08-13 13:58:04 +04:00
|
|
|
return GetMMPerPixel();
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_CM:
|
2010-08-13 13:58:04 +04:00
|
|
|
return GetMMPerPixel() / 10.0f;
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_IN:
|
2010-08-13 13:58:04 +04:00
|
|
|
return GetMMPerPixel() / MM_PER_INCH_FLOAT;
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PT:
|
2010-08-13 13:58:04 +04:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT;
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PC:
|
2010-08-13 13:58:04 +04:00
|
|
|
return GetMMPerPixel() * POINTS_PER_INCH_FLOAT / MM_PER_INCH_FLOAT / 12.0f;
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE:
|
2014-09-15 14:12:50 +04:00
|
|
|
return 100.0f / aMetrics.GetAxisLength(mCtxType);
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EMS:
|
2014-09-15 14:12:50 +04:00
|
|
|
return 1 / aMetrics.GetEmLength();
|
2008-09-11 04:24:16 +04:00
|
|
|
case nsIDOMSVGLength::SVG_LENGTHTYPE_EXS:
|
2014-09-15 14:12:50 +04:00
|
|
|
return 1 / aMetrics.GetExLength();
|
2008-09-11 04:24:16 +04:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unknown unit type");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
void
|
|
|
|
nsSVGLength2::SetBaseValueInSpecifiedUnits(float aValue,
|
2012-02-16 03:40:45 +04:00
|
|
|
nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2012-02-16 03:40:45 +04:00
|
|
|
if (mIsBaseSet && mBaseVal == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
}
|
2010-02-11 22:41:48 +03:00
|
|
|
mBaseVal = aValue;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBaseSet = true;
|
2010-02-11 22:41:48 +03:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-22 04:00:27 +03:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-16 03:40:45 +04:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
2010-01-20 22:58:58 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLength2::ConvertToSpecifiedUnits(uint16_t unitType,
|
2006-04-14 19:09:39 +04:00
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
if (!IsValidUnitType(unitType))
|
2010-01-20 22:58:58 +03:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
if (mIsBaseSet && mSpecifiedUnitType == uint8_t(unitType))
|
2012-02-16 03:40:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Even though we're not changing the visual effect this length will have
|
|
|
|
// on the document, we still need to send out notifications in case we have
|
|
|
|
// mutation listeners, since the actual string value of the attribute will
|
|
|
|
// change.
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
|
|
|
|
float valueInUserUnits =
|
2009-01-22 04:00:27 +03:00
|
|
|
mBaseVal / GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType);
|
2012-08-22 19:56:38 +04:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2012-02-16 03:40:45 +04:00
|
|
|
// Setting aDoSetAttr to false here will ensure we don't call
|
|
|
|
// Will/DidChangeAngle a second time (and dispatch duplicate notifications).
|
|
|
|
SetBaseValue(valueInUserUnits, aSVGElement, false);
|
|
|
|
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
2010-01-20 22:58:58 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
2010-01-20 22:58:58 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsSVGLength2::NewValueSpecifiedUnits(uint16_t unitType,
|
2006-04-14 19:09:39 +04:00
|
|
|
float valueInSpecifiedUnits,
|
|
|
|
nsSVGElement *aSVGElement)
|
|
|
|
{
|
2010-01-20 22:58:58 +03:00
|
|
|
NS_ENSURE_FINITE(valueInSpecifiedUnits, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
2006-04-14 19:09:39 +04:00
|
|
|
if (!IsValidUnitType(unitType))
|
2010-01-20 22:58:58 +03:00
|
|
|
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2012-02-16 03:40:45 +04:00
|
|
|
if (mIsBaseSet && mBaseVal == valueInSpecifiedUnits &&
|
2012-08-22 19:56:38 +04:00
|
|
|
mSpecifiedUnitType == uint8_t(unitType)) {
|
2012-02-16 03:40:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
2010-02-11 22:41:48 +03:00
|
|
|
mBaseVal = valueInSpecifiedUnits;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBaseSet = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2010-02-11 22:41:48 +03:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-22 04:00:27 +03:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
2012-02-16 03:40:45 +04:00
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
2010-01-20 22:58:58 +03:00
|
|
|
return NS_OK;
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-04-12 01:26:29 +04:00
|
|
|
nsSVGLength2::ToDOMBaseVal(DOMSVGLength **aResult, nsSVGElement *aSVGElement)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-04-12 01:26:29 +04:00
|
|
|
nsRefPtr<DOMSVGLength> domBaseVal =
|
|
|
|
DOMSVGLength::GetTearOff(this, aSVGElement, false);
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2012-08-23 10:24:43 +04:00
|
|
|
domBaseVal.forget(aResult);
|
2006-04-14 19:09:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-04-12 01:26:29 +04:00
|
|
|
nsSVGLength2::ToDOMAnimVal(DOMSVGLength **aResult, nsSVGElement *aSVGElement)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2014-04-12 01:26:29 +04:00
|
|
|
nsRefPtr<DOMSVGLength> domAnimVal =
|
|
|
|
DOMSVGLength::GetTearOff(this, aSVGElement, true);
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2012-08-23 10:24:43 +04:00
|
|
|
domAnimVal.forget(aResult);
|
2006-04-14 19:09:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-03 13:02:19 +04:00
|
|
|
/* Implementation */
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SetBaseValueString(const nsAString &aValueAsString,
|
|
|
|
nsSVGElement *aSVGElement,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aDoSetAttr)
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
|
|
|
float value;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t unitType;
|
2012-02-16 03:40:45 +04:00
|
|
|
|
2013-10-01 11:50:40 +04:00
|
|
|
if (!GetValueFromString(aValueAsString, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2007-10-15 16:06:42 +04:00
|
|
|
}
|
2012-02-16 03:40:45 +04:00
|
|
|
|
2013-10-01 11:50:40 +04:00
|
|
|
if (mIsBaseSet && mBaseVal == float(value) &&
|
2012-08-22 19:56:38 +04:00
|
|
|
mSpecifiedUnitType == uint8_t(unitType)) {
|
2012-02-16 03:40:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAttrValue emptyOrOldValue;
|
|
|
|
if (aDoSetAttr) {
|
|
|
|
emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum);
|
|
|
|
}
|
2010-02-11 22:41:48 +03:00
|
|
|
mBaseVal = value;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBaseSet = true;
|
2012-08-22 19:56:38 +04:00
|
|
|
mSpecifiedUnitType = uint8_t(unitType);
|
2010-02-11 22:41:48 +03:00
|
|
|
if (!mIsAnimated) {
|
|
|
|
mAnimVal = mBaseVal;
|
|
|
|
}
|
|
|
|
else {
|
2009-01-22 04:00:27 +03:00
|
|
|
aSVGElement->AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
|
2012-02-16 03:40:45 +04:00
|
|
|
if (aDoSetAttr) {
|
|
|
|
aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue);
|
|
|
|
}
|
2007-10-03 13:02:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 03:40:45 +04:00
|
|
|
nsSVGLength2::GetBaseValueString(nsAString & aValueAsString) const
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
|
|
|
GetValueString(aValueAsString, mBaseVal, mSpecifiedUnitType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 03:40:45 +04:00
|
|
|
nsSVGLength2::GetAnimValueString(nsAString & aValueAsString) const
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
|
|
|
GetValueString(aValueAsString, mAnimVal, mSpecifiedUnitType);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-16 03:40:45 +04:00
|
|
|
nsSVGLength2::SetBaseValue(float aValue, nsSVGElement *aSVGElement,
|
|
|
|
bool aDoSetAttr)
|
2007-10-03 13:02:19 +04:00
|
|
|
{
|
2011-03-31 23:29:44 +04:00
|
|
|
SetBaseValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
|
|
|
|
mSpecifiedUnitType),
|
2012-02-16 03:40:45 +04:00
|
|
|
aSVGElement, aDoSetAttr);
|
2007-10-03 13:02:19 +04:00
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
void
|
2011-03-31 23:29:44 +04:00
|
|
|
nsSVGLength2::SetAnimValueInSpecifiedUnits(float aValue,
|
|
|
|
nsSVGElement* aSVGElement)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2012-06-02 03:52:15 +04:00
|
|
|
if (mAnimVal == aValue && mIsAnimated) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-31 23:29:44 +04:00
|
|
|
mAnimVal = aValue;
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsAnimated = true;
|
2009-01-15 07:38:07 +03:00
|
|
|
aSVGElement->DidAnimateLength(mAttrEnum);
|
|
|
|
}
|
|
|
|
|
2011-03-31 23:29:44 +04:00
|
|
|
void
|
|
|
|
nsSVGLength2::SetAnimValue(float aValue, nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
SetAnimValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
|
|
|
|
mSpecifiedUnitType),
|
|
|
|
aSVGElement);
|
|
|
|
}
|
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
already_AddRefed<SVGAnimatedLength>
|
2013-01-06 13:32:02 +04:00
|
|
|
nsSVGLength2::ToDOMAnimatedLength(nsSVGElement* aSVGElement)
|
2006-04-14 19:09:39 +04:00
|
|
|
{
|
2013-01-20 00:56:00 +04:00
|
|
|
nsRefPtr<SVGAnimatedLength> svgAnimatedLength =
|
2012-08-23 10:24:43 +04:00
|
|
|
sSVGAnimatedLengthTearoffTable.GetTearoff(this);
|
2013-01-20 00:56:00 +04:00
|
|
|
if (!svgAnimatedLength) {
|
|
|
|
svgAnimatedLength = new SVGAnimatedLength(this, aSVGElement);
|
|
|
|
sSVGAnimatedLengthTearoffTable.AddTearoff(this, svgAnimatedLength);
|
2009-08-27 08:30:51 +04:00
|
|
|
}
|
2006-04-14 19:09:39 +04:00
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
return svgAnimatedLength.forget();
|
2006-04-14 19:09:39 +04:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-20 00:56:00 +04:00
|
|
|
SVGAnimatedLength::~SVGAnimatedLength()
|
2009-08-27 08:30:51 +04:00
|
|
|
{
|
|
|
|
sSVGAnimatedLengthTearoffTable.RemoveTearoff(mVal);
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
nsISMILAttr*
|
|
|
|
nsSVGLength2::ToSMILAttr(nsSVGElement *aSVGElement)
|
|
|
|
{
|
|
|
|
return new SMILLength(this, aSVGElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SMILLength::ValueFromString(const nsAString& aStr,
|
2013-03-19 07:18:45 +04:00
|
|
|
const SVGAnimationElement* /*aSrcElement*/,
|
2010-02-21 00:13:11 +03:00
|
|
|
nsSMILValue& aValue,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aPreventCachingOfSandwich) const
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2009-01-22 04:00:27 +03:00
|
|
|
float value;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t unitType;
|
2009-01-22 04:00:27 +03:00
|
|
|
|
2013-10-01 11:50:40 +04:00
|
|
|
if (!GetValueFromString(aStr, value, &unitType)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2009-01-22 04:00:27 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-05-31 02:34:53 +04:00
|
|
|
nsSMILValue val(nsSMILFloatType::Singleton());
|
2009-01-22 04:00:27 +03:00
|
|
|
val.mU.mDouble = value / mVal->GetUnitScaleFactor(mSVGElement, unitType);
|
2009-01-15 07:38:07 +03:00
|
|
|
aValue = val;
|
2010-06-24 04:30:55 +04:00
|
|
|
aPreventCachingOfSandwich =
|
|
|
|
(unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE ||
|
|
|
|
unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_EMS ||
|
|
|
|
unitType == nsIDOMSVGLength::SVG_LENGTHTYPE_EXS);
|
2010-02-21 00:13:11 +03:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILValue
|
|
|
|
nsSVGLength2::SMILLength::GetBaseValue() const
|
|
|
|
{
|
2013-05-31 02:34:53 +04:00
|
|
|
nsSMILValue val(nsSMILFloatType::Singleton());
|
2009-01-15 07:38:07 +03:00
|
|
|
val.mU.mDouble = mVal->GetBaseValue(mSVGElement);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-07-14 23:33:29 +04:00
|
|
|
void
|
|
|
|
nsSVGLength2::SMILLength::ClearAnimValue()
|
|
|
|
{
|
|
|
|
if (mVal->mIsAnimated) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mVal->mIsAnimated = false;
|
2012-03-03 13:21:09 +04:00
|
|
|
mVal->mAnimVal = mVal->mBaseVal;
|
|
|
|
mSVGElement->DidAnimateLength(mVal->mAttrEnum);
|
2009-07-14 23:33:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
nsresult
|
|
|
|
nsSVGLength2::SMILLength::SetAnimValue(const nsSMILValue& aValue)
|
|
|
|
{
|
2013-05-31 02:34:53 +04:00
|
|
|
NS_ASSERTION(aValue.mType == nsSMILFloatType::Singleton(),
|
2009-01-15 07:38:07 +03:00
|
|
|
"Unexpected type to assign animated value");
|
2013-05-31 02:34:53 +04:00
|
|
|
if (aValue.mType == nsSMILFloatType::Singleton()) {
|
2009-01-22 04:00:27 +03:00
|
|
|
mVal->SetAnimValue(float(aValue.mU.mDouble), mSVGElement);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|