Bug 1889091 - Part 6: Remove "scratch" register parameter from emitPushArguments...
[gecko.git] / dom / svg / SVGAnimationElement.h
blob02602172a80f7d6fe022ccf123f80cae456dd640
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_SVG_SVGANIMATIONELEMENT_H_
8 #define DOM_SVG_SVGANIMATIONELEMENT_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SMILTimedElement.h"
12 #include "mozilla/dom/IDTracker.h"
13 #include "mozilla/dom/SVGElement.h"
14 #include "mozilla/dom/SVGTests.h"
16 namespace mozilla::dom {
18 using SVGAnimationElementBase = SVGElement;
20 class SVGAnimationElement : public SVGAnimationElementBase, public SVGTests {
21 protected:
22 explicit SVGAnimationElement(
23 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
24 nsresult Init();
25 virtual ~SVGAnimationElement() = default;
27 public:
28 // interfaces:
29 NS_DECL_ISUPPORTS_INHERITED
31 NS_IMPL_FROMNODE_HELPER(SVGAnimationElement, IsSVGAnimationElement())
33 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGAnimationElement,
34 SVGAnimationElementBase)
36 bool IsSVGAnimationElement() const final { return true; }
37 bool PassesConditionalProcessingTests() const final {
38 return SVGTests::PassesConditionalProcessingTests();
40 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override = 0;
42 // nsIContent specializations
43 nsresult BindToTree(BindContext&, nsINode& aParent) override;
44 void UnbindFromTree(UnbindContext&) override;
46 // Element specializations
47 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
48 const nsAString& aValue,
49 nsIPrincipal* aMaybeScriptedPrincipal,
50 nsAttrValue& aResult) override;
51 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
52 const nsAttrValue* aValue, const nsAttrValue* aOldValue,
53 nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
55 Element* GetTargetElementContent();
56 virtual bool GetTargetAttributeName(int32_t* aNamespaceID,
57 nsAtom** aLocalName) const;
58 mozilla::SMILTimedElement& TimedElement();
59 mozilla::SMILTimeContainer* GetTimeContainer();
60 virtual SMILAnimationFunction& AnimationFunction() = 0;
62 bool IsEventAttributeNameInternal(nsAtom* aName) override;
64 // Utility methods for within SVG
65 void ActivateByHyperlink();
67 // WebIDL
68 SVGElement* GetTargetElement();
69 float GetStartTime(ErrorResult& rv);
70 float GetCurrentTimeAsFloat();
71 float GetSimpleDuration(ErrorResult& rv);
72 void BeginElement(ErrorResult& rv) { BeginElementAt(0.f, rv); }
73 void BeginElementAt(float offset, ErrorResult& rv);
74 void EndElement(ErrorResult& rv) { EndElementAt(0.f, rv); }
75 void EndElementAt(float offset, ErrorResult& rv);
77 // Manually implement onbegin/onrepeat/onend IDL property getters/setters.
78 // We don't autogenerate these methods because the property name differs
79 // from the event type atom - the event type atom has an extra 'Event' tacked
80 // on at the end. (i.e. 'onbegin' corresponds to an event whose name is
81 // literally 'beginEvent' rather than 'begin')
83 EventHandlerNonNull* GetOnbegin() {
84 return GetEventHandler(nsGkAtoms::onbeginEvent);
86 void SetOnbegin(EventHandlerNonNull* handler) {
87 EventTarget::SetEventHandler(nsGkAtoms::onbeginEvent, handler);
90 EventHandlerNonNull* GetOnrepeat() {
91 return GetEventHandler(nsGkAtoms::onrepeatEvent);
93 void SetOnrepeat(EventHandlerNonNull* handler) {
94 EventTarget::SetEventHandler(nsGkAtoms::onrepeatEvent, handler);
97 EventHandlerNonNull* GetOnend() {
98 return GetEventHandler(nsGkAtoms::onendEvent);
100 void SetOnend(EventHandlerNonNull* handler) {
101 EventTarget::SetEventHandler(nsGkAtoms::onendEvent, handler);
104 // SVGTests
105 SVGElement* AsSVGElement() final { return this; }
107 protected:
108 // SVGElement overrides
110 void UpdateHrefTarget(const nsAString& aHrefStr);
111 void AnimationTargetChanged();
114 * Helper that provides a reference to the element with the ID that is
115 * referenced by the animation element's 'href' attribute, if any, and that
116 * will notify the animation element if the element that that ID identifies
117 * changes to a different element (or none). (If the 'href' attribute is not
118 * specified, then the animation target is the parent element and this helper
119 * is not used.)
121 class HrefTargetTracker final : public IDTracker {
122 public:
123 explicit HrefTargetTracker(SVGAnimationElement* aAnimationElement)
124 : mAnimationElement(aAnimationElement) {}
126 protected:
127 // We need to be notified when target changes, in order to request a
128 // sample (which will clear animation effects from old target and apply
129 // them to the new target) and update any event registrations.
130 void ElementChanged(Element* aFrom, Element* aTo) override {
131 IDTracker::ElementChanged(aFrom, aTo);
132 mAnimationElement->AnimationTargetChanged();
135 // We need to override IsPersistent to get persistent tracking (beyond the
136 // first time the target changes)
137 bool IsPersistent() override { return true; }
139 private:
140 SVGAnimationElement* const mAnimationElement;
143 HrefTargetTracker mHrefTarget;
144 mozilla::SMILTimedElement mTimedElement;
147 } // namespace mozilla::dom
149 #endif // DOM_SVG_SVGANIMATIONELEMENT_H_