Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/SVGAnimationElement.h
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#ifndef mozilla_dom_SVGAnimationElement_h
8
#define mozilla_dom_SVGAnimationElement_h
9
10
#include "mozilla/Attributes.h"
11
#include "mozilla/dom/IDTracker.h"
12
#include "mozilla/dom/SVGTests.h"
13
#include "nsSMILTimedElement.h"
14
#include "nsSVGElement.h"
15
16
typedef nsSVGElement SVGAnimationElementBase;
17
18
namespace mozilla {
19
namespace dom {
20
21
enum nsSMILTargetAttrType {
22
  eSMILTargetAttrType_auto,
23
  eSMILTargetAttrType_CSS,
24
  eSMILTargetAttrType_XML
25
};
26
27
class SVGAnimationElement : public SVGAnimationElementBase,
28
                            public SVGTests
29
{
30
protected:
31
  explicit SVGAnimationElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
32
  nsresult Init();
33
  virtual ~SVGAnimationElement();
34
35
public:
36
  // interfaces:
37
  NS_DECL_ISUPPORTS_INHERITED
38
39
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGAnimationElement,
40
                                           SVGAnimationElementBase)
41
42
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override = 0;
43
44
  // nsIContent specializations
45
  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
46
                              nsIContent* aBindingParent) override;
47
  virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
48
49
  virtual bool IsNodeOfType(uint32_t aFlags) const override;
50
51
  // Element specializations
52
  virtual bool ParseAttribute(int32_t aNamespaceID,
53
                                nsAtom* aAttribute,
54
                                const nsAString& aValue,
55
                                nsIPrincipal* aMaybeScriptedPrincipal,
56
                                nsAttrValue& aResult) override;
57
  virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
58
                                const nsAttrValue* aValue,
59
                                const nsAttrValue* aOldValue,
60
                                nsIPrincipal* aSubjectPrincipal,
61
                                bool aNotify) override;
62
63
  Element* GetTargetElementContent();
64
  virtual bool GetTargetAttributeName(int32_t* aNamespaceID,
65
                                      nsAtom** aLocalName) const;
66
  nsSMILTimedElement& TimedElement();
67
  nsSMILTimeContainer* GetTimeContainer();
68
  virtual nsSMILAnimationFunction& AnimationFunction() = 0;
69
70
  virtual bool IsEventAttributeNameInternal(nsAtom* aName) override;
71
72
  // Utility methods for within SVG
73
  void ActivateByHyperlink();
74
75
  // WebIDL
76
  nsSVGElement* GetTargetElement();
77
  float GetStartTime(ErrorResult& rv);
78
  float GetCurrentTime();
79
  float GetSimpleDuration(ErrorResult& rv);
80
0
  void BeginElement(ErrorResult& rv) { BeginElementAt(0.f, rv); }
81
  void BeginElementAt(float offset, ErrorResult& rv);
82
0
  void EndElement(ErrorResult& rv) { EndElementAt(0.f, rv); }
83
  void EndElementAt(float offset, ErrorResult& rv);
84
85
  // SVGTests
86
0
  nsSVGElement* AsSVGElement() final { return this; }
87
88
 protected:
89
  // nsSVGElement overrides
90
91
  void UpdateHrefTarget(const nsAString& aHrefStr);
92
  void AnimationTargetChanged();
93
94
  /**
95
   * Helper that provides a reference to the element with the ID that is
96
   * referenced by the animation element's 'href' attribute, if any, and that
97
   * will notify the animation element if the element that that ID identifies
98
   * changes to a different element (or none).  (If the 'href' attribute is not
99
   * specified, then the animation target is the parent element and this helper
100
   * is not used.)
101
   */
102
  class HrefTargetTracker final : public IDTracker {
103
  public:
104
    explicit HrefTargetTracker(SVGAnimationElement* aAnimationElement)
105
      : mAnimationElement(aAnimationElement)
106
0
    {}
107
  protected:
108
    // We need to be notified when target changes, in order to request a
109
    // sample (which will clear animation effects from old target and apply
110
    // them to the new target) and update any event registrations.
111
0
    virtual void ElementChanged(Element* aFrom, Element* aTo) override {
112
0
      IDTracker::ElementChanged(aFrom, aTo);
113
0
      mAnimationElement->AnimationTargetChanged();
114
0
    }
115
116
    // We need to override IsPersistent to get persistent tracking (beyond the
117
    // first time the target changes)
118
0
    virtual bool IsPersistent() override { return true; }
119
  private:
120
    SVGAnimationElement* const mAnimationElement;
121
  };
122
123
  HrefTargetTracker    mHrefTarget;
124
  nsSMILTimedElement   mTimedElement;
125
};
126
127
} // namespace dom
128
} // namespace mozilla
129
130
#endif // mozilla_dom_SVGAnimationElement_h