SVGLineElement.h (2254B)
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 #ifndef DOM_SVG_SVGLINEELEMENT_H_ 8 #define DOM_SVG_SVGLINEELEMENT_H_ 9 10 #include "SVGAnimatedLength.h" 11 #include "SVGGeometryElement.h" 12 13 nsresult NS_NewSVGLineElement( 14 nsIContent** aResult, already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 15 16 namespace mozilla::dom { 17 18 using SVGLineElementBase = SVGGeometryElement; 19 20 class SVGLineElement final : public SVGLineElementBase { 21 protected: 22 explicit SVGLineElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 23 JSObject* WrapNode(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override; 24 friend nsresult(::NS_NewSVGLineElement( 25 nsIContent** aResult, 26 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)); 27 // If the input line has length zero and linecaps aren't butt, adjust |aX2| by 28 // a tiny amount to a barely-nonzero-length line that all of our draw targets 29 // will render 30 void MaybeAdjustForZeroLength(float aX1, float aY1, float& aX2, float aY2); 31 32 public: 33 // SVGGeometryElement methods: 34 bool IsMarkable() override { return true; } 35 void GetMarkPoints(nsTArray<SVGMark>* aMarks) override; 36 void GetAsSimplePath(SimplePath* aSimplePath) override; 37 already_AddRefed<Path> BuildPath(PathBuilder* aBuilder) override; 38 bool GetGeometryBounds( 39 Rect* aBounds, const StrokeOptions& aStrokeOptions, 40 const Matrix& aToBoundsSpace, 41 const Matrix* aToNonScalingStrokeSpace = nullptr) override; 42 43 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 44 45 // WebIDL 46 already_AddRefed<DOMSVGAnimatedLength> X1(); 47 already_AddRefed<DOMSVGAnimatedLength> Y1(); 48 already_AddRefed<DOMSVGAnimatedLength> X2(); 49 already_AddRefed<DOMSVGAnimatedLength> Y2(); 50 51 protected: 52 LengthAttributesInfo GetLengthInfo() override; 53 54 enum { ATTR_X1, ATTR_Y1, ATTR_X2, ATTR_Y2 }; 55 SVGAnimatedLength mLengthAttributes[4]; 56 static LengthInfo sLengthInfo[4]; 57 }; 58 59 } // namespace mozilla::dom 60 61 #endif // DOM_SVG_SVGLINEELEMENT_H_