Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / svg / SVGPolygonElement.cpp
blobdef80151531de016e63b7398ed28f67554ce9ae3
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 //----------------------------------------------------------------------
24 // Implementation
26 SVGPolygonElement::SVGPolygonElement(
27 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
28 : SVGPolygonElementBase(std::move(aNodeInfo)) {}
30 //----------------------------------------------------------------------
31 // nsINode methods
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) {
42 return;
45 SVGMark* endMark = &aMarks->LastElement();
46 SVGMark* startMark = &aMarks->ElementAt(0);
47 float angle =
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
55 // doesn't return
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()) {
64 return nullptr;
67 aBuilder->MoveTo(points[0]);
68 for (uint32_t i = 1; i < points.Length(); ++i) {
69 aBuilder->LineTo(points[i]);
72 aBuilder->Close();
74 return aBuilder->Finish();
77 } // namespace mozilla::dom