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 // Keep in (case-insensitive) order:
9 #include "nsSVGEffects.h"
10 #include "nsSVGGFrame.h"
11 #include "mozilla/dom/SVGSwitchElement.h"
12 #include "nsSVGUtils.h"
14 class nsRenderingContext
;
16 typedef nsSVGGFrame nsSVGSwitchFrameBase
;
18 class nsSVGSwitchFrame
: public nsSVGSwitchFrameBase
21 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
23 nsSVGSwitchFrame(nsStyleContext
* aContext
) :
24 nsSVGSwitchFrameBase(aContext
) {}
27 NS_DECL_FRAMEARENA_HELPERS
30 virtual void Init(nsIContent
* aContent
,
32 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
36 * Get the "type" of the frame
38 * @see nsGkAtoms::svgSwitchFrame
40 virtual nsIAtom
* GetType() const;
43 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const
45 return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult
);
49 virtual void BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
50 const nsRect
& aDirtyRect
,
51 const nsDisplayListSet
& aLists
) MOZ_OVERRIDE
;
53 // nsISVGChildFrame interface:
54 NS_IMETHOD
PaintSVG(nsRenderingContext
* aContext
, const nsIntRect
*aDirtyRect
);
55 NS_IMETHODIMP_(nsIFrame
*) GetFrameForPoint(const nsPoint
&aPoint
);
56 NS_IMETHODIMP_(nsRect
) GetCoveredRegion();
57 virtual void ReflowSVG();
58 virtual SVGBBox
GetBBoxContribution(const gfxMatrix
&aToBBoxUserspace
,
62 nsIFrame
*GetActiveChildFrame();
65 //----------------------------------------------------------------------
69 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
71 return new (aPresShell
) nsSVGSwitchFrame(aContext
);
74 NS_IMPL_FRAMEARENA_HELPERS(nsSVGSwitchFrame
)
78 nsSVGSwitchFrame::Init(nsIContent
* aContent
,
80 nsIFrame
* aPrevInFlow
)
82 NS_ASSERTION(aContent
->IsSVG(nsGkAtoms::svgSwitch
),
83 "Content is not an SVG switch");
85 nsSVGSwitchFrameBase::Init(aContent
, aParent
, aPrevInFlow
);
90 nsSVGSwitchFrame::GetType() const
92 return nsGkAtoms::svgSwitchFrame
;
96 nsSVGSwitchFrame::BuildDisplayList(nsDisplayListBuilder
* aBuilder
,
97 const nsRect
& aDirtyRect
,
98 const nsDisplayListSet
& aLists
)
100 nsIFrame
* kid
= GetActiveChildFrame();
102 BuildDisplayListForChild(aBuilder
, kid
, aDirtyRect
, aLists
);
107 nsSVGSwitchFrame::PaintSVG(nsRenderingContext
* aContext
,
108 const nsIntRect
*aDirtyRect
)
110 NS_ASSERTION(!NS_SVGDisplayListPaintingEnabled() ||
111 (mState
& NS_STATE_SVG_NONDISPLAY_CHILD
),
112 "If display lists are enabled, only painting of non-display "
113 "SVG should take this code path");
115 if (StyleDisplay()->mOpacity
== 0.0)
118 nsIFrame
*kid
= GetActiveChildFrame();
120 nsSVGUtils::PaintFrameWithEffects(aContext
, aDirtyRect
, kid
);
126 NS_IMETHODIMP_(nsIFrame
*)
127 nsSVGSwitchFrame::GetFrameForPoint(const nsPoint
&aPoint
)
129 NS_ASSERTION(!NS_SVGDisplayListHitTestingEnabled() ||
130 (mState
& NS_STATE_SVG_NONDISPLAY_CHILD
),
131 "If display lists are enabled, only hit-testing of non-display "
132 "SVG should take this code path");
134 nsIFrame
*kid
= GetActiveChildFrame();
136 nsISVGChildFrame
* svgFrame
= do_QueryFrame(kid
);
138 return svgFrame
->GetFrameForPoint(aPoint
);
145 NS_IMETHODIMP_(nsRect
)
146 nsSVGSwitchFrame::GetCoveredRegion()
150 nsIFrame
*kid
= GetActiveChildFrame();
152 nsISVGChildFrame
* child
= do_QueryFrame(kid
);
154 rect
= child
->GetCoveredRegion();
161 nsSVGSwitchFrame::ReflowSVG()
163 NS_ASSERTION(nsSVGUtils::OuterSVGIsCallingReflowSVG(this),
164 "This call is probably a wasteful mistake");
166 NS_ABORT_IF_FALSE(!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD
),
167 "ReflowSVG mechanism not designed for this");
169 if (!nsSVGUtils::NeedsReflowSVG(this)) {
173 // If the NS_FRAME_FIRST_REFLOW bit has been removed from our parent frame,
174 // then our outer-<svg> has previously had its initial reflow. In that case
175 // we need to make sure that that bit has been removed from ourself _before_
176 // recursing over our children to ensure that they know too. Otherwise, we
177 // need to remove it _after_ recursing over our children so that they know
178 // the initial reflow is currently underway.
180 bool outerSVGHasHadFirstReflow
=
181 (GetParent()->GetStateBits() & NS_FRAME_FIRST_REFLOW
) == 0;
183 if (outerSVGHasHadFirstReflow
) {
184 mState
&= ~NS_FRAME_FIRST_REFLOW
; // tell our children
187 nsOverflowAreas overflowRects
;
189 nsIFrame
*child
= GetActiveChildFrame();
191 nsISVGChildFrame
* svgChild
= do_QueryFrame(child
);
193 NS_ABORT_IF_FALSE(!(child
->GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD
),
194 "Check for this explicitly in the |if|, then");
195 svgChild
->ReflowSVG();
197 // We build up our child frame overflows here instead of using
198 // nsLayoutUtils::UnionChildOverflow since SVG frame's all use the same
199 // frame list, and we're iterating over that list now anyway.
200 ConsiderChildOverflow(overflowRects
, child
);
204 if (mState
& NS_FRAME_FIRST_REFLOW
) {
205 // Make sure we have our filter property (if any) before calling
206 // FinishAndStoreOverflow (subsequent filter changes are handled off
207 // nsChangeHint_UpdateEffects):
208 nsSVGEffects::UpdateEffects(this);
211 FinishAndStoreOverflow(overflowRects
, mRect
.Size());
213 // Remove state bits after FinishAndStoreOverflow so that it doesn't
214 // invalidate on first reflow:
215 mState
&= ~(NS_FRAME_FIRST_REFLOW
| NS_FRAME_IS_DIRTY
|
216 NS_FRAME_HAS_DIRTY_CHILDREN
);
220 nsSVGSwitchFrame::GetBBoxContribution(const gfxMatrix
&aToBBoxUserspace
,
223 nsIFrame
* kid
= GetActiveChildFrame();
225 nsISVGChildFrame
* svgKid
= do_QueryFrame(kid
);
227 nsIContent
*content
= kid
->GetContent();
228 gfxMatrix transform
= aToBBoxUserspace
;
229 if (content
->IsSVG()) {
230 transform
= static_cast<nsSVGElement
*>(content
)->
231 PrependLocalTransformsTo(aToBBoxUserspace
);
233 return svgKid
->GetBBoxContribution(transform
, aFlags
);
240 nsSVGSwitchFrame::GetActiveChildFrame()
242 nsIContent
*activeChild
=
243 static_cast<mozilla::dom::SVGSwitchElement
*>(mContent
)->GetActiveChild();
246 for (nsIFrame
* kid
= mFrames
.FirstChild(); kid
;
247 kid
= kid
->GetNextSibling()) {
249 if (activeChild
== kid
->GetContent()) {