layout/generic/nsCanvasFrame.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* rendering object that goes directly inside the document's scrollbars */
michael@0 7
michael@0 8 #ifndef nsCanvasFrame_h___
michael@0 9 #define nsCanvasFrame_h___
michael@0 10
michael@0 11 #include "mozilla/Attributes.h"
michael@0 12 #include "mozilla/EventForwards.h"
michael@0 13 #include "nsContainerFrame.h"
michael@0 14 #include "nsIScrollPositionListener.h"
michael@0 15 #include "nsDisplayList.h"
michael@0 16
michael@0 17 class nsPresContext;
michael@0 18 class nsRenderingContext;
michael@0 19
michael@0 20 /**
michael@0 21 * Root frame class.
michael@0 22 *
michael@0 23 * The root frame is the parent frame for the document element's frame.
michael@0 24 * It only supports having a single child frame which must be an area
michael@0 25 * frame
michael@0 26 */
michael@0 27 class nsCanvasFrame : public nsContainerFrame,
michael@0 28 public nsIScrollPositionListener
michael@0 29 {
michael@0 30 public:
michael@0 31 nsCanvasFrame(nsStyleContext* aContext)
michael@0 32 : nsContainerFrame(aContext),
michael@0 33 mDoPaintFocus(false),
michael@0 34 mAddedScrollPositionListener(false) {}
michael@0 35
michael@0 36 NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
michael@0 37 NS_DECL_QUERYFRAME
michael@0 38 NS_DECL_FRAMEARENA_HELPERS
michael@0 39
michael@0 40
michael@0 41 virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
michael@0 42
michael@0 43 virtual nsresult SetInitialChildList(ChildListID aListID,
michael@0 44 nsFrameList& aChildList) MOZ_OVERRIDE;
michael@0 45 virtual nsresult AppendFrames(ChildListID aListID,
michael@0 46 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 47 virtual nsresult InsertFrames(ChildListID aListID,
michael@0 48 nsIFrame* aPrevFrame,
michael@0 49 nsFrameList& aFrameList) MOZ_OVERRIDE;
michael@0 50 virtual nsresult RemoveFrame(ChildListID aListID,
michael@0 51 nsIFrame* aOldFrame) MOZ_OVERRIDE;
michael@0 52
michael@0 53 virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 54 virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
michael@0 55 virtual nsresult Reflow(nsPresContext* aPresContext,
michael@0 56 nsHTMLReflowMetrics& aDesiredSize,
michael@0 57 const nsHTMLReflowState& aReflowState,
michael@0 58 nsReflowStatus& aStatus) MOZ_OVERRIDE;
michael@0 59 virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
michael@0 60 {
michael@0 61 return nsContainerFrame::IsFrameOfType(aFlags &
michael@0 62 ~(nsIFrame::eCanContainOverflowContainers));
michael@0 63 }
michael@0 64
michael@0 65 /** SetHasFocus tells the CanvasFrame to draw with focus ring
michael@0 66 * @param aHasFocus true to show focus ring, false to hide it
michael@0 67 */
michael@0 68 NS_IMETHOD SetHasFocus(bool aHasFocus);
michael@0 69
michael@0 70 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
michael@0 71 const nsRect& aDirtyRect,
michael@0 72 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
michael@0 73
michael@0 74 void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
michael@0 75
michael@0 76 // nsIScrollPositionListener
michael@0 77 virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
michael@0 78 virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE {}
michael@0 79
michael@0 80 /**
michael@0 81 * Get the "type" of the frame
michael@0 82 *
michael@0 83 * @see nsGkAtoms::canvasFrame
michael@0 84 */
michael@0 85 virtual nsIAtom* GetType() const MOZ_OVERRIDE;
michael@0 86
michael@0 87 virtual nsresult StealFrame(nsIFrame* aChild, bool aForceNormal) MOZ_OVERRIDE
michael@0 88 {
michael@0 89 NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
michael@0 90
michael@0 91 // nsCanvasFrame keeps overflow container continuations of its child
michael@0 92 // frame in main child list
michael@0 93 nsresult rv = nsContainerFrame::StealFrame(aChild, true);
michael@0 94 if (NS_FAILED(rv)) {
michael@0 95 rv = nsContainerFrame::StealFrame(aChild);
michael@0 96 }
michael@0 97 return rv;
michael@0 98 }
michael@0 99
michael@0 100 #ifdef DEBUG_FRAME_DUMP
michael@0 101 virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
michael@0 102 #endif
michael@0 103 virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
michael@0 104 nsIContent** aContent) MOZ_OVERRIDE;
michael@0 105
michael@0 106 nsRect CanvasArea() const;
michael@0 107
michael@0 108 protected:
michael@0 109 // Data members
michael@0 110 bool mDoPaintFocus;
michael@0 111 bool mAddedScrollPositionListener;
michael@0 112 };
michael@0 113
michael@0 114 /**
michael@0 115 * Override nsDisplayBackground methods so that we pass aBGClipRect to
michael@0 116 * PaintBackground, covering the whole overflow area.
michael@0 117 * We can also paint an "extra background color" behind the normal
michael@0 118 * background.
michael@0 119 */
michael@0 120 class nsDisplayCanvasBackgroundColor : public nsDisplayItem {
michael@0 121 public:
michael@0 122 nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
michael@0 123 : nsDisplayItem(aBuilder, aFrame)
michael@0 124 , mColor(NS_RGBA(0,0,0,0))
michael@0 125 {
michael@0 126 }
michael@0 127
michael@0 128 virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
michael@0 129 nsRegion* aVisibleRegion,
michael@0 130 const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE
michael@0 131 {
michael@0 132 return NS_GET_A(mColor) > 0;
michael@0 133 }
michael@0 134 virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
michael@0 135 bool* aSnap) MOZ_OVERRIDE
michael@0 136 {
michael@0 137 if (NS_GET_A(mColor) == 255) {
michael@0 138 return nsRegion(GetBounds(aBuilder, aSnap));
michael@0 139 }
michael@0 140 return nsRegion();
michael@0 141 }
michael@0 142 virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) MOZ_OVERRIDE
michael@0 143 {
michael@0 144 *aColor = mColor;
michael@0 145 return true;
michael@0 146 }
michael@0 147 virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
michael@0 148 {
michael@0 149 nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
michael@0 150 *aSnap = true;
michael@0 151 return frame->CanvasArea() + ToReferenceFrame();
michael@0 152 }
michael@0 153 virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
michael@0 154 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE
michael@0 155 {
michael@0 156 // We need to override so we don't consider border-radius.
michael@0 157 aOutFrames->AppendElement(mFrame);
michael@0 158 }
michael@0 159
michael@0 160 virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
michael@0 161 {
michael@0 162 return new nsDisplayItemBoundsGeometry(this, aBuilder);
michael@0 163 }
michael@0 164
michael@0 165 virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
michael@0 166 const nsDisplayItemGeometry* aGeometry,
michael@0 167 nsRegion* aInvalidRegion) MOZ_OVERRIDE
michael@0 168 {
michael@0 169 const nsDisplayItemBoundsGeometry* geometry = static_cast<const nsDisplayItemBoundsGeometry*>(aGeometry);
michael@0 170 ComputeInvalidationRegionDifference(aBuilder, geometry, aInvalidRegion);
michael@0 171 }
michael@0 172
michael@0 173 virtual void Paint(nsDisplayListBuilder* aBuilder,
michael@0 174 nsRenderingContext* aCtx) MOZ_OVERRIDE;
michael@0 175
michael@0 176 void SetExtraBackgroundColor(nscolor aColor)
michael@0 177 {
michael@0 178 mColor = aColor;
michael@0 179 }
michael@0 180
michael@0 181 NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
michael@0 182
michael@0 183 private:
michael@0 184 nscolor mColor;
michael@0 185 };
michael@0 186
michael@0 187 class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
michael@0 188 public:
michael@0 189 nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
michael@0 190 uint32_t aLayer, const nsStyleBackground* aBg)
michael@0 191 : nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBg)
michael@0 192 {}
michael@0 193
michael@0 194 virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
michael@0 195
michael@0 196 virtual void NotifyRenderingChanged() MOZ_OVERRIDE
michael@0 197 {
michael@0 198 mFrame->Properties().Delete(nsIFrame::CachedBackgroundImage());
michael@0 199 mFrame->Properties().Delete(nsIFrame::CachedBackgroundImageDT());
michael@0 200 }
michael@0 201
michael@0 202 virtual bool ShouldFixToViewport(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
michael@0 203 {
michael@0 204 // Put background-attachment:fixed canvas background images in their own
michael@0 205 // compositing layer. Since we know their background painting area can't
michael@0 206 // change (unless the viewport size itself changes), async scrolling
michael@0 207 // will work well.
michael@0 208 return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
michael@0 209 !mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
michael@0 210 }
michael@0 211
michael@0 212 // We still need to paint a background color as well as an image for this item,
michael@0 213 // so we can't support this yet.
michael@0 214 virtual bool SupportsOptimizingToImage() MOZ_OVERRIDE { return false; }
michael@0 215
michael@0 216
michael@0 217 NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
michael@0 218 };
michael@0 219
michael@0 220 class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
michael@0 221 public:
michael@0 222 nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
michael@0 223 : nsDisplayThemedBackground(aBuilder, aFrame)
michael@0 224 {}
michael@0 225
michael@0 226 virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
michael@0 227
michael@0 228 NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
michael@0 229 };
michael@0 230
michael@0 231 #endif /* nsCanvasFrame_h___ */

mercurial