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 "nsSVGTSpanFrame.h"
40 #include "nsISVGGlyphFragmentNode.h"
41 #include "nsSVGGraphicElement.h"
42 #include "nsSVGMatrix.h"
43 #include "nsIDOMSVGAElement.h"
44 #include "nsSVGUtils.h"
46 // <a> elements can contain text. nsSVGGlyphFrames expect to have
47 // a class derived from nsSVGTextContainerFrame as a parent. We
48 // also need something that implements nsISVGGlyphFragmentNode to get
49 // the text DOM to work.
51 typedef nsSVGTSpanFrame nsSVGAFrameBase
;
53 class nsSVGAFrame
: public nsSVGAFrameBase
56 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
,
57 nsStyleContext
* aContext
);
59 nsSVGAFrame(nsStyleContext
* aContext
) :
60 nsSVGAFrameBase(aContext
) {}
64 NS_IMETHOD
AttributeChanged(PRInt32 aNameSpaceID
,
69 * Get the "type" of the frame
71 * @see nsGkAtoms::svgAFrame
73 virtual nsIAtom
* GetType() const;
76 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const
78 return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult
);
81 // nsISVGChildFrame interface:
82 virtual void NotifySVGChanged(PRUint32 aFlags
);
84 // nsSVGContainerFrame methods:
85 virtual already_AddRefed
<nsIDOMSVGMatrix
> GetCanvasTM();
88 nsCOMPtr
<nsIDOMSVGMatrix
> mCanvasTM
;
91 //----------------------------------------------------------------------
95 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsIContent
* aContent
, nsStyleContext
* aContext
)
97 nsCOMPtr
<nsIDOMSVGAElement
> elem
= do_QueryInterface(aContent
);
99 NS_ERROR("Trying to construct an SVGAFrame for a "
100 "content element that doesn't support the right interfaces");
104 return new (aPresShell
) nsSVGAFrame(aContext
);
107 //----------------------------------------------------------------------
111 nsSVGAFrame::AttributeChanged(PRInt32 aNameSpaceID
,
115 if (aNameSpaceID
!= kNameSpaceID_None
)
118 if (aAttribute
== nsGkAtoms::transform
) {
119 // transform has changed
121 // make sure our cached transform matrix gets (lazily) updated
124 nsSVGUtils::NotifyChildrenOfSVGChange(this, TRANSFORM_CHANGED
);
131 nsSVGAFrame::GetType() const
133 return nsGkAtoms::svgAFrame
;
136 //----------------------------------------------------------------------
137 // nsISVGChildFrame methods
140 nsSVGAFrame::NotifySVGChanged(PRUint32 aFlags
)
142 if (aFlags
& TRANSFORM_CHANGED
) {
143 // make sure our cached transform matrix gets (lazily) updated
147 nsSVGAFrameBase::NotifySVGChanged(aFlags
);
150 //----------------------------------------------------------------------
151 // nsSVGContainerFrame methods:
153 already_AddRefed
<nsIDOMSVGMatrix
>
154 nsSVGAFrame::GetCanvasTM()
156 if (!GetMatrixPropagation()) {
157 nsIDOMSVGMatrix
*retval
;
158 NS_NewSVGMatrix(&retval
);
163 // get our parent's tm and append local transforms (if any):
164 NS_ASSERTION(mParent
, "null parent");
165 nsSVGContainerFrame
*containerFrame
= static_cast<nsSVGContainerFrame
*>
167 nsCOMPtr
<nsIDOMSVGMatrix
> parentTM
= containerFrame
->GetCanvasTM();
168 NS_ASSERTION(parentTM
, "null TM");
170 // got the parent tm, now check for local tm:
171 nsSVGGraphicElement
*element
=
172 static_cast<nsSVGGraphicElement
*>(mContent
);
173 nsCOMPtr
<nsIDOMSVGMatrix
> localTM
= element
->GetLocalTransformMatrix();
176 parentTM
->Multiply(localTM
, getter_AddRefs(mCanvasTM
));
178 mCanvasTM
= parentTM
;
181 nsIDOMSVGMatrix
* retval
= mCanvasTM
.get();
182 NS_IF_ADDREF(retval
);