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_SVGCONTAINERFRAME_H_
8 #define LAYOUT_SVG_SVGCONTAINERFRAME_H_
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ISVGDisplayableFrame.h"
12 #include "mozilla/UniquePtr.h"
13 #include "nsContainerFrame.h"
15 #include "nsQueryFrame.h"
26 } // namespace mozilla
28 nsIFrame
* NS_NewSVGContainerFrame(mozilla::PresShell
* aPresShell
,
29 mozilla::ComputedStyle
* aStyle
);
34 * Base class for SVG container frames. Frame sub-classes that do not
35 * display their contents directly (such as the frames for <marker> or
36 * <pattern>) just inherit this class. Frame sub-classes that do or can
37 * display their contents directly (such as the frames for inner-<svg> or
38 * <g>) inherit our SVGDisplayContainerFrame sub-class.
42 * Do *not* blindly cast to SVG element types in this class's methods (see the
43 * warning comment for SVGDisplayContainerFrame below).
45 class SVGContainerFrame
: public nsContainerFrame
{
46 friend nsIFrame
* ::NS_NewSVGContainerFrame(mozilla::PresShell
* aPresShell
,
47 ComputedStyle
* aStyle
);
50 SVGContainerFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
,
52 : nsContainerFrame(aStyle
, aPresContext
, aID
) {
53 AddStateBits(NS_FRAME_SVG_LAYOUT
);
58 NS_DECL_FRAMEARENA_HELPERS(SVGContainerFrame
)
60 // Returns the transform to our gfxContext (to device pixels, not CSS px)
61 virtual gfxMatrix
GetCanvasTM() { return gfxMatrix(); }
64 * Returns true if the frame's content has a transform that applies only to
65 * its children, and not to the frame itself. For example, an implicit
66 * transform introduced by a 'viewBox' attribute, or an explicit transform
67 * due to a root-<svg> having its currentScale/currentTransform properties
68 * set. If aTransform is non-null, then it will be set to the transform.
70 virtual bool HasChildrenOnlyTransform(Matrix
* aTransform
) const {
75 void AppendFrames(ChildListID aListID
, nsFrameList
&& aFrameList
) override
;
76 void InsertFrames(ChildListID aListID
, nsIFrame
* aPrevFrame
,
77 const nsLineList::iterator
* aPrevFrameLine
,
78 nsFrameList
&& aFrameList
) override
;
79 void RemoveFrame(DestroyContext
&, ChildListID
, nsIFrame
*) override
;
81 bool IsFrameOfType(uint32_t aFlags
) const override
{
82 if (aFlags
& eSupportsContainLayoutAndPaint
) {
86 return nsContainerFrame::IsFrameOfType(
87 aFlags
& ~(nsIFrame::eSVG
| nsIFrame::eSVGContainer
));
90 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
91 const nsDisplayListSet
& aLists
) override
{}
93 bool ComputeCustomOverflow(mozilla::OverflowAreas
& aOverflowAreas
) override
;
97 * Traverses a frame tree, marking any SVGTextFrame frames as dirty
98 * and calling InvalidateRenderingObservers() on it.
100 static void ReflowSVGNonDisplayText(nsIFrame
* aContainer
);
104 * Frame class or base-class for SVG containers that can or do display their
109 * This class's methods can *not* assume that mContent points to an instance of
110 * an SVG element class since this class is inherited by
111 * SVGGenericContainerFrame which is used for unrecognized elements in the
112 * SVG namespace. Do *not* blindly cast to SVG element types.
114 class SVGDisplayContainerFrame
: public SVGContainerFrame
,
115 public ISVGDisplayableFrame
{
117 SVGDisplayContainerFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
,
118 nsIFrame::ClassID aID
)
119 : SVGContainerFrame(aStyle
, aPresContext
, aID
) {
120 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED
);
125 NS_DECL_QUERYFRAME_TARGET(SVGDisplayContainerFrame
)
126 NS_DECL_ABSTRACT_FRAME(SVGDisplayContainerFrame
)
129 void InsertFrames(ChildListID aListID
, nsIFrame
* aPrevFrame
,
130 const nsLineList::iterator
* aPrevFrameLine
,
131 nsFrameList
&& aFrameList
) override
;
132 void RemoveFrame(DestroyContext
&, ChildListID
, nsIFrame
*) override
;
133 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
134 nsIFrame
* aPrevInFlow
) override
;
136 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
137 const nsDisplayListSet
& aLists
) override
;
139 bool IsSVGTransformed(Matrix
* aOwnTransform
= nullptr,
140 Matrix
* aFromParentTransform
= nullptr) const override
;
142 // ISVGDisplayableFrame interface:
143 void PaintSVG(gfxContext
& aContext
, const gfxMatrix
& aTransform
,
144 imgDrawingParams
& aImgParams
) override
;
145 nsIFrame
* GetFrameForPoint(const gfxPoint
& aPoint
) override
;
146 void ReflowSVG() override
;
147 void NotifySVGChanged(uint32_t aFlags
) override
;
148 SVGBBox
GetBBoxContribution(const Matrix
& aToBBoxUserspace
,
149 uint32_t aFlags
) override
;
150 bool IsDisplayContainer() override
{ return true; }
151 gfxMatrix
GetCanvasTM() override
;
155 * Cached canvasTM value.
157 UniquePtr
<gfxMatrix
> mCanvasTM
;
160 } // namespace mozilla
162 #endif // LAYOUT_SVG_SVGCONTAINERFRAME_H_