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
18 * Crocodile Clips Ltd..
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
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"
42 #include "nsSVGMatrix.h"
43 #include "nsGkAtoms.h"
44 #include "nsSVGUtils.h"
45 #include "nsISVGValueUtils.h"
46 #include "nsSVGGraphicElement.h"
48 //----------------------------------------------------------------------
52 NS_NewSVGGFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
)
54 nsCOMPtr
<nsIDOMSVGTransformable
> transformable
= do_QueryInterface(aContent
);
56 NS_ERROR("Can't create frame. The element doesn't support the right interface\n");
60 return new (aPresShell
) nsSVGGFrame(aContext
);
64 nsSVGGFrame::GetType() const
66 return nsGkAtoms::svgGFrame
;
69 //----------------------------------------------------------------------
70 // nsISVGChildFrame methods
73 nsSVGGFrame::NotifySVGChanged(PRUint32 aFlags
)
75 if (aFlags
& TRANSFORM_CHANGED
) {
76 // make sure our cached transform matrix gets (lazily) updated
80 nsSVGGFrameBase::NotifySVGChanged(aFlags
);
83 already_AddRefed
<nsIDOMSVGMatrix
>
84 nsSVGGFrame::GetCanvasTM()
86 if (!GetMatrixPropagation()) {
87 nsIDOMSVGMatrix
*retval
;
88 NS_NewSVGMatrix(&retval
);
93 // get our parent's tm and append local transforms (if any):
94 NS_ASSERTION(mParent
, "null parent");
95 nsSVGContainerFrame
*containerFrame
= static_cast<nsSVGContainerFrame
*>
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();
106 parentTM
->Multiply(localTM
, getter_AddRefs(mCanvasTM
));
108 mCanvasTM
= parentTM
;
111 nsIDOMSVGMatrix
* retval
= mCanvasTM
.get();
112 NS_IF_ADDREF(retval
);
117 nsSVGGFrame::AttributeChanged(PRInt32 aNameSpaceID
,
121 if (aNameSpaceID
== kNameSpaceID_None
&&
122 aAttribute
== nsGkAtoms::transform
) {
123 // make sure our cached transform matrix gets (lazily) updated
126 nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED
);