Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/SVGUseElement.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_SVGUseElement_h
8
#define mozilla_dom_SVGUseElement_h
9
10
#include "mozilla/dom/FromParser.h"
11
#include "mozilla/dom/IDTracker.h"
12
#include "nsStubMutationObserver.h"
13
#include "mozilla/dom/SVGGraphicsElement.h"
14
#include "nsSVGLength2.h"
15
#include "nsSVGString.h"
16
#include "nsTArray.h"
17
18
class nsIContent;
19
class nsSVGUseFrame;
20
21
nsresult
22
NS_NewSVGSVGElement(nsIContent **aResult,
23
                    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
24
                    mozilla::dom::FromParser aFromParser);
25
nsresult NS_NewSVGUseElement(nsIContent **aResult,
26
                             already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
27
28
namespace mozilla {
29
struct URLExtraData;
30
31
namespace dom {
32
33
typedef SVGGraphicsElement SVGUseElementBase;
34
35
class SVGUseElement final : public SVGUseElementBase,
36
                            public nsStubMutationObserver
37
{
38
  friend class ::nsSVGUseFrame;
39
protected:
40
  friend nsresult (::NS_NewSVGUseElement(nsIContent **aResult,
41
                                         already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo));
42
  explicit SVGUseElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
43
  virtual ~SVGUseElement();
44
  virtual JSObject* WrapNode(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
45
46
public:
47
  NS_IMPL_FROMNODE_WITH_TAG(SVGUseElement, kNameSpaceID_SVG, use)
48
49
  nsresult BindToTree(nsIDocument* aDocument,
50
                      nsIContent* aParent,
51
                      nsIContent* aBindingParent) override;
52
  void UnbindFromTree(bool aDeep = true,
53
                      bool aNullParent = true) override;
54
55
  // interfaces:
56
  NS_DECL_ISUPPORTS_INHERITED
57
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGUseElement, SVGUseElementBase)
58
59
  NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
60
  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
61
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
62
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
63
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
64
  NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
65
66
  // nsSVGElement specializations:
67
  virtual gfxMatrix PrependLocalTransformsTo(
68
    const gfxMatrix &aMatrix,
69
    SVGTransformTypes aWhich = eAllTransforms) const override;
70
  virtual bool HasValidDimensions() const override;
71
72
  // nsIContent interface
73
  virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
74
  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
75
76
  // WebIDL
77
  already_AddRefed<SVGAnimatedString> Href();
78
  already_AddRefed<SVGAnimatedLength> X();
79
  already_AddRefed<SVGAnimatedLength> Y();
80
  already_AddRefed<SVGAnimatedLength> Width();
81
  already_AddRefed<SVGAnimatedLength> Height();
82
83
  nsIURI* GetSourceDocURI();
84
0
  URLExtraData* GetContentURLData() const { return mContentURLData; }
85
86
  // Updates the internal shadow tree to be an up-to-date clone of the
87
  // referenced element.
88
  void UpdateShadowTree();
89
90
protected:
91
  /**
92
   * Helper that provides a reference to the element with the ID that is
93
   * referenced by the 'use' element's 'href' attribute, and that will update
94
   * the 'use' element if the element that that ID identifies changes to a
95
   * different element (or none).
96
   */
97
  class ElementTracker final : public IDTracker {
98
  public:
99
    explicit ElementTracker(SVGUseElement* aOwningUseElement)
100
      : mOwningUseElement(aOwningUseElement)
101
0
    {}
102
103
  private:
104
105
    void ElementChanged(Element* aFrom, Element* aTo) override
106
0
    {
107
0
      IDTracker::ElementChanged(aFrom, aTo);
108
0
      if (aFrom) {
109
0
        aFrom->RemoveMutationObserver(mOwningUseElement);
110
0
      }
111
0
      mOwningUseElement->TriggerReclone();
112
0
    }
113
114
    SVGUseElement* mOwningUseElement;
115
  };
116
117
  nsSVGUseFrame* GetFrame() const;
118
119
  virtual LengthAttributesInfo GetLengthInfo() override;
120
  virtual StringAttributesInfo GetStringInfo() override;
121
122
  /**
123
   * Returns true if our width and height should be used, or false if they
124
   * should be ignored. As per the spec, this depends on the type of the
125
   * element that we're referencing.
126
   */
127
  bool OurWidthAndHeightAreUsed() const;
128
  void SyncWidthOrHeight(nsAtom *aName);
129
  void LookupHref();
130
  void TriggerReclone();
131
  void UnlinkSource();
132
133
  enum { ATTR_X, ATTR_Y, ATTR_WIDTH, ATTR_HEIGHT };
134
  nsSVGLength2 mLengthAttributes[4];
135
  static LengthInfo sLengthInfo[4];
136
137
  enum { HREF, XLINK_HREF };
138
  nsSVGString mStringAttributes[2];
139
  static StringInfo sStringInfo[2];
140
141
  nsCOMPtr<nsIContent> mOriginal; // if we've been cloned, our "real" copy
142
  ElementTracker mReferencedElementTracker;
143
  RefPtr<URLExtraData> mContentURLData; // URL data for its anonymous content
144
};
145
146
} // namespace dom
147
} // namespace mozilla
148
149
#endif // mozilla_dom_SVGUseElement_h