Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/DOMSVGPoint.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_DOMSVGPOINT_H__
8
#define MOZILLA_DOMSVGPOINT_H__
9
10
#include "DOMSVGPointList.h"
11
#include "mozilla/gfx/2D.h"
12
#include "nsDebug.h"
13
#include "nsISVGPoint.h"
14
#include "SVGPoint.h"
15
#include "mozilla/Attributes.h"
16
#include "mozilla/FloatingPoint.h"
17
18
class nsSVGElement;
19
20
namespace mozilla {
21
22
namespace dom {
23
class SVGMatrix;
24
} // namespace dom
25
26
/**
27
 * Class DOMSVGPoint
28
 *
29
 * This class creates the DOM objects that wrap internal SVGPoint objects that
30
 * are in an SVGPointList. It is also used to create the objects returned by
31
 * SVGSVGElement.createSVGPoint() and other functions that return DOM SVGPoint
32
 * objects.
33
 *
34
 * See the architecture comment in DOMSVGPointList.h for an overview of the
35
 * important points regarding these DOM wrapper structures.
36
 *
37
 * See the architecture comment in DOMSVGLength.h (yes, LENGTH) for an overview
38
 * of the important points regarding how this specific class works.
39
 */
40
class DOMSVGPoint final : public nsISVGPoint
41
{
42
  friend class AutoChangePointNotifier;
43
44
  typedef mozilla::gfx::Point Point;
45
46
public:
47
  /**
48
   * Generic ctor for DOMSVGPoint objects that are created for an attribute.
49
   */
50
  DOMSVGPoint(DOMSVGPointList *aList,
51
              uint32_t aListIndex,
52
              bool aIsAnimValItem)
53
    : nsISVGPoint()
54
0
  {
55
0
    mList = aList;
56
0
    mListIndex = aListIndex;
57
0
    mIsAnimValItem = aIsAnimValItem;
58
0
59
0
    // These shifts are in sync with the members.
60
0
    MOZ_ASSERT(aList && aListIndex <= MaxListIndex(), "bad arg");
61
0
62
0
    MOZ_ASSERT(IndexIsValid(), "Bad index for DOMSVGPoint!");
63
0
  }
64
65
  explicit DOMSVGPoint(const DOMSVGPoint *aPt = nullptr)
66
    : nsISVGPoint()
67
0
  {
68
0
    if (aPt) {
69
0
      mPt = aPt->ToSVGPoint();
70
0
    }
71
0
  }
72
73
  DOMSVGPoint(float aX, float aY)
74
    : nsISVGPoint()
75
0
  {
76
0
    mPt.mX = aX;
77
0
    mPt.mY = aY;
78
0
  }
79
80
  explicit DOMSVGPoint(const Point& aPt)
81
    : nsISVGPoint()
82
0
  {
83
0
    mPt.mX = aPt.x;
84
0
    mPt.mY = aPt.y;
85
0
    NS_ASSERTION(IsFinite(mPt.mX) && IsFinite(mPt.mY),
86
0
                 "DOMSVGPoint coords are not finite");
87
0
  }
88
89
90
  // WebIDL
91
  virtual float X() override;
92
  virtual void SetX(float aX, ErrorResult& rv) override;
93
  virtual float Y() override;
94
  virtual void SetY(float aY, ErrorResult& rv) override;
95
  virtual already_AddRefed<nsISVGPoint> MatrixTransform(dom::SVGMatrix& matrix) override;
96
0
  nsISupports* GetParentObject() override {
97
0
    return mList;
98
0
  }
99
100
0
  virtual DOMSVGPoint* Copy() override {
101
0
    return new DOMSVGPoint(this);
102
0
  }
103
104
protected:
105
106
0
  nsSVGElement* Element() {
107
0
    return mList->Element();
108
0
  }
109
};
110
111
} // namespace mozilla
112
113
#endif // MOZILLA_DOMSVGPOINT_H__