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