Bumping manifests a=b2g-bump
[gecko.git] / layout / generic / nsCanvasFrame.h
blobb23803872c3960b9ec87f06c4de28e7ec4e315cf
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/. */
6 /* rendering object that goes directly inside the document's scrollbars */
8 #ifndef nsCanvasFrame_h___
9 #define nsCanvasFrame_h___
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 "nsIDOMEventListener.h"
19 class nsPresContext;
20 class nsRenderingContext;
22 /**
23 * Root frame class.
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
29 class nsCanvasFrame MOZ_FINAL : public nsContainerFrame,
30 public nsIScrollPositionListener,
31 public nsIAnonymousContentCreator
33 public:
34 explicit nsCanvasFrame(nsStyleContext* aContext)
35 : nsContainerFrame(aContext),
36 mDoPaintFocus(false),
37 mAddedScrollPositionListener(false) {}
39 NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
40 NS_DECL_QUERYFRAME
41 NS_DECL_FRAMEARENA_HELPERS
44 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
46 virtual mozilla::WritingMode GetWritingMode() const MOZ_OVERRIDE
48 nsIContent* rootElem = GetContent();
49 if (rootElem) {
50 nsIFrame* rootElemFrame = rootElem->GetPrimaryFrame();
51 if (rootElemFrame) {
52 return rootElemFrame->GetWritingMode();
55 return nsIFrame::GetWritingMode();
58 #ifdef DEBUG
59 virtual void SetInitialChildList(ChildListID aListID,
60 nsFrameList& aChildList) MOZ_OVERRIDE;
61 virtual void AppendFrames(ChildListID aListID,
62 nsFrameList& aFrameList) MOZ_OVERRIDE;
63 virtual void InsertFrames(ChildListID aListID,
64 nsIFrame* aPrevFrame,
65 nsFrameList& aFrameList) MOZ_OVERRIDE;
66 virtual void RemoveFrame(ChildListID aListID,
67 nsIFrame* aOldFrame) MOZ_OVERRIDE;
68 #endif
70 virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
71 virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
72 virtual void Reflow(nsPresContext* aPresContext,
73 nsHTMLReflowMetrics& aDesiredSize,
74 const nsHTMLReflowState& aReflowState,
75 nsReflowStatus& aStatus) MOZ_OVERRIDE;
76 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
78 return nsContainerFrame::IsFrameOfType(aFlags &
79 ~(nsIFrame::eCanContainOverflowContainers));
82 // nsIAnonymousContentCreator
83 virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
84 virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter) MOZ_OVERRIDE;
86 // Touch caret handle function
87 mozilla::dom::Element* GetTouchCaretElement() const
89 return mTouchCaretElement;
92 // Selection Caret Handle function
93 mozilla::dom::Element* GetSelectionCaretsStartElement() const
95 return mSelectionCaretsStartElement;
98 mozilla::dom::Element* GetSelectionCaretsEndElement() const
100 return mSelectionCaretsEndElement;
103 mozilla::dom::Element* GetCustomContentContainer() const
105 return mCustomContentContainer;
108 /** SetHasFocus tells the CanvasFrame to draw with focus ring
109 * @param aHasFocus true to show focus ring, false to hide it
111 NS_IMETHOD SetHasFocus(bool aHasFocus);
113 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
114 const nsRect& aDirtyRect,
115 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
117 void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
119 // nsIScrollPositionListener
120 virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
121 virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE {}
124 * Get the "type" of the frame
126 * @see nsGkAtoms::canvasFrame
128 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
130 virtual nsresult StealFrame(nsIFrame* aChild, bool aForceNormal) MOZ_OVERRIDE
132 NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
134 // nsCanvasFrame keeps overflow container continuations of its child
135 // frame in main child list
136 nsresult rv = nsContainerFrame::StealFrame(aChild, true);
137 if (NS_FAILED(rv)) {
138 rv = nsContainerFrame::StealFrame(aChild);
140 return rv;
143 #ifdef DEBUG_FRAME_DUMP
144 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
145 #endif
146 virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
147 nsIContent** aContent) MOZ_OVERRIDE;
149 nsRect CanvasArea() const;
151 protected:
152 // Data members
153 bool mDoPaintFocus;
154 bool mAddedScrollPositionListener;
156 nsCOMPtr<mozilla::dom::Element> mTouchCaretElement;
157 nsCOMPtr<mozilla::dom::Element> mSelectionCaretsStartElement;
158 nsCOMPtr<mozilla::dom::Element> mSelectionCaretsEndElement;
159 nsCOMPtr<mozilla::dom::Element> mCustomContentContainer;
161 class DummyTouchListener MOZ_FINAL : public nsIDOMEventListener
163 public:
164 NS_DECL_ISUPPORTS
166 NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE
168 return NS_OK;
170 private:
171 ~DummyTouchListener() {}
175 * A no-op touch-listener used for APZ purposes.
177 nsRefPtr<DummyTouchListener> mDummyTouchListener;
181 * Override nsDisplayBackground methods so that we pass aBGClipRect to
182 * PaintBackground, covering the whole overflow area.
183 * We can also paint an "extra background color" behind the normal
184 * background.
186 class nsDisplayCanvasBackgroundColor : public nsDisplayItem {
187 public:
188 nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
189 : nsDisplayItem(aBuilder, aFrame)
190 , mColor(NS_RGBA(0,0,0,0))
194 virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
195 nsRegion* aVisibleRegion) MOZ_OVERRIDE
197 return NS_GET_A(mColor) > 0;
199 virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
200 bool* aSnap) MOZ_OVERRIDE
202 if (NS_GET_A(mColor) == 255) {
203 return nsRegion(GetBounds(aBuilder, aSnap));
205 return nsRegion();
207 virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) MOZ_OVERRIDE
209 *aColor = mColor;
210 return true;
212 virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
214 nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
215 *aSnap = true;
216 return frame->CanvasArea() + ToReferenceFrame();
218 virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
219 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE
221 // We need to override so we don't consider border-radius.
222 aOutFrames->AppendElement(mFrame);
225 virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
227 return new nsDisplayItemBoundsGeometry(this, aBuilder);
230 virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
231 const nsDisplayItemGeometry* aGeometry,
232 nsRegion* aInvalidRegion) MOZ_OVERRIDE
234 const nsDisplayItemBoundsGeometry* geometry = static_cast<const nsDisplayItemBoundsGeometry*>(aGeometry);
235 ComputeInvalidationRegionDifference(aBuilder, geometry, aInvalidRegion);
238 virtual void Paint(nsDisplayListBuilder* aBuilder,
239 nsRenderingContext* aCtx) MOZ_OVERRIDE;
241 void SetExtraBackgroundColor(nscolor aColor)
243 mColor = aColor;
246 NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
247 #ifdef MOZ_DUMP_PAINTING
248 virtual void WriteDebugInfo(std::stringstream& aStream) MOZ_OVERRIDE;
249 #endif
251 private:
252 nscolor mColor;
255 class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
256 public:
257 nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
258 uint32_t aLayer, const nsStyleBackground* aBg)
259 : nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBg)
262 virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
264 virtual void NotifyRenderingChanged() MOZ_OVERRIDE
266 mFrame->Properties().Delete(nsIFrame::CachedBackgroundImage());
267 mFrame->Properties().Delete(nsIFrame::CachedBackgroundImageDT());
270 virtual bool ShouldFixToViewport(LayerManager* aManager) MOZ_OVERRIDE
272 // Put background-attachment:fixed canvas background images in their own
273 // compositing layer. Since we know their background painting area can't
274 // change (unless the viewport size itself changes), async scrolling
275 // will work well.
276 return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
277 !mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
280 // We still need to paint a background color as well as an image for this item,
281 // so we can't support this yet.
282 virtual bool SupportsOptimizingToImage() MOZ_OVERRIDE { return false; }
285 NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
288 class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
289 public:
290 nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
291 : nsDisplayThemedBackground(aBuilder, aFrame)
294 virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
296 NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
299 #endif /* nsCanvasFrame_h___ */