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