Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/SVGMPathElement.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_SVGMPathElement_h
8
#define mozilla_dom_SVGMPathElement_h
9
10
#include "mozilla/dom/IDTracker.h"
11
#include "nsSVGElement.h"
12
#include "nsStubMutationObserver.h"
13
#include "nsSVGString.h"
14
15
nsresult NS_NewSVGMPathElement(nsIContent **aResult,
16
                               already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
17
18
typedef nsSVGElement SVGMPathElementBase;
19
20
namespace mozilla {
21
namespace dom {
22
class SVGPathElement;
23
24
class SVGMPathElement final : public SVGMPathElementBase,
25
                              public nsStubMutationObserver
26
{
27
protected:
28
  friend nsresult (::NS_NewSVGMPathElement(nsIContent **aResult,
29
                                           already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
30
  explicit SVGMPathElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
31
  ~SVGMPathElement();
32
33
  virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
34
35
public:
36
  // interfaces:
37
  NS_DECL_ISUPPORTS_INHERITED
38
39
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGMPathElement,
40
                                           SVGMPathElementBase)
41
42
  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
43
44
  // nsIContent interface
45
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
46
  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
47
                              nsIContent* aBindingParent) override;
48
  virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
49
50
  // Element specializations
51
  virtual bool ParseAttribute(int32_t aNamespaceID,
52
                                nsAtom* aAttribute,
53
                                const nsAString& aValue,
54
                                nsIPrincipal* aMaybeScriptedPrincipal,
55
                                nsAttrValue& aResult) override;
56
  virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
57
                                const nsAttrValue* aValue,
58
                                const nsAttrValue* aOldValue,
59
                                nsIPrincipal* aMaybeScriptedPrincipal,
60
                                bool aNotify) override;
61
62
  // Public helper method: If our xlink:href attribute links to a <path>
63
  // element, this method returns a pointer to that element. Otherwise,
64
  // this returns nullptr.
65
  SVGPathElement* GetReferencedPath();
66
67
  // WebIDL
68
  already_AddRefed<SVGAnimatedString> Href();
69
70
protected:
71
  /**
72
   * Helper that provides a reference to the 'path' element with the ID that is
73
   * referenced by the 'mpath' element's 'href' attribute, and that will
74
   * invalidate the parent of the 'mpath' and update mutation observers to the
75
   * new path element if the element that that ID identifies changes to a
76
   * different element (or none).
77
   */
78
  class PathElementTracker final : public IDTracker {
79
  public:
80
    explicit PathElementTracker(SVGMPathElement* aMpathElement)
81
      : mMpathElement(aMpathElement)
82
0
    {}
83
  protected:
84
    // We need to be notified when target changes, in order to request a sample
85
    // (which will clear animation effects that used the old target-path
86
    // and recompute the animation effects using the new target-path).
87
0
    virtual void ElementChanged(Element* aFrom, Element* aTo) override {
88
0
      IDTracker::ElementChanged(aFrom, aTo);
89
0
      if (aFrom) {
90
0
        aFrom->RemoveMutationObserver(mMpathElement);
91
0
      }
92
0
      if (aTo) {
93
0
        aTo->AddMutationObserver(mMpathElement);
94
0
      }
95
0
      mMpathElement->NotifyParentOfMpathChange(mMpathElement->GetParent());
96
0
    }
97
98
    // We need to override IsPersistent to get persistent tracking (beyond the
99
    // first time the target changes)
100
0
    virtual bool IsPersistent() override { return true; }
101
  private:
102
    SVGMPathElement* const mMpathElement;
103
  };
104
105
  virtual StringAttributesInfo GetStringInfo() override;
106
107
  void UpdateHrefTarget(nsIContent* aParent, const nsAString& aHrefStr);
108
  void UnlinkHrefTarget(bool aNotifyParent);
109
  void NotifyParentOfMpathChange(nsIContent* aParent);
110
111
  enum { HREF, XLINK_HREF };
112
  nsSVGString        mStringAttributes[2];
113
  static StringInfo  sStringInfo[2];
114
  PathElementTracker mPathTracker;
115
};
116
117
} // namespace dom
118
} // namespace mozilla
119
120
#endif // mozilla_dom_SVGMPathElement_h