Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/svg/SVGPolygonElement.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/SVGPolygonElement.h"
8
#include "mozilla/dom/SVGPolygonElementBinding.h"
9
#include "mozilla/gfx/2D.h"
10
#include "SVGContentUtils.h"
11
12
using namespace mozilla;
13
using namespace mozilla::gfx;
14
15
NS_IMPL_NS_NEW_NAMESPACED_SVG_ELEMENT(Polygon)
16
17
namespace mozilla {
18
namespace dom {
19
20
JSObject*
21
SVGPolygonElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
22
0
{
23
0
  return SVGPolygonElement_Binding::Wrap(aCx, this, aGivenProto);
24
0
}
25
26
//----------------------------------------------------------------------
27
// Implementation
28
29
SVGPolygonElement::SVGPolygonElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
30
  : SVGPolygonElementBase(std::move(aNodeInfo))
31
0
{
32
0
}
33
34
//----------------------------------------------------------------------
35
// nsINode methods
36
37
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolygonElement)
38
39
//----------------------------------------------------------------------
40
// SVGGeometryElement methods
41
42
void
43
SVGPolygonElement::GetMarkPoints(nsTArray<nsSVGMark> *aMarks)
44
0
{
45
0
  SVGPolyElement::GetMarkPoints(aMarks);
46
0
47
0
  if (aMarks->IsEmpty() || aMarks->LastElement().type != nsSVGMark::eEnd) {
48
0
    return;
49
0
  }
50
0
51
0
  nsSVGMark *endMark = &aMarks->LastElement();
52
0
  nsSVGMark *startMark = &aMarks->ElementAt(0);
53
0
  float angle = atan2(startMark->y - endMark->y, startMark->x - endMark->x);
54
0
55
0
  endMark->type = nsSVGMark::eMid;
56
0
  endMark->angle = SVGContentUtils::AngleBisect(angle, endMark->angle);
57
0
  startMark->angle = SVGContentUtils::AngleBisect(angle, startMark->angle);
58
0
  // for a polygon (as opposed to a polyline) there's an implicit extra point
59
0
  // co-located with the start point that SVGPolyElement::GetMarkPoints
60
0
  // doesn't return
61
0
  aMarks->AppendElement(nsSVGMark(startMark->x, startMark->y, startMark->angle,
62
0
                                  nsSVGMark::eEnd));
63
0
}
64
65
already_AddRefed<Path>
66
SVGPolygonElement::BuildPath(PathBuilder* aBuilder)
67
0
{
68
0
  const SVGPointList &points = mPoints.GetAnimValue();
69
0
70
0
  if (points.IsEmpty()) {
71
0
    return nullptr;
72
0
  }
73
0
74
0
  aBuilder->MoveTo(points[0]);
75
0
  for (uint32_t i = 1; i < points.Length(); ++i) {
76
0
    aBuilder->LineTo(points[i]);
77
0
  }
78
0
79
0
  aBuilder->Close();
80
0
81
0
  return aBuilder->Finish();
82
0
}
83
84
} // namespace dom
85
} // namespace mozilla