Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / svg / base / src / nsSVGSwitchFrame.cpp
blob5e5ffeacb7d5f8d35ad9fd83cbaac291a9f8343a
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
13 * License.
15 * The Original Code is the Mozilla SVG project.
17 * The Initial Developer of the Original Code is
18 * Robert Longson
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
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
47 friend nsIFrame*
48 NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
49 protected:
50 nsSVGSwitchFrame(nsStyleContext* aContext) :
51 nsSVGSwitchFrameBase(aContext) {}
53 public:
54 /**
55 * Get the "type" of the frame
57 * @see nsGkAtoms::svgSwitchFrame
59 virtual nsIAtom* GetType() const;
61 #ifdef DEBUG
62 NS_IMETHOD GetFrameName(nsAString& aResult) const
64 return MakeFrameName(NS_LITERAL_STRING("SVGSwitch"), aResult);
66 #endif
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);
77 private:
78 nsIFrame *GetActiveChildFrame();
81 //----------------------------------------------------------------------
82 // Implementation
84 nsIFrame*
85 NS_NewSVGSwitchFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
87 nsCOMPtr<nsIDOMSVGSwitchElement> svgSwitch = do_QueryInterface(aContent);
88 if (!svgSwitch) {
89 NS_ERROR("Can't create frame. Content is not an SVG switch\n");
90 return nsnull;
93 return new (aPresShell) nsSVGSwitchFrame(aContext);
96 nsIAtom *
97 nsSVGSwitchFrame::GetType() const
99 return nsGkAtoms::svgSwitchFrame;
102 NS_IMETHODIMP
103 nsSVGSwitchFrame::PaintSVG(nsSVGRenderState* aContext,
104 const nsIntRect *aDirtyRect)
106 const nsStyleDisplay *display = mStyleContext->GetStyleDisplay();
107 if (display->mOpacity == 0.0)
108 return NS_OK;
110 nsIFrame *kid = GetActiveChildFrame();
111 if (kid) {
112 nsSVGUtils::PaintFrameWithEffects(aContext, aDirtyRect, kid);
114 return NS_OK;
118 NS_IMETHODIMP_(nsIFrame*)
119 nsSVGSwitchFrame::GetFrameForPoint(const nsPoint &aPoint)
121 nsIFrame *kid = GetActiveChildFrame();
122 if (kid) {
123 nsISVGChildFrame* svgFrame;
124 CallQueryInterface(kid, &svgFrame);
125 if (svgFrame) {
126 return svgFrame->GetFrameForPoint(aPoint);
130 return nsnull;
133 NS_IMETHODIMP_(nsRect)
134 nsSVGSwitchFrame::GetCoveredRegion()
136 nsRect rect;
138 nsIFrame *kid = GetActiveChildFrame();
139 if (kid) {
140 nsISVGChildFrame* child = nsnull;
141 CallQueryInterface(kid, &child);
142 if (child) {
143 rect = child->GetCoveredRegion();
146 return rect;
149 NS_IMETHODIMP
150 nsSVGSwitchFrame::UpdateCoveredRegion()
152 static_cast<nsSVGSwitchElement*>(mContent)->UpdateActiveChild();
154 return nsSVGSwitchFrameBase::UpdateCoveredRegion();
157 NS_IMETHODIMP
158 nsSVGSwitchFrame::InitialUpdate()
160 nsSVGUtils::UpdateGraphic(this);
162 return nsSVGSwitchFrameBase::InitialUpdate();
165 NS_IMETHODIMP
166 nsSVGSwitchFrame::NotifyRedrawUnsuspended()
168 if (GetStateBits() & NS_STATE_SVG_DIRTY)
169 nsSVGUtils::UpdateGraphic(this);
171 return nsSVGSwitchFrameBase::NotifyRedrawUnsuspended();
174 NS_IMETHODIMP
175 nsSVGSwitchFrame::GetBBox(nsIDOMSVGRect **aRect)
177 *aRect = nsnull;
179 nsIFrame *kid = GetActiveChildFrame();
180 if (kid) {
181 nsISVGChildFrame* svgFrame = nsnull;
182 CallQueryInterface(kid, &svgFrame);
183 if (svgFrame) {
184 nsCOMPtr<nsIDOMSVGRect> box;
185 svgFrame->GetBBox(getter_AddRefs(box));
186 if (box) {
187 box.swap(*aRect);
188 return NS_OK;
192 return NS_ERROR_FAILURE;
195 nsIFrame *
196 nsSVGSwitchFrame::GetActiveChildFrame()
198 nsIContent *activeChild =
199 static_cast<nsSVGSwitchElement*>(mContent)->GetActiveChild();
201 if (activeChild) {
202 for (nsIFrame* kid = mFrames.FirstChild(); kid;
203 kid = kid->GetNextSibling()) {
205 if (activeChild == kid->GetContent()) {
206 return kid;
210 return nsnull;