Bug 886842 - Add clang trunk builds for ASan. r=froydnj
[gecko.git] / layout / svg / nsSVGAFrame.cpp
blob9701a87a173b518480bbc4b85e286b61d5176b7e
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 "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
25 friend nsIFrame*
26 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
27 protected:
28 nsSVGAFrame(nsStyleContext* aContext) :
29 nsSVGAFrameBase(aContext) {}
31 public:
32 NS_DECL_FRAMEARENA_HELPERS
34 #ifdef DEBUG
35 virtual void Init(nsIContent* aContent,
36 nsIFrame* aParent,
37 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
38 #endif
40 // nsIFrame:
41 NS_IMETHOD AttributeChanged(int32_t aNameSpaceID,
42 nsIAtom* aAttribute,
43 int32_t aModType);
45 /**
46 * Get the "type" of the frame
48 * @see nsGkAtoms::svgAFrame
50 virtual nsIAtom* GetType() const;
52 #ifdef DEBUG
53 NS_IMETHOD GetFrameName(nsAString& aResult) const
55 return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult);
57 #endif
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() {
68 return nullptr;
71 private:
72 nsAutoPtr<gfxMatrix> mCanvasTM;
75 //----------------------------------------------------------------------
76 // Implementation
78 nsIFrame*
79 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
81 return new (aPresShell) nsSVGAFrame(aContext);
84 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame)
86 //----------------------------------------------------------------------
87 // nsIFrame methods
88 #ifdef DEBUG
89 void
90 nsSVGAFrame::Init(nsIContent* aContent,
91 nsIFrame* aParent,
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);
100 #endif /* DEBUG */
102 NS_IMETHODIMP
103 nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID,
104 nsIAtom* aAttribute,
105 int32_t aModType)
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);
116 return NS_OK;
119 nsIAtom *
120 nsSVGAFrame::GetType() const
122 return nsGkAtoms::svgAFrame;
125 //----------------------------------------------------------------------
126 // nsISVGChildFrame methods
128 void
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
136 mCanvasTM = nullptr;
139 nsSVGAFrameBase::NotifySVGChanged(aFlags);
142 //----------------------------------------------------------------------
143 // nsSVGContainerFrame methods:
145 gfxMatrix
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);
154 if (!mCanvasTM) {
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);
165 return *mCanvasTM;
168 //----------------------------------------------------------------------
169 // nsSVGTextContainerFrame methods:
171 void
172 nsSVGAFrame::GetXY(SVGUserUnitList *aX, SVGUserUnitList *aY)
174 aX->Clear();
175 aY->Clear();
178 void
179 nsSVGAFrame::GetDxDy(SVGUserUnitList *aDx, SVGUserUnitList *aDy)
181 aDx->Clear();
182 aDy->Clear();