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/. */
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
#include "mozilla/dom/SVGAnimationElement.h"
|
2013-01-10 03:02:45 +04:00
|
|
|
#include "mozilla/dom/SVGSVGElement.h"
|
2018-05-30 17:56:24 +03:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
#include "nsSMILTimeContainer.h"
|
|
|
|
#include "nsSMILAnimationController.h"
|
|
|
|
#include "nsSMILAnimationFunction.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2016-08-19 03:03:49 +03:00
|
|
|
#include "nsIContentInlines.h"
|
2013-08-24 06:42:40 +04:00
|
|
|
#include "nsIURI.h"
|
2013-07-03 19:56:26 +04:00
|
|
|
#include "prtime.h"
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2010-05-14 21:04:51 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports methods
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(SVGAnimationElement, SVGAnimationElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(SVGAnimationElement, SVGAnimationElementBase)
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAnimationElement)
|
2013-03-02 10:08:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::SVGTests)
|
2013-01-06 13:32:02 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(SVGAnimationElementBase)
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2014-09-10 14:18:58 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGAnimationElement,
|
|
|
|
SVGAnimationElementBase,
|
|
|
|
mHrefTarget, mTimedElement)
|
2009-07-16 08:20:16 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation
|
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
SVGAnimationElement::SVGAnimationElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2013-01-06 13:32:02 +04:00
|
|
|
: SVGAnimationElementBase(aNodeInfo),
|
2015-01-07 08:39:46 +03:00
|
|
|
mHrefTarget(this)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-07-09 01:23:16 +04:00
|
|
|
SVGAnimationElement::~SVGAnimationElement()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
nsresult
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::Init()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2013-01-06 13:32:02 +04:00
|
|
|
nsresult rv = SVGAnimationElementBase::Init();
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
mTimedElement.SetAnimationElement(this);
|
2009-01-15 07:38:07 +03:00
|
|
|
AnimationFunction().SetAnimationElement(this);
|
|
|
|
mTimedElement.SetTimeClient(&AnimationFunction());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2010-05-14 21:04:51 +04:00
|
|
|
Element*
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::GetTargetElementContent()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2016-07-07 10:43:37 +03:00
|
|
|
if (HasAttr(kNameSpaceID_XLink, nsGkAtoms::href) ||
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
2009-07-16 08:20:16 +04:00
|
|
|
return mHrefTarget.get();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
2016-07-07 10:43:37 +03:00
|
|
|
"We shouldn't have a href target "
|
|
|
|
"if we don't have an xlink:href or href attribute");
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2016-07-07 10:43:37 +03:00
|
|
|
// No "href" or "xlink:href" attribute --> I should target my parent.
|
2018-05-30 17:56:24 +03:00
|
|
|
return GetFlattenedTreeParentElement();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::GetTargetAttributeName(int32_t *aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom **aLocalName) const
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
const nsAttrValue* nameAttr
|
|
|
|
= mAttrsAndChildren.GetAttr(nsGkAtoms::attributeName);
|
|
|
|
|
|
|
|
if (!nameAttr)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(nameAttr->Type() == nsAttrValue::eAtom,
|
|
|
|
"attributeName should have been parsed as an atom");
|
2010-10-07 23:19:32 +04:00
|
|
|
|
|
|
|
return NS_SUCCEEDED(nsContentUtils::SplitQName(
|
|
|
|
this, nsDependentAtomString(nameAttr->GetAtomValue()),
|
|
|
|
aNamespaceID, aLocalName));
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsSMILTimedElement&
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::TimedElement()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
return mTimedElement;
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
nsSVGElement*
|
|
|
|
SVGAnimationElement::GetTargetElement()
|
|
|
|
{
|
|
|
|
FlushAnimations();
|
|
|
|
|
|
|
|
// We'll just call the other GetTargetElement method, and QI to the right type
|
|
|
|
nsIContent* target = GetTargetElementContent();
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
return (target && target->IsSVGElement())
|
|
|
|
? static_cast<nsSVGElement*>(target) : nullptr;
|
2013-01-06 13:32:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
SVGAnimationElement::GetStartTime(ErrorResult& rv)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2009-01-22 04:00:27 +03:00
|
|
|
FlushAnimations();
|
|
|
|
|
2009-01-19 12:10:53 +03:00
|
|
|
nsSMILTimeValue startTime = mTimedElement.GetStartTime();
|
2013-01-06 13:32:03 +04:00
|
|
|
if (!startTime.IsDefinite()) {
|
|
|
|
rv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
return 0.f;
|
|
|
|
}
|
2009-01-19 12:10:53 +03:00
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
return float(double(startTime.GetMillis()) / PR_MSEC_PER_SEC);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
float
|
|
|
|
SVGAnimationElement::GetCurrentTime()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2009-01-22 04:00:27 +03:00
|
|
|
// Not necessary to call FlushAnimations() for this
|
|
|
|
|
2009-01-19 12:10:53 +03:00
|
|
|
nsSMILTimeContainer* root = GetTimeContainer();
|
|
|
|
if (root) {
|
2013-01-06 13:32:03 +04:00
|
|
|
return float(double(root->GetCurrentTime()) / PR_MSEC_PER_SEC);
|
2009-01-19 12:10:53 +03:00
|
|
|
}
|
2013-01-06 13:32:03 +04:00
|
|
|
|
|
|
|
return 0.0f;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
float
|
|
|
|
SVGAnimationElement::GetSimpleDuration(ErrorResult& rv)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2009-01-22 04:00:27 +03:00
|
|
|
// Not necessary to call FlushAnimations() for this
|
|
|
|
|
2009-01-19 12:10:53 +03:00
|
|
|
nsSMILTimeValue simpleDur = mTimedElement.GetSimpleDuration();
|
2011-09-07 04:20:40 +04:00
|
|
|
if (!simpleDur.IsDefinite()) {
|
2013-01-06 13:32:03 +04:00
|
|
|
rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return 0.f;
|
2009-01-19 12:10:53 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
return float(double(simpleDur.GetMillis()) / PR_MSEC_PER_SEC);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIContent methods
|
|
|
|
|
|
|
|
nsresult
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
|
|
|
"Shouldn't have href-target yet (or it should've been cleared)");
|
2013-01-06 13:32:02 +04:00
|
|
|
nsresult rv = SVGAnimationElementBase::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2011-02-26 13:21:11 +03:00
|
|
|
// XXXdholbert is GetCtx (as a check for SVG parent) still needed here?
|
|
|
|
if (!GetCtx()) {
|
2009-01-15 07:38:07 +03:00
|
|
|
// No use proceeding. We don't have an SVG parent (yet) so we won't be able
|
|
|
|
// to register ourselves etc. Maybe next time we'll have more luck.
|
|
|
|
// (This sort of situation will arise a lot when trees are being constructed
|
|
|
|
// piece by piece via script)
|
|
|
|
return NS_OK;
|
2011-02-26 13:21:11 +03:00
|
|
|
}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
// Add myself to the animation controller's master set of animation elements.
|
2018-07-17 20:04:58 +03:00
|
|
|
if (nsIDocument* doc = GetComposedDoc()) {
|
|
|
|
nsSMILAnimationController* controller = doc->GetAnimationController();
|
2009-01-15 07:38:07 +03:00
|
|
|
if (controller) {
|
|
|
|
controller->RegisterAnimationElement(this);
|
|
|
|
}
|
2016-07-07 10:43:37 +03:00
|
|
|
const nsAttrValue* href =
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::href)
|
|
|
|
? mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_None)
|
|
|
|
: mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2009-07-16 08:20:16 +04:00
|
|
|
if (href) {
|
|
|
|
nsAutoString hrefStr;
|
|
|
|
href->ToString(hrefStr);
|
|
|
|
|
|
|
|
// Pass in |aParent| instead of |this| -- first argument is only used
|
2014-10-03 16:32:26 +04:00
|
|
|
// for a call to GetComposedDoc(), and |this| might not have a current
|
2009-07-16 08:20:16 +04:00
|
|
|
// document yet.
|
|
|
|
UpdateHrefTarget(aParent, hrefStr);
|
|
|
|
}
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
mTimedElement.BindToTree(aParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2009-01-22 04:00:27 +03:00
|
|
|
AnimationNeedsResample();
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2011-10-18 15:19:44 +04:00
|
|
|
nsSMILAnimationController *controller = OwnerDoc()->GetAnimationController();
|
|
|
|
if (controller) {
|
|
|
|
controller->UnregisterAnimationElement(this);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2009-07-16 08:20:16 +04:00
|
|
|
mHrefTarget.Unlink();
|
2010-01-12 23:00:49 +03:00
|
|
|
mTimedElement.DissolveReferences();
|
2009-07-16 08:20:16 +04:00
|
|
|
|
2009-01-22 04:00:27 +03:00
|
|
|
AnimationNeedsResample();
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElementBase::UnbindFromTree(aDeep, aNullParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::ParseAttribute(int32_t aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aAttribute,
|
2013-01-06 13:32:02 +04:00
|
|
|
const nsAString& aValue,
|
2017-11-02 06:35:52 +03:00
|
|
|
nsIPrincipal* aMaybeScriptedPrincipal,
|
2013-01-06 13:32:02 +04:00
|
|
|
nsAttrValue& aResult)
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
// Deal with target-related attributes here
|
2017-03-30 07:10:06 +03:00
|
|
|
if (aAttribute == nsGkAtoms::attributeName) {
|
2009-01-15 07:38:07 +03:00
|
|
|
aResult.ParseAtom(aValue);
|
2009-01-22 04:00:27 +03:00
|
|
|
AnimationNeedsResample();
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// First let the animation function try to parse it...
|
2011-09-29 10:19:26 +04:00
|
|
|
bool foundMatch =
|
2009-01-15 07:38:07 +03:00
|
|
|
AnimationFunction().SetAttr(aAttribute, aValue, aResult, &rv);
|
|
|
|
|
|
|
|
// ... and if that didn't recognize the attribute, let the timed element
|
|
|
|
// try to parse it.
|
|
|
|
if (!foundMatch) {
|
2010-01-12 23:00:49 +03:00
|
|
|
foundMatch =
|
|
|
|
mTimedElement.SetAttr(aAttribute, aValue, aResult, this, &rv);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2009-07-15 22:33:31 +04:00
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
if (foundMatch) {
|
2009-01-22 04:00:27 +03:00
|
|
|
AnimationNeedsResample();
|
2009-01-15 07:38:07 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-18 14:53:36 +04:00
|
|
|
ReportAttributeParseFailure(OwnerDoc(), aAttribute, aValue);
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
return SVGAnimationElementBase::ParseAttribute(aNamespaceID, aAttribute,
|
2017-11-02 06:35:52 +03:00
|
|
|
aValue,
|
|
|
|
aMaybeScriptedPrincipal,
|
|
|
|
aResult);
|
2010-08-18 14:20:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGAnimationElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify)
|
2010-08-18 14:20:24 +04:00
|
|
|
{
|
2018-01-04 05:03:27 +03:00
|
|
|
if (!aValue && aNamespaceID == kNameSpaceID_None) {
|
|
|
|
// Attribute is being removed.
|
|
|
|
if (AnimationFunction().UnsetAttr(aName) ||
|
|
|
|
mTimedElement.UnsetAttr(aName)) {
|
|
|
|
AnimationNeedsResample();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 14:20:24 +04:00
|
|
|
nsresult rv =
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElementBase::AfterSetAttr(aNamespaceID, aName, aValue,
|
2017-10-10 00:33:38 +03:00
|
|
|
aOldValue, aSubjectPrincipal, aNotify);
|
2010-08-18 14:20:24 +04:00
|
|
|
|
2014-05-28 09:15:30 +04:00
|
|
|
if (SVGTests::IsConditionalProcessingAttribute(aName)) {
|
|
|
|
bool isDisabled = !SVGTests::PassesConditionalProcessingTests();
|
|
|
|
if (mTimedElement.SetIsDisabled(isDisabled)) {
|
|
|
|
AnimationNeedsResample();
|
|
|
|
}
|
2014-05-28 09:14:02 +04:00
|
|
|
}
|
|
|
|
|
2016-07-07 10:43:37 +03:00
|
|
|
if (!((aNamespaceID == kNameSpaceID_None ||
|
|
|
|
aNamespaceID == kNameSpaceID_XLink) &&
|
|
|
|
aName == nsGkAtoms::href)) {
|
2010-08-18 14:20:24 +04:00
|
|
|
return rv;
|
2016-07-07 10:43:37 +03:00
|
|
|
}
|
2010-08-18 14:20:24 +04:00
|
|
|
|
|
|
|
if (!aValue) {
|
2016-07-07 10:43:37 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
mHrefTarget.Unlink();
|
|
|
|
AnimationTargetChanged();
|
|
|
|
|
|
|
|
// After unsetting href, we may still have xlink:href, so we
|
|
|
|
// should try to add it back.
|
|
|
|
const nsAttrValue* xlinkHref =
|
|
|
|
mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
|
|
|
if (xlinkHref) {
|
|
|
|
UpdateHrefTarget(this, xlinkHref->GetStringValue());
|
|
|
|
}
|
|
|
|
} else if (!HasAttr(kNameSpaceID_None, nsGkAtoms::href)) {
|
|
|
|
mHrefTarget.Unlink();
|
|
|
|
AnimationTargetChanged();
|
|
|
|
} // else: we unset xlink:href, but we still have href attribute, so keep
|
|
|
|
// mHrefTarget linking to href.
|
2018-07-17 20:04:58 +03:00
|
|
|
} else if (IsInComposedDoc() &&
|
2016-07-07 10:43:37 +03:00
|
|
|
!(aNamespaceID == kNameSpaceID_XLink &&
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::href))) {
|
|
|
|
// Note: "href" takes priority over xlink:href. So if "xlink:href" is being
|
|
|
|
// set here, we only let that update our target if "href" is *unset*.
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue->Type() == nsAttrValue::eString,
|
|
|
|
"Expected href attribute to be string type");
|
2012-02-14 06:00:56 +04:00
|
|
|
UpdateHrefTarget(this, aValue->GetStringValue());
|
2010-08-18 14:20:24 +04:00
|
|
|
} // else: we're not yet in a document -- we'll update the target on
|
|
|
|
// next BindToTree call.
|
|
|
|
|
|
|
|
return rv;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::IsNodeOfType(uint32_t aFlags) const
|
2010-03-19 14:17:49 +03:00
|
|
|
{
|
2017-10-25 18:19:11 +03:00
|
|
|
return !(aFlags & ~eANIMATION);
|
2010-03-19 14:17:49 +03:00
|
|
|
}
|
|
|
|
|
2012-05-17 13:56:57 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// SVG utility methods
|
|
|
|
|
|
|
|
void
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::ActivateByHyperlink()
|
2012-05-17 13:56:57 +04:00
|
|
|
{
|
|
|
|
FlushAnimations();
|
|
|
|
|
|
|
|
// The behavior for when the target is an animation element is defined in
|
|
|
|
// SMIL Animation:
|
|
|
|
// http://www.w3.org/TR/smil-animation/#HyperlinkSemantics
|
|
|
|
nsSMILTimeValue seekTime = mTimedElement.GetHyperlinkTime();
|
|
|
|
if (seekTime.IsDefinite()) {
|
|
|
|
nsSMILTimeContainer* timeContainer = GetTimeContainer();
|
|
|
|
if (timeContainer) {
|
|
|
|
timeContainer->SetCurrentTime(seekTime.GetMillis());
|
|
|
|
AnimationNeedsResample();
|
2013-01-10 03:02:45 +04:00
|
|
|
// As with SVGSVGElement::SetCurrentTime, we need to trigger
|
2012-05-17 13:56:57 +04:00
|
|
|
// a synchronous sample now.
|
|
|
|
FlushAnimations();
|
|
|
|
}
|
|
|
|
// else, silently fail. We mustn't be part of an SVG document fragment that
|
|
|
|
// is attached to the document tree so there's nothing we can do here
|
|
|
|
} else {
|
2018-02-01 22:21:14 +03:00
|
|
|
BeginElement(IgnoreErrors());
|
2012-05-17 13:56:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-15 07:38:07 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation helpers
|
|
|
|
|
|
|
|
nsSMILTimeContainer*
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::GetTimeContainer()
|
2009-01-15 07:38:07 +03:00
|
|
|
{
|
2013-01-10 03:02:45 +04:00
|
|
|
SVGSVGElement *element = SVGContentUtils::GetOuterSVGElement(this);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2011-02-26 13:21:11 +03:00
|
|
|
if (element) {
|
|
|
|
return element->GetTimedDocumentRoot();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
void
|
|
|
|
SVGAnimationElement::BeginElementAt(float offset, ErrorResult& rv)
|
|
|
|
{
|
2010-12-23 08:48:31 +03:00
|
|
|
// Make sure the timegraph is up-to-date
|
|
|
|
FlushAnimations();
|
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
// This will fail if we're not attached to a time container (SVG document
|
|
|
|
// fragment).
|
2013-01-06 13:32:03 +04:00
|
|
|
rv = mTimedElement.BeginElementAt(offset);
|
|
|
|
if (rv.Failed())
|
|
|
|
return;
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2009-01-22 04:00:27 +03:00
|
|
|
AnimationNeedsResample();
|
2010-12-23 08:48:31 +03:00
|
|
|
// Force synchronous sample so that events resulting from this call arrive in
|
|
|
|
// the expected order and we get an up-to-date paint.
|
|
|
|
FlushAnimations();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
void
|
|
|
|
SVGAnimationElement::EndElementAt(float offset, ErrorResult& rv)
|
|
|
|
{
|
2010-12-23 08:48:31 +03:00
|
|
|
// Make sure the timegraph is up-to-date
|
|
|
|
FlushAnimations();
|
|
|
|
|
2013-01-06 13:32:03 +04:00
|
|
|
rv = mTimedElement.EndElementAt(offset);
|
|
|
|
if (rv.Failed())
|
|
|
|
return;
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2010-01-12 23:00:49 +03:00
|
|
|
AnimationNeedsResample();
|
2010-12-23 08:48:31 +03:00
|
|
|
// Force synchronous sample
|
|
|
|
FlushAnimations();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
2009-07-16 08:20:16 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
SVGAnimationElement::IsEventAttributeNameInternal(nsAtom* aName)
|
2010-07-31 11:02:52 +04:00
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_SMIL);
|
|
|
|
}
|
|
|
|
|
2009-07-16 08:20:16 +04:00
|
|
|
void
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::UpdateHrefTarget(nsIContent* aNodeForContext,
|
|
|
|
const nsAString& aHrefStr)
|
2009-07-16 08:20:16 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI),
|
2011-10-18 14:53:36 +04:00
|
|
|
aHrefStr, OwnerDoc(), baseURI);
|
2009-07-16 08:20:16 +04:00
|
|
|
mHrefTarget.Reset(aNodeForContext, targetURI);
|
2010-08-18 14:20:24 +04:00
|
|
|
AnimationTargetChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-06 13:32:02 +04:00
|
|
|
SVGAnimationElement::AnimationTargetChanged()
|
2010-08-18 14:20:24 +04:00
|
|
|
{
|
|
|
|
mTimedElement.HandleTargetElementChange(GetTargetElementContent());
|
|
|
|
AnimationNeedsResample();
|
2009-07-16 08:20:16 +04:00
|
|
|
}
|
2013-01-06 13:32:02 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|