Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/svg/nsSVGOuterSVGFrame.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef __NS_SVGOUTERSVGFRAME_H__
8
#define __NS_SVGOUTERSVGFRAME_H__
9
10
#include "mozilla/Attributes.h"
11
#include "nsAutoPtr.h"
12
#include "nsISVGSVGFrame.h"
13
#include "nsSVGContainerFrame.h"
14
#include "nsRegion.h"
15
16
class gfxContext;
17
class nsSVGForeignObjectFrame;
18
19
////////////////////////////////////////////////////////////////////////
20
// nsSVGOuterSVGFrame class
21
22
class nsSVGOuterSVGFrame final : public nsSVGDisplayContainerFrame
23
                               , public nsISVGSVGFrame
24
{
25
  typedef mozilla::image::imgDrawingParams imgDrawingParams;
26
27
  friend nsContainerFrame*
28
  NS_NewSVGOuterSVGFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle);
29
protected:
30
  explicit nsSVGOuterSVGFrame(ComputedStyle* aStyle);
31
32
public:
33
  NS_DECL_QUERYFRAME
34
  NS_DECL_FRAMEARENA_HELPERS(nsSVGOuterSVGFrame)
35
36
#ifdef DEBUG
37
  ~nsSVGOuterSVGFrame() {
38
    NS_ASSERTION(!mForeignObjectHash || mForeignObjectHash->Count() == 0,
39
                 "foreignObject(s) still registered!");
40
  }
41
#endif
42
43
  // nsIFrame:
44
  virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
45
  virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
46
47
  virtual mozilla::IntrinsicSize GetIntrinsicSize() override;
48
  virtual nsSize  GetIntrinsicRatio() override;
49
50
  virtual mozilla::LogicalSize
51
  ComputeSize(gfxContext *aRenderingContext,
52
              mozilla::WritingMode aWritingMode,
53
              const mozilla::LogicalSize& aCBSize,
54
              nscoord aAvailableISize,
55
              const mozilla::LogicalSize& aMargin,
56
              const mozilla::LogicalSize& aBorder,
57
              const mozilla::LogicalSize& aPadding,
58
              ComputeSizeFlags aFlags) override;
59
60
  virtual void Reflow(nsPresContext*           aPresContext,
61
                      ReflowOutput&     aDesiredSize,
62
                      const ReflowInput& aReflowInput,
63
                      nsReflowStatus&          aStatus) override;
64
65
  virtual void DidReflow(nsPresContext*   aPresContext,
66
                         const ReflowInput*  aReflowInput) override;
67
68
  virtual void UnionChildOverflow(nsOverflowAreas& aOverflowAreas) override;
69
70
  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
71
                                const nsDisplayListSet& aLists) override;
72
73
  virtual void Init(nsIContent*       aContent,
74
                    nsContainerFrame* aParent,
75
                    nsIFrame*         aPrevInFlow) override;
76
77
  bool IsFrameOfType(uint32_t aFlags) const override
78
0
  {
79
0
    return nsSVGDisplayContainerFrame::IsFrameOfType(
80
0
      aFlags & ~eSupportsContainLayoutAndPaint);
81
0
  }
82
83
  virtual nsSplittableType GetSplittableType() const override;
84
85
#ifdef DEBUG_FRAME_DUMP
86
  virtual nsresult GetFrameName(nsAString& aResult) const override
87
  {
88
    return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVG"), aResult);
89
  }
90
#endif
91
92
  virtual nsresult  AttributeChanged(int32_t         aNameSpaceID,
93
                                     nsAtom*        aAttribute,
94
                                     int32_t         aModType) override;
95
96
0
  virtual nsContainerFrame* GetContentInsertionFrame() override {
97
0
    // Any children must be added to our single anonymous inner frame kid.
98
0
    MOZ_ASSERT(PrincipalChildList().FirstChild() &&
99
0
               PrincipalChildList().FirstChild()->IsSVGOuterSVGAnonChildFrame(),
100
0
               "Where is our anonymous child?");
101
0
    return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
102
0
  }
103
104
  bool IsSVGTransformed(Matrix* aOwnTransform,
105
                        Matrix* aFromParentTransform) const override;
106
107
  // Return our anonymous box child.
108
  void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
109
110
  // nsISVGSVGFrame interface:
111
  virtual void NotifyViewportOrTransformChanged(uint32_t aFlags) override;
112
113
  // nsSVGDisplayableFrame methods:
114
  virtual void PaintSVG(gfxContext& aContext,
115
                        const gfxMatrix& aTransform,
116
                        imgDrawingParams& aImgParams,
117
                        const nsIntRect* aDirtyRect = nullptr) override;
118
  virtual SVGBBox GetBBoxContribution(const Matrix &aToBBoxUserspace,
119
                                      uint32_t aFlags) override;
120
121
  // nsSVGContainerFrame methods:
122
  virtual gfxMatrix GetCanvasTM() override;
123
124
  /* Methods to allow descendant nsSVGForeignObjectFrame frames to register and
125
   * unregister themselves with their nearest nsSVGOuterSVGFrame ancestor. This
126
   * is temporary until display list based invalidation is impleented for SVG.
127
   * Maintaining a list of our foreignObject descendants allows us to search
128
   * them for areas that need to be invalidated, without having to also search
129
   * the SVG frame tree for foreignObjects. This is important so that bug 539356
130
   * does not slow down SVG in general (only foreignObjects, until bug 614732 is
131
   * fixed).
132
   */
133
  void RegisterForeignObject(nsSVGForeignObjectFrame* aFrame);
134
  void UnregisterForeignObject(nsSVGForeignObjectFrame* aFrame);
135
136
0
  virtual bool HasChildrenOnlyTransform(Matrix *aTransform) const override {
137
0
    // Our anonymous wrapper child must claim our children-only transforms as
138
0
    // its own so that our real children (the frames it wraps) are transformed
139
0
    // by them, and we must pretend we don't have any children-only transforms
140
0
    // so that our anonymous child is _not_ transformed by them.
141
0
    return false;
142
0
  }
143
144
  /**
145
   * Return true only if the height is unspecified (defaulting to 100%) or else
146
   * the height is explicitly set to a percentage value no greater than 100%.
147
   */
148
  bool VerticalScrollbarNotNeeded() const;
149
150
0
  bool IsCallingReflowSVG() const {
151
0
    return mCallingReflowSVG;
152
0
  }
153
154
  void InvalidateSVG(const nsRegion& aRegion)
155
0
  {
156
0
    if (!aRegion.IsEmpty()) {
157
0
      mInvalidRegion.Or(mInvalidRegion, aRegion);
158
0
      InvalidateFrame();
159
0
    }
160
0
  }
161
162
0
  void ClearInvalidRegion() { mInvalidRegion.SetEmpty(); }
163
164
0
  const nsRegion& GetInvalidRegion() {
165
0
    nsRect rect;
166
0
    if (!IsInvalid(rect)) {
167
0
      mInvalidRegion.SetEmpty();
168
0
    }
169
0
    return mInvalidRegion;
170
0
  }
171
172
  nsRegion FindInvalidatedForeignObjectFrameChildren(nsIFrame* aFrame);
173
174
protected:
175
176
  bool mCallingReflowSVG;
177
178
  /* Returns true if our content is the document element and our document is
179
   * embedded in an HTML 'object' or 'embed' element. Set
180
   * aEmbeddingFrame to obtain the nsIFrame for the embedding HTML element.
181
   */
182
  bool IsRootOfReplacedElementSubDoc(nsIFrame **aEmbeddingFrame = nullptr);
183
184
  /* Returns true if our content is the document element and our document is
185
   * being used as an image.
186
   */
187
  bool IsRootOfImage();
188
189
  // This is temporary until display list based invalidation is implemented for
190
  // SVG.
191
  // A hash-set containing our nsSVGForeignObjectFrame descendants. Note we use
192
  // a hash-set to avoid the O(N^2) behavior we'd get tearing down an SVG frame
193
  // subtree if we were to use a list (see bug 381285 comment 20).
194
  nsAutoPtr<nsTHashtable<nsPtrHashKey<nsSVGForeignObjectFrame> > > mForeignObjectHash;
195
196
  nsRegion mInvalidRegion;
197
198
  float mFullZoom;
199
200
  bool mViewportInitialized;
201
  bool mIsRootContent;
202
};
203
204
////////////////////////////////////////////////////////////////////////
205
// nsSVGOuterSVGAnonChildFrame class
206
207
/**
208
 * nsSVGOuterSVGFrames have a single direct child that is an instance of this
209
 * class, and which is used to wrap their real child frames. Such anonymous
210
 * wrapper frames created from this class exist because SVG frames need their
211
 * GetPosition() offset to be their offset relative to "user space" (in app
212
 * units) so that they can play nicely with nsDisplayTransform. This is fine
213
 * for all SVG frames except for direct children of an nsSVGOuterSVGFrame,
214
 * since an nsSVGOuterSVGFrame can have CSS border and padding (unlike other
215
 * SVG frames). The direct children can't include the offsets due to any such
216
 * border/padding in their mRects since that would break nsDisplayTransform,
217
 * but not including these offsets would break other parts of the Mozilla code
218
 * that assume a frame's mRect contains its border-box-to-parent-border-box
219
 * offset, in particular nsIFrame::GetOffsetTo and the functions that depend on
220
 * it. Wrapping an nsSVGOuterSVGFrame's children in an instance of this class
221
 * with its GetPosition() set to its nsSVGOuterSVGFrame's border/padding offset
222
 * keeps both nsDisplayTransform and nsIFrame::GetOffsetTo happy.
223
 *
224
 * The reason that this class inherit from nsSVGDisplayContainerFrame rather
225
 * than simply from nsContainerFrame is so that we can avoid having special
226
 * handling for these inner wrappers in multiple parts of the SVG code. For
227
 * example, the implementations of IsSVGTransformed and GetCanvasTM assume
228
 * nsSVGContainerFrame instances all the way up to the nsSVGOuterSVGFrame.
229
 */
230
class nsSVGOuterSVGAnonChildFrame final : public nsSVGDisplayContainerFrame
231
{
232
  friend nsContainerFrame*
233
  NS_NewSVGOuterSVGAnonChildFrame(nsIPresShell* aPresShell,
234
                                  ComputedStyle* aStyle);
235
236
  explicit nsSVGOuterSVGAnonChildFrame(ComputedStyle* aStyle)
237
    : nsSVGDisplayContainerFrame(aStyle, kClassID)
238
0
  {}
239
240
public:
241
  NS_DECL_FRAMEARENA_HELPERS(nsSVGOuterSVGAnonChildFrame)
242
243
#ifdef DEBUG
244
  virtual void Init(nsIContent*       aContent,
245
                    nsContainerFrame* aParent,
246
                    nsIFrame*         aPrevInFlow) override;
247
#endif
248
249
  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
250
                                const nsDisplayListSet& aLists) override;
251
252
#ifdef DEBUG_FRAME_DUMP
253
  virtual nsresult GetFrameName(nsAString& aResult) const override {
254
    return MakeFrameName(NS_LITERAL_STRING("SVGOuterSVGAnonChild"), aResult);
255
  }
256
#endif
257
258
  bool IsSVGTransformed(Matrix *aOwnTransform,
259
                        Matrix *aFromParentTransform) const override;
260
261
  // nsSVGContainerFrame methods:
262
0
  virtual gfxMatrix GetCanvasTM() override {
263
0
    // GetCanvasTM returns the transform from an SVG frame to the frame's
264
0
    // nsSVGOuterSVGFrame's content box, so we do not include any x/y offset
265
0
    // set on us for any CSS border or padding on our nsSVGOuterSVGFrame.
266
0
    return static_cast<nsSVGOuterSVGFrame*>(GetParent())->GetCanvasTM();
267
0
  }
268
};
269
270
#endif