Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/svg/nsSVGMarkerFrame.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_SVGMARKERFRAME_H__
8
#define __NS_SVGMARKERFRAME_H__
9
10
#include "mozilla/Attributes.h"
11
#include "gfxMatrix.h"
12
#include "gfxRect.h"
13
#include "nsFrame.h"
14
#include "nsLiteralString.h"
15
#include "nsQueryFrame.h"
16
#include "nsSVGContainerFrame.h"
17
#include "nsSVGUtils.h"
18
19
class gfxContext;
20
21
namespace mozilla {
22
class SVGGeometryFrame;
23
namespace dom {
24
class SVGViewportElement;
25
} // namespace dom
26
} // namespace mozilla
27
28
struct nsSVGMark;
29
30
class nsSVGMarkerFrame final : public nsSVGContainerFrame
31
{
32
  typedef mozilla::image::imgDrawingParams imgDrawingParams;
33
34
  friend class nsSVGMarkerAnonChildFrame;
35
  friend nsContainerFrame*
36
  NS_NewSVGMarkerFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle);
37
protected:
38
  explicit nsSVGMarkerFrame(ComputedStyle* aStyle)
39
    : nsSVGContainerFrame(aStyle, kClassID)
40
    , mMarkedFrame(nullptr)
41
    , mInUse(false)
42
    , mInUse2(false)
43
0
  {
44
0
    AddStateBits(NS_FRAME_IS_NONDISPLAY);
45
0
  }
46
47
public:
48
  NS_DECL_FRAMEARENA_HELPERS(nsSVGMarkerFrame)
49
50
  // nsIFrame interface:
51
#ifdef DEBUG
52
  virtual void Init(nsIContent*       aContent,
53
                    nsContainerFrame* aParent,
54
                    nsIFrame*         aPrevInFlow) override;
55
#endif
56
57
  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
58
0
                                const nsDisplayListSet& aLists) override {}
59
60
  virtual nsresult AttributeChanged(int32_t         aNameSpaceID,
61
                                    nsAtom*        aAttribute,
62
                                    int32_t         aModType) override;
63
64
#ifdef DEBUG_FRAME_DUMP
65
  virtual nsresult GetFrameName(nsAString& aResult) const override
66
  {
67
    return MakeFrameName(NS_LITERAL_STRING("SVGMarker"), aResult);
68
  }
69
#endif
70
71
0
  virtual nsContainerFrame* GetContentInsertionFrame() override {
72
0
    // Any children must be added to our single anonymous inner frame kid.
73
0
    MOZ_ASSERT(PrincipalChildList().FirstChild() &&
74
0
               PrincipalChildList().FirstChild()->IsSVGMarkerAnonChildFrame(),
75
0
               "Where is our anonymous child?");
76
0
    return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
77
0
  }
78
79
  // nsSVGMarkerFrame methods:
80
  void PaintMark(gfxContext& aContext,
81
                 const gfxMatrix& aToMarkedFrameUserSpace,
82
                 mozilla::SVGGeometryFrame* aMarkedFrame,
83
                 const nsSVGMark& aMark,
84
                 float aStrokeWidth,
85
                 imgDrawingParams& aImgParams);
86
87
  SVGBBox GetMarkBBoxContribution(const Matrix& aToBBoxUserspace,
88
                                  uint32_t aFlags,
89
                                  mozilla::SVGGeometryFrame* aMarkedFrame,
90
                                  const nsSVGMark& aMark,
91
                                  float aStrokeWidth);
92
93
  // Return our anonymous box child.
94
  void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
95
96
private:
97
  // stuff needed for callback
98
  mozilla::SVGGeometryFrame *mMarkedFrame;
99
  Matrix mMarkerTM;
100
101
  // nsSVGContainerFrame methods:
102
  virtual gfxMatrix GetCanvasTM() override;
103
104
  // A helper class to allow us to paint markers safely. The helper
105
  // automatically sets and clears the mInUse flag on the marker frame (to
106
  // prevent nasty reference loops) as well as the reference to the marked
107
  // frame and its coordinate context. It's easy to mess this up
108
  // and break things, so this helper makes the code far more robust.
109
  class MOZ_RAII AutoMarkerReferencer
110
  {
111
  public:
112
    AutoMarkerReferencer(nsSVGMarkerFrame *aFrame,
113
                         mozilla::SVGGeometryFrame *aMarkedFrame
114
                         MOZ_GUARD_OBJECT_NOTIFIER_PARAM);
115
    ~AutoMarkerReferencer();
116
  private:
117
    nsSVGMarkerFrame *mFrame;
118
    MOZ_DECL_USE_GUARD_OBJECT_NOTIFIER
119
  };
120
121
  // nsSVGMarkerFrame methods:
122
  void SetParentCoordCtxProvider(mozilla::dom::SVGViewportElement *aContext);
123
124
  // recursion prevention flag
125
  bool mInUse;
126
127
  // second recursion prevention flag, for GetCanvasTM()
128
  bool mInUse2;
129
};
130
131
////////////////////////////////////////////////////////////////////////
132
// nsMarkerAnonChildFrame class
133
134
class nsSVGMarkerAnonChildFrame final : public nsSVGDisplayContainerFrame
135
{
136
  friend nsContainerFrame*
137
  NS_NewSVGMarkerAnonChildFrame(nsIPresShell* aPresShell,
138
                                ComputedStyle* aStyle);
139
140
  explicit nsSVGMarkerAnonChildFrame(ComputedStyle* aStyle)
141
    : nsSVGDisplayContainerFrame(aStyle, kClassID)
142
0
  {}
143
144
public:
145
  NS_DECL_FRAMEARENA_HELPERS(nsSVGMarkerAnonChildFrame)
146
147
#ifdef DEBUG
148
  virtual void Init(nsIContent*       aContent,
149
                    nsContainerFrame* aParent,
150
                    nsIFrame*         aPrevInFlow) override;
151
#endif
152
153
#ifdef DEBUG_FRAME_DUMP
154
  virtual nsresult GetFrameName(nsAString& aResult) const override {
155
    return MakeFrameName(NS_LITERAL_STRING("SVGMarkerAnonChild"), aResult);
156
  }
157
#endif
158
159
  // nsSVGContainerFrame methods:
160
  virtual gfxMatrix GetCanvasTM() override
161
0
  {
162
0
    return static_cast<nsSVGMarkerFrame*>(GetParent())->GetCanvasTM();
163
0
  }
164
};
165
#endif