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
|
53 NS_STATE_SVG_RENDERING_OBSERVER_CONTAINER
);
57 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerFrame
)
59 // nsIFrame interface:
61 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
62 nsIFrame
* aPrevInFlow
) override
;
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
);
77 nsContainerFrame
* GetContentInsertionFrame() override
{
78 // Any children must be added to our single anonymous inner frame kid.
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
,
93 SVGGeometryFrame
* aMarkedFrame
,
94 const SVGMark
& aMark
, float aStrokeWidth
);
96 // Return our anonymous box child.
97 void AppendDirectlyOwnedAnonBoxes(nsTArray
<OwnedAnonBox
>& aResult
) override
;
100 // stuff needed for callback
101 SVGGeometryFrame
* mMarkedFrame
;
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
{
114 AutoMarkerReferencer(SVGMarkerFrame
* aFrame
,
115 SVGGeometryFrame
* aMarkedFrame
);
116 ~AutoMarkerReferencer();
119 SVGMarkerFrame
* mFrame
;
122 // SVGMarkerFrame methods:
123 void SetParentCoordCtxProvider(dom::SVGViewportElement
* aContext
);
125 // recursion prevention flag
128 // second recursion prevention flag, for GetCanvasTM()
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
) {}
144 NS_DECL_FRAMEARENA_HELPERS(SVGMarkerAnonChildFrame
)
147 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
148 nsIFrame
* aPrevInFlow
) override
;
151 #ifdef DEBUG_FRAME_DUMP
152 nsresult
GetFrameName(nsAString
& aResult
) const override
{
153 return MakeFrameName(u
"SVGMarkerAnonChild"_ns
, aResult
);
157 // SVGContainerFrame methods:
158 gfxMatrix
GetCanvasTM() override
{
159 return static_cast<SVGMarkerFrame
*>(GetParent())->GetCanvasTM();
163 } // namespace mozilla
165 #endif // LAYOUT_SVG_SVGMARKERFRAME_H_