Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGCircleElement.cpp
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
#include "mozilla/dom/SVGCircleElement.h"
8
#include "mozilla/gfx/2D.h"
9
#include "nsGkAtoms.h"
10
#include "mozilla/dom/SVGCircleElementBinding.h"
11
#include "mozilla/dom/SVGLengthBinding.h"
12
13
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Circle)
14
15
using namespace mozilla::gfx;
16
17
namespace mozilla {
18
namespace dom {
19
20
JSObject*
21
SVGCircleElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
22
0
{
23
0
  return SVGCircleElement_Binding::Wrap(aCx, this, aGivenProto);
24
0
}
25
26
nsSVGElement::LengthInfo SVGCircleElement::sLengthInfo[3] =
27
{
28
  { &nsGkAtoms::cx, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::X },
29
  { &nsGkAtoms::cy, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::Y },
30
  { &nsGkAtoms::r, 0, SVGLength_Binding::SVG_LENGTHTYPE_NUMBER, SVGContentUtils::XY }
31
};
32
33
//----------------------------------------------------------------------
34
// Implementation
35
36
SVGCircleElement::SVGCircleElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
37
  : SVGCircleElementBase(std::move(aNodeInfo))
38
0
{
39
0
}
40
41
//----------------------------------------------------------------------
42
// nsINode methods
43
44
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGCircleElement)
45
46
//----------------------------------------------------------------------
47
48
already_AddRefed<SVGAnimatedLength>
49
SVGCircleElement::Cx()
50
0
{
51
0
  return mLengthAttributes[ATTR_CX].ToDOMAnimatedLength(this);
52
0
}
53
54
already_AddRefed<SVGAnimatedLength>
55
SVGCircleElement::Cy()
56
0
{
57
0
  return mLengthAttributes[ATTR_CY].ToDOMAnimatedLength(this);
58
0
}
59
60
already_AddRefed<SVGAnimatedLength>
61
SVGCircleElement::R()
62
0
{
63
0
  return mLengthAttributes[ATTR_R].ToDOMAnimatedLength(this);
64
0
}
65
66
//----------------------------------------------------------------------
67
// nsSVGElement methods
68
69
/* virtual */ bool
70
SVGCircleElement::HasValidDimensions() const
71
0
{
72
0
  return mLengthAttributes[ATTR_R].IsExplicitlySet() &&
73
0
         mLengthAttributes[ATTR_R].GetAnimValInSpecifiedUnits() > 0;
74
0
}
75
76
nsSVGElement::LengthAttributesInfo
77
SVGCircleElement::GetLengthInfo()
78
0
{
79
0
  return LengthAttributesInfo(mLengthAttributes, sLengthInfo,
80
0
                              ArrayLength(sLengthInfo));
81
0
}
82
83
//----------------------------------------------------------------------
84
// SVGGeometryElement methods
85
86
bool
87
SVGCircleElement::GetGeometryBounds(Rect* aBounds,
88
                                    const StrokeOptions& aStrokeOptions,
89
                                    const Matrix& aToBoundsSpace,
90
                                    const Matrix* aToNonScalingStrokeSpace)
91
0
{
92
0
  float x, y, r;
93
0
  GetAnimatedLengthValues(&x, &y, &r, nullptr);
94
0
95
0
  if (r <= 0.f) {
96
0
    // Rendering of the element is disabled
97
0
    *aBounds = Rect(aToBoundsSpace.TransformPoint(Point(x, y)), Size());
98
0
    return true;
99
0
  }
100
0
101
0
  if (aToBoundsSpace.IsRectilinear()) {
102
0
    // Optimize the case where we can treat the circle as a rectangle and
103
0
    // still get tight bounds.
104
0
    if (aStrokeOptions.mLineWidth > 0.f) {
105
0
      if (aToNonScalingStrokeSpace) {
106
0
        if (aToNonScalingStrokeSpace->IsRectilinear()) {
107
0
          MOZ_ASSERT(!aToNonScalingStrokeSpace->IsSingular());
108
0
          Rect userBounds(x - r, y - r, 2 * r, 2 * r);
109
0
          SVGContentUtils::RectilinearGetStrokeBounds(
110
0
            userBounds, aToBoundsSpace, *aToNonScalingStrokeSpace,
111
0
            aStrokeOptions.mLineWidth, aBounds);
112
0
          return true;
113
0
        }
114
0
        return false;
115
0
      }
116
0
      r += aStrokeOptions.mLineWidth / 2.f;
117
0
    }
118
0
    Rect rect(x - r, y - r, 2 * r, 2 * r);
119
0
    *aBounds = aToBoundsSpace.TransformBounds(rect);
120
0
    return true;
121
0
  }
122
0
123
0
  return false;
124
0
}
125
126
already_AddRefed<Path>
127
SVGCircleElement::BuildPath(PathBuilder* aBuilder)
128
0
{
129
0
  float x, y, r;
130
0
  GetAnimatedLengthValues(&x, &y, &r, nullptr);
131
0
132
0
  if (r <= 0.0f) {
133
0
    return nullptr;
134
0
  }
135
0
136
0
  aBuilder->Arc(Point(x, y), r, 0, Float(2*M_PI));
137
0
138
0
  return aBuilder->Finish();
139
0
}
140
141
} // namespace dom
142
} // namespace mozilla