SVGPolylineElement.cpp (1915B)
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/SVGPolylineElement.h" 8 9 #include "mozilla/dom/SVGAnimatedLength.h" 10 #include "mozilla/dom/SVGPolylineElementBinding.h" 11 #include "mozilla/gfx/2D.h" 12 13 using namespace mozilla::gfx; 14 15 NS_IMPL_NS_NEW_SVG_ELEMENT(Polyline) 16 17 namespace mozilla::dom { 18 19 JSObject* SVGPolylineElement::WrapNode(JSContext* aCx, 20 JS::Handle<JSObject*> aGivenProto) { 21 return SVGPolylineElement_Binding::Wrap(aCx, this, aGivenProto); 22 } 23 24 //---------------------------------------------------------------------- 25 // Implementation 26 27 SVGPolylineElement::SVGPolylineElement( 28 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 29 : SVGPolylineElementBase(std::move(aNodeInfo)) {} 30 31 //---------------------------------------------------------------------- 32 // nsINode methods 33 34 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGPolylineElement) 35 36 //---------------------------------------------------------------------- 37 // SVGGeometryElement methods 38 39 already_AddRefed<Path> SVGPolylineElement::BuildPath(PathBuilder* aBuilder) { 40 const SVGPointList& points = mPoints.GetAnimValue(); 41 42 if (points.IsEmpty()) { 43 return nullptr; 44 } 45 46 float zoom = UserSpaceMetrics::GetZoom(this); 47 48 Point zoomedPoint = Point(points[0]) * zoom; 49 if (!zoomedPoint.IsFinite()) { 50 return nullptr; 51 } 52 aBuilder->MoveTo(zoomedPoint); 53 for (uint32_t i = 1; i < points.Length(); ++i) { 54 zoomedPoint = Point(points[i]) * zoom; 55 if (!zoomedPoint.IsFinite()) { 56 return nullptr; 57 } 58 aBuilder->LineTo(zoomedPoint); 59 } 60 61 return aBuilder->Finish(); 62 } 63 64 } // namespace mozilla::dom