Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / layout / svg / SVGMarkerFrame.h
blob7f4da9c5a5d41d3e0561ba07ae599712852a85e3
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 #ifndef LAYOUT_SVG_SVGMARKERFRAME_H_
8 #define LAYOUT_SVG_SVGMARKERFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/SVGContainerFrame.h"
12 #include "gfxMatrix.h"
13 #include "gfxRect.h"
14 #include "nsIFrame.h"
15 #include "nsLiteralString.h"
16 #include "nsQueryFrame.h"
18 class gfxContext;
20 namespace mozilla {
22 class PresShell;
23 class SVGGeometryFrame;
25 struct SVGMark;
27 namespace dom {
28 class SVGViewportElement;
29 } // namespace dom
30 } // namespace mozilla
32 nsContainerFrame* NS_NewSVGMarkerFrame(mozilla::PresShell* aPresShell,
33 mozilla::ComputedStyle* aStyle);
34 nsContainerFrame* NS_NewSVGMarkerAnonChildFrame(mozilla::PresShell* aPresShell,
35 mozilla::ComputedStyle* aStyle);
37 namespace mozilla {
39 class SVGMarkerFrame final : public SVGContainerFrame {
40 using imgDrawingParams = image::imgDrawingParams;
42 friend class SVGMarkerAnonChildFrame;
43 friend nsContainerFrame* ::NS_NewSVGMarkerFrame(
44 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
46 protected:
47 explicit SVGMarkerFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
48 : SVGContainerFrame(aStyle, aPresContext, kClassID),
49 mMarkedFrame(nullptr),
50 mInUse(false),
51 mInUse2(false) {
52 AddStateBits(NS_FRAME_IS_NONDISPLAY);
55 public:
56 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerFrame)
58 // nsIFrame interface:
59 #ifdef DEBUG
60 void Init(nsIContent* aContent, nsContainerFrame* aParent,
61 nsIFrame* aPrevInFlow) override;
62 #endif
64 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
65 const nsDisplayListSet& aLists) override {}
67 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
68 int32_t aModType) override;
70 #ifdef DEBUG_FRAME_DUMP
71 nsresult GetFrameName(nsAString& aResult) const override {
72 return MakeFrameName(u"SVGMarker"_ns, aResult);
74 #endif
76 nsContainerFrame* GetContentInsertionFrame() override {
77 // Any children must be added to our single anonymous inner frame kid.
78 MOZ_ASSERT(
79 PrincipalChildList().FirstChild() &&
80 PrincipalChildList().FirstChild()->IsSVGMarkerAnonChildFrame(),
81 "Where is our anonymous child?");
82 return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
85 // SVGMarkerFrame methods:
86 void PaintMark(gfxContext& aContext, const gfxMatrix& aToMarkedFrameUserSpace,
87 SVGGeometryFrame* aMarkedFrame, const SVGMark& aMark,
88 float aStrokeWidth, imgDrawingParams& aImgParams);
90 SVGBBox GetMarkBBoxContribution(const Matrix& aToBBoxUserspace,
91 uint32_t aFlags,
92 SVGGeometryFrame* aMarkedFrame,
93 const SVGMark& aMark, float aStrokeWidth);
95 // Return our anonymous box child.
96 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
98 private:
99 // stuff needed for callback
100 SVGGeometryFrame* mMarkedFrame;
101 Matrix mMarkerTM;
103 // SVGContainerFrame methods:
104 gfxMatrix GetCanvasTM() override;
106 // A helper class to allow us to paint markers safely. The helper
107 // automatically sets and clears the mInUse flag on the marker frame (to
108 // prevent nasty reference loops) as well as the reference to the marked
109 // frame and its coordinate context. It's easy to mess this up
110 // and break things, so this helper makes the code far more robust.
111 class MOZ_RAII AutoMarkerReferencer {
112 public:
113 AutoMarkerReferencer(SVGMarkerFrame* aFrame,
114 SVGGeometryFrame* aMarkedFrame);
115 ~AutoMarkerReferencer();
117 private:
118 SVGMarkerFrame* mFrame;
121 // SVGMarkerFrame methods:
122 void SetParentCoordCtxProvider(dom::SVGViewportElement* aContext);
124 // recursion prevention flag
125 bool mInUse;
127 // second recursion prevention flag, for GetCanvasTM()
128 bool mInUse2;
131 ////////////////////////////////////////////////////////////////////////
132 // nsMarkerAnonChildFrame class
134 class SVGMarkerAnonChildFrame final : public SVGDisplayContainerFrame {
135 friend nsContainerFrame* ::NS_NewSVGMarkerAnonChildFrame(
136 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
138 explicit SVGMarkerAnonChildFrame(ComputedStyle* aStyle,
139 nsPresContext* aPresContext)
140 : SVGDisplayContainerFrame(aStyle, aPresContext, kClassID) {}
142 public:
143 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerAnonChildFrame)
145 #ifdef DEBUG
146 void Init(nsIContent* aContent, nsContainerFrame* aParent,
147 nsIFrame* aPrevInFlow) override;
148 #endif
150 #ifdef DEBUG_FRAME_DUMP
151 nsresult GetFrameName(nsAString& aResult) const override {
152 return MakeFrameName(u"SVGMarkerAnonChild"_ns, aResult);
154 #endif
156 // SVGContainerFrame methods:
157 gfxMatrix GetCanvasTM() override {
158 return static_cast<SVGMarkerFrame*>(GetParent())->GetCanvasTM();
162 } // namespace mozilla
164 #endif // LAYOUT_SVG_SVGMARKERFRAME_H_