Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / svg / base / src / nsSVGUseFrame.cpp
blobcc1afb368564eabca82cd963c4d5bc6c57039f17
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 IBM Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2004
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #include "nsSVGGFrame.h"
38 #include "nsIAnonymousContentCreator.h"
39 #include "nsSVGMatrix.h"
40 #include "nsIDOMSVGUseElement.h"
41 #include "nsIDOMSVGTransformable.h"
42 #include "nsSVGElement.h"
43 #include "nsSVGUseElement.h"
45 typedef nsSVGGFrame nsSVGUseFrameBase;
47 class nsSVGUseFrame : public nsSVGUseFrameBase,
48 public nsIAnonymousContentCreator
50 friend nsIFrame*
51 NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext);
53 protected:
54 nsSVGUseFrame(nsStyleContext* aContext) : nsSVGUseFrameBase(aContext) {}
56 // nsISupports interface:
57 NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
58 private:
59 NS_IMETHOD_(nsrefcnt) AddRef() { return 1; }
60 NS_IMETHOD_(nsrefcnt) Release() { return 1; }
62 public:
63 // nsIFrame interface:
64 NS_IMETHOD AttributeChanged(PRInt32 aNameSpaceID,
65 nsIAtom* aAttribute,
66 PRInt32 aModType);
68 virtual void Destroy();
70 // nsSVGContainerFrame methods:
71 virtual already_AddRefed<nsIDOMSVGMatrix> GetCanvasTM();
73 /**
74 * Get the "type" of the frame
76 * @see nsGkAtoms::svgUseFrame
78 virtual nsIAtom* GetType() const;
80 #ifdef DEBUG
81 NS_IMETHOD GetFrameName(nsAString& aResult) const
83 return MakeFrameName(NS_LITERAL_STRING("SVGUse"), aResult);
85 #endif
87 // nsIAnonymousContentCreator
88 virtual nsresult CreateAnonymousContent(nsTArray<nsIContent*>& aElements);
91 //----------------------------------------------------------------------
92 // Implementation
94 nsIFrame*
95 NS_NewSVGUseFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
97 nsCOMPtr<nsIDOMSVGUseElement> use = do_QueryInterface(aContent);
98 if (!use) {
99 NS_ERROR("Can't create frame! Content is not an SVG use!");
100 return nsnull;
103 return new (aPresShell) nsSVGUseFrame(aContext);
106 nsIAtom *
107 nsSVGUseFrame::GetType() const
109 return nsGkAtoms::svgUseFrame;
112 //----------------------------------------------------------------------
113 // nsISupports methods
115 NS_INTERFACE_MAP_BEGIN(nsSVGUseFrame)
116 NS_INTERFACE_MAP_ENTRY(nsIAnonymousContentCreator)
117 NS_INTERFACE_MAP_END_INHERITING(nsSVGUseFrameBase)
119 //----------------------------------------------------------------------
120 // nsIFrame methods:
122 NS_IMETHODIMP
123 nsSVGUseFrame::AttributeChanged(PRInt32 aNameSpaceID,
124 nsIAtom* aAttribute,
125 PRInt32 aModType)
127 if (aNameSpaceID == kNameSpaceID_None &&
128 (aAttribute == nsGkAtoms::x ||
129 aAttribute == nsGkAtoms::y)) {
130 // make sure our cached transform matrix gets (lazily) updated
131 mCanvasTM = nsnull;
133 nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
134 return NS_OK;
137 return nsSVGUseFrameBase::AttributeChanged(aNameSpaceID,
138 aAttribute, aModType);
141 void
142 nsSVGUseFrame::Destroy()
144 nsRefPtr<nsSVGUseElement> use = static_cast<nsSVGUseElement*>(mContent);
145 nsSVGUseFrameBase::Destroy();
146 use->DestroyAnonymousContent();
150 //----------------------------------------------------------------------
151 // nsSVGContainerFrame methods:
153 already_AddRefed<nsIDOMSVGMatrix>
154 nsSVGUseFrame::GetCanvasTM()
156 if (!GetMatrixPropagation()) {
157 nsIDOMSVGMatrix *retval;
158 NS_NewSVGMatrix(&retval);
159 return retval;
162 nsCOMPtr<nsIDOMSVGMatrix> currentTM = nsSVGUseFrameBase::GetCanvasTM();
164 // x and y:
165 float x, y;
166 nsSVGElement *element = static_cast<nsSVGElement*>(mContent);
167 element->GetAnimatedLengthValues(&x, &y, nsnull);
169 nsCOMPtr<nsIDOMSVGMatrix> fini;
170 currentTM->Translate(x, y, getter_AddRefs(fini));
172 nsIDOMSVGMatrix *retval = fini.get();
173 NS_IF_ADDREF(retval);
174 return retval;
178 //----------------------------------------------------------------------
179 // nsIAnonymousContentCreator methods:
181 nsresult
182 nsSVGUseFrame::CreateAnonymousContent(nsTArray<nsIContent*>& aElements)
184 nsSVGUseElement *use = static_cast<nsSVGUseElement*>(mContent);
186 nsIContent* clone = use->CreateAnonymousContent();
187 if (!clone)
188 return NS_ERROR_FAILURE;
189 if (!aElements.AppendElement(clone))
190 return NS_ERROR_OUT_OF_MEMORY;
191 return NS_OK;