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"
|
2019-05-31 17:33:33 +03:00
|
|
|
#include "mozilla/dom/BindContext.h"
|
2018-05-30 17:56:24 +03:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2019-01-01 12:16:21 +03:00
|
|
|
#include "mozilla/SMILAnimationController.h"
|
|
|
|
#include "mozilla/SMILAnimationFunction.h"
|
2019-01-02 10:21:13 +03:00
|
|
|
#include "mozilla/SMILTimeContainer.h"
|
2011-08-11 17:29:50 +04:00
|
|
|
#include "nsContentUtils.h"
|
2016-08-19 03:03:49 +03:00
|
|
|
#include "nsIContentInlines.h"
|
2019-07-16 14:43:56 +03:00
|
|
|
#include "nsIReferrerInfo.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
|
|
|
|
|
2018-09-21 23:45:49 +03:00
|
|
|
SVGAnimationElement::SVGAnimationElement(
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
|
|
|
: SVGAnimationElementBase(std::move(aNodeInfo)), mHrefTarget(this) {}
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
nsresult SVGAnimationElement::Init() {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
Element* SVGAnimationElement::GetTargetElementContent() {
|
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-07-17 20:09:15 +03:00
|
|
|
//
|
|
|
|
// Note that we want to use GetParentElement instead of the flattened tree to
|
|
|
|
// allow <use><animate>, for example.
|
|
|
|
return GetParentElement();
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
bool SVGAnimationElement::GetTargetAttributeName(int32_t* aNamespaceID,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom** aLocalName) const {
|
2018-08-07 22:07:26 +03:00
|
|
|
const nsAttrValue* nameAttr = mAttrs.GetAttr(nsGkAtoms::attributeName);
|
2009-01-15 07:38:07 +03:00
|
|
|
|
|
|
|
if (!nameAttr) return false;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-01-01 12:16:21 +03:00
|
|
|
SMILTimedElement& SVGAnimationElement::TimedElement() { return mTimedElement; }
|
2009-01-15 07:38:07 +03:00
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
SVGElement* SVGAnimationElement::GetTargetElement() {
|
2013-01-06 13:32:03 +04:00
|
|
|
FlushAnimations();
|
|
|
|
|
|
|
|
// We'll just call the other GetTargetElement method, and QI to the right type
|
|
|
|
nsIContent* target = GetTargetElementContent();
|
|
|
|
|
2018-12-21 11:58:14 +03:00
|
|
|
return (target && target->IsSVGElement()) ? static_cast<SVGElement*>(target)
|
2015-03-03 14:08:59 +03:00
|
|
|
: nullptr;
|
2013-01-06 13:32:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
float SVGAnimationElement::GetStartTime(ErrorResult& rv) {
|
2009-01-22 04:00:27 +03:00
|
|
|
FlushAnimations();
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILTimeValue 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
|
|
|
}
|
|
|
|
|
2018-12-21 08:37:58 +03:00
|
|
|
float SVGAnimationElement::GetCurrentTimeAsFloat() {
|
2009-01-22 04:00:27 +03:00
|
|
|
// Not necessary to call FlushAnimations() for this
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* root = GetTimeContainer();
|
2009-01-19 12:10:53 +03:00
|
|
|
if (root) {
|
2018-12-21 08:37:58 +03:00
|
|
|
return float(double(root->GetCurrentTimeAsSMILTime()) / 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-22 04:00:27 +03:00
|
|
|
// Not necessary to call FlushAnimations() for this
|
|
|
|
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILTimeValue 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
|
|
|
|
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
nsresult SVGAnimationElement::BindToTree(BindContext& aContext,
|
|
|
|
nsINode& aParent) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mHrefTarget.get(),
|
|
|
|
"Shouldn't have href-target yet (or it should've been cleared)");
|
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky
BindContext was going to have way more information at first, but then I realized
that most of the things I wanted to know were basically a flag away using the
parent node.
Still I think it's worth it, now experimenting with BindToTree will only mean
adding a field to a struct that's included from a couple cpp files, instead of a
massive pain.
I also think this is clearer, and doing this highlights quite a few
inconsistencies in our code which I've left untouched, but commented with
FIXMEs.
Steps are:
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done
$ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done
$ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done
$ ./mach clang-format
Then manual fixups.
Depends on D32948
Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
|
|
|
nsresult rv = SVGAnimationElementBase::BindToTree(aContext, aParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Add myself to the animation controller's master set of animation elements.
|
2019-06-01 17:40:33 +03:00
|
|
|
if (Document* doc = aContext.GetComposedDoc()) {
|
|
|
|
if (SMILAnimationController* controller = doc->GetAnimationController()) {
|
2009-01-15 07:38:07 +03:00
|
|
|
controller->RegisterAnimationElement(this);
|
|
|
|
}
|
2016-07-07 10:43:37 +03:00
|
|
|
const nsAttrValue* href =
|
|
|
|
HasAttr(kNameSpaceID_None, nsGkAtoms::href)
|
2018-08-07 22:07:26 +03:00
|
|
|
? mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_None)
|
|
|
|
: mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2009-07-16 08:20:16 +04:00
|
|
|
if (href) {
|
|
|
|
nsAutoString hrefStr;
|
|
|
|
href->ToString(hrefStr);
|
|
|
|
|
2018-07-24 03:03:49 +03:00
|
|
|
UpdateHrefTarget(hrefStr);
|
2009-07-16 08:20:16 +04:00
|
|
|
}
|
2010-01-12 23:00:49 +03:00
|
|
|
|
2018-08-28 12:06:08 +03:00
|
|
|
mTimedElement.BindToTree(*this);
|
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;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void SVGAnimationElement::UnbindFromTree(bool aNullParent) {
|
2018-12-28 14:47:58 +03:00
|
|
|
SMILAnimationController* controller = OwnerDoc()->GetAnimationController();
|
2011-10-18 15:19:44 +04:00
|
|
|
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();
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
SVGAnimationElementBase::UnbindFromTree(aNullParent);
|
2009-01-15 07:38:07 +03:00
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
bool 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 =
|
2018-08-28 12:06:08 +03:00
|
|
|
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(
|
2017-11-02 06:35:52 +03:00
|
|
|
aNamespaceID, aAttribute, aValue, aMaybeScriptedPrincipal, aResult);
|
2010-08-18 14:20:24 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsresult 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) {
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
nsresult rv = SVGAnimationElementBase::AfterSetAttr(
|
2017-10-10 00:33:38 +03:00
|
|
|
aNamespaceID, aName, aValue, 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
|
|
|
}
|
|
|
|
|
2018-07-24 13:55:53 +03:00
|
|
|
if (!IsInComposedDoc()) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
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 =
|
2018-08-07 22:07:26 +03:00
|
|
|
mAttrs.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink);
|
2016-07-07 10:43:37 +03:00
|
|
|
if (xlinkHref) {
|
2018-07-24 03:03:49 +03:00
|
|
|
UpdateHrefTarget(xlinkHref->GetStringValue());
|
2016-07-07 10:43:37 +03:00
|
|
|
}
|
|
|
|
} 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-24 13:55:53 +03:00
|
|
|
} else if (!(aNamespaceID == kNameSpaceID_XLink &&
|
2016-07-07 10:43:37 +03:00
|
|
|
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");
|
2018-07-24 03:03:49 +03:00
|
|
|
UpdateHrefTarget(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
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
bool SVGAnimationElement::IsNodeOfType(uint32_t aFlags) const {
|
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
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
void 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
|
2019-01-22 10:28:40 +03:00
|
|
|
SMILTimeValue seekTime = mTimedElement.GetHyperlinkTime();
|
2012-05-17 13:56:57 +04:00
|
|
|
if (seekTime.IsDefinite()) {
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* timeContainer = GetTimeContainer();
|
2012-05-17 13:56:57 +04:00
|
|
|
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
|
|
|
|
|
2019-01-02 10:21:13 +03:00
|
|
|
SMILTimeContainer* SVGAnimationElement::GetTimeContainer() {
|
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
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool SVGAnimationElement::IsEventAttributeNameInternal(nsAtom* aName) {
|
2010-07-31 11:02:52 +04:00
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_SMIL);
|
|
|
|
}
|
|
|
|
|
2018-07-24 03:03:49 +03:00
|
|
|
void SVGAnimationElement::UpdateHrefTarget(const nsAString& aHrefStr) {
|
2009-07-16 08:20:16 +04:00
|
|
|
nsCOMPtr<nsIURI> targetURI;
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), aHrefStr,
|
2019-07-15 21:29:05 +03:00
|
|
|
OwnerDoc(), GetBaseURI());
|
2019-07-16 14:43:56 +03:00
|
|
|
nsCOMPtr<nsIReferrerInfo> referrerInfo =
|
|
|
|
ReferrerInfo::CreateForSVGResources(OwnerDoc());
|
|
|
|
|
|
|
|
mHrefTarget.ResetToURIFragmentID(this, targetURI, referrerInfo);
|
2010-08-18 14:20:24 +04:00
|
|
|
AnimationTargetChanged();
|
|
|
|
}
|
|
|
|
|
2013-01-06 13:32:02 +04:00
|
|
|
void 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
|