1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is the Mozilla SVG project.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
23 * Robert Longson <longsonr@gmail.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "nsSVGGFrame.h"
40 #include "nsSVGSwitchElement.h"
41 #include "nsIDOMSVGRect.h"
43 typedef nsSVGGFrame nsSVGSwitchFrameBase
;
45 class nsSVGSwitchFrame
: public nsSVGSwitchFrameBase
48 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
);
50 nsSVGSwitchFrame(nsStyleContext
* aContext
) :
51 nsSVGSwitchFrameBase(aContext
) {}
55 * Get the "type" of the frame
57 * @see nsGkAtoms::svgSwitchFrame
59 virtual nsIAtom
* GetType() const;
62 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const
64 return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult
);
68 // nsISVGChildFrame interface:
69 NS_IMETHOD
PaintSVG(nsSVGRenderState
* aContext
, const nsIntRect
*aDirtyRect
);
70 NS_IMETHODIMP_(nsIFrame
*) GetFrameForPoint(const nsPoint
&aPoint
);
71 NS_IMETHODIMP_(nsRect
) GetCoveredRegion();
72 NS_IMETHOD
UpdateCoveredRegion();
73 NS_IMETHOD
InitialUpdate();
74 NS_IMETHOD
NotifyRedrawUnsuspended();
75 NS_IMETHOD
GetBBox(nsIDOMSVGRect
**aRect
);
78 nsIFrame
*GetActiveChildFrame();
81 //----------------------------------------------------------------------
85 NS_NewSVGSwitchFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
)
87 nsCOMPtr
<nsIDOMSVGSwitchElement
> svgSwitch
= do_QueryInterface(aContent
);
89 NS_ERROR("Can't create frame. Content is not an SVG switch\n");
93 return new (aPresShell
) nsSVGSwitchFrame(aContext
);
97 nsSVGSwitchFrame::GetType() const
99 return nsGkAtoms::svgSwitchFrame
;
103 nsSVGSwitchFrame::PaintSVG(nsSVGRenderState
* aContext
,
104 const nsIntRect
*aDirtyRect
)
106 const nsStyleDisplay
*display
= mStyleContext
->GetStyleDisplay();
107 if (display
->mOpacity
== 0.0)
110 nsIFrame
*kid
= GetActiveChildFrame();
112 nsSVGUtils::PaintFrameWithEffects(aContext
, aDirtyRect
, kid
);
118 NS_IMETHODIMP_(nsIFrame
*)
119 nsSVGSwitchFrame::GetFrameForPoint(const nsPoint
&aPoint
)
121 nsIFrame
*kid
= GetActiveChildFrame();
123 nsISVGChildFrame
* svgFrame
;
124 CallQueryInterface(kid
, &svgFrame
);
126 return svgFrame
->GetFrameForPoint(aPoint
);
133 NS_IMETHODIMP_(nsRect
)
134 nsSVGSwitchFrame::GetCoveredRegion()
138 nsIFrame
*kid
= GetActiveChildFrame();
140 nsISVGChildFrame
* child
= nsnull
;
141 CallQueryInterface(kid
, &child
);
143 rect
= child
->GetCoveredRegion();
150 nsSVGSwitchFrame::UpdateCoveredRegion()
152 static_cast<nsSVGSwitchElement
*>(mContent
)->UpdateActiveChild();
154 return nsSVGSwitchFrameBase::UpdateCoveredRegion();
158 nsSVGSwitchFrame::InitialUpdate()
160 nsSVGUtils::UpdateGraphic(this);
162 return nsSVGSwitchFrameBase::InitialUpdate();
166 nsSVGSwitchFrame::NotifyRedrawUnsuspended()
168 if (GetStateBits() & NS_STATE_SVG_DIRTY
)
169 nsSVGUtils::UpdateGraphic(this);
171 return nsSVGSwitchFrameBase::NotifyRedrawUnsuspended();
175 nsSVGSwitchFrame::GetBBox(nsIDOMSVGRect
**aRect
)
179 nsIFrame
*kid
= GetActiveChildFrame();
181 nsISVGChildFrame
* svgFrame
= nsnull
;
182 CallQueryInterface(kid
, &svgFrame
);
184 nsCOMPtr
<nsIDOMSVGRect
> box
;
185 svgFrame
->GetBBox(getter_AddRefs(box
));
192 return NS_ERROR_FAILURE
;
196 nsSVGSwitchFrame::GetActiveChildFrame()
198 nsIContent
*activeChild
=
199 static_cast<nsSVGSwitchElement
*>(mContent
)->GetActiveChild();
202 for (nsIFrame
* kid
= mFrames
.FirstChild(); kid
;
203 kid
= kid
->GetNextSibling()) {
205 if (activeChild
== kid
->GetContent()) {