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"
15 #include "nsLiteralString.h"
16 #include "nsQueryFrame.h"
23 class SVGGeometryFrame
;
28 class SVGViewportElement
;
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
);
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
);
47 explicit SVGMarkerFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
)
48 : SVGContainerFrame(aStyle
, aPresContext
, kClassID
),
49 mMarkedFrame(nullptr),
52 AddStateBits(NS_FRAME_IS_NONDISPLAY
);
56 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerFrame
)
58 // nsIFrame interface:
60 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
61 nsIFrame
* aPrevInFlow
) override
;
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
);
76 nsContainerFrame
* GetContentInsertionFrame() override
{
77 // Any children must be added to our single anonymous inner frame kid.
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
,
92 SVGGeometryFrame
* aMarkedFrame
,
93 const SVGMark
& aMark
, float aStrokeWidth
);
95 // Return our anonymous box child.
96 void AppendDirectlyOwnedAnonBoxes(nsTArray
<OwnedAnonBox
>& aResult
) override
;
99 // stuff needed for callback
100 SVGGeometryFrame
* mMarkedFrame
;
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
{
113 AutoMarkerReferencer(SVGMarkerFrame
* aFrame
,
114 SVGGeometryFrame
* aMarkedFrame
);
115 ~AutoMarkerReferencer();
118 SVGMarkerFrame
* mFrame
;
121 // SVGMarkerFrame methods:
122 void SetParentCoordCtxProvider(dom::SVGViewportElement
* aContext
);
124 // recursion prevention flag
127 // second recursion prevention flag, for GetCanvasTM()
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
) {}
143 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerAnonChildFrame
)
146 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
147 nsIFrame
* aPrevInFlow
) override
;
150 #ifdef DEBUG_FRAME_DUMP
151 nsresult
GetFrameName(nsAString
& aResult
) const override
{
152 return MakeFrameName(u
"SVGMarkerAnonChild"_ns
, aResult
);
156 // SVGContainerFrame methods:
157 gfxMatrix
GetCanvasTM() override
{
158 return static_cast<SVGMarkerFrame
*>(GetParent())->GetCanvasTM();
162 } // namespace mozilla
164 #endif // LAYOUT_SVG_SVGMARKERFRAME_H_