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
|
|
|
|
2012-09-14 20:10:08 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 14:04:14 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
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"
|
2014-06-03 11:08:25 +04:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2015-02-01 22:17:00 +03:00
|
|
|
#include "nsIDOMEventListener.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;
|
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
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsCanvasFrame final : public nsContainerFrame,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsIScrollPositionListener,
|
|
|
|
public nsIAnonymousContentCreator
|
2009-10-08 10:18:18 +04:00
|
|
|
{
|
2009-09-19 14:20:42 +04:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit 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
|
|
|
|
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual mozilla::WritingMode GetWritingMode() const override
|
2014-12-16 12:45:11 +03:00
|
|
|
{
|
|
|
|
nsIContent* rootElem = GetContent();
|
|
|
|
if (rootElem) {
|
|
|
|
nsIFrame* rootElemFrame = rootElem->GetPrimaryFrame();
|
|
|
|
if (rootElemFrame) {
|
|
|
|
return rootElemFrame->GetWritingMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsIFrame::GetWritingMode();
|
|
|
|
}
|
|
|
|
|
2014-05-28 23:36:59 +04:00
|
|
|
#ifdef DEBUG
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aChildList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void InsertFrames(ChildListID aListID,
|
2014-05-28 23:36:58 +04:00
|
|
|
nsIFrame* aPrevFrame,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 23:36:58 +04:00
|
|
|
virtual void RemoveFrame(ChildListID aListID,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIFrame* aOldFrame) override;
|
2014-05-28 23:36:59 +04:00
|
|
|
#endif
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
|
2014-05-13 04:47:52 +04:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsReflowStatus& aStatus) override;
|
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override
|
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));
|
|
|
|
}
|
|
|
|
|
2014-06-03 11:08:25 +04:00
|
|
|
// nsIAnonymousContentCreator
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
|
|
|
|
virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter) override;
|
2014-06-03 11:08:25 +04:00
|
|
|
|
|
|
|
// Touch caret handle function
|
|
|
|
mozilla::dom::Element* GetTouchCaretElement() const
|
|
|
|
{
|
|
|
|
return mTouchCaretElement;
|
|
|
|
}
|
|
|
|
|
2014-06-05 00:58:00 +04:00
|
|
|
// Selection Caret Handle function
|
|
|
|
mozilla::dom::Element* GetSelectionCaretsStartElement() const
|
|
|
|
{
|
|
|
|
return mSelectionCaretsStartElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::dom::Element* GetSelectionCaretsEndElement() const
|
|
|
|
{
|
|
|
|
return mSelectionCaretsEndElement;
|
|
|
|
}
|
|
|
|
|
2014-10-28 13:15:25 +03:00
|
|
|
mozilla::dom::Element* GetCustomContentContainer() const
|
|
|
|
{
|
|
|
|
return mCustomContentContainer;
|
|
|
|
}
|
|
|
|
|
2015-01-20 21:20:04 +03:00
|
|
|
/**
|
|
|
|
* Unhide the CustomContentContainer. This call only has an effect if
|
|
|
|
* mCustomContentContainer is non-null.
|
|
|
|
*/
|
|
|
|
void ShowCustomContentContainer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide the CustomContentContainer. This call only has an effect if
|
|
|
|
* mCustomContentContainer is non-null.
|
|
|
|
*/
|
|
|
|
void HideCustomContentContainer();
|
|
|
|
|
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
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2015-03-21 19:28:04 +03:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2011-04-08 05:04:40 +04:00
|
|
|
void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
|
2009-09-19 14:20:42 +04:00
|
|
|
|
|
|
|
// nsIScrollPositionListener
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override {}
|
2009-09-19 14:20:42 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the "type" of the frame
|
|
|
|
*
|
|
|
|
* @see nsGkAtoms::canvasFrame
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsIAtom* GetType() const override;
|
2009-09-19 14:20:42 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult StealFrame(nsIFrame* aChild, bool aForceNormal) override
|
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
|
2014-02-07 02:07:47 +04:00
|
|
|
nsresult rv = nsContainerFrame::StealFrame(aChild, true);
|
2009-09-19 14:20:42 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-02-07 02:07:47 +04:00
|
|
|
rv = nsContainerFrame::StealFrame(aChild);
|
2009-09-19 14:20:42 +04:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override;
|
2009-09-19 14:20:42 +04:00
|
|
|
#endif
|
2014-02-18 11:47:48 +04:00
|
|
|
virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIContent** aContent) override;
|
2009-09-19 14:20:42 +04:00
|
|
|
|
|
|
|
nsRect CanvasArea() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Data members
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDoPaintFocus;
|
|
|
|
bool mAddedScrollPositionListener;
|
2014-06-03 11:08:25 +04:00
|
|
|
|
|
|
|
nsCOMPtr<mozilla::dom::Element> mTouchCaretElement;
|
2014-06-05 00:58:00 +04:00
|
|
|
nsCOMPtr<mozilla::dom::Element> mSelectionCaretsStartElement;
|
|
|
|
nsCOMPtr<mozilla::dom::Element> mSelectionCaretsEndElement;
|
2014-10-28 13:15:25 +03:00
|
|
|
nsCOMPtr<mozilla::dom::Element> mCustomContentContainer;
|
2015-02-01 22:17:00 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DummyTouchListener final : public nsIDOMEventListener
|
2015-02-01 22:17:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent) override
|
2015-02-01 22:17:00 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
~DummyTouchListener() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A no-op touch-listener used for APZ purposes.
|
|
|
|
*/
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DummyTouchListener> mDummyTouchListener;
|
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.
|
|
|
|
*/
|
2015-09-19 04:45:05 +03:00
|
|
|
class nsDisplayCanvasBackgroundColor : public nsDisplaySolidColorBase {
|
2010-07-16 01:07:53 +04:00
|
|
|
public:
|
2012-12-13 05:15:55 +04:00
|
|
|
nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
|
2015-09-19 04:45:05 +03:00
|
|
|
: nsDisplaySolidColorBase(aBuilder, aFrame, NS_RGBA(0,0,0,0))
|
2010-07-16 01:07:53 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRegion* aVisibleRegion) override
|
2010-07-16 01:08:06 +04:00
|
|
|
{
|
2012-12-13 05:15:55 +04:00
|
|
|
return NS_GET_A(mColor) > 0;
|
2010-07-16 01:08:06 +04:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
|
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,
|
2015-03-21 19:28:04 +03:00
|
|
|
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) override
|
2010-10-11 22:03:12 +04:00
|
|
|
{
|
|
|
|
// We need to override so we don't consider border-radius.
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2013-03-08 06:15:10 +04:00
|
|
|
|
2010-07-16 01:07:53 +04:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsRenderingContext* aCtx) override;
|
2010-07-16 01:07:53 +04:00
|
|
|
|
|
|
|
void SetExtraBackgroundColor(nscolor aColor)
|
|
|
|
{
|
2012-12-13 05:15:55 +04:00
|
|
|
mColor = aColor;
|
2010-07-16 01:07:53 +04:00
|
|
|
}
|
|
|
|
|
2012-12-13 05:15:55 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
|
2014-06-04 00:21:39 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void WriteDebugInfo(std::stringstream& aStream) override;
|
2014-06-04 00:21:39 +04:00
|
|
|
#endif
|
2012-12-13 05:15:55 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
|
2013-07-18 10:34:58 +04:00
|
|
|
uint32_t aLayer, const nsStyleBackground* aBg)
|
|
|
|
: nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBg)
|
2015-10-06 00:09:34 +03:00
|
|
|
{
|
|
|
|
if (ShouldFixToViewport(aBuilder)) {
|
|
|
|
mAnimatedGeometryRoot = nsLayoutUtils::GetAnimatedGeometryRootFor(this, aBuilder);
|
|
|
|
}
|
|
|
|
}
|
2012-12-13 05:15:55 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;
|
2012-12-13 05:15:55 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void NotifyRenderingChanged() override
|
2014-04-24 06:56:15 +04:00
|
|
|
{
|
|
|
|
mFrame->Properties().Delete(nsIFrame::CachedBackgroundImage());
|
|
|
|
mFrame->Properties().Delete(nsIFrame::CachedBackgroundImageDT());
|
|
|
|
}
|
|
|
|
|
2015-09-25 01:25:08 +03:00
|
|
|
virtual bool ShouldFixToViewport(nsDisplayListBuilder* aBuilder) override
|
2012-12-13 05:15:55 +04:00
|
|
|
{
|
|
|
|
// 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.
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool SupportsOptimizingToImage() override { return false; }
|
2012-12-13 05:15:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
|
2010-07-16 01:07:53 +04:00
|
|
|
};
|
|
|
|
|
2013-07-18 10:34:58 +04:00
|
|
|
class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayThemedBackground(aBuilder, aFrame)
|
|
|
|
{}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;
|
2013-07-18 10:34:58 +04:00
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
|
|
|
|
};
|
|
|
|
|
2009-10-08 10:18:18 +04:00
|
|
|
#endif /* nsCanvasFrame_h___ */
|