Bug 867089 - Validate the playbackRate before using it. r=ehsan
[gecko.git] / layout / svg / nsSVGAFrame.cpp
blob1739250b57dff30e6d5d5d2cc142d8653ed37294
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 // Don't invalidate (the layers code does that).
110 NotifySVGChanged(TRANSFORM_CHANGED);
111 SchedulePaint();
114 return NS_OK;
117 nsIAtom *
118 nsSVGAFrame::GetType() const
120 return nsGkAtoms::svgAFrame;
123 //----------------------------------------------------------------------
124 // nsISVGChildFrame methods
126 void
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
134 mCanvasTM = nullptr;
137 nsSVGAFrameBase::NotifySVGChanged(aFlags);
140 //----------------------------------------------------------------------
141 // nsSVGContainerFrame methods:
143 gfxMatrix
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);
152 if (!mCanvasTM) {
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);
163 return *mCanvasTM;
166 //----------------------------------------------------------------------
167 // nsSVGTextContainerFrame methods:
169 void
170 nsSVGAFrame::GetXY(SVGUserUnitList *aX, SVGUserUnitList *aY)
172 aX->Clear();
173 aY->Clear();
176 void
177 nsSVGAFrame::GetDxDy(SVGUserUnitList *aDx, SVGUserUnitList *aDy)
179 aDx->Clear();
180 aDy->Clear();