2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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
|
|
|
|
2012-09-14 16:10:08 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-24 10:04:14 +00:00
|
|
|
#include "mozilla/EventForwards.h"
|
2011-12-27 20:18:48 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2009-09-19 10:20:42 +00:00
|
|
|
#include "nsIScrollPositionListener.h"
|
2018-06-27 00:29:55 +00:00
|
|
|
#include "nsIPopupContainer.h"
|
2011-04-08 01:04:40 +00:00
|
|
|
#include "nsDisplayList.h"
|
2014-06-03 07:08:25 +00:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2010-04-10 20:10:12 +00:00
|
|
|
class nsPresContext;
|
2017-06-09 19:14:53 +00:00
|
|
|
class gfxContext;
|
2018-06-05 01:02:32 +00:00
|
|
|
class nsPopupSetFrame;
|
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
|
2016-06-10 00:56:23 +00:00
|
|
|
* frame.
|
|
|
|
* @note nsCanvasFrame keeps overflow container continuations of its child
|
|
|
|
* frame in the main child list.
|
2009-09-19 10:20:42 +00:00
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsCanvasFrame final : public nsContainerFrame,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIScrollPositionListener,
|
2018-06-05 01:02:32 +00:00
|
|
|
public nsIAnonymousContentCreator,
|
2018-06-27 00:29:55 +00:00
|
|
|
public nsIPopupContainer {
|
2019-11-29 20:39:36 +00:00
|
|
|
using Element = mozilla::dom::Element;
|
|
|
|
|
2009-09-19 10:20:42 +00:00
|
|
|
public:
|
2019-02-05 16:45:54 +00:00
|
|
|
explicit nsCanvasFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
|
|
|
|
: nsContainerFrame(aStyle, aPresContext, kClassID),
|
2017-04-30 15:30:08 +00:00
|
|
|
mDoPaintFocus(false),
|
|
|
|
mAddedScrollPositionListener(false),
|
2018-06-05 01:02:32 +00:00
|
|
|
mPopupSetFrame(nullptr) {}
|
2009-09-19 10:20:42 +00:00
|
|
|
|
|
|
|
NS_DECL_QUERYFRAME
|
2017-05-26 10:11:11 +00:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS(nsCanvasFrame)
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2018-06-05 01:02:32 +00:00
|
|
|
nsPopupSetFrame* GetPopupSetFrame() override;
|
|
|
|
void SetPopupSetFrame(nsPopupSetFrame* aPopupSet) override;
|
|
|
|
Element* GetDefaultTooltip() override;
|
|
|
|
void SetDefaultTooltip(Element* aTooltip) override;
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2017-11-07 00:20:33 +00:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) override;
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsFrameList& aChildList) override;
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void AppendFrames(ChildListID aListID,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsFrameList& aFrameList) override;
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void InsertFrames(ChildListID aListID, nsIFrame* aPrevFrame,
|
2019-07-17 23:34:45 +00:00
|
|
|
const nsLineList::iterator* aPrevFrameLine,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsFrameList& aFrameList) override;
|
2017-02-28 17:58:30 +00:00
|
|
|
#ifdef DEBUG
|
2014-05-28 19:36:58 +00:00
|
|
|
virtual void RemoveFrame(ChildListID aListID, nsIFrame* aOldFrame) override;
|
2014-05-28 19:36:59 +00:00
|
|
|
#endif
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
|
2014-05-13 00:47:52 +00:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
|
2016-07-21 10:36:39 +00:00
|
|
|
const ReflowInput& aReflowInput,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsReflowStatus& aStatus) override;
|
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override {
|
2011-12-27 20:18:48 +00:00
|
|
|
return nsContainerFrame::IsFrameOfType(
|
2009-09-19 10:20:42 +00:00
|
|
|
aFlags & ~(nsIFrame::eCanContainOverflowContainers));
|
|
|
|
}
|
|
|
|
|
2014-06-03 07:08:25 +00:00
|
|
|
// nsIAnonymousContentCreator
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) override;
|
|
|
|
virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
|
|
|
uint32_t aFilter) override;
|
2014-06-03 07:08:25 +00:00
|
|
|
|
2019-11-29 20:39:36 +00:00
|
|
|
Element* GetCustomContentContainer() const { return mCustomContentContainer; }
|
2014-10-28 10:15:25 +00:00
|
|
|
|
2015-01-20 18:20:04 +00: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 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
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
2015-03-21 16:28:04 +00:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2015-12-04 03:16:59 +00:00
|
|
|
void PaintFocus(mozilla::gfx::DrawTarget* aRenderingContext, nsPoint aPt);
|
2009-09-19 10:20:42 +00:00
|
|
|
|
|
|
|
// nsIScrollPositionListener
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
|
|
|
|
virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override {}
|
2009-09-19 10:20:42 +00:00
|
|
|
|
2014-01-05 23:31:14 +00:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override;
|
2009-09-19 10:20:42 +00:00
|
|
|
#endif
|
2014-02-18 07:47:48 +00:00
|
|
|
virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsIContent** aContent) override;
|
2009-09-19 10:20:42 +00:00
|
|
|
|
|
|
|
nsRect CanvasArea() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Data members
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDoPaintFocus;
|
|
|
|
bool mAddedScrollPositionListener;
|
2014-06-03 07:08:25 +00:00
|
|
|
|
2019-11-29 20:39:36 +00:00
|
|
|
nsCOMPtr<Element> mCustomContentContainer;
|
2018-06-05 01:02:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsPopupSetFrame* mPopupSetFrame;
|
2019-11-29 20:39:36 +00:00
|
|
|
nsCOMPtr<Element> mPopupgroupContent;
|
|
|
|
nsCOMPtr<Element> mTooltipContent;
|
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.
|
|
|
|
*/
|
2018-09-06 01:23:14 +00:00
|
|
|
class nsDisplayCanvasBackgroundColor final : public nsDisplaySolidColorBase {
|
2010-07-15 21:07:53 +00:00
|
|
|
public:
|
2012-12-13 01:15:55 +00:00
|
|
|
nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2015-09-19 01:45:05 +00:00
|
|
|
: nsDisplaySolidColorBase(aBuilder, aFrame, NS_RGBA(0, 0, 0, 0)) {}
|
2010-07-15 21:07:53 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsRegion* aVisibleRegion) override {
|
2012-12-13 01:15:55 +00:00
|
|
|
return NS_GET_A(mColor) > 0;
|
2010-07-15 21:08:06 +00:00
|
|
|
}
|
2017-08-24 15:09:44 +00:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
|
|
|
bool* aSnap) const override {
|
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,
|
2015-03-21 16:28:04 +00:00
|
|
|
HitTestState* aState,
|
|
|
|
nsTArray<nsIFrame*>* aOutFrames) override {
|
2010-10-11 18:03:12 +00:00
|
|
|
// We need to override so we don't consider border-radius.
|
|
|
|
aOutFrames->AppendElement(mFrame);
|
|
|
|
}
|
2017-03-20 06:41:55 +00:00
|
|
|
virtual already_AddRefed<Layer> BuildLayer(
|
|
|
|
nsDisplayListBuilder* aBuilder, LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aContainerParameters) override;
|
2017-07-01 00:23:20 +00:00
|
|
|
virtual bool CreateWebRenderCommands(
|
|
|
|
mozilla::wr::DisplayListBuilder& aBuilder,
|
2017-09-14 16:48:55 +00:00
|
|
|
mozilla::wr::IpcResourceUpdateQueue& aResources,
|
2017-05-03 12:48:07 +00:00
|
|
|
const StackingContextHelper& aSc,
|
2019-01-07 21:33:10 +00:00
|
|
|
mozilla::layers::RenderRootStateManager* aManager,
|
2017-07-01 00:23:20 +00:00
|
|
|
nsDisplayListBuilder* aDisplayListBuilder) override;
|
2016-11-24 05:11:29 +00:00
|
|
|
virtual LayerState GetLayerState(
|
|
|
|
nsDisplayListBuilder* aBuilder, LayerManager* aManager,
|
|
|
|
const ContainerLayerParameters& aParameters) override {
|
2018-02-21 15:29:49 +00:00
|
|
|
if (ForceActiveLayers()) {
|
2019-05-18 20:11:11 +00:00
|
|
|
return mozilla::LayerState::LAYER_ACTIVE;
|
2016-11-24 05:11:29 +00:00
|
|
|
}
|
2019-05-18 20:11:11 +00:00
|
|
|
return mozilla::LayerState::LAYER_NONE;
|
2016-11-24 05:11:29 +00:00
|
|
|
}
|
2010-07-15 21:07:53 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
|
|
|
|
|
|
|
|
void SetExtraBackgroundColor(nscolor aColor) { mColor = aColor; }
|
|
|
|
|
2012-12-13 01:15:55 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
|
2020-02-11 12:17:34 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void WriteDebugInfo(std::stringstream& aStream) override;
|
2012-12-13 01:15:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
|
|
|
|
public:
|
2018-02-13 00:43:28 +00:00
|
|
|
explicit nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder,
|
2019-05-05 21:45:31 +00:00
|
|
|
nsIFrame* aFrame,
|
2018-02-13 00:43:28 +00:00
|
|
|
const InitData& aInitData)
|
2019-05-05 21:45:31 +00:00
|
|
|
: nsDisplayBackgroundImage(aBuilder, aFrame, aInitData) {}
|
2012-12-13 01:15:55 +00:00
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
|
2012-12-13 01:15:55 +00:00
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
// We still need to paint a background color as well as an image for this
|
2012-12-13 01:15:55 +00:00
|
|
|
// item, so we can't support this yet.
|
2017-08-24 15:09:44 +00:00
|
|
|
virtual bool SupportsOptimizingToImage() const override { return false; }
|
2016-04-22 05:50:11 +00:00
|
|
|
|
2016-08-19 23:36:57 +00:00
|
|
|
bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
|
2016-04-22 05:50:11 +00:00
|
|
|
const nsRect& aClipRect, gfxRect* aDestRect);
|
2017-07-06 12:00:35 +00:00
|
|
|
|
2012-12-13 01:15:55 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
|
2010-07-15 21:07:53 +00:00
|
|
|
};
|
|
|
|
|
2013-07-18 06:34:58 +00:00
|
|
|
class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
|
|
|
|
public:
|
|
|
|
nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder,
|
|
|
|
nsIFrame* aFrame)
|
2016-05-04 18:14:23 +00:00
|
|
|
: nsDisplayThemedBackground(aBuilder, aFrame,
|
|
|
|
aFrame->GetRectRelativeToSelf() +
|
|
|
|
aBuilder->ToReferenceFrame(aFrame)) {
|
2018-08-30 00:01:45 +00:00
|
|
|
nsDisplayThemedBackground::Init(aBuilder);
|
|
|
|
}
|
2013-07-18 06:34:58 +00:00
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
virtual void Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) override;
|
2013-07-18 06:34:58 +00:00
|
|
|
|
|
|
|
NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
|
|
|
|
};
|
|
|
|
|
2009-10-08 06:18:18 +00:00
|
|
|
#endif /* nsCanvasFrame_h___ */
|