2009-09-19 03:20:42 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
/* rendering object that goes directly inside the document's scrollbars */
|
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
#ifndef nsCanvasFrame_h___
|
|
|
|
#define nsCanvasFrame_h___
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 03:04:14 -07:00
|
|
|
#include "mozilla/EventForwards.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2009-09-19 03:20:42 -07:00
|
|
|
#include "nsIScrollPositionListener.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsDisplayList.h"
|
2014-06-03 00:08:25 -07:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2010-04-10 13:10:12 -07:00
|
|
|
class nsPresContext;
|
2011-04-07 18:04:40 -07:00
|
|
|
class nsRenderingContext;
|
2010-04-10 13:10:12 -07:00
|
|
|
|
2009-09-19 03:20:42 -07:00
|
|
|
/**
|
|
|
|
* Root frame class.
|
|
|
|
*
|
|
|
|
* The root frame is the parent frame for the document element's frame.
|
|
|
|
* It only supports having a single child frame which must be an area
|
|
|
|
* frame
|
|
|
|
*/
|
2011-12-27 12:18:48 -08:00
|
|
|
class nsCanvasFrame : public nsContainerFrame,
|
2014-06-03 00:08:25 -07:00
|
|
|
public nsIScrollPositionListener,
|
|
|
|
public nsIAnonymousContentCreator
|
2009-10-07 23:18:18 -07:00
|
|
|
{
|
2009-09-19 03:20:42 -07:00
|
|
|
public:
|
2009-10-07 23:18:18 -07:00
|
|
|
nsCanvasFrame(nsStyleContext* aContext)
|
2011-12-27 12:18:48 -08:00
|
|
|
: nsContainerFrame(aContext),
|
2011-10-17 07:59:28 -07:00
|
|
|
mDoPaintFocus(false),
|
2011-04-29 16:02:33 -07:00
|
|
|
mAddedScrollPositionListener(false) {}
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
|
2009-09-19 03:20:42 -07:00
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
|
|
|
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2014-05-28 12:36:59 -07:00
|
|
|
#ifdef DEBUG
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2014-05-28 12:36:58 -07:00
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2014-05-28 12:36:58 -07:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
2014-05-28 12:36:58 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
2014-05-28 12:36:58 -07:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
2014-05-28 12:36:59 -07:00
|
|
|
#endif
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
|
|
|
|
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
|
2014-05-12 17:47:52 -07:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
|
2009-09-19 03:20:42 -07:00
|
|
|
{
|
2011-12-27 12:18:48 -08:00
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
2009-09-19 03:20:42 -07:00
|
|
|
~(nsIFrame::eCanContainOverflowContainers));
|
|
|
|
}
|
|
|
|
|
2014-06-03 00:08:25 -07:00
|
|
|
// nsIAnonymousContentCreator
|
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
|
|
|
|
virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, uint32_t aFilter) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// Touch caret handle function
|
|
|
|
mozilla::dom::Element* GetTouchCaretElement() const
|
|
|
|
{
|
|
|
|
return mTouchCaretElement;
|
|
|
|
}
|
|
|
|
|
2014-06-04 13:58:00 -07:00
|
|
|
// Selection Caret Handle function
|
|
|
|
mozilla::dom::Element* GetSelectionCaretsStartElement() const
|
|
|
|
{
|
|
|
|
return mSelectionCaretsStartElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::dom::Element* GetSelectionCaretsEndElement() const
|
|
|
|
{
|
|
|
|
return mSelectionCaretsEndElement;
|
|
|
|
}
|
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
/** SetHasFocus tells the CanvasFrame to draw with focus ring
|
2011-10-17 07:59:28 -07:00
|
|
|
* @param aHasFocus true to show focus ring, false to hide it
|
2009-10-07 23:18:18 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD SetHasFocus(bool aHasFocus);
|
2009-10-07 23:18:18 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2011-04-07 18:04:40 -07:00
|
|
|
void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
// nsIScrollPositionListener
|
2013-05-14 09:33:23 -07:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE {}
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::canvasFrame
|
|
|
|
*/
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nsIAtom* GetType() const MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2014-02-06 14:07:48 -08:00
|
|
|
virtual nsresult StealFrame(nsIFrame* aChild, bool aForceNormal) MOZ_OVERRIDE
|
2009-09-19 03:20:42 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
|
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
// nsCanvasFrame keeps overflow container continuations of its child
|
2009-09-19 03:20:42 -07:00
|
|
|
// frame in main child list
|
2014-02-06 14:07:47 -08:00
|
|
|
nsresult rv = nsContainerFrame::StealFrame(aChild, true);
|
2009-09-19 03:20:42 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-02-06 14:07:47 -08:00
|
|
|
rv = nsContainerFrame::StealFrame(aChild);
|
2009-09-19 03:20:42 -07:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
#endif
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIContent** aContent) MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
nsRect CanvasArea() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Data members
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDoPaintFocus;
|
|
|
|
bool mAddedScrollPositionListener;
|
2014-06-03 00:08:25 -07:00
|
|
|
|
|
|
|
nsCOMPtr<mozilla::dom::Element> mTouchCaretElement;
|
2014-06-04 13:58:00 -07:00
|
|
|
nsCOMPtr<mozilla::dom::Element> mSelectionCaretsStartElement;
|
|
|
|
nsCOMPtr<mozilla::dom::Element> mSelectionCaretsEndElement;
|
2009-09-19 03:20:42 -07:00
|
|
|
};
|
|
|
|
|
2010-07-15 14:07:53 -07:00
|
|
|
/**
|
|
|
|
* Override nsDisplayBackground methods so that we pass aBGClipRect to
|
|
|
|
* PaintBackground, covering the whole overflow area.
|
|
|
|
* We can also paint an "extra background color" behind the normal
|
|
|
|
* background.
|
|
|
|
*/
|
2012-12-12 17:15:55 -08:00
|
|
|
class nsDisplayCanvasBackgroundColor : public nsDisplayItem {
|
2010-07-15 14:07:53 -07:00
|
|
|
public:
|
2012-12-12 17:15:55 -08:00
|
|
|
nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
|
|
|
, mColor(NS_RGBA(0,0,0,0))
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2014-07-15 01:29:55 -07:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE
|
2010-07-15 14:08:06 -07:00
|
|
|
{
|
2012-12-12 17:15:55 -08:00
|
|
|
return NS_GET_A(mColor) > 0;
|
2010-07-15 14:08:06 -07:00
|
|
|
}
|
2011-01-02 17:48:09 -08:00
|
|
|
virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-09-14 09:10:08 -07:00
|
|
|
bool* aSnap) MOZ_OVERRIDE
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
2012-12-12 17:15:55 -08:00
|
|
|
if (NS_GET_A(mColor) == 255) {
|
2012-04-10 04:24:18 -07:00
|
|
|
return nsRegion(GetBounds(aBuilder, aSnap));
|
2010-10-19 10:02:25 -07:00
|
|
|
}
|
2012-12-12 17:15:55 -08:00
|
|
|
return nsRegion();
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) MOZ_OVERRIDE
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
2012-12-12 17:15:55 -08:00
|
|
|
*aColor = mColor;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
2012-09-14 09:10:08 -07:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
|
|
|
nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
|
2012-04-10 04:24:18 -07:00
|
|
|
*aSnap = true;
|
|
|
|
return frame->CanvasArea() + ToReferenceFrame();
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
2010-10-11 11:03:12 -07:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
2012-09-14 09:10:08 -07:00
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE
|
2010-10-11 11:03:12 -07:00
|
|
|
{
|
|
|
|
// We need to override so we don't consider border-radius.
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2013-03-07 18:15:10 -08:00
|
|
|
|
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return new nsDisplayItemBoundsGeometry(this, aBuilder);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
2013-05-14 09:33:23 -07:00
|
|
|
nsRegion* aInvalidRegion) MOZ_OVERRIDE
|
2013-03-07 18:15:10 -08:00
|
|
|
{
|
|
|
|
const nsDisplayItemBoundsGeometry* geometry = static_cast<const nsDisplayItemBoundsGeometry*>(aGeometry);
|
|
|
|
ComputeInvalidationRegionDifference(aBuilder, geometry, aInvalidRegion);
|
|
|
|
}
|
|
|
|
|
2010-07-15 14:07:53 -07:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
2010-07-15 14:07:53 -07:00
|
|
|
|
|
|
|
void SetExtraBackgroundColor(nscolor aColor)
|
|
|
|
{
|
2012-12-12 17:15:55 -08:00
|
|
|
mColor = aColor;
|
2010-07-15 14:07:53 -07:00
|
|
|
}
|
|
|
|
|
2012-12-12 17:15:55 -08:00
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
|
2014-06-03 13:21:39 -07:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
virtual void WriteDebugInfo(nsACString& aTo) MOZ_OVERRIDE;
|
|
|
|
#endif
|
2010-07-15 14:07:53 -07:00
|
|
|
|
|
|
|
private:
|
2012-12-12 17:15:55 -08:00
|
|
|
nscolor mColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
2013-07-17 23:34:58 -07:00
|
|
|
uint32_t aLayer, const nsStyleBackground* aBg)
|
|
|
|
: nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBg)
|
2012-12-12 17:15:55 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
|
|
|
|
2014-04-23 19:56:15 -07:00
|
|
|
virtual void NotifyRenderingChanged() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
mFrame->Properties().Delete(nsIFrame::CachedBackgroundImage());
|
|
|
|
mFrame->Properties().Delete(nsIFrame::CachedBackgroundImageDT());
|
|
|
|
}
|
|
|
|
|
2012-12-12 17:15:55 -08:00
|
|
|
virtual bool ShouldFixToViewport(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
// Put background-attachment:fixed canvas background images in their own
|
|
|
|
// compositing layer. Since we know their background painting area can't
|
|
|
|
// change (unless the viewport size itself changes), async scrolling
|
|
|
|
// will work well.
|
|
|
|
return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
|
|
|
|
!mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We still need to paint a background color as well as an image for this item,
|
|
|
|
// so we can't support this yet.
|
|
|
|
virtual bool SupportsOptimizingToImage() MOZ_OVERRIDE { return false; }
|
|
|
|
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
|
2010-07-15 14:07:53 -07:00
|
|
|
};
|
|
|
|
|
2013-07-17 23:34:58 -07:00
|
|
|
class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayThemedBackground(aBuilder, aFrame)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
|
|
|
|
};
|
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
#endif /* nsCanvasFrame_h___ */
|