2005-04-18 10:33:23 +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/. */
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2006-03-29 22:29:03 +04:00
|
|
|
/* rendering object for the HTML <canvas> element */
|
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
#include "nsHTMLCanvasFrame.h"
|
2013-09-25 05:43:43 +04:00
|
|
|
|
|
|
|
#include "nsGkAtoms.h"
|
2014-11-26 22:29:49 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2013-01-04 09:16:14 +04:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2009-07-22 04:44:57 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2014-11-27 06:43:36 +03:00
|
|
|
#include "nsStyleUtil.h"
|
2012-08-21 08:06:46 +04:00
|
|
|
#include "Layers.h"
|
2013-09-04 15:30:57 +04:00
|
|
|
#include "ActiveLayerTracker.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2009-03-05 16:43:45 +03:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
using namespace mozilla;
|
2013-01-04 09:16:14 +04:00
|
|
|
using namespace mozilla::dom;
|
2010-05-18 08:04:22 +04:00
|
|
|
using namespace mozilla::layers;
|
2014-09-10 17:26:12 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2014-11-26 22:29:49 +03:00
|
|
|
/* Helper for our nsIFrame::GetIntrinsicSize() impl. Takes the result of
|
|
|
|
* "GetCanvasSize()" as a parameter, which may help avoid redundant
|
|
|
|
* indirect calls to GetCanvasSize().
|
|
|
|
*
|
|
|
|
* @param aCanvasSizeInPx The canvas's size in CSS pixels, as returned
|
|
|
|
* by GetCanvasSize().
|
|
|
|
* @return The canvas's intrinsic size, as an IntrinsicSize object.
|
|
|
|
*/
|
|
|
|
static IntrinsicSize
|
|
|
|
IntrinsicSizeFromCanvasSize(const nsIntSize& aCanvasSizeInPx)
|
|
|
|
{
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.width));
|
|
|
|
intrinsicSize.height.SetCoordValue(
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.height));
|
|
|
|
|
|
|
|
return intrinsicSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper for our nsIFrame::GetIntrinsicRatio() impl. Takes the result of
|
|
|
|
* "GetCanvasSize()" as a parameter, which may help avoid redundant
|
|
|
|
* indirect calls to GetCanvasSize().
|
|
|
|
*
|
|
|
|
* @param aCanvasSizeInPx The canvas's size in CSS pixels, as returned
|
|
|
|
* by GetCanvasSize().
|
|
|
|
* @return The canvas's intrinsic ratio, as a nsSize.
|
|
|
|
*/
|
|
|
|
static nsSize
|
|
|
|
IntrinsicRatioFromCanvasSize(const nsIntSize& aCanvasSizeInPx)
|
|
|
|
{
|
|
|
|
return nsSize(nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(aCanvasSizeInPx.height));
|
|
|
|
}
|
|
|
|
|
2010-07-16 01:07:44 +04:00
|
|
|
class nsDisplayCanvas : public nsDisplayItem {
|
2009-03-05 16:43:45 +03:00
|
|
|
public:
|
2010-08-13 14:01:13 +04:00
|
|
|
nsDisplayCanvas(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
2009-03-05 16:43:45 +03:00
|
|
|
{
|
2010-07-16 01:07:44 +04:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayCanvas);
|
2009-03-05 16:43:45 +03:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-07-16 01:07:44 +04:00
|
|
|
virtual ~nsDisplayCanvas() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayCanvas);
|
2009-03-05 16:43:45 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-16 01:07:49 +04:00
|
|
|
NS_DISPLAY_DECL_NAME("nsDisplayCanvas", TYPE_CANVAS)
|
2009-03-05 16:43:45 +03:00
|
|
|
|
2011-01-03 04:48:09 +03:00
|
|
|
virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool* aSnap) override {
|
2012-04-10 15:24:18 +04:00
|
|
|
*aSnap = false;
|
2014-11-27 06:43:36 +03:00
|
|
|
nsHTMLCanvasFrame* f = static_cast<nsHTMLCanvasFrame*>(Frame());
|
|
|
|
HTMLCanvasElement* canvas =
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement::FromContent(f->GetContent());
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
|
|
|
if (canvas->GetIsOpaque()) {
|
2014-11-27 06:43:36 +03:00
|
|
|
// OK, the entire region painted by the canvas is opaque. But what is
|
|
|
|
// that region? It's the canvas's "dest rect" (controlled by the
|
|
|
|
// object-fit/object-position CSS properties), clipped to the container's
|
|
|
|
// content box (which is what GetBounds() returns). So, we grab those
|
|
|
|
// rects and intersect them.
|
|
|
|
nsRect constraintRect = GetBounds(aBuilder, aSnap);
|
|
|
|
|
|
|
|
// Need intrinsic size & ratio, for ComputeObjectDestRect:
|
|
|
|
nsIntSize canvasSize = f->GetCanvasSize();
|
|
|
|
IntrinsicSize intrinsicSize = IntrinsicSizeFromCanvasSize(canvasSize);
|
|
|
|
nsSize intrinsicRatio = IntrinsicRatioFromCanvasSize(canvasSize);
|
|
|
|
|
|
|
|
const nsRect destRect =
|
|
|
|
nsLayoutUtils::ComputeObjectDestRect(constraintRect,
|
|
|
|
intrinsicSize, intrinsicRatio,
|
|
|
|
f->StylePosition());
|
|
|
|
return nsRegion(destRect.Intersect(constraintRect));
|
2011-01-03 04:48:09 +03:00
|
|
|
}
|
|
|
|
return result;
|
2009-03-05 16:43:45 +03:00
|
|
|
}
|
|
|
|
|
2014-02-24 18:41:56 +04:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool* aSnap) override {
|
2012-11-13 23:56:47 +04:00
|
|
|
*aSnap = true;
|
2013-04-19 16:02:13 +04:00
|
|
|
nsHTMLCanvasFrame* f = static_cast<nsHTMLCanvasFrame*>(Frame());
|
2010-08-13 14:01:58 +04:00
|
|
|
return f->GetInnerArea() + ToReferenceFrame();
|
2009-03-05 16:43:45 +03:00
|
|
|
}
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 16:11:27 +04:00
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aContainerParameters) override
|
2010-05-18 08:04:22 +04:00
|
|
|
{
|
2010-07-16 01:07:46 +04:00
|
|
|
return static_cast<nsHTMLCanvasFrame*>(mFrame)->
|
2012-09-17 02:25:33 +04:00
|
|
|
BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2010-07-16 01:08:05 +04:00
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 18:05:55 +04:00
|
|
|
LayerManager* aManager,
|
2015-03-21 19:28:04 +03:00
|
|
|
const ContainerLayerParameters& aParameters) override
|
2010-07-16 01:08:05 +04:00
|
|
|
{
|
2013-01-04 09:16:14 +04:00
|
|
|
if (HTMLCanvasElement::FromContent(mFrame->GetContent())->ShouldForceInactiveLayer(aManager))
|
2011-07-08 14:42:21 +04:00
|
|
|
return LAYER_INACTIVE;
|
|
|
|
|
2011-02-04 21:11:24 +03:00
|
|
|
// If compositing is cheap, just do that
|
2013-09-04 15:30:57 +04:00
|
|
|
if (aManager->IsCompositingCheap() ||
|
|
|
|
ActiveLayerTracker::IsContentActive(mFrame))
|
2011-02-04 21:11:24 +03:00
|
|
|
return mozilla::LAYER_ACTIVE;
|
|
|
|
|
2013-09-04 15:30:57 +04:00
|
|
|
return LAYER_INACTIVE;
|
2010-07-16 01:08:05 +04:00
|
|
|
}
|
2009-03-05 16:43:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewHTMLCanvasFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2005-04-18 10:33:23 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsHTMLCanvasFrame(aContext);
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
2013-04-04 03:35:07 +04:00
|
|
|
NS_QUERYFRAME_HEAD(nsHTMLCanvasFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsHTMLCanvasFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLCanvasFrame)
|
|
|
|
|
2013-03-20 05:47:48 +04:00
|
|
|
void
|
2014-05-25 02:20:40 +04:00
|
|
|
nsHTMLCanvasFrame::Init(nsIContent* aContent,
|
|
|
|
nsContainerFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
2011-02-04 21:11:24 +03:00
|
|
|
{
|
2013-03-21 23:09:15 +04:00
|
|
|
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2011-02-04 21:11:24 +03:00
|
|
|
|
|
|
|
// We can fill in the canvas before the canvas frame is created, in
|
2013-09-04 15:30:57 +04:00
|
|
|
// which case we never get around to marking the content as active. Therefore,
|
2011-02-04 21:11:24 +03:00
|
|
|
// we mark it active here when we create the frame.
|
2013-09-04 15:30:57 +04:00
|
|
|
ActiveLayerTracker::NotifyContentChange(this);
|
2011-02-04 21:11:24 +03:00
|
|
|
}
|
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
nsHTMLCanvasFrame::~nsHTMLCanvasFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntSize
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLCanvasFrame::GetCanvasSize()
|
|
|
|
{
|
2010-05-18 08:04:22 +04:00
|
|
|
nsIntSize size(0,0);
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement *canvas =
|
|
|
|
HTMLCanvasElement::FromContentOrNull(GetContent());
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (canvas) {
|
2010-05-18 08:04:22 +04:00
|
|
|
size = canvas->GetSize();
|
2014-11-26 22:29:49 +03:00
|
|
|
MOZ_ASSERT(size.width >= 0 && size.height >= 0,
|
|
|
|
"we should've required <canvas> width/height attrs to be "
|
|
|
|
"unsigned (non-negative) values");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("couldn't get canvas size");
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
return size;
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 21:03:25 +04:00
|
|
|
nsHTMLCanvasFrame::GetMinISize(nsRenderingContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2014-12-09 17:00:38 +03:00
|
|
|
bool vertical = GetWritingMode().IsVertical();
|
|
|
|
nscoord result = nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
vertical ? GetCanvasSize().height : GetCanvasSize().width);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2014-07-24 21:03:25 +04:00
|
|
|
nsHTMLCanvasFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2014-12-09 17:00:38 +03:00
|
|
|
bool vertical = GetWritingMode().IsVertical();
|
|
|
|
nscoord result = nsPresContext::CSSPixelsToAppUnits(
|
|
|
|
vertical ? GetCanvasSize().height : GetCanvasSize().width);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-11-26 22:29:49 +03:00
|
|
|
/* virtual */ IntrinsicSize
|
|
|
|
nsHTMLCanvasFrame::GetIntrinsicSize()
|
|
|
|
{
|
|
|
|
return IntrinsicSizeFromCanvasSize(GetCanvasSize());
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsHTMLCanvasFrame::GetIntrinsicRatio()
|
|
|
|
{
|
2014-11-26 22:29:49 +03:00
|
|
|
return IntrinsicRatioFromCanvasSize(GetCanvasSize());
|
2007-06-12 22:27:09 +04:00
|
|
|
}
|
|
|
|
|
2014-08-24 18:34:44 +04:00
|
|
|
/* virtual */
|
|
|
|
LogicalSize
|
2011-04-08 05:04:40 +04:00
|
|
|
nsHTMLCanvasFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
2014-08-24 18:34:44 +04:00
|
|
|
WritingMode aWM,
|
|
|
|
const LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder,
|
|
|
|
const LogicalSize& aPadding,
|
2014-11-11 14:02:41 +03:00
|
|
|
ComputeSizeFlags aFlags)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntSize size = GetCanvasSize();
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(nsPresContext::CSSPixelsToAppUnits(size.width));
|
|
|
|
intrinsicSize.height.SetCoordValue(nsPresContext::CSSPixelsToAppUnits(size.height));
|
|
|
|
|
2009-01-15 06:27:09 +03:00
|
|
|
nsSize intrinsicRatio = GetIntrinsicRatio(); // won't actually be used
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
|
2014-08-24 18:34:57 +04:00
|
|
|
return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
|
|
|
aWM,
|
2007-11-18 15:09:03 +03:00
|
|
|
aRenderingContext, this,
|
2014-08-24 18:34:44 +04:00
|
|
|
intrinsicSize, intrinsicRatio,
|
2014-08-24 18:34:57 +04:00
|
|
|
aCBSize,
|
|
|
|
aMargin,
|
|
|
|
aBorder,
|
|
|
|
aPadding);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2014-05-13 04:47:52 +04:00
|
|
|
void
|
2005-04-18 10:33:23 +04:00
|
|
|
nsHTMLCanvasFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
2015-03-30 01:38:40 +03:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLCanvasFrame");
|
2005-04-18 10:33:23 +04:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsHTMLCanvasFrame::Reflow: availSize=%d,%d",
|
2013-12-27 21:59:21 +04:00
|
|
|
aReflowState.AvailableWidth(), aReflowState.AvailableHeight()));
|
2005-04-18 10:33:23 +04:00
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
WritingMode wm = aReflowState.GetWritingMode();
|
|
|
|
LogicalSize finalSize(wm,
|
|
|
|
aReflowState.ComputedISize(),
|
|
|
|
aReflowState.ComputedBSize());
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2005-05-07 07:45:06 +04:00
|
|
|
// stash this away so we can compute our inner area later
|
2014-07-24 12:30:07 +04:00
|
|
|
mBorderPadding = aReflowState.ComputedLogicalBorderPadding();
|
2005-05-07 07:45:06 +04:00
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
finalSize.ISize(wm) += mBorderPadding.IStartEnd(wm);
|
|
|
|
finalSize.BSize(wm) += mBorderPadding.BStartEnd(wm);
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (GetPrevInFlow()) {
|
2014-07-24 12:30:07 +04:00
|
|
|
nscoord y = GetContinuationOffset(&finalSize.ISize(wm));
|
|
|
|
finalSize.BSize(wm) -= y + mBorderPadding.BStart(wm);
|
|
|
|
finalSize.BSize(wm) = std::max(0, finalSize.BSize(wm));
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
2014-07-24 12:30:07 +04:00
|
|
|
aMetrics.SetSize(wm, finalSize);
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2005-04-18 10:33:23 +04:00
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
|
2012-02-18 08:26:37 +04:00
|
|
|
// Reflow the single anon block child.
|
|
|
|
nsReflowStatus childStatus;
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
2014-07-24 12:30:07 +04:00
|
|
|
WritingMode childWM = childFrame->GetWritingMode();
|
|
|
|
LogicalSize availSize = aReflowState.ComputedSize(childWM);
|
|
|
|
availSize.BSize(childWM) = NS_UNCONSTRAINEDSIZE;
|
2012-02-18 08:26:37 +04:00
|
|
|
NS_ASSERTION(!childFrame->GetNextSibling(), "HTML canvas should have 1 kid");
|
2013-12-27 21:59:52 +04:00
|
|
|
nsHTMLReflowMetrics childDesiredSize(aReflowState.GetWritingMode(), aMetrics.mFlags);
|
2012-02-18 08:26:37 +04:00
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState, childFrame,
|
|
|
|
availSize);
|
|
|
|
ReflowChild(childFrame, aPresContext, childDesiredSize, childReflowState,
|
2012-07-30 18:20:58 +04:00
|
|
|
0, 0, 0, childStatus, nullptr);
|
2014-01-17 05:34:44 +04:00
|
|
|
FinishReflowChild(childFrame, aPresContext, childDesiredSize,
|
|
|
|
&childReflowState, 0, 0, 0);
|
2012-02-18 08:26:37 +04:00
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("exit nsHTMLCanvasFrame::Reflow: size=%d,%d",
|
2014-07-24 12:30:07 +04:00
|
|
|
aMetrics.ISize(wm), aMetrics.BSize(wm)));
|
2005-04-18 10:33:23 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
}
|
|
|
|
|
2005-05-07 07:45:06 +04:00
|
|
|
// FIXME taken from nsImageFrame, but then had splittable frame stuff
|
|
|
|
// removed. That needs to be fixed.
|
2014-09-12 01:29:59 +04:00
|
|
|
// XXXdholbert As in nsImageFrame, this function's clients should probably
|
|
|
|
// just be calling GetContentRectRelativeToSelf().
|
2005-05-07 07:45:06 +04:00
|
|
|
nsRect
|
|
|
|
nsHTMLCanvasFrame::GetInnerArea() const
|
|
|
|
{
|
2014-07-24 12:30:07 +04:00
|
|
|
nsMargin bp = mBorderPadding.GetPhysicalMargin(GetWritingMode());
|
2005-05-07 07:45:06 +04:00
|
|
|
nsRect r;
|
2014-07-24 12:30:07 +04:00
|
|
|
r.x = bp.left;
|
|
|
|
r.y = bp.top;
|
|
|
|
r.width = mRect.width - bp.left - bp.right;
|
|
|
|
r.height = mRect.height - bp.top - bp.bottom;
|
2005-05-07 07:45:06 +04:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsHTMLCanvasFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2010-07-16 01:07:46 +04:00
|
|
|
LayerManager* aManager,
|
2012-09-17 02:25:33 +04:00
|
|
|
nsDisplayItem* aItem,
|
2013-09-27 10:01:16 +04:00
|
|
|
const ContainerLayerParameters& aContainerParameters)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2014-09-12 01:29:59 +04:00
|
|
|
nsRect area = GetContentRectRelativeToSelf() + aItem->ToReferenceFrame();
|
2013-01-04 09:16:14 +04:00
|
|
|
HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(GetContent());
|
2014-11-27 06:43:36 +03:00
|
|
|
nsIntSize canvasSizeInPx = GetCanvasSize();
|
2009-05-07 00:02:59 +04:00
|
|
|
|
2012-08-31 04:24:35 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
element->HandlePrintCallback(presContext->Type());
|
|
|
|
|
2014-11-27 06:43:36 +03:00
|
|
|
if (canvasSizeInPx.width <= 0 || canvasSizeInPx.height <= 0 || area.IsEmpty())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-01-17 05:41:47 +03:00
|
|
|
|
2010-07-16 01:07:46 +04:00
|
|
|
CanvasLayer* oldLayer = static_cast<CanvasLayer*>
|
2012-08-29 09:47:15 +04:00
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
|
2011-03-28 03:59:47 +04:00
|
|
|
nsRefPtr<CanvasLayer> layer = element->GetCanvasLayer(aBuilder, oldLayer, aManager);
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!layer)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2014-11-27 06:43:36 +03:00
|
|
|
IntrinsicSize intrinsicSize = IntrinsicSizeFromCanvasSize(canvasSizeInPx);
|
|
|
|
nsSize intrinsicRatio = IntrinsicRatioFromCanvasSize(canvasSizeInPx);
|
|
|
|
|
|
|
|
nsRect dest =
|
|
|
|
nsLayoutUtils::ComputeObjectDestRect(area, intrinsicSize, intrinsicRatio,
|
|
|
|
StylePosition());
|
|
|
|
|
|
|
|
gfxRect destGFXRect = presContext->AppUnitsToGfxUnits(dest);
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// Transform the canvas into the right place
|
2014-11-27 06:43:36 +03:00
|
|
|
gfxPoint p = destGFXRect.TopLeft() + aContainerParameters.mOffset;
|
2014-09-10 17:26:12 +04:00
|
|
|
Matrix transform = Matrix::Translation(p.x, p.y);
|
2014-11-27 06:43:36 +03:00
|
|
|
transform.PreScale(destGFXRect.Width() / canvasSizeInPx.width,
|
|
|
|
destGFXRect.Height() / canvasSizeInPx.height);
|
2014-01-27 19:28:33 +04:00
|
|
|
layer->SetBaseTransform(gfx::Matrix4x4::From2D(transform));
|
2010-05-18 08:04:22 +04:00
|
|
|
layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2010-08-06 02:11:23 +04:00
|
|
|
return layer.forget();
|
2006-01-26 05:29:17 +03:00
|
|
|
}
|
|
|
|
|
2013-02-14 15:12:27 +04:00
|
|
|
void
|
2006-01-26 05:29:17 +03:00
|
|
|
nsHTMLCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2005-04-18 10:33:23 +04:00
|
|
|
{
|
2006-01-26 05:29:17 +03:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 15:12:27 +04:00
|
|
|
return;
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2013-02-14 15:08:08 +04:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2006-01-26 05:29:17 +03:00
|
|
|
|
2014-11-27 06:43:36 +03:00
|
|
|
uint32_t clipFlags =
|
|
|
|
nsStyleUtil::ObjectPropsMightCauseOverflow(StylePosition()) ?
|
|
|
|
0 : DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT;
|
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
2014-11-27 06:43:36 +03:00
|
|
|
clip(aBuilder, this, clipFlags);
|
2010-09-09 19:21:47 +04:00
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
aLists.Content()->AppendNewToTop(
|
2013-02-14 15:08:08 +04:00
|
|
|
new (aBuilder) nsDisplayCanvas(aBuilder, this));
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2013-03-04 13:56:02 +04:00
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content(),
|
2013-02-14 15:08:08 +04:00
|
|
|
nsISelectionDisplay::DISPLAY_IMAGES);
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLCanvasFrame::GetType() const
|
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::HTMLCanvasFrame;
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the offset into the content area of the image where aImg starts if it is a continuation.
|
|
|
|
// from nsImageFrame
|
|
|
|
nscoord
|
|
|
|
nsHTMLCanvasFrame::GetContinuationOffset(nscoord* aWidth) const
|
|
|
|
{
|
|
|
|
nscoord offset = 0;
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (GetPrevInFlow()) {
|
|
|
|
for (nsIFrame* prevInFlow = GetPrevInFlow() ; prevInFlow; prevInFlow = prevInFlow->GetPrevInFlow()) {
|
2005-04-18 10:33:23 +04:00
|
|
|
nsRect rect = prevInFlow->GetRect();
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = rect.width;
|
|
|
|
}
|
|
|
|
offset += rect.height;
|
|
|
|
}
|
2014-07-24 12:30:07 +04:00
|
|
|
offset -= mBorderPadding.GetPhysicalMargin(GetWritingMode()).top;
|
2013-01-15 16:22:03 +04:00
|
|
|
offset = std::max(0, offset);
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-29 01:53:44 +04:00
|
|
|
a11y::AccType
|
|
|
|
nsHTMLCanvasFrame::AccessibleType()
|
2005-04-18 10:33:23 +04:00
|
|
|
{
|
2012-12-18 05:25:52 +04:00
|
|
|
return a11y::eHTMLCanvasType;
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-06 03:31:14 +04:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2014-02-18 11:47:48 +04:00
|
|
|
nsresult
|
2005-05-07 07:45:06 +04:00
|
|
|
nsHTMLCanvasFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLCanvas"), aResult);
|
|
|
|
}
|
2005-04-18 10:33:23 +04:00
|
|
|
#endif
|
|
|
|
|