1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 // Keep in (case-insensitive) order:
8 #include "mozilla/dom/SVGAElement.h"
9 #include "nsSVGIntegrationUtils.h"
10 #include "nsSVGTSpanFrame.h"
11 #include "nsSVGUtils.h"
12 #include "SVGLengthList.h"
14 // <a> elements can contain text. nsSVGGlyphFrames expect to have
15 // a class derived from nsSVGTextContainerFrame as a parent. We
16 // also need something that implements nsISVGGlyphFragmentNode to get
17 // the text DOM to work.
19 using namespace mozilla
;
21 typedef nsSVGTSpanFrame nsSVGAFrameBase
;
23 class nsSVGAFrame
: public nsSVGAFrameBase
26 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
28 nsSVGAFrame(nsStyleContext
* aContext
) :
29 nsSVGAFrameBase(aContext
) {}
32 NS_DECL_FRAMEARENA_HELPERS
35 virtual void Init(nsIContent
* aContent
,
37 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
41 NS_IMETHOD
AttributeChanged(int32_t aNameSpaceID
,
46 * Get the "type" of the frame
48 * @see nsGkAtoms::svgAFrame
50 virtual nsIAtom
* GetType() const;
53 NS_IMETHOD
GetFrameName(nsAString
& aResult
) const
55 return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult
);
58 // nsISVGChildFrame interface:
59 virtual void NotifySVGChanged(uint32_t aFlags
);
61 // nsSVGContainerFrame methods:
62 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
);
64 // nsSVGTextContainerFrame methods:
65 virtual void GetXY(mozilla::SVGUserUnitList
*aX
, mozilla::SVGUserUnitList
*aY
);
66 virtual void GetDxDy(mozilla::SVGUserUnitList
*aDx
, mozilla::SVGUserUnitList
*aDy
);
67 virtual const SVGNumberList
* GetRotate() {
72 nsAutoPtr
<gfxMatrix
> mCanvasTM
;
75 //----------------------------------------------------------------------
79 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
81 return new (aPresShell
) nsSVGAFrame(aContext
);
84 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame
)
86 //----------------------------------------------------------------------
90 nsSVGAFrame::Init(nsIContent
* aContent
,
92 nsIFrame
* aPrevInFlow
)
94 NS_ASSERTION(aContent
->IsSVG(nsGkAtoms::a
),
95 "Trying to construct an SVGAFrame for a "
96 "content element that doesn't support the right interfaces");
98 nsSVGAFrameBase::Init(aContent
, aParent
, aPrevInFlow
);
103 nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID
,
107 if (aNameSpaceID
== kNameSpaceID_None
&&
108 aAttribute
== nsGkAtoms::transform
) {
109 // We don't invalidate for transform changes (the layers code does that).
110 // Also note that SVGTransformableElement::GetAttributeChangeHint will
111 // return nsChangeHint_UpdateOverflow for "transform" attribute changes
112 // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
113 NotifySVGChanged(TRANSFORM_CHANGED
);
120 nsSVGAFrame::GetType() const
122 return nsGkAtoms::svgAFrame
;
125 //----------------------------------------------------------------------
126 // nsISVGChildFrame methods
129 nsSVGAFrame::NotifySVGChanged(uint32_t aFlags
)
131 NS_ABORT_IF_FALSE(aFlags
& (TRANSFORM_CHANGED
| COORD_CONTEXT_CHANGED
),
132 "Invalidation logic may need adjusting");
134 if (aFlags
& TRANSFORM_CHANGED
) {
135 // make sure our cached transform matrix gets (lazily) updated
139 nsSVGAFrameBase::NotifySVGChanged(aFlags
);
142 //----------------------------------------------------------------------
143 // nsSVGContainerFrame methods:
146 nsSVGAFrame::GetCanvasTM(uint32_t aFor
)
148 if (!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD
)) {
149 if ((aFor
== FOR_PAINTING
&& NS_SVGDisplayListPaintingEnabled()) ||
150 (aFor
== FOR_HIT_TESTING
&& NS_SVGDisplayListHitTestingEnabled())) {
151 return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
155 NS_ASSERTION(mParent
, "null parent");
157 nsSVGContainerFrame
*parent
= static_cast<nsSVGContainerFrame
*>(mParent
);
158 dom::SVGAElement
*content
= static_cast<dom::SVGAElement
*>(mContent
);
160 gfxMatrix tm
= content
->PrependLocalTransformsTo(parent
->GetCanvasTM(aFor
));
162 mCanvasTM
= new gfxMatrix(tm
);
168 //----------------------------------------------------------------------
169 // nsSVGTextContainerFrame methods:
172 nsSVGAFrame::GetXY(SVGUserUnitList
*aX
, SVGUserUnitList
*aY
)
179 nsSVGAFrame::GetDxDy(SVGUserUnitList
*aDx
, SVGUserUnitList
*aDy
)