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_SVGOUTERSVGFRAME_H__
7 #define __NS_SVGOUTERSVGFRAME_H__
9 #include "mozilla/Attributes.h"
10 #include "nsISVGSVGFrame.h"
11 #include "nsSVGContainerFrame.h"
14 class nsSVGForeignObjectFrame
;
16 ////////////////////////////////////////////////////////////////////////
17 // nsSVGOuterSVGFrame class
19 typedef nsSVGDisplayContainerFrame nsSVGOuterSVGFrameBase
;
21 class nsSVGOuterSVGFrame MOZ_FINAL
: public nsSVGOuterSVGFrameBase
,
24 friend nsContainerFrame
*
25 NS_NewSVGOuterSVGFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
27 explicit nsSVGOuterSVGFrame(nsStyleContext
* aContext
);
31 NS_DECL_FRAMEARENA_HELPERS
34 ~nsSVGOuterSVGFrame() {
35 NS_ASSERTION(!mForeignObjectHash
|| mForeignObjectHash
->Count() == 0,
36 "foreignObject(s) still registered!");
41 virtual nscoord
GetMinISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
42 virtual nscoord
GetPrefISize(nsRenderingContext
*aRenderingContext
) MOZ_OVERRIDE
;
44 virtual mozilla::IntrinsicSize
GetIntrinsicSize() MOZ_OVERRIDE
;
45 virtual nsSize
GetIntrinsicRatio() MOZ_OVERRIDE
;
47 virtual mozilla::LogicalSize
48 ComputeSize(nsRenderingContext
*aRenderingContext
,
49 mozilla::WritingMode aWritingMode
,
50 const mozilla::LogicalSize
& aCBSize
,
51 nscoord aAvailableISize
,
52 const mozilla::LogicalSize
& aMargin
,
53 const mozilla::LogicalSize
& aBorder
,
54 const mozilla::LogicalSize
& aPadding
,
55 uint32_t aFlags
) MOZ_OVERRIDE
;
57 virtual void Reflow(nsPresContext
* aPresContext
,
58 nsHTMLReflowMetrics
& aDesiredSize
,
59 const nsHTMLReflowState
& aReflowState
,
60 nsReflowStatus
& aStatus
) MOZ_OVERRIDE
;
62 virtual void DidReflow(nsPresContext
* aPresContext
,
63 const nsHTMLReflowState
* aReflowState
,
64 nsDidReflowStatus aStatus
) MOZ_OVERRIDE
;
66 virtual bool UpdateOverflow() MOZ_OVERRIDE
;
68 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
69 const nsRect
& aDirtyRect
,
70 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
72 virtual void Init(nsIContent
* aContent
,
73 nsContainerFrame
* aParent
,
74 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
76 virtual nsSplittableType
GetSplittableType() const MOZ_OVERRIDE
;
79 * Get the "type" of the frame
81 * @see nsGkAtoms::svgOuterSVGFrame
83 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
85 #ifdef DEBUG_FRAME_DUMP
86 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
88 return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVG"), aResult
);
92 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
94 int32_t aModType
) MOZ_OVERRIDE
;
96 virtual nsContainerFrame
* GetContentInsertionFrame() MOZ_OVERRIDE
{
97 // Any children must be added to our single anonymous inner frame kid.
98 NS_ABORT_IF_FALSE(GetFirstPrincipalChild() &&
99 GetFirstPrincipalChild()->GetType() ==
100 nsGkAtoms::svgOuterSVGAnonChildFrame
,
101 "Where is our anonymous child?");
102 return GetFirstPrincipalChild()->GetContentInsertionFrame();
105 virtual bool IsSVGTransformed(Matrix
*aOwnTransform
,
106 Matrix
*aFromParentTransform
) const MOZ_OVERRIDE
{
107 // Our anonymous wrapper performs the transforms. We simply
108 // return whether we are transformed here but don't apply the transforms
110 return GetFirstPrincipalChild()->IsSVGTransformed();
113 // nsISVGSVGFrame interface:
114 virtual void NotifyViewportOrTransformChanged(uint32_t aFlags
) MOZ_OVERRIDE
;
116 // nsISVGChildFrame methods:
117 virtual nsresult
PaintSVG(nsRenderingContext
* aContext
,
118 const nsIntRect
*aDirtyRect
,
119 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
;
120 virtual SVGBBox
GetBBoxContribution(const Matrix
&aToBBoxUserspace
,
121 uint32_t aFlags
) MOZ_OVERRIDE
;
123 // nsSVGContainerFrame methods:
124 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
125 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
;
127 /* Methods to allow descendant nsSVGForeignObjectFrame frames to register and
128 * unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This
129 * is temporary until display list based invalidation is impleented for SVG.
130 * Maintaining a list of our foreignObject descendants allows us to search
131 * them for areas that need to be invalidated, without having to also search
132 * the SVG frame tree for foreignObjects. This is important so that bug 539356
133 * does not slow down SVG in general (only foreignObjects, until bug 614732 is
136 void RegisterForeignObject(nsSVGForeignObjectFrame
* aFrame
);
137 void UnregisterForeignObject(nsSVGForeignObjectFrame
* aFrame
);
139 virtual bool HasChildrenOnlyTransform(Matrix
*aTransform
) const MOZ_OVERRIDE
{
140 // Our anonymous wrapper child must claim our children-only transforms as
141 // its own so that our real children (the frames it wraps) are transformed
142 // by them, and we must pretend we don't have any children-only transforms
143 // so that our anonymous child is _not_ transformed by them.
148 * Return true only if the height is unspecified (defaulting to 100%) or else
149 * the height is explicitly set to a percentage value no greater than 100%.
151 bool VerticalScrollbarNotNeeded() const;
153 bool IsCallingReflowSVG() const {
154 return mCallingReflowSVG
;
157 void InvalidateSVG(const nsRegion
& aRegion
)
159 if (!aRegion
.IsEmpty()) {
160 mInvalidRegion
.Or(mInvalidRegion
, aRegion
);
165 void ClearInvalidRegion() { mInvalidRegion
.SetEmpty(); }
167 const nsRegion
& GetInvalidRegion() {
169 if (!IsInvalid(rect
)) {
170 mInvalidRegion
.SetEmpty();
172 return mInvalidRegion
;
175 nsRegion
FindInvalidatedForeignObjectFrameChildren(nsIFrame
* aFrame
);
179 bool mCallingReflowSVG
;
181 /* Returns true if our content is the document element and our document is
182 * embedded in an HTML 'object', 'embed' or 'applet' element. Set
183 * aEmbeddingFrame to obtain the nsIFrame for the embedding HTML element.
185 bool IsRootOfReplacedElementSubDoc(nsIFrame
**aEmbeddingFrame
= nullptr);
187 /* Returns true if our content is the document element and our document is
188 * being used as an image.
190 bool IsRootOfImage();
192 // This is temporary until display list based invalidation is implemented for
194 // A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use
195 // a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame
196 // subtree if we were to use a list (see bug 381285 comment 20).
197 nsAutoPtr
<nsTHashtable
<nsPtrHashKey
<nsSVGForeignObjectFrame
> > > mForeignObjectHash
;
199 nsAutoPtr
<gfxMatrix
> mCanvasTM
;
201 nsRegion mInvalidRegion
;
205 bool mViewportInitialized
;
209 ////////////////////////////////////////////////////////////////////////
210 // nsSVGOuterSVGAnonChildFrame class
212 typedef nsSVGDisplayContainerFrame nsSVGOuterSVGAnonChildFrameBase
;
215 * nsSVGOuterSVGFrames have a single direct child that is an instance of this
216 * class, and which is used to wrap their real child frames. Such anonymous
217 * wrapper frames created from this class exist because SVG frames need their
218 * GetPosition() offset to be their offset relative to "user space" (in app
219 * units) so that they can play nicely with nsDisplayTransform. This is fine
220 * for all SVG frames except for direct children of an nsSVGOuterSVGFrame,
221 * since an nsSVGOuterSVGFrame can have CSS border and padding (unlike other
222 * SVG frames). The direct children can't include the offsets due to any such
223 * border/padding in their mRects since that would break nsDisplayTransform,
224 * but not including these offsets would break other parts of the Mozilla code
225 * that assume a frame's mRect contains its border-box-to-parent-border-box
226 * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
227 * it. Wrapping an nsSVGOuterSVGFrame's children in an instance of this class
228 * with its GetPosition() set to its nsSVGOuterSVGFrame's border/padding offset
229 * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
231 * The reason that this class inherit from nsSVGDisplayContainerFrame rather
232 * than simply from nsContainerFrame is so that we can avoid having special
233 * handling for these inner wrappers in multiple parts of the SVG code. For
234 * example, the implementations of IsSVGTransformed and GetCanvasTM assume
235 * nsSVGContainerFrame instances all the way up to the nsSVGOuterSVGFrame.
237 class nsSVGOuterSVGAnonChildFrame
238 : public nsSVGOuterSVGAnonChildFrameBase
240 friend nsContainerFrame
*
241 NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell
* aPresShell
,
242 nsStyleContext
* aContext
);
244 explicit nsSVGOuterSVGAnonChildFrame(nsStyleContext
* aContext
)
245 : nsSVGOuterSVGAnonChildFrameBase(aContext
)
249 NS_DECL_FRAMEARENA_HELPERS
252 virtual void Init(nsIContent
* aContent
,
253 nsContainerFrame
* aParent
,
254 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
257 #ifdef DEBUG_FRAME_DUMP
258 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
{
259 return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVGAnonChild"), aResult
);
264 * Get the "type" of the frame
266 * @see nsGkAtoms::svgOuterSVGAnonChildFrame
268 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
270 // nsSVGContainerFrame methods:
271 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
272 nsIFrame
* aTransformRoot
) MOZ_OVERRIDE
{
273 // GetCanvasTM returns the transform from an SVG frame to the frame's
274 // nsSVGOuterSVGFrame's content box, so we do not include any x/y offset
275 // set on us for any CSS border or padding on our nsSVGOuterSVGFrame.
276 return static_cast<nsSVGOuterSVGFrame
*>(GetParent())->GetCanvasTM(aFor
, aTransformRoot
);
279 virtual bool HasChildrenOnlyTransform(Matrix
*aTransform
) const MOZ_OVERRIDE
;