Bug 1919824 - Make `NativeKey::GetFollowingCharMessage` return `false` when removed...
[gecko.git] / dom / svg / SVGPolygonElement.cpp
blob12461a43753f92717f9ca64f6d39cff8db4a784d
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/dom/SVGAnimatedLength.h"
10 #include "mozilla/gfx/2D.h"
11 #include "SVGContentUtils.h"
13 using namespace mozilla::gfx;
15 NS_IMPL_NS_NEW_SVG_ELEMENT(Polygon)
17 namespace mozilla::dom {
19 JSObject* SVGPolygonElement::WrapNode(JSContext* aCx,
20 JS::Handle<JSObject*> aGivenProto) {
21 return SVGPolygonElement_Binding::Wrap(aCx, this, aGivenProto);
24 //----------------------------------------------------------------------
25 // Implementation
27 SVGPolygonElement::SVGPolygonElement(
28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
29 : SVGPolygonElementBase(std::move(aNodeInfo)) {}
31 //----------------------------------------------------------------------
32 // nsINode methods
34 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolygonElement)
36 //----------------------------------------------------------------------
37 // SVGGeometryElement methods
39 void SVGPolygonElement::GetMarkPoints(nsTArray<SVGMark>* aMarks) {
40 SVGPolyElement::GetMarkPoints(aMarks);
42 if (aMarks->IsEmpty() || aMarks->LastElement().type != SVGMark::eEnd) {
43 return;
46 SVGMark* endMark = &aMarks->LastElement();
47 SVGMark* startMark = &aMarks->ElementAt(0);
48 float angle =
49 std::atan2(startMark->y - endMark->y, startMark->x - endMark->x);
51 endMark->type = SVGMark::eMid;
52 endMark->angle = SVGContentUtils::AngleBisect(angle, endMark->angle);
53 startMark->angle = SVGContentUtils::AngleBisect(angle, startMark->angle);
54 // for a polygon (as opposed to a polyline) there's an implicit extra point
55 // co-located with the start point that SVGPolyElement::GetMarkPoints
56 // doesn't return
57 aMarks->AppendElement(
58 SVGMark(startMark->x, startMark->y, startMark->angle, SVGMark::eEnd));
61 already_AddRefed<Path> SVGPolygonElement::BuildPath(PathBuilder* aBuilder) {
62 const SVGPointList& points = mPoints.GetAnimValue();
64 if (points.IsEmpty()) {
65 return nullptr;
68 float zoom = UserSpaceMetrics::GetZoom(this);
70 aBuilder->MoveTo(points[0] * zoom);
71 for (uint32_t i = 1; i < points.Length(); ++i) {
72 aBuilder->LineTo(points[i] * zoom);
75 aBuilder->Close();
77 return aBuilder->Finish();
80 } // namespace mozilla::dom