Bumping manifests a=b2g-bump
[gecko.git] / layout / svg / nsSVGAFrame.cpp
blobc7d9fd294ddb00eda39b2e2254416ced08bcea3e
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:
7 #include "gfxMatrix.h"
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
20 friend nsIFrame*
21 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
22 protected:
23 explicit nsSVGAFrame(nsStyleContext* aContext) :
24 nsSVGAFrameBase(aContext) {}
26 public:
27 NS_DECL_FRAMEARENA_HELPERS
29 #ifdef DEBUG
30 virtual void Init(nsIContent* aContent,
31 nsContainerFrame* aParent,
32 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
33 #endif
35 // nsIFrame:
36 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
37 nsIAtom* aAttribute,
38 int32_t aModType) MOZ_OVERRIDE;
40 /**
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);
52 #endif
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;
60 private:
61 nsAutoPtr<gfxMatrix> mCanvasTM;
64 //----------------------------------------------------------------------
65 // Implementation
67 nsIFrame*
68 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
70 return new (aPresShell) nsSVGAFrame(aContext);
73 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame)
75 //----------------------------------------------------------------------
76 // nsIFrame methods
77 #ifdef DEBUG
78 void
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);
89 #endif /* DEBUG */
91 nsresult
92 nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID,
93 nsIAtom* aAttribute,
94 int32_t aModType)
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);
105 return NS_OK;
108 nsIAtom *
109 nsSVGAFrame::GetType() const
111 return nsGkAtoms::svgAFrame;
114 //----------------------------------------------------------------------
115 // nsISVGChildFrame methods
117 void
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
125 mCanvasTM = nullptr;
128 nsSVGAFrameBase::NotifySVGChanged(aFlags);
131 //----------------------------------------------------------------------
132 // nsSVGContainerFrame methods:
134 gfxMatrix
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);
142 if (!mCanvasTM) {
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);
155 return *mCanvasTM;