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 // Don't invalidate (the layers code does that).
110 NotifySVGChanged(TRANSFORM_CHANGED
);
118 nsSVGAFrame::GetType() const
120 return nsGkAtoms::svgAFrame
;
123 //----------------------------------------------------------------------
124 // nsISVGChildFrame methods
127 nsSVGAFrame::NotifySVGChanged(uint32_t aFlags
)
129 NS_ABORT_IF_FALSE(aFlags
& (TRANSFORM_CHANGED
| COORD_CONTEXT_CHANGED
),
130 "Invalidation logic may need adjusting");
132 if (aFlags
& TRANSFORM_CHANGED
) {
133 // make sure our cached transform matrix gets (lazily) updated
137 nsSVGAFrameBase::NotifySVGChanged(aFlags
);
140 //----------------------------------------------------------------------
141 // nsSVGContainerFrame methods:
144 nsSVGAFrame::GetCanvasTM(uint32_t aFor
)
146 if (!(GetStateBits() & NS_STATE_SVG_NONDISPLAY_CHILD
)) {
147 if ((aFor
== FOR_PAINTING
&& NS_SVGDisplayListPaintingEnabled()) ||
148 (aFor
== FOR_HIT_TESTING
&& NS_SVGDisplayListHitTestingEnabled())) {
149 return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
153 NS_ASSERTION(mParent
, "null parent");
155 nsSVGContainerFrame
*parent
= static_cast<nsSVGContainerFrame
*>(mParent
);
156 dom::SVGAElement
*content
= static_cast<dom::SVGAElement
*>(mContent
);
158 gfxMatrix tm
= content
->PrependLocalTransformsTo(parent
->GetCanvasTM(aFor
));
160 mCanvasTM
= new gfxMatrix(tm
);
166 //----------------------------------------------------------------------
167 // nsSVGTextContainerFrame methods:
170 nsSVGAFrame::GetXY(SVGUserUnitList
*aX
, SVGUserUnitList
*aY
)
177 nsSVGAFrame::GetDxDy(SVGUserUnitList
*aDx
, SVGUserUnitList
*aDy
)