Backed out changeset 2960ea3e50ca (bug 1881157) for causing crashtest assertion failu...
[gecko.git] / layout / svg / SVGMarkerFrame.h
blobe5b6f2f561c59363ad4b92d940e2a40174cbfe5e
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 |
53 NS_STATE_SVG_RENDERING_OBSERVER_CONTAINER);
56 public:
57 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerFrame)
59 // nsIFrame interface:
60 #ifdef DEBUG
61 void Init(nsIContent* aContent, nsContainerFrame* aParent,
62 nsIFrame* aPrevInFlow) override;
63 #endif
65 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
66 const nsDisplayListSet& aLists) override {}
68 nsresult AttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
69 int32_t aModType) override;
71 #ifdef DEBUG_FRAME_DUMP
72 nsresult GetFrameName(nsAString& aResult) const override {
73 return MakeFrameName(u"SVGMarker"_ns, aResult);
75 #endif
77 nsContainerFrame* GetContentInsertionFrame() override {
78 // Any children must be added to our single anonymous inner frame kid.
79 MOZ_ASSERT(
80 PrincipalChildList().FirstChild() &&
81 PrincipalChildList().FirstChild()->IsSVGMarkerAnonChildFrame(),
82 "Where is our anonymous child?");
83 return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
86 // SVGMarkerFrame methods:
87 void PaintMark(gfxContext& aContext, const gfxMatrix& aToMarkedFrameUserSpace,
88 SVGGeometryFrame* aMarkedFrame, const SVGMark& aMark,
89 float aStrokeWidth, imgDrawingParams& aImgParams);
91 SVGBBox GetMarkBBoxContribution(const Matrix& aToBBoxUserspace,
92 uint32_t aFlags,
93 SVGGeometryFrame* aMarkedFrame,
94 const SVGMark& aMark, float aStrokeWidth);
96 // Return our anonymous box child.
97 void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
99 private:
100 // stuff needed for callback
101 SVGGeometryFrame* mMarkedFrame;
102 Matrix mMarkerTM;
104 // SVGContainerFrame methods:
105 gfxMatrix GetCanvasTM() override;
107 // A helper class to allow us to paint markers safely. The helper
108 // automatically sets and clears the mInUse flag on the marker frame (to
109 // prevent nasty reference loops) as well as the reference to the marked
110 // frame and its coordinate context. It's easy to mess this up
111 // and break things, so this helper makes the code far more robust.
112 class MOZ_RAII AutoMarkerReferencer {
113 public:
114 AutoMarkerReferencer(SVGMarkerFrame* aFrame,
115 SVGGeometryFrame* aMarkedFrame);
116 ~AutoMarkerReferencer();
118 private:
119 SVGMarkerFrame* mFrame;
122 // SVGMarkerFrame methods:
123 void SetParentCoordCtxProvider(dom::SVGViewportElement* aContext);
125 // recursion prevention flag
126 bool mInUse;
128 // second recursion prevention flag, for GetCanvasTM()
129 bool mInUse2;
132 ////////////////////////////////////////////////////////////////////////
133 // nsMarkerAnonChildFrame class
135 class SVGMarkerAnonChildFrame final : public SVGDisplayContainerFrame {
136 friend nsContainerFrame* ::NS_NewSVGMarkerAnonChildFrame(
137 mozilla::PresShell* aPresShell, ComputedStyle* aStyle);
139 explicit SVGMarkerAnonChildFrame(ComputedStyle* aStyle,
140 nsPresContext* aPresContext)
141 : SVGDisplayContainerFrame(aStyle, aPresContext, kClassID) {}
143 public:
144 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerAnonChildFrame)
146 #ifdef DEBUG
147 void Init(nsIContent* aContent, nsContainerFrame* aParent,
148 nsIFrame* aPrevInFlow) override;
149 #endif
151 #ifdef DEBUG_FRAME_DUMP
152 nsresult GetFrameName(nsAString& aResult) const override {
153 return MakeFrameName(u"SVGMarkerAnonChild"_ns, aResult);
155 #endif
157 // SVGContainerFrame methods:
158 gfxMatrix GetCanvasTM() override {
159 return static_cast<SVGMarkerFrame*>(GetParent())->GetCanvasTM();
163 } // namespace mozilla
165 #endif // LAYOUT_SVG_SVGMARKERFRAME_H_