Backed out changeset 496886cb30a5 (bug 1867152) for bc failures on browser_user_input...
[gecko.git] / layout / generic / nsCanvasFrame.h
blob6922428a1db953b0673743564ce79afafd94e907
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/. */
7 /* rendering object that goes directly inside the document's scrollbars */
9 #ifndef nsCanvasFrame_h___
10 #define nsCanvasFrame_h___
12 #include "mozilla/Attributes.h"
13 #include "mozilla/EventForwards.h"
14 #include "nsContainerFrame.h"
15 #include "nsDisplayList.h"
16 #include "nsIAnonymousContentCreator.h"
17 #include "nsIPopupContainer.h"
18 #include "nsIScrollPositionListener.h"
20 class nsPresContext;
21 class gfxContext;
23 /**
24 * Root frame class.
26 * The root frame is the parent frame for the document element's frame.
27 * It only supports having a single child frame which must be an area
28 * frame.
29 * @note nsCanvasFrame keeps overflow container continuations of its child
30 * frame in the main child list.
32 class nsCanvasFrame final : public nsContainerFrame,
33 public nsIScrollPositionListener,
34 public nsIAnonymousContentCreator,
35 public nsIPopupContainer {
36 using Element = mozilla::dom::Element;
38 public:
39 explicit nsCanvasFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
40 : nsContainerFrame(aStyle, aPresContext, kClassID),
41 mDoPaintFocus(false),
42 mAddedScrollPositionListener(false) {}
44 NS_DECL_QUERYFRAME
45 NS_DECL_FRAMEARENA_HELPERS(nsCanvasFrame)
47 Element* GetDefaultTooltip() override;
49 void Destroy(DestroyContext&) override;
51 void SetInitialChildList(ChildListID aListID,
52 nsFrameList&& aChildList) override;
53 void AppendFrames(ChildListID aListID, nsFrameList&& aFrameList) override;
54 void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
55 const nsLineList::iterator* aPrevFrameLine,
56 nsFrameList&& aFrameList) override;
57 #ifdef DEBUG
58 void RemoveFrame(DestroyContext&, ChildListID, nsIFrame*) override;
59 #endif
61 nscoord GetMinISize(gfxContext* aRenderingContext) override;
62 nscoord GetPrefISize(gfxContext* aRenderingContext) override;
63 void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
64 const ReflowInput& aReflowInput,
65 nsReflowStatus& aStatus) override;
67 // nsIAnonymousContentCreator
68 nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
69 void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
70 uint32_t aFilter) override;
72 Element* GetCustomContentContainer() const { return mCustomContentContainer; }
74 /**
75 * Unhide the CustomContentContainer. This call only has an effect if
76 * mCustomContentContainer is non-null.
78 void ShowCustomContentContainer();
80 /**
81 * Hide the CustomContentContainer. This call only has an effect if
82 * mCustomContentContainer is non-null.
84 void HideCustomContentContainer();
86 /** SetHasFocus tells the CanvasFrame to draw with focus ring
87 * @param aHasFocus true to show focus ring, false to hide it
89 NS_IMETHOD SetHasFocus(bool aHasFocus);
91 void BuildDisplayList(nsDisplayListBuilder* aBuilder,
92 const nsDisplayListSet& aLists) override;
94 void PaintFocus(mozilla::gfx::DrawTarget* aRenderingContext, nsPoint aPt);
96 // nsIScrollPositionListener
97 void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
98 void ScrollPositionDidChange(nscoord aX, nscoord aY) override {}
100 #ifdef DEBUG_FRAME_DUMP
101 nsresult GetFrameName(nsAString& aResult) const override;
102 #endif
103 nsresult GetContentForEvent(const mozilla::WidgetEvent* aEvent,
104 nsIContent** aContent) override;
106 nsRect CanvasArea() const;
108 protected:
109 // Data members
110 bool mDoPaintFocus;
111 bool mAddedScrollPositionListener;
113 nsCOMPtr<Element> mCustomContentContainer;
114 nsCOMPtr<Element> mTooltipContent;
117 namespace mozilla {
119 * Override nsDisplayBackground methods so that we pass aBGClipRect to
120 * PaintBackground, covering the whole overflow area.
121 * We can also paint an "extra background color" behind the normal
122 * background.
124 class nsDisplayCanvasBackgroundColor final : public nsDisplaySolidColorBase {
125 public:
126 nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder,
127 nsIFrame* aFrame)
128 : nsDisplaySolidColorBase(aBuilder, aFrame, NS_RGBA(0, 0, 0, 0)) {}
130 nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) const override {
131 nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
132 *aSnap = true;
133 return frame->CanvasArea() + ToReferenceFrame();
135 void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
136 HitTestState* aState, nsTArray<nsIFrame*>* aOutFrames) override {
137 // We need to override so we don't consider border-radius.
138 aOutFrames->AppendElement(mFrame);
140 bool CreateWebRenderCommands(
141 mozilla::wr::DisplayListBuilder& aBuilder,
142 mozilla::wr::IpcResourceUpdateQueue& aResources,
143 const StackingContextHelper& aSc,
144 mozilla::layers::RenderRootStateManager* aManager,
145 nsDisplayListBuilder* aDisplayListBuilder) override;
146 void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
148 void SetExtraBackgroundColor(nscolor aColor) { mColor = aColor; }
150 NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
152 void WriteDebugInfo(std::stringstream& aStream) override;
155 class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
156 public:
157 explicit nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder,
158 nsIFrame* aFrame,
159 const InitData& aInitData)
160 : nsDisplayBackgroundImage(aBuilder, aFrame, aInitData) {}
162 void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
164 // We still need to paint a background color as well as an image for this
165 // item, so we can't support this yet.
166 bool SupportsOptimizingToImage() const override { return false; }
168 bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
169 const nsRect& aClipRect, gfxRect* aDestRect);
171 NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
174 class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
175 public:
176 nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder,
177 nsIFrame* aFrame)
178 : nsDisplayThemedBackground(aBuilder, aFrame,
179 aFrame->GetRectRelativeToSelf() +
180 aBuilder->ToReferenceFrame(aFrame)) {
181 nsDisplayThemedBackground::Init(aBuilder);
184 void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
186 NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
189 } // namespace mozilla
191 #endif /* nsCanvasFrame_h___ */