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"
|
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"
|
|
|
|
#include "nsGkAtoms.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;
|
|
|
|
class nsEvent;
|
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,
|
2009-10-07 23:18:18 -07:00
|
|
|
public nsIScrollPositionListener
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
2009-12-23 21:21:15 -08:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2009-09-19 03:20:42 -07:00
|
|
|
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_IMETHOD SetInitialChildList(ChildListID aListID,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsFrameList& aChildList) MOZ_OVERRIDE;
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_IMETHOD AppendFrames(ChildListID aListID,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_IMETHOD InsertFrames(ChildListID aListID,
|
2009-09-19 03:20:42 -07:00
|
|
|
nsIFrame* aPrevFrame,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsFrameList& aFrameList) MOZ_OVERRIDE;
|
2011-08-24 13:54:30 -07:00
|
|
|
NS_IMETHOD RemoveFrame(ChildListID aListID,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsIFrame* aOldFrame) MOZ_OVERRIDE;
|
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;
|
2009-09-19 03:20:42 -07:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsReflowStatus& aStatus) MOZ_OVERRIDE;
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const
|
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));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-09-19 03:20:42 -07:00
|
|
|
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2012-09-14 09:10:08 -07:00
|
|
|
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
|
2010-01-28 16:03:42 -08:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY);
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) {}
|
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
|
|
|
|
|
|
|
virtual nsresult StealFrame(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChild,
|
2012-09-14 09:10:08 -07:00
|
|
|
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
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = nsContainerFrame::StealFrame(aPresContext, aChild, true);
|
2009-09-19 03:20:42 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = nsContainerFrame::StealFrame(aPresContext, aChild);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-09-14 09:10:08 -07:00
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
#endif
|
2011-09-26 13:55:04 -07:00
|
|
|
NS_IMETHOD GetContentForEvent(nsEvent* aEvent,
|
2012-09-14 09:10:08 -07:00
|
|
|
nsIContent** aContent) MOZ_OVERRIDE;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
nsRect CanvasArea() const;
|
|
|
|
|
|
|
|
protected:
|
2012-08-09 00:09:40 -07:00
|
|
|
virtual int GetSkipSides() const;
|
2009-09-19 03:20:42 -07:00
|
|
|
|
|
|
|
// Data members
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDoPaintFocus;
|
|
|
|
bool mAddedScrollPositionListener;
|
2009-09-19 03:20:42 -07:00
|
|
|
};
|
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
class nsDisplayCanvasBackgroundGeometry : public nsDisplayItemGeometry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasBackgroundGeometry(nsDisplayItem* aItem, nsDisplayListBuilder* aBuilder, const nsRect& aChildBorder)
|
|
|
|
: nsDisplayItemGeometry(aItem, aBuilder)
|
|
|
|
, mChildBorder(aChildBorder)
|
|
|
|
, mPaddingRect(aItem->GetPaddingRect())
|
|
|
|
, mContentRect(aItem->GetContentRect())
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual void MoveBy(const nsPoint& aOffset)
|
|
|
|
{
|
|
|
|
mBounds.MoveBy(aOffset);
|
|
|
|
mPaddingRect.MoveBy(aOffset);
|
|
|
|
mContentRect.MoveBy(aOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect mChildBorder;
|
|
|
|
nsRect mPaddingRect;
|
|
|
|
nsRect mContentRect;
|
|
|
|
};
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class nsDisplayCanvasBackground : public nsDisplayBackground {
|
|
|
|
public:
|
2012-09-13 03:34:23 -07:00
|
|
|
nsDisplayCanvasBackground(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame, uint32_t aLayer)
|
2012-09-13 03:34:34 -07:00
|
|
|
: nsDisplayBackground(aBuilder, aFrame, aLayer, true)
|
2010-07-15 14:07:53 -07:00
|
|
|
{
|
|
|
|
mExtraBackgroundColor = NS_RGBA(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2012-04-10 04:24:18 -07:00
|
|
|
nsRegion* aVisibleRegion,
|
2012-09-14 09:10:08 -07:00
|
|
|
const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE
|
2010-07-15 14:08:06 -07:00
|
|
|
{
|
2011-05-13 09:40:46 -07:00
|
|
|
return NS_GET_A(mExtraBackgroundColor) > 0 ||
|
|
|
|
nsDisplayBackground::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aAllowVisibleRegionExpansion);
|
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-04-10 04:24:18 -07:00
|
|
|
if (NS_GET_A(mExtraBackgroundColor) == 255) {
|
|
|
|
return nsRegion(GetBounds(aBuilder, aSnap));
|
2010-10-19 10:02:25 -07:00
|
|
|
}
|
2012-05-02 21:29:05 -07:00
|
|
|
return nsDisplayBackground::GetOpaqueRegion(aBuilder, aSnap);
|
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
|
|
|
{
|
|
|
|
nscolor background;
|
|
|
|
if (!nsDisplayBackground::IsUniform(aBuilder, &background))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-15 14:07:53 -07:00
|
|
|
NS_ASSERTION(background == NS_RGBA(0,0,0,0),
|
|
|
|
"The nsDisplayBackground for a canvas frame doesn't paint "
|
|
|
|
"its background color normally");
|
|
|
|
*aColor = mExtraBackgroundColor;
|
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);
|
|
|
|
}
|
2012-08-28 22:39:01 -07:00
|
|
|
|
|
|
|
virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder)
|
|
|
|
{
|
|
|
|
nsIFrame *child = mFrame->GetFirstPrincipalChild();
|
|
|
|
return new nsDisplayCanvasBackgroundGeometry(this, aBuilder,
|
|
|
|
child ? child->GetRect() : nsRect());;
|
|
|
|
}
|
2010-07-15 14:07:53 -07:00
|
|
|
|
2012-08-28 22:39:01 -07:00
|
|
|
virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayItemGeometry* aGeometry,
|
|
|
|
nsRegion* aInvalidRegion)
|
|
|
|
{
|
|
|
|
const nsDisplayCanvasBackgroundGeometry* geometry = static_cast<const nsDisplayCanvasBackgroundGeometry*>(aGeometry);
|
|
|
|
if (ShouldFixToViewport(aBuilder)) {
|
|
|
|
// This is incorrect, We definitely need to check more things here.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *child = mFrame->GetFirstPrincipalChild();
|
|
|
|
|
|
|
|
bool snap;
|
|
|
|
if (!geometry->mBounds.IsEqualInterior(GetBounds(aBuilder, &snap)) ||
|
|
|
|
(child && !geometry->mChildBorder.IsEqualInterior(child->GetRect())) ||
|
|
|
|
!geometry->mPaddingRect.IsEqualInterior(GetPaddingRect()) ||
|
|
|
|
!geometry->mContentRect.IsEqualInterior(GetContentRect())) {
|
|
|
|
if (!RenderingMightDependOnFrameSize() && geometry->mBounds.TopLeft() == GetBounds(aBuilder, &snap).TopLeft()) {
|
|
|
|
aInvalidRegion->Xor(GetBounds(aBuilder, &snap), geometry->mBounds);
|
|
|
|
} else {
|
|
|
|
aInvalidRegion->Or(GetBounds(aBuilder, &snap), geometry->mBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
mExtraBackgroundColor = aColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackground", TYPE_CANVAS_BACKGROUND)
|
|
|
|
|
|
|
|
private:
|
|
|
|
nscolor mExtraBackgroundColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-07 23:18:18 -07:00
|
|
|
#endif /* nsCanvasFrame_h___ */
|