2009-09-19 14:20:42 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 14:20:42 +04:00
|
|
|
|
|
|
|
/* rendering object that goes directly inside the document's scrollbars */
|
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
#ifndef nsCanvasFrame_h___
|
|
|
|
#define nsCanvasFrame_h___
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2011-12-28 00:18:48 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2009-09-19 14:20:42 +04:00
|
|
|
#include "nsIScrollPositionListener.h"
|
2011-04-08 05:04:40 +04:00
|
|
|
#include "nsDisplayList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2010-04-11 00:10:12 +04:00
|
|
|
class nsPresContext;
|
2011-04-08 05:04:40 +04:00
|
|
|
class nsRenderingContext;
|
|
|
|
class nsEvent;
|
2010-04-11 00:10:12 +04:00
|
|
|
|
2009-09-19 14:20:42 +04: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-28 00:18:48 +04:00
|
|
|
class nsCanvasFrame : public nsContainerFrame,
|
2009-10-08 10:18:18 +04:00
|
|
|
public nsIScrollPositionListener
|
|
|
|
{
|
2009-09-19 14:20:42 +04:00
|
|
|
public:
|
2009-10-08 10:18:18 +04:00
|
|
|
nsCanvasFrame(nsStyleContext* aContext)
|
2011-12-28 00:18:48 +04:00
|
|
|
: nsContainerFrame(aContext),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDoPaintFocus(false),
|
2011-04-30 03:02:33 +04:00
|
|
|
mAddedScrollPositionListener(false) {}
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
|
2009-09-19 14:20:42 +04:00
|
|
|
NS_DECL_QUERYFRAME
|
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
|
|
|
|
2009-12-24 08:21:15 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot);
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_IMETHOD SetInitialChildList(ChildListID aListID,
|
2009-09-19 14:20:42 +04:00
|
|
|
nsFrameList& aChildList);
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_IMETHOD AppendFrames(ChildListID aListID,
|
2009-09-19 14:20:42 +04:00
|
|
|
nsFrameList& aFrameList);
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_IMETHOD InsertFrames(ChildListID aListID,
|
2009-09-19 14:20:42 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsFrameList& aFrameList);
|
2011-08-25 00:54:30 +04:00
|
|
|
NS_IMETHOD RemoveFrame(ChildListID aListID,
|
2009-09-19 14:20:42 +04:00
|
|
|
nsIFrame* aOldFrame);
|
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
|
|
|
|
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
|
2009-09-19 14:20:42 +04:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsFrameOfType(PRUint32 aFlags) const
|
2009-09-19 14:20:42 +04:00
|
|
|
{
|
2011-12-28 00:18:48 +04:00
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
2009-09-19 14:20:42 +04:00
|
|
|
~(nsIFrame::eCanContainOverflowContainers));
|
|
|
|
}
|
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
/** SetHasFocus tells the CanvasFrame to draw with focus ring
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aHasFocus true to show focus ring, false to hide it
|
2009-10-08 10:18:18 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHOD SetHasFocus(bool aHasFocus);
|
2009-10-08 10:18:18 +04:00
|
|
|
|
2009-09-19 14:20:42 +04:00
|
|
|
NS_IMETHOD BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists);
|
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
|
2009-09-19 14:20:42 +04:00
|
|
|
|
|
|
|
// nsIScrollPositionListener
|
2010-01-29 03:03:42 +03:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY);
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) {}
|
2009-09-19 14:20:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::canvasFrame
|
|
|
|
*/
|
|
|
|
virtual nsIAtom* GetType() const;
|
|
|
|
|
|
|
|
virtual nsresult StealFrame(nsPresContext* aPresContext,
|
|
|
|
nsIFrame* aChild,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aForceNormal)
|
2009-09-19 14:20:42 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
|
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
// nsCanvasFrame keeps overflow container continuations of its child
|
2009-09-19 14:20:42 +04:00
|
|
|
// frame in main child list
|
2011-10-17 18:59:28 +04:00
|
|
|
nsresult rv = nsContainerFrame::StealFrame(aPresContext, aChild, true);
|
2009-09-19 14:20:42 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
rv = nsContainerFrame::StealFrame(aPresContext, aChild);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHOD GetFrameName(nsAString& aResult) const;
|
|
|
|
#endif
|
2011-09-27 00:55:04 +04:00
|
|
|
NS_IMETHOD GetContentForEvent(nsEvent* aEvent,
|
2009-09-19 14:20:42 +04:00
|
|
|
nsIContent** aContent);
|
|
|
|
|
|
|
|
nsRect CanvasArea() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual PRIntn GetSkipSides() const;
|
|
|
|
|
|
|
|
// Data members
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDoPaintFocus;
|
|
|
|
bool mAddedScrollPositionListener;
|
2009-09-19 14:20:42 +04:00
|
|
|
};
|
|
|
|
|
2010-07-16 01:07:53 +04: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:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayCanvasBackground(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
|
|
|
|
: nsDisplayBackground(aBuilder, aFrame)
|
2010-07-16 01:07:53 +04:00
|
|
|
{
|
|
|
|
mExtraBackgroundColor = NS_RGBA(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2012-04-10 15:24:18 +04:00
|
|
|
nsRegion* aVisibleRegion,
|
|
|
|
const nsRect& aAllowVisibleRegionExpansion)
|
2010-07-16 01:08:06 +04:00
|
|
|
{
|
2011-05-13 20:40:46 +04:00
|
|
|
return NS_GET_A(mExtraBackgroundColor) > 0 ||
|
|
|
|
nsDisplayBackground::ComputeVisibility(aBuilder, aVisibleRegion,
|
|
|
|
aAllowVisibleRegionExpansion);
|
2010-07-16 01:08:06 +04:00
|
|
|
}
|
2011-01-03 04:48:09 +03:00
|
|
|
virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-05-03 08:29:05 +04:00
|
|
|
bool* aSnap)
|
2010-07-16 01:07:53 +04:00
|
|
|
{
|
2012-04-10 15:24:18 +04:00
|
|
|
if (NS_GET_A(mExtraBackgroundColor) == 255) {
|
|
|
|
return nsRegion(GetBounds(aBuilder, aSnap));
|
2010-10-19 21:02:25 +04:00
|
|
|
}
|
2012-05-03 08:29:05 +04:00
|
|
|
return nsDisplayBackground::GetOpaqueRegion(aBuilder, aSnap);
|
2010-07-16 01:07:53 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
|
2010-07-16 01:07:53 +04:00
|
|
|
{
|
|
|
|
nscolor background;
|
|
|
|
if (!nsDisplayBackground::IsUniform(aBuilder, &background))
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-16 01:07:53 +04: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 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 01:07:53 +04:00
|
|
|
}
|
2012-04-10 15:24:18 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap)
|
2010-07-16 01:07:53 +04:00
|
|
|
{
|
|
|
|
nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = true;
|
|
|
|
return frame->CanvasArea() + ToReferenceFrame();
|
2010-07-16 01:07:53 +04:00
|
|
|
}
|
2010-10-11 22:03:12 +04:00
|
|
|
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
|
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
|
|
|
|
{
|
|
|
|
// We need to override so we don't consider border-radius.
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2010-07-16 01:07:53 +04:00
|
|
|
|
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2011-04-08 05:04:40 +04:00
|
|
|
nsRenderingContext* aCtx);
|
2010-07-16 01:07:53 +04:00
|
|
|
|
|
|
|
void SetExtraBackgroundColor(nscolor aColor)
|
|
|
|
{
|
|
|
|
mExtraBackgroundColor = aColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackground", TYPE_CANVAS_BACKGROUND)
|
|
|
|
|
|
|
|
private:
|
|
|
|
nscolor mExtraBackgroundColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
#endif /* nsCanvasFrame_h___ */
|