Bug 1936278 - Prevent search mode chiclet from being dismissed when clicking in page...
[gecko.git] / dom / svg / SVGAnimationElement.h
blobd2bf0149523c1066765ac2c3ae75b6cdc68e4364
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 bool IsDisabled();
69 // WebIDL
70 SVGElement* GetTargetElement();
71 float GetStartTime(ErrorResult& rv);
72 float GetCurrentTimeAsFloat();
73 float GetSimpleDuration(ErrorResult& rv);
74 void BeginElement(ErrorResult& rv) { BeginElementAt(0.f, rv); }
75 void BeginElementAt(float offset, ErrorResult& rv);
76 void EndElement(ErrorResult& rv) { EndElementAt(0.f, rv); }
77 void EndElementAt(float offset, ErrorResult& rv);
79 // Manually implement onbegin/onrepeat/onend IDL property getters/setters.
80 // We don't autogenerate these methods because the property name differs
81 // from the event type atom - the event type atom has an extra 'Event' tacked
82 // on at the end. (i.e. 'onbegin' corresponds to an event whose name is
83 // literally 'beginEvent' rather than 'begin')
85 EventHandlerNonNull* GetOnbegin() {
86 return GetEventHandler(nsGkAtoms::onbeginEvent);
88 void SetOnbegin(EventHandlerNonNull* handler) {
89 EventTarget::SetEventHandler(nsGkAtoms::onbeginEvent, handler);
92 EventHandlerNonNull* GetOnrepeat() {
93 return GetEventHandler(nsGkAtoms::onrepeatEvent);
95 void SetOnrepeat(EventHandlerNonNull* handler) {
96 EventTarget::SetEventHandler(nsGkAtoms::onrepeatEvent, handler);
99 EventHandlerNonNull* GetOnend() {
100 return GetEventHandler(nsGkAtoms::onendEvent);
102 void SetOnend(EventHandlerNonNull* handler) {
103 EventTarget::SetEventHandler(nsGkAtoms::onendEvent, handler);
106 // SVGTests
107 SVGElement* AsSVGElement() final { return this; }
109 protected:
110 // SVGElement overrides
112 void UpdateHrefTarget(const nsAString& aHrefStr);
113 void AnimationTargetChanged();
116 * Helper that provides a reference to the element with the ID that is
117 * referenced by the animation element's 'href' attribute, if any, and that
118 * will notify the animation element if the element that that ID identifies
119 * changes to a different element (or none). (If the 'href' attribute is not
120 * specified, then the animation target is the parent element and this helper
121 * is not used.)
123 class HrefTargetTracker final : public IDTracker {
124 public:
125 explicit HrefTargetTracker(SVGAnimationElement* aAnimationElement)
126 : mAnimationElement(aAnimationElement) {}
128 protected:
129 // We need to be notified when target changes, in order to request a
130 // sample (which will clear animation effects from old target and apply
131 // them to the new target) and update any event registrations.
132 void ElementChanged(Element* aFrom, Element* aTo) override {
133 IDTracker::ElementChanged(aFrom, aTo);
134 mAnimationElement->AnimationTargetChanged();
137 // We need to override IsPersistent to get persistent tracking (beyond the
138 // first time the target changes)
139 bool IsPersistent() override { return true; }
141 private:
142 SVGAnimationElement* const mAnimationElement;
145 HrefTargetTracker mHrefTarget;
146 mozilla::SMILTimedElement mTimedElement;
149 } // namespace mozilla::dom
151 #endif // DOM_SVG_SVGANIMATIONELEMENT_H_