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/. */
7 #include "mozilla/dom/SVGPolygonElement.h"
8 #include "mozilla/dom/SVGPolygonElementBinding.h"
9 #include "mozilla/gfx/2D.h"
10 #include "SVGContentUtils.h"
12 using namespace mozilla::gfx
;
14 NS_IMPL_NS_NEW_SVG_ELEMENT(Polygon
)
16 namespace mozilla::dom
{
18 JSObject
* SVGPolygonElement::WrapNode(JSContext
* aCx
,
19 JS::Handle
<JSObject
*> aGivenProto
) {
20 return SVGPolygonElement_Binding::Wrap(aCx
, this, aGivenProto
);
23 //----------------------------------------------------------------------
26 SVGPolygonElement::SVGPolygonElement(
27 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
28 : SVGPolygonElementBase(std::move(aNodeInfo
)) {}
30 //----------------------------------------------------------------------
33 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolygonElement
)
35 //----------------------------------------------------------------------
36 // SVGGeometryElement methods
38 void SVGPolygonElement::GetMarkPoints(nsTArray
<SVGMark
>* aMarks
) {
39 SVGPolyElement::GetMarkPoints(aMarks
);
41 if (aMarks
->IsEmpty() || aMarks
->LastElement().type
!= SVGMark::eEnd
) {
45 SVGMark
* endMark
= &aMarks
->LastElement();
46 SVGMark
* startMark
= &aMarks
->ElementAt(0);
48 std::atan2(startMark
->y
- endMark
->y
, startMark
->x
- endMark
->x
);
50 endMark
->type
= SVGMark::eMid
;
51 endMark
->angle
= SVGContentUtils::AngleBisect(angle
, endMark
->angle
);
52 startMark
->angle
= SVGContentUtils::AngleBisect(angle
, startMark
->angle
);
53 // for a polygon (as opposed to a polyline) there's an implicit extra point
54 // co-located with the start point that SVGPolyElement::GetMarkPoints
56 aMarks
->AppendElement(
57 SVGMark(startMark
->x
, startMark
->y
, startMark
->angle
, SVGMark::eEnd
));
60 already_AddRefed
<Path
> SVGPolygonElement::BuildPath(PathBuilder
* aBuilder
) {
61 const SVGPointList
& points
= mPoints
.GetAnimValue();
63 if (points
.IsEmpty()) {
67 aBuilder
->MoveTo(points
[0]);
68 for (uint32_t i
= 1; i
< points
.Length(); ++i
) {
69 aBuilder
->LineTo(points
[i
]);
74 return aBuilder
->Finish();
77 } // namespace mozilla::dom