Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/generic/nsCanvasFrame.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
/* rendering object that goes directly inside the document's scrollbars */
8
9
#ifndef nsCanvasFrame_h___
10
#define nsCanvasFrame_h___
11
12
#include "mozilla/Attributes.h"
13
#include "mozilla/EventForwards.h"
14
#include "nsContainerFrame.h"
15
#include "nsIScrollPositionListener.h"
16
#include "nsIPopupContainer.h"
17
#include "nsDisplayList.h"
18
#include "nsIAnonymousContentCreator.h"
19
#include "gfxPrefs.h"
20
21
class nsPresContext;
22
class gfxContext;
23
class nsPopupSetFrame;
24
25
/**
26
 * Root frame class.
27
 *
28
 * The root frame is the parent frame for the document element's frame.
29
 * It only supports having a single child frame which must be an area
30
 * frame.
31
 * @note nsCanvasFrame keeps overflow container continuations of its child
32
 * frame in the main child list.
33
 */
34
class nsCanvasFrame final : public nsContainerFrame,
35
                            public nsIScrollPositionListener,
36
                            public nsIAnonymousContentCreator,
37
                            public nsIPopupContainer
38
{
39
public:
40
  explicit nsCanvasFrame(ComputedStyle* aStyle)
41
    : nsContainerFrame(aStyle, kClassID)
42
    , mDoPaintFocus(false)
43
    , mAddedScrollPositionListener(false)
44
    , mPopupSetFrame(nullptr)
45
0
  {}
46
47
  NS_DECL_QUERYFRAME
48
  NS_DECL_FRAMEARENA_HELPERS(nsCanvasFrame)
49
50
  nsPopupSetFrame* GetPopupSetFrame() override;
51
  void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) override;
52
  Element* GetDefaultTooltip() override;
53
  void SetDefaultTooltip(Element* aTooltip) override;
54
55
  virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override;
56
57
  virtual void SetInitialChildList(ChildListID     aListID,
58
                                   nsFrameList&    aChildList) override;
59
  virtual void AppendFrames(ChildListID     aListID,
60
                            nsFrameList&    aFrameList) override;
61
  virtual void InsertFrames(ChildListID     aListID,
62
                            nsIFrame*       aPrevFrame,
63
                            nsFrameList&    aFrameList) override;
64
#ifdef DEBUG
65
  virtual void RemoveFrame(ChildListID     aListID,
66
                           nsIFrame*       aOldFrame) override;
67
#endif
68
69
  virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
70
  virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
71
  virtual void Reflow(nsPresContext*           aPresContext,
72
                      ReflowOutput&     aDesiredSize,
73
                      const ReflowInput& aReflowInput,
74
                      nsReflowStatus&          aStatus) override;
75
  virtual bool IsFrameOfType(uint32_t aFlags) const override
76
0
  {
77
0
    return nsContainerFrame::IsFrameOfType(aFlags &
78
0
             ~(nsIFrame::eCanContainOverflowContainers));
79
0
  }
80
81
  // nsIAnonymousContentCreator
82
  virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
83
  virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter) override;
84
85
  mozilla::dom::Element* GetCustomContentContainer() const
86
0
  {
87
0
    return mCustomContentContainer;
88
0
  }
89
90
  /**
91
   * Unhide the CustomContentContainer. This call only has an effect if
92
   * mCustomContentContainer is non-null.
93
   */
94
  void ShowCustomContentContainer();
95
96
  /**
97
   * Hide the CustomContentContainer. This call only has an effect if
98
   * mCustomContentContainer is non-null.
99
   */
100
  void HideCustomContentContainer();
101
102
  /** SetHasFocus tells the CanvasFrame to draw with focus ring
103
   *  @param aHasFocus true to show focus ring, false to hide it
104
   */
105
  NS_IMETHOD SetHasFocus(bool aHasFocus);
106
107
  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
108
                                const nsDisplayListSet& aLists) override;
109
110
  void PaintFocus(mozilla::gfx::DrawTarget* aRenderingContext, nsPoint aPt);
111
112
  // nsIScrollPositionListener
113
  virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
114
0
  virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override {}
115
116
#ifdef DEBUG_FRAME_DUMP
117
  virtual nsresult GetFrameName(nsAString& aResult) const override;
118
#endif
119
  virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
120
                                      nsIContent** aContent) override;
121
122
  nsRect CanvasArea() const;
123
124
protected:
125
  // Utility function to propagate the WritingMode from our first child to
126
  // 'this' and all its ancestors.
127
  void MaybePropagateRootElementWritingMode();
128
129
  // Data members
130
  bool                      mDoPaintFocus;
131
  bool                      mAddedScrollPositionListener;
132
133
  nsCOMPtr<mozilla::dom::Element> mCustomContentContainer;
134
135
private:
136
  nsPopupSetFrame* mPopupSetFrame;
137
  nsCOMPtr<mozilla::dom::Element> mPopupgroupContent;
138
  nsCOMPtr<mozilla::dom::Element> mTooltipContent;
139
};
140
141
/**
142
 * Override nsDisplayBackground methods so that we pass aBGClipRect to
143
 * PaintBackground, covering the whole overflow area.
144
 * We can also paint an "extra background color" behind the normal
145
 * background.
146
 */
147
class nsDisplayCanvasBackgroundColor final : public nsDisplaySolidColorBase
148
{
149
public:
150
  nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
151
    : nsDisplaySolidColorBase(aBuilder, aFrame, NS_RGBA(0,0,0,0))
152
0
  {
153
0
  }
154
155
  virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
156
                                 nsRegion* aVisibleRegion) override
157
0
  {
158
0
    return NS_GET_A(mColor) > 0;
159
0
  }
160
  virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
161
                           bool* aSnap) const override
162
0
  {
163
0
    nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
164
0
    *aSnap = true;
165
0
    return frame->CanvasArea() + ToReferenceFrame();
166
0
  }
167
  virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
168
                       HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) override
169
0
  {
170
0
    // We need to override so we don't consider border-radius.
171
0
    aOutFrames->AppendElement(mFrame);
172
0
  }
173
  virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
174
                                             LayerManager* aManager,
175
                                             const ContainerLayerParameters& aContainerParameters) override;
176
  virtual bool CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
177
                                       mozilla::wr::IpcResourceUpdateQueue& aResources,
178
                                       const StackingContextHelper& aSc,
179
                                       mozilla::layers::WebRenderLayerManager* aManager,
180
                                       nsDisplayListBuilder* aDisplayListBuilder) override;
181
  virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
182
                                   LayerManager* aManager,
183
                                   const ContainerLayerParameters& aParameters) override
184
0
  {
185
0
    if (ForceActiveLayers()) {
186
0
      return mozilla::LAYER_ACTIVE;
187
0
    }
188
0
    return mozilla::LAYER_NONE;
189
0
  }
190
  virtual void Paint(nsDisplayListBuilder* aBuilder,
191
                     gfxContext* aCtx) override;
192
193
  void SetExtraBackgroundColor(nscolor aColor)
194
0
  {
195
0
    mColor = aColor;
196
0
  }
197
198
  NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
199
#ifdef MOZ_DUMP_PAINTING
200
  virtual void WriteDebugInfo(std::stringstream& aStream) override;
201
#endif
202
};
203
204
class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
205
public:
206
  explicit nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, const InitData& aInitData)
207
    : nsDisplayBackgroundImage(aBuilder, aInitData)
208
0
  {
209
0
  }
210
211
  virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
212
213
  // We still need to paint a background color as well as an image for this item,
214
  // so we can't support this yet.
215
0
  virtual bool SupportsOptimizingToImage() const override { return false; }
216
217
  bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
218
                                  const nsRect& aClipRect,
219
                                  gfxRect* aDestRect);
220
221
222
  NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
223
};
224
225
class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
226
public:
227
  nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
228
    : nsDisplayThemedBackground(aBuilder, aFrame,
229
                                aFrame->GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(aFrame))
230
0
  {
231
0
    nsDisplayThemedBackground::Init(aBuilder);
232
0
  }
233
234
  virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
235
236
  NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
237
};
238
239
#endif /* nsCanvasFrame_h___ */