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
;
80 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
81 const nsDisplayListSet
& aLists
) override
{}
83 bool ComputeCustomOverflow(mozilla::OverflowAreas
& aOverflowAreas
) override
;
87 * Traverses a frame tree, marking any SVGTextFrame frames as dirty
88 * and calling InvalidateRenderingObservers() on it.
90 static void ReflowSVGNonDisplayText(nsIFrame
* aContainer
);
94 * Frame class or base-class for SVG containers that can or do display their
99 * This class's methods can *not* assume that mContent points to an instance of
100 * an SVG element class since this class is inherited by
101 * SVGGenericContainerFrame which is used for unrecognized elements in the
102 * SVG namespace. Do *not* blindly cast to SVG element types.
104 class SVGDisplayContainerFrame
: public SVGContainerFrame
,
105 public ISVGDisplayableFrame
{
107 SVGDisplayContainerFrame(ComputedStyle
* aStyle
, nsPresContext
* aPresContext
,
108 nsIFrame::ClassID aID
)
109 : SVGContainerFrame(aStyle
, aPresContext
, aID
) {
110 AddStateBits(NS_FRAME_MAY_BE_TRANSFORMED
);
115 NS_DECL_QUERYFRAME_TARGET(SVGDisplayContainerFrame
)
116 NS_DECL_ABSTRACT_FRAME(SVGDisplayContainerFrame
)
119 void DidSetComputedStyle(ComputedStyle
*) override
;
120 void InsertFrames(ChildListID aListID
, nsIFrame
* aPrevFrame
,
121 const nsLineList::iterator
* aPrevFrameLine
,
122 nsFrameList
&& aFrameList
) override
;
123 void RemoveFrame(DestroyContext
&, ChildListID
, nsIFrame
*) override
;
124 void Init(nsIContent
* aContent
, nsContainerFrame
* aParent
,
125 nsIFrame
* aPrevInFlow
) override
;
127 void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
128 const nsDisplayListSet
& aLists
) override
;
130 bool DoGetParentSVGTransforms(Matrix
*) const override
;
132 // ISVGDisplayableFrame interface:
133 void PaintSVG(gfxContext
& aContext
, const gfxMatrix
& aTransform
,
134 imgDrawingParams
& aImgParams
) override
;
135 nsIFrame
* GetFrameForPoint(const gfxPoint
& aPoint
) override
;
136 void ReflowSVG() override
;
137 void NotifySVGChanged(uint32_t aFlags
) override
;
138 SVGBBox
GetBBoxContribution(const Matrix
& aToBBoxUserspace
,
139 uint32_t aFlags
) override
;
140 bool IsDisplayContainer() override
{ return true; }
141 gfxMatrix
GetCanvasTM() override
;
145 * Cached canvasTM value.
147 UniquePtr
<gfxMatrix
> mCanvasTM
;
150 } // namespace mozilla
152 #endif // LAYOUT_SVG_SVGCONTAINERFRAME_H_