2005-04-18 06:33:23 +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/. */
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2006-03-29 18:29:03 +00:00
|
|
|
/* rendering object for the HTML <canvas> element */
|
|
|
|
|
2005-04-18 06:33:23 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2005-04-18 06:33:23 +00:00
|
|
|
|
|
|
|
#include "nsHTMLCanvasFrame.h"
|
2013-01-04 05:16:14 +00:00
|
|
|
#include "mozilla/dom/HTMLCanvasElement.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2009-07-22 00:44:57 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2012-08-21 04:06:46 +00:00
|
|
|
#include "Layers.h"
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2006-04-18 21:23:15 +00:00
|
|
|
#include "nsTransform2D.h"
|
|
|
|
|
2009-04-08 20:27:20 +00:00
|
|
|
#include "gfxContext.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2009-03-05 13:43:45 +00:00
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
using namespace mozilla;
|
2013-01-04 05:16:14 +00:00
|
|
|
using namespace mozilla::dom;
|
2010-05-18 04:04:22 +00:00
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
2010-07-15 21:07:44 +00:00
|
|
|
class nsDisplayCanvas : public nsDisplayItem {
|
2009-03-05 13:43:45 +00:00
|
|
|
public:
|
2010-08-13 10:01:13 +00:00
|
|
|
nsDisplayCanvas(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
|
|
|
|
: nsDisplayItem(aBuilder, aFrame)
|
2009-03-05 13:43:45 +00:00
|
|
|
{
|
2010-07-15 21:07:44 +00:00
|
|
|
MOZ_COUNT_CTOR(nsDisplayCanvas);
|
2009-03-05 13:43:45 +00:00
|
|
|
}
|
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2010-07-15 21:07:44 +00:00
|
|
|
virtual ~nsDisplayCanvas() {
|
|
|
|
MOZ_COUNT_DTOR(nsDisplayCanvas);
|
2009-03-05 13:43:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-15 21:07:49 +00:00
|
|
|
NS_DISPLAY_DECL_NAME("nsDisplayCanvas", TYPE_CANVAS)
|
2009-03-05 13:43:45 +00:00
|
|
|
|
2011-01-03 01:48:09 +00:00
|
|
|
virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
|
2012-06-21 07:21:55 +00:00
|
|
|
bool* aSnap) {
|
2012-04-10 11:24:18 +00:00
|
|
|
*aSnap = false;
|
2013-04-19 12:02:13 +00:00
|
|
|
nsIFrame* f = Frame();
|
2013-01-04 05:16:14 +00:00
|
|
|
HTMLCanvasElement *canvas =
|
|
|
|
HTMLCanvasElement::FromContent(f->GetContent());
|
2011-01-03 01:48:09 +00:00
|
|
|
nsRegion result;
|
|
|
|
if (canvas->GetIsOpaque()) {
|
2012-04-10 11:24:18 +00:00
|
|
|
result = GetBounds(aBuilder, aSnap);
|
2011-01-03 01:48:09 +00:00
|
|
|
}
|
|
|
|
return result;
|
2009-03-05 13:43:45 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 11:24:18 +00:00
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) {
|
2012-11-13 19:56:47 +00:00
|
|
|
*aSnap = true;
|
2013-04-19 12:02:13 +00:00
|
|
|
nsHTMLCanvasFrame* f = static_cast<nsHTMLCanvasFrame*>(Frame());
|
2010-08-13 10:01:58 +00:00
|
|
|
return f->GetInnerArea() + ToReferenceFrame();
|
2009-03-05 13:43:45 +00:00
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
|
|
|
virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
|
2011-06-22 12:11:27 +00:00
|
|
|
LayerManager* aManager,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2010-05-18 04:04:22 +00:00
|
|
|
{
|
2010-07-15 21:07:46 +00:00
|
|
|
return static_cast<nsHTMLCanvasFrame*>(mFrame)->
|
2012-09-16 22:25:33 +00:00
|
|
|
BuildLayer(aBuilder, aManager, this, aContainerParameters);
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
2010-07-15 21:08:05 +00:00
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
2012-05-03 14:05:55 +00:00
|
|
|
LayerManager* aManager,
|
|
|
|
const FrameLayerBuilder::ContainerParameters& aParameters)
|
2010-07-15 21:08:05 +00:00
|
|
|
{
|
2013-01-04 05:16:14 +00:00
|
|
|
if (HTMLCanvasElement::FromContent(mFrame->GetContent())->ShouldForceInactiveLayer(aManager))
|
2011-07-08 10:42:21 +00:00
|
|
|
return LAYER_INACTIVE;
|
|
|
|
|
2011-02-04 18:11:24 +00:00
|
|
|
// If compositing is cheap, just do that
|
|
|
|
if (aManager->IsCompositingCheap())
|
|
|
|
return mozilla::LAYER_ACTIVE;
|
|
|
|
|
|
|
|
return mFrame->AreLayersMarkedActive() ? LAYER_ACTIVE : LAYER_INACTIVE;
|
2010-07-15 21:08:05 +00:00
|
|
|
}
|
2009-03-05 13:43:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-01 20:40:54 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewHTMLCanvasFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2005-04-18 06:33:23 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsHTMLCanvasFrame(aContext);
|
2005-04-18 06:33:23 +00:00
|
|
|
}
|
|
|
|
|
2013-04-03 23:35:07 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsHTMLCanvasFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsHTMLCanvasFrame)
|
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLCanvasFrame)
|
|
|
|
|
2013-03-20 01:47:48 +00:00
|
|
|
void
|
2011-02-04 18:11:24 +00:00
|
|
|
nsHTMLCanvasFrame::Init(nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
2013-03-21 19:09:15 +00:00
|
|
|
nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
|
2011-02-04 18:11:24 +00:00
|
|
|
|
|
|
|
// We can fill in the canvas before the canvas frame is created, in
|
|
|
|
// which case we never get around to marking the layer active. Therefore,
|
|
|
|
// we mark it active here when we create the frame.
|
2011-06-22 12:11:28 +00:00
|
|
|
MarkLayersActive(nsChangeHint(0));
|
2011-02-04 18:11:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-18 06:33:23 +00:00
|
|
|
nsHTMLCanvasFrame::~nsHTMLCanvasFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:27:09 +00: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 05:38:33 +00:00
|
|
|
nsHTMLCanvasFrame::GetCanvasSize()
|
|
|
|
{
|
2010-05-18 04:04:22 +00:00
|
|
|
nsIntSize size(0,0);
|
2013-01-04 05:16:14 +00: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 05:38:33 +00:00
|
|
|
if (canvas) {
|
2010-05-18 04:04:22 +00:00
|
|
|
size = canvas->GetSize();
|
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 05:38:33 +00:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("couldn't get canvas size");
|
|
|
|
}
|
|
|
|
|
2010-05-18 04:04:22 +00: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 05:38:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-08 01:04:40 +00:00
|
|
|
nsHTMLCanvasFrame::GetMinWidth(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 05:38:33 +00:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord result = nsPresContext::CSSPixelsToAppUnits(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 05:38:33 +00:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-08 01:04:40 +00:00
|
|
|
nsHTMLCanvasFrame::GetPrefWidth(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 05:38:33 +00:00
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2007-02-07 07:46:44 +00:00
|
|
|
nscoord result = nsPresContext::CSSPixelsToAppUnits(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 05:38:33 +00:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-06-12 18:27:09 +00:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsHTMLCanvasFrame::GetIntrinsicRatio()
|
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntSize size(GetCanvasSize());
|
|
|
|
return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(size.height));
|
2007-06-12 18:27:09 +00:00
|
|
|
}
|
|
|
|
|
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 05:38:33 +00:00
|
|
|
/* virtual */ nsSize
|
2011-04-08 01:04:40 +00:00
|
|
|
nsHTMLCanvasFrame::ComputeSize(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 05:38:33 +00:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t 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 05:38:33 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntSize size = GetCanvasSize();
|
2007-11-18 12:09:03 +00:00
|
|
|
|
|
|
|
IntrinsicSize intrinsicSize;
|
|
|
|
intrinsicSize.width.SetCoordValue(nsPresContext::CSSPixelsToAppUnits(size.width));
|
|
|
|
intrinsicSize.height.SetCoordValue(nsPresContext::CSSPixelsToAppUnits(size.height));
|
|
|
|
|
2009-01-15 03:27:09 +00: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 05:38:33 +00:00
|
|
|
|
|
|
|
return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
2007-11-18 12:09:03 +00:00
|
|
|
aRenderingContext, this,
|
|
|
|
intrinsicSize, intrinsicRatio, 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 05:38:33 +00:00
|
|
|
}
|
2005-04-18 06:33:23 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLCanvasFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
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 05:38:33 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsHTMLCanvasFrame");
|
2005-04-18 06:33:23 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsHTMLCanvasFrame::Reflow: availSize=%d,%d",
|
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2007-01-26 00:05:12 +00:00
|
|
|
aMetrics.width = aReflowState.ComputedWidth();
|
2007-08-02 18:08:05 +00:00
|
|
|
aMetrics.height = aReflowState.ComputedHeight();
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2005-05-07 03:45:06 +00:00
|
|
|
// stash this away so we can compute our inner area later
|
|
|
|
mBorderPadding = aReflowState.mComputedBorderPadding;
|
|
|
|
|
|
|
|
aMetrics.width += mBorderPadding.left + mBorderPadding.right;
|
|
|
|
aMetrics.height += mBorderPadding.top + mBorderPadding.bottom;
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2006-02-21 21:33:47 +00:00
|
|
|
if (GetPrevInFlow()) {
|
2005-04-18 06:33:23 +00:00
|
|
|
nscoord y = GetContinuationOffset(&aMetrics.width);
|
|
|
|
aMetrics.height -= y + mBorderPadding.top;
|
2013-01-15 12:22:03 +00:00
|
|
|
aMetrics.height = std::max(0, aMetrics.height);
|
2005-04-18 06:33:23 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 04:25:46 +00:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2005-04-18 06:33:23 +00:00
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
|
2012-02-18 04:26:37 +00:00
|
|
|
// Reflow the single anon block child.
|
|
|
|
nsReflowStatus childStatus;
|
|
|
|
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsIFrame* childFrame = mFrames.FirstChild();
|
|
|
|
NS_ASSERTION(!childFrame->GetNextSibling(), "HTML canvas should have 1 kid");
|
|
|
|
nsHTMLReflowMetrics childDesiredSize(aMetrics.mFlags);
|
|
|
|
nsHTMLReflowState childReflowState(aPresContext, aReflowState, childFrame,
|
|
|
|
availSize);
|
|
|
|
ReflowChild(childFrame, aPresContext, childDesiredSize, childReflowState,
|
2012-07-30 14:20:58 +00:00
|
|
|
0, 0, 0, childStatus, nullptr);
|
2012-02-18 04:26:37 +00:00
|
|
|
FinishReflowChild(childFrame, aPresContext, &childReflowState,
|
|
|
|
childDesiredSize, 0, 0, 0);
|
|
|
|
|
2005-04-18 06:33:23 +00:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("exit nsHTMLCanvasFrame::Reflow: size=%d,%d",
|
|
|
|
aMetrics.width, aMetrics.height));
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
2012-02-18 04:26:37 +00:00
|
|
|
|
2005-04-18 06:33:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-07 03:45:06 +00:00
|
|
|
// FIXME taken from nsImageFrame, but then had splittable frame stuff
|
|
|
|
// removed. That needs to be fixed.
|
|
|
|
nsRect
|
|
|
|
nsHTMLCanvasFrame::GetInnerArea() const
|
|
|
|
{
|
|
|
|
nsRect r;
|
|
|
|
r.x = mBorderPadding.left;
|
|
|
|
r.y = mBorderPadding.top;
|
|
|
|
r.width = mRect.width - mBorderPadding.left - mBorderPadding.right;
|
|
|
|
r.height = mRect.height - mBorderPadding.top - mBorderPadding.bottom;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsHTMLCanvasFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2010-07-15 21:07:46 +00:00
|
|
|
LayerManager* aManager,
|
2012-09-16 22:25:33 +00:00
|
|
|
nsDisplayItem* aItem,
|
|
|
|
const ContainerParameters& aContainerParameters)
|
2006-01-26 02:29:17 +00:00
|
|
|
{
|
2010-08-13 10:01:58 +00:00
|
|
|
nsRect area = GetContentRect() - GetPosition() + aItem->ToReferenceFrame();
|
2013-01-04 05:16:14 +00:00
|
|
|
HTMLCanvasElement* element = static_cast<HTMLCanvasElement*>(GetContent());
|
2010-05-18 04:04:22 +00:00
|
|
|
nsIntSize canvasSize = GetCanvasSize();
|
2009-05-06 20:02:59 +00:00
|
|
|
|
2012-08-31 00:24:35 +00:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
element->HandlePrintCallback(presContext->Type());
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
if (canvasSize.width <= 0 || canvasSize.height <= 0 || area.IsEmpty())
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2007-01-17 02:41:47 +00:00
|
|
|
|
2010-07-15 21:07:46 +00:00
|
|
|
CanvasLayer* oldLayer = static_cast<CanvasLayer*>
|
2012-08-29 05:47:15 +00:00
|
|
|
(aManager->GetLayerBuilder()->GetLeafLayerFor(aBuilder, aItem));
|
2011-03-27 23:59:47 +00:00
|
|
|
nsRefPtr<CanvasLayer> layer = element->GetCanvasLayer(aBuilder, oldLayer, aManager);
|
2010-05-18 04:04:22 +00:00
|
|
|
if (!layer)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-04-18 21:23:15 +00:00
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
gfxRect r = gfxRect(presContext->AppUnitsToGfxUnits(area.x),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.y),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.width),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.height));
|
2006-04-18 21:23:15 +00:00
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
// Transform the canvas into the right place
|
|
|
|
gfxMatrix transform;
|
2012-09-16 22:25:33 +00:00
|
|
|
transform.Translate(r.TopLeft() + aContainerParameters.mOffset);
|
2010-05-18 04:04:22 +00:00
|
|
|
transform.Scale(r.Width()/canvasSize.width, r.Height()/canvasSize.height);
|
2012-07-31 02:20:00 +00:00
|
|
|
layer->SetBaseTransform(gfx3DMatrix::From2D(transform));
|
2010-05-18 04:04:22 +00:00
|
|
|
layer->SetFilter(nsLayoutUtils::GetGraphicsFilterForFrame(this));
|
2011-02-23 05:38:09 +00:00
|
|
|
layer->SetVisibleRegion(nsIntRect(0, 0, canvasSize.width, canvasSize.height));
|
2006-04-18 21:23:15 +00:00
|
|
|
|
2010-08-05 22:11:23 +00:00
|
|
|
return layer.forget();
|
2006-01-26 02:29:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsHTMLCanvasFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2005-04-18 06:33:23 +00:00
|
|
|
{
|
2006-01-26 02:29:17 +00:00
|
|
|
if (!IsVisibleForPainting(aBuilder))
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-02-14 11:08:08 +00:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2006-01-26 02:29:17 +00:00
|
|
|
|
2013-03-04 09:56:02 +00:00
|
|
|
DisplayListClipState::AutoClipContainingBlockDescendantsToContentBox
|
|
|
|
clip(aBuilder, this, DisplayListClipState::ASSUME_DRAWING_RESTRICTED_TO_CONTENT_RECT);
|
2010-09-09 15:21:47 +00:00
|
|
|
|
2013-03-04 09:56:02 +00:00
|
|
|
aLists.Content()->AppendNewToTop(
|
2013-02-14 11:08:08 +00:00
|
|
|
new (aBuilder) nsDisplayCanvas(aBuilder, this));
|
2005-04-18 06:33:23 +00:00
|
|
|
|
2013-03-04 09:56:02 +00:00
|
|
|
DisplaySelectionOverlay(aBuilder, aLists.Content(),
|
2013-02-14 11:08:08 +00:00
|
|
|
nsISelectionDisplay::DISPLAY_IMAGES);
|
2005-04-18 06:33:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsHTMLCanvasFrame::GetType() const
|
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::HTMLCanvasFrame;
|
2005-04-18 06:33:23 +00: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-21 21:33:47 +00:00
|
|
|
if (GetPrevInFlow()) {
|
|
|
|
for (nsIFrame* prevInFlow = GetPrevInFlow() ; prevInFlow; prevInFlow = prevInFlow->GetPrevInFlow()) {
|
2005-04-18 06:33:23 +00:00
|
|
|
nsRect rect = prevInFlow->GetRect();
|
|
|
|
if (aWidth) {
|
|
|
|
*aWidth = rect.width;
|
|
|
|
}
|
|
|
|
offset += rect.height;
|
|
|
|
}
|
|
|
|
offset -= mBorderPadding.top;
|
2013-01-15 12:22:03 +00:00
|
|
|
offset = std::max(0, offset);
|
2005-04-18 06:33:23 +00:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 21:53:44 +00:00
|
|
|
a11y::AccType
|
|
|
|
nsHTMLCanvasFrame::AccessibleType()
|
2005-04-18 06:33:23 +00:00
|
|
|
{
|
2012-12-18 01:25:52 +00:00
|
|
|
return a11y::eHTMLCanvasType;
|
2005-04-18 06:33:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-05-07 03:45:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLCanvasFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLCanvas"), aResult);
|
|
|
|
}
|
2005-04-18 06:33:23 +00:00
|
|
|
#endif
|
|
|
|
|