Bumping manifests a=b2g-bump
[gecko.git] / layout / svg / nsSVGMarkerFrame.h
blobd20b542c291ce0099fef61dbeb66e1b0744de318
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"
11 #include "gfxRect.h"
12 #include "nsFrame.h"
13 #include "nsLiteralString.h"
14 #include "nsQueryFrame.h"
15 #include "nsSVGContainerFrame.h"
16 #include "nsSVGUtils.h"
18 class nsRenderingContext;
19 class nsSVGPathGeometryFrame;
21 namespace mozilla {
22 namespace dom {
23 class SVGSVGElement;
27 struct nsSVGMark;
29 typedef nsSVGContainerFrame nsSVGMarkerFrameBase;
31 class nsSVGMarkerFrame : public nsSVGMarkerFrameBase
33 friend class nsSVGMarkerAnonChildFrame;
34 friend nsContainerFrame*
35 NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
36 protected:
37 explicit nsSVGMarkerFrame(nsStyleContext* aContext)
38 : nsSVGMarkerFrameBase(aContext)
39 , mMarkedFrame(nullptr)
40 , mInUse(false)
41 , mInUse2(false)
43 AddStateBits(NS_FRAME_IS_NONDISPLAY);
46 public:
47 NS_DECL_FRAMEARENA_HELPERS
49 // nsIFrame interface:
50 #ifdef DEBUG
51 virtual void Init(nsIContent* aContent,
52 nsContainerFrame* aParent,
53 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
54 #endif
56 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
57 const nsRect& aDirtyRect,
58 const nsDisplayListSet& aLists) MOZ_OVERRIDE {}
60 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
61 nsIAtom* aAttribute,
62 int32_t aModType) MOZ_OVERRIDE;
63 /**
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);
75 #endif
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,
89 nsSVGMark *aMark,
90 float aStrokeWidth);
92 SVGBBox GetMarkBBoxContribution(const Matrix &aToBBoxUserspace,
93 uint32_t aFlags,
94 nsSVGPathGeometryFrame *aMarkedFrame,
95 const nsSVGMark *aMark,
96 float aStrokeWidth);
98 private:
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
115 public:
116 AutoMarkerReferencer(nsSVGMarkerFrame *aFrame,
117 nsSVGPathGeometryFrame *aMarkedFrame
118 MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
119 ~AutoMarkerReferencer();
120 private:
121 nsSVGMarkerFrame *mFrame;
122 MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
125 // nsSVGMarkerFrame methods:
126 void SetParentCoordCtxProvider(mozilla::dom::SVGSVGElement *aContext);
128 // recursion prevention flag
129 bool mInUse;
131 // second recursion prevention flag, for GetCanvasTM()
132 bool mInUse2;
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)
153 public:
154 NS_DECL_FRAMEARENA_HELPERS
156 #ifdef DEBUG
157 virtual void Init(nsIContent* aContent,
158 nsContainerFrame* aParent,
159 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
160 #endif
162 #ifdef DEBUG_FRAME_DUMP
163 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE {
164 return MakeFrameName(NS_LITERAL_STRING("SVGMarkerAnonChild"), aResult);
166 #endif
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);
183 #endif