layout/svg/nsSVGAFrame.cpp

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:8cdfb473e841
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/. */
5
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"
13
14 using namespace mozilla;
15
16 typedef nsSVGDisplayContainerFrame nsSVGAFrameBase;
17
18 class nsSVGAFrame : public nsSVGAFrameBase
19 {
20 friend nsIFrame*
21 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
22 protected:
23 nsSVGAFrame(nsStyleContext* aContext) :
24 nsSVGAFrameBase(aContext) {}
25
26 public:
27 NS_DECL_FRAMEARENA_HELPERS
28
29 #ifdef DEBUG
30 virtual void Init(nsIContent* aContent,
31 nsIFrame* aParent,
32 nsIFrame* aPrevInFlow) MOZ_OVERRIDE;
33 #endif
34
35 // nsIFrame:
36 virtual nsresult AttributeChanged(int32_t aNameSpaceID,
37 nsIAtom* aAttribute,
38 int32_t aModType) MOZ_OVERRIDE;
39
40 /**
41 * Get the "type" of the frame
42 *
43 * @see nsGkAtoms::svgAFrame
44 */
45 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
46
47 #ifdef DEBUG_FRAME_DUMP
48 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE
49 {
50 return MakeFrameName(NS_LITERAL_STRING("SVGA"), aResult);
51 }
52 #endif
53 // nsISVGChildFrame interface:
54 virtual void NotifySVGChanged(uint32_t aFlags) MOZ_OVERRIDE;
55
56 // nsSVGContainerFrame methods:
57 virtual gfxMatrix GetCanvasTM(uint32_t aFor,
58 nsIFrame* aTransformRoot = nullptr) MOZ_OVERRIDE;
59
60 private:
61 nsAutoPtr<gfxMatrix> mCanvasTM;
62 };
63
64 //----------------------------------------------------------------------
65 // Implementation
66
67 nsIFrame*
68 NS_NewSVGAFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
69 {
70 return new (aPresShell) nsSVGAFrame(aContext);
71 }
72
73 NS_IMPL_FRAMEARENA_HELPERS(nsSVGAFrame)
74
75 //----------------------------------------------------------------------
76 // nsIFrame methods
77 #ifdef DEBUG
78 void
79 nsSVGAFrame::Init(nsIContent* aContent,
80 nsIFrame* aParent,
81 nsIFrame* aPrevInFlow)
82 {
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");
86
87 nsSVGAFrameBase::Init(aContent, aParent, aPrevInFlow);
88 }
89 #endif /* DEBUG */
90
91 nsresult
92 nsSVGAFrame::AttributeChanged(int32_t aNameSpaceID,
93 nsIAtom* aAttribute,
94 int32_t aModType)
95 {
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);
103 }
104
105 return NS_OK;
106 }
107
108 nsIAtom *
109 nsSVGAFrame::GetType() const
110 {
111 return nsGkAtoms::svgAFrame;
112 }
113
114 //----------------------------------------------------------------------
115 // nsISVGChildFrame methods
116
117 void
118 nsSVGAFrame::NotifySVGChanged(uint32_t aFlags)
119 {
120 NS_ABORT_IF_FALSE(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
121 "Invalidation logic may need adjusting");
122
123 if (aFlags & TRANSFORM_CHANGED) {
124 // make sure our cached transform matrix gets (lazily) updated
125 mCanvasTM = nullptr;
126 }
127
128 nsSVGAFrameBase::NotifySVGChanged(aFlags);
129 }
130
131 //----------------------------------------------------------------------
132 // nsSVGContainerFrame methods:
133
134 gfxMatrix
135 nsSVGAFrame::GetCanvasTM(uint32_t aFor, nsIFrame* aTransformRoot)
136 {
137 if (!(GetStateBits() & NS_FRAME_IS_NONDISPLAY) && !aTransformRoot) {
138 if ((aFor == FOR_PAINTING && NS_SVGDisplayListPaintingEnabled()) ||
139 (aFor == FOR_HIT_TESTING && NS_SVGDisplayListHitTestingEnabled())) {
140 return nsSVGIntegrationUtils::GetCSSPxToDevPxMatrix(this);
141 }
142 }
143 if (!mCanvasTM) {
144 NS_ASSERTION(mParent, "null parent");
145
146 nsSVGContainerFrame *parent = static_cast<nsSVGContainerFrame*>(mParent);
147 dom::SVGAElement *content = static_cast<dom::SVGAElement*>(mContent);
148
149 gfxMatrix tm = content->PrependLocalTransformsTo(
150 this == aTransformRoot ? gfxMatrix() :
151 parent->GetCanvasTM(aFor, aTransformRoot));
152
153 mCanvasTM = new gfxMatrix(tm);
154 }
155
156 return *mCanvasTM;
157 }

mercurial