Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / layout / svg / base / src / nsSVGGFrame.cpp
blob03ceb79d1ded1d6d3443daf32fa43bddd3ca751d
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 * Crocodile Clips Ltd..
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Alex Fritze <alex.fritze@crocodile-clips.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 "nsIDOMSVGTransformable.h"
40 #include "nsSVGGFrame.h"
41 #include "nsIFrame.h"
42 #include "nsSVGMatrix.h"
43 #include "nsGkAtoms.h"
44 #include "nsSVGUtils.h"
45 #include "nsISVGValueUtils.h"
46 #include "nsSVGGraphicElement.h"
48 //----------------------------------------------------------------------
49 // Implementation
51 nsIFrame*
52 NS_NewSVGGFrame(nsIPresShell* aPresShell, nsIContent* aContent, nsStyleContext* aContext)
54 nsCOMPtr<nsIDOMSVGTransformable> transformable = do_QueryInterface(aContent);
55 if (!transformable) {
56 NS_ERROR("Can't create frame. The element doesn't support the right interface\n");
57 return nsnull;
60 return new (aPresShell) nsSVGGFrame(aContext);
63 nsIAtom *
64 nsSVGGFrame::GetType() const
66 return nsGkAtoms::svgGFrame;
69 //----------------------------------------------------------------------
70 // nsISVGChildFrame methods
72 void
73 nsSVGGFrame::NotifySVGChanged(PRUint32 aFlags)
75 if (aFlags & TRANSFORM_CHANGED) {
76 // make sure our cached transform matrix gets (lazily) updated
77 mCanvasTM = nsnull;
80 nsSVGGFrameBase::NotifySVGChanged(aFlags);
83 already_AddRefed<nsIDOMSVGMatrix>
84 nsSVGGFrame::GetCanvasTM()
86 if (!GetMatrixPropagation()) {
87 nsIDOMSVGMatrix *retval;
88 NS_NewSVGMatrix(&retval);
89 return retval;
92 if (!mCanvasTM) {
93 // get our parent's tm and append local transforms (if any):
94 NS_ASSERTION(mParent, "null parent");
95 nsSVGContainerFrame *containerFrame = static_cast<nsSVGContainerFrame*>
96 (mParent);
97 nsCOMPtr<nsIDOMSVGMatrix> parentTM = containerFrame->GetCanvasTM();
98 NS_ASSERTION(parentTM, "null TM");
100 // got the parent tm, now check for local tm:
101 nsSVGGraphicElement *element =
102 static_cast<nsSVGGraphicElement*>(mContent);
103 nsCOMPtr<nsIDOMSVGMatrix> localTM = element->GetLocalTransformMatrix();
105 if (localTM)
106 parentTM->Multiply(localTM, getter_AddRefs(mCanvasTM));
107 else
108 mCanvasTM = parentTM;
111 nsIDOMSVGMatrix* retval = mCanvasTM.get();
112 NS_IF_ADDREF(retval);
113 return retval;
116 NS_IMETHODIMP
117 nsSVGGFrame::AttributeChanged(PRInt32 aNameSpaceID,
118 nsIAtom* aAttribute,
119 PRInt32 aModType)
121 if (aNameSpaceID == kNameSpaceID_None &&
122 aAttribute == nsGkAtoms::transform) {
123 // make sure our cached transform matrix gets (lazily) updated
124 mCanvasTM = nsnull;
126 nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED);
129 return NS_OK;