1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef __NS_SVGMARKERFRAME_H__
7 #define __NS_SVGMARKERFRAME_H__
9 #include "mozilla/Attributes.h"
10 #include "gfxMatrix.h"
13 #include "nsLiteralString.h"
14 #include "nsQueryFrame.h"
15 #include "nsSVGContainerFrame.h"
16 #include "nsSVGUtils.h"
18 class nsRenderingContext
;
19 class nsSVGPathGeometryFrame
;
29 typedef nsSVGContainerFrame nsSVGMarkerFrameBase
;
31 class nsSVGMarkerFrame
: public nsSVGMarkerFrameBase
33 friend class nsSVGMarkerAnonChildFrame
;
34 friend nsContainerFrame
*
35 NS_NewSVGMarkerFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
37 explicit nsSVGMarkerFrame(nsStyleContext
* aContext
)
38 : nsSVGMarkerFrameBase(aContext
)
39 , mMarkedFrame(nullptr)
43 AddStateBits(NS_FRAME_IS_NONDISPLAY
);
47 NS_DECL_FRAMEARENA_HELPERS
49 // nsIFrame interface:
51 virtual void Init(nsIContent
* aContent
,
52 nsContainerFrame
* aParent
,
53 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
56 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
57 const nsRect
& aDirtyRect
,
58 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
{}
60 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
62 int32_t aModType
) MOZ_OVERRIDE
;
64 * Get the "type" of the frame
66 * @see nsGkAtoms::svgMarkerFrame
68 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
70 #ifdef DEBUG_FRAME_DUMP
71 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
73 return MakeFrameName(NS_LITERAL_STRING("SVGMarker"), aResult
);
77 virtual nsContainerFrame
* GetContentInsertionFrame() MOZ_OVERRIDE
{
78 // Any children must be added to our single anonymous inner frame kid.
79 NS_ABORT_IF_FALSE(GetFirstPrincipalChild() &&
80 GetFirstPrincipalChild()->GetType() ==
81 nsGkAtoms::svgMarkerAnonChildFrame
,
82 "Where is our anonymous child?");
83 return GetFirstPrincipalChild()->GetContentInsertionFrame();
86 // nsSVGMarkerFrame methods:
87 nsresult
PaintMark(nsRenderingContext
*aContext
,
88 nsSVGPathGeometryFrame
*aMarkedFrame
,
92 SVGBBox
GetMarkBBoxContribution(const Matrix
&aToBBoxUserspace
,
94 nsSVGPathGeometryFrame
*aMarkedFrame
,
95 const nsSVGMark
*aMark
,
99 // stuff needed for callback
100 nsSVGPathGeometryFrame
*mMarkedFrame
;
101 float mStrokeWidth
, mX
, mY
, mAutoAngle
;
102 bool mIsStart
; // whether the callback is for a marker-start marker
104 // nsSVGContainerFrame methods:
105 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
106 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
;
108 // A helper class to allow us to paint markers safely. The helper
109 // automatically sets and clears the mInUse flag on the marker frame (to
110 // prevent nasty reference loops) as well as the reference to the marked
111 // frame and its coordinate context. It's easy to mess this up
112 // and break things, so this helper makes the code far more robust.
113 class MOZ_STACK_CLASS AutoMarkerReferencer
116 AutoMarkerReferencer(nsSVGMarkerFrame
*aFrame
,
117 nsSVGPathGeometryFrame
*aMarkedFrame
118 MOZ_GUARD_OBJECT_NOTIFIER_PARAM
);
119 ~AutoMarkerReferencer();
121 nsSVGMarkerFrame
*mFrame
;
122 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
125 // nsSVGMarkerFrame methods:
126 void SetParentCoordCtxProvider(mozilla::dom::SVGSVGElement
*aContext
);
128 // recursion prevention flag
131 // second recursion prevention flag, for GetCanvasTM()
135 ////////////////////////////////////////////////////////////////////////
136 // nsMarkerAnonChildFrame class
138 typedef nsSVGDisplayContainerFrame nsSVGMarkerAnonChildFrameBase
;
142 class nsSVGMarkerAnonChildFrame
143 : public nsSVGMarkerAnonChildFrameBase
145 friend nsContainerFrame
*
146 NS_NewSVGMarkerAnonChildFrame(nsIPresShell
* aPresShell
,
147 nsStyleContext
* aContext
);
149 explicit nsSVGMarkerAnonChildFrame(nsStyleContext
* aContext
)
150 : nsSVGMarkerAnonChildFrameBase(aContext
)
154 NS_DECL_FRAMEARENA_HELPERS
157 virtual void Init(nsIContent
* aContent
,
158 nsContainerFrame
* aParent
,
159 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
162 #ifdef DEBUG_FRAME_DUMP
163 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
{
164 return MakeFrameName(NS_LITERAL_STRING("SVGMarkerAnonChild"), aResult
);
169 * Get the "type" of the frame
171 * @see nsGkAtoms::svgMarkerAnonChildFrame
173 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
175 // nsSVGContainerFrame methods:
176 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
177 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
179 nsSVGMarkerFrame
* marker
= static_cast<nsSVGMarkerFrame
*>(GetParent());
180 return marker
->GetCanvasTM(aFor
, aTransformRoot
);