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_SVGCONTAINERFRAME_H
7 #define NS_SVGCONTAINERFRAME_H
9 #include "mozilla/Attributes.h"
10 #include "nsContainerFrame.h"
13 #include "nsISVGChildFrame.h"
14 #include "nsQueryFrame.h"
16 #include "nsSVGUtils.h"
21 class nsRenderingContext
;
28 typedef nsContainerFrame nsSVGContainerFrameBase
;
31 * Base class for SVG container frames. Frame sub-classes that do not
32 * display their contents directly (such as the frames for <marker> or
33 * <pattern>) just inherit this class. Frame sub-classes that do or can
34 * display their contents directly (such as the frames for inner-<svg> or
35 * <g>) inherit our nsDisplayContainerFrame sub-class.
39 * Do *not* blindly cast to SVG element types in this class's methods (see the
40 * warning comment for nsSVGDisplayContainerFrame below).
42 class nsSVGContainerFrame
: public nsSVGContainerFrameBase
44 friend nsIFrame
* NS_NewSVGContainerFrame(nsIPresShell
* aPresShell
,
45 nsStyleContext
* aContext
);
47 explicit nsSVGContainerFrame(nsStyleContext
* aContext
)
48 : nsSVGContainerFrameBase(aContext
)
50 AddStateBits(NS_FRAME_SVG_LAYOUT
);
54 NS_DECL_QUERYFRAME_TARGET(nsSVGContainerFrame
)
56 NS_DECL_FRAMEARENA_HELPERS
58 // Returns the transform to our gfxContext (to device pixels, not CSS px)
59 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
60 nsIFrame
* aTransformRoot
= nullptr) {
65 * Returns true if the frame's content has a transform that applies only to
66 * its children, and not to the frame itself. For example, an implicit
67 * transform introduced by a 'viewBox' attribute, or an explicit transform
68 * due to a root-<svg> having its currentScale/currentTransform properties
69 * set. If aTransform is non-null, then it will be set to the transform.
71 virtual bool HasChildrenOnlyTransform(Matrix
*aTransform
) const {
76 virtual void AppendFrames(ChildListID aListID
,
77 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
78 virtual void InsertFrames(ChildListID aListID
,
80 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
81 virtual void RemoveFrame(ChildListID aListID
,
82 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
84 virtual bool IsFrameOfType(uint32_t aFlags
) const MOZ_OVERRIDE
86 return nsSVGContainerFrameBase::IsFrameOfType(
87 aFlags
& ~(nsIFrame::eSVG
| nsIFrame::eSVGContainer
));
90 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
91 const nsRect
& aDirtyRect
,
92 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
{}
94 virtual bool UpdateOverflow() MOZ_OVERRIDE
;
98 * Traverses a frame tree, marking any SVGTextFrame frames as dirty
99 * and calling InvalidateRenderingObservers() on it.
101 static void ReflowSVGNonDisplayText(nsIFrame
* aContainer
);
105 * Frame class or base-class for SVG containers that can or do display their
110 * This class's methods can *not* assume that mContent points to an instance of
111 * an SVG element class since this class is inherited by
112 * nsSVGGenericContainerFrame which is used for unrecognized elements in the
113 * SVG namespace. Do *not* blindly cast to SVG element types.
115 class nsSVGDisplayContainerFrame
: public nsSVGContainerFrame
,
116 public nsISVGChildFrame
119 explicit nsSVGDisplayContainerFrame(nsStyleContext
* aContext
)
120 : nsSVGContainerFrame(aContext
)
122 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED
);
126 NS_DECL_QUERYFRAME_TARGET(nsSVGDisplayContainerFrame
)
128 NS_DECL_FRAMEARENA_HELPERS
131 virtual void InsertFrames(ChildListID aListID
,
132 nsIFrame
* aPrevFrame
,
133 nsFrameList
& aFrameList
) MOZ_OVERRIDE
;
134 virtual void RemoveFrame(ChildListID aListID
,
135 nsIFrame
* aOldFrame
) MOZ_OVERRIDE
;
136 virtual void Init(nsIContent
* aContent
,
137 nsContainerFrame
* aParent
,
138 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
140 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
141 const nsRect
& aDirtyRect
,
142 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
144 virtual bool IsSVGTransformed(Matrix
*aOwnTransform
= nullptr,
145 Matrix
*aFromParentTransform
= nullptr) const MOZ_OVERRIDE
;
147 // nsISVGChildFrame interface:
148 virtual nsresult
PaintSVG(nsRenderingContext
* aContext
,
149 const nsIntRect
*aDirtyRect
,
150 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
;
151 virtual nsIFrame
* GetFrameForPoint(const gfxPoint
& aPoint
) MOZ_OVERRIDE
;
152 virtual nsRect
GetCoveredRegion() MOZ_OVERRIDE
;
153 virtual void ReflowSVG() MOZ_OVERRIDE
;
154 virtual void NotifySVGChanged(uint32_t aFlags
) MOZ_OVERRIDE
;
155 virtual SVGBBox
GetBBoxContribution(const Matrix
&aToBBoxUserspace
,
156 uint32_t aFlags
) MOZ_OVERRIDE
;
157 virtual bool IsDisplayContainer() MOZ_OVERRIDE
{ return true; }