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 "nsSVGContainerFrame.h"
10 #include "nsSVGIntegrationUtils.h"
11 #include "nsSVGUtils.h"
12 #include "SVGLengthList.h"
14 using namespace mozilla
;
16 typedef nsSVGDisplayContainerFrame nsSVGAFrameBase
;
18 class nsSVGAFrame
: public nsSVGAFrameBase
21 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
);
23 explicit nsSVGAFrame(nsStyleContext
* aContext
) :
24 nsSVGAFrameBase(aContext
) {}
27 NS_DECL_FRAMEARENA_HELPERS
30 virtual void Init(nsIContent
* aContent
,
31 nsContainerFrame
* aParent
,
32 nsIFrame
* aPrevInFlow
) MOZ_OVERRIDE
;
36 virtual nsresult
AttributeChanged(int32_t aNameSpaceID
,
38 int32_t aModType
) MOZ_OVERRIDE
;
41 * Get the "type" of the frame
43 * @see nsGkAtoms::svgAFrame
45 virtual nsIAtom
* GetType() const MOZ_OVERRIDE
;
47 #ifdef DEBUG_FRAME_DUMP
48 virtual nsresult
GetFrameName(nsAString
& aResult
) const MOZ_OVERRIDE
50 return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult
);
53 // nsISVGChildFrame interface:
54 virtual void NotifySVGChanged(uint32_t aFlags
) MOZ_OVERRIDE
;
56 // nsSVGContainerFrame methods:
57 virtual gfxMatrix
GetCanvasTM(uint32_t aFor
,
58 nsIFrame
* aTransformRoot
= nullptr) MOZ_OVERRIDE
;
61 nsAutoPtr
<gfxMatrix
> mCanvasTM
;
64 //----------------------------------------------------------------------
68 NS_NewSVGAFrame(nsIPresShell
* aPresShell
, nsStyleContext
* aContext
)
70 return new (aPresShell
) nsSVGAFrame(aContext
);
73 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame
)
75 //----------------------------------------------------------------------
79 nsSVGAFrame::Init(nsIContent
* aContent
,
80 nsContainerFrame
* aParent
,
81 nsIFrame
* aPrevInFlow
)
83 NS_ASSERTION(aContent
->IsSVG(nsGkAtoms::a
),
84 "Trying to construct an SVGAFrame for a "
85 "content element that doesn't support the right interfaces");
87 nsSVGAFrameBase::Init(aContent
, aParent
, aPrevInFlow
);
92 nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID
,
96 if (aNameSpaceID
== kNameSpaceID_None
&&
97 aAttribute
== nsGkAtoms::transform
) {
98 // We don't invalidate for transform changes (the layers code does that).
99 // Also note that SVGTransformableElement::GetAttributeChangeHint will
100 // return nsChangeHint_UpdateOverflow for "transform" attribute changes
101 // and cause DoApplyRenderingChangeToTree to make the SchedulePaint call.
102 NotifySVGChanged(TRANSFORM_CHANGED
);
109 nsSVGAFrame::GetType() const
111 return nsGkAtoms::svgAFrame
;
114 //----------------------------------------------------------------------
115 // nsISVGChildFrame methods
118 nsSVGAFrame::NotifySVGChanged(uint32_t aFlags
)
120 NS_ABORT_IF_FALSE(aFlags
& (TRANSFORM_CHANGED
| COORD_CONTEXT_CHANGED
),
121 "Invalidation logic may need adjusting");
123 if (aFlags
& TRANSFORM_CHANGED
) {
124 // make sure our cached transform matrix gets (lazily) updated
128 nsSVGAFrameBase::NotifySVGChanged(aFlags
);
131 //----------------------------------------------------------------------
132 // nsSVGContainerFrame methods:
135 nsSVGAFrame::GetCanvasTM(uint32_t aFor
, nsIFrame
* aTransformRoot
)
137 if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY
) && !aTransformRoot
) {
138 if (aFor
== FOR_PAINTING
&& NS_SVGDisplayListPaintingEnabled()) {
139 return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
143 NS_ASSERTION(GetParent(), "null parent");
145 nsSVGContainerFrame
*parent
= static_cast<nsSVGContainerFrame
*>(GetParent());
146 dom::SVGAElement
*content
= static_cast<dom::SVGAElement
*>(mContent
);
148 gfxMatrix tm
= content
->PrependLocalTransformsTo(
149 this == aTransformRoot
? gfxMatrix() :
150 parent
->GetCanvasTM(aFor
, aTransformRoot
));
152 mCanvasTM
= new gfxMatrix(tm
);