2005-04-18 10:33:23 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com> (original author)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2006-03-29 22:29:03 +04:00
|
|
|
/* rendering object for the HTML <canvas> element */
|
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIServiceManager.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
|
|
|
|
#include "nsHTMLCanvasFrame.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
#include "nsHTMLCanvasElement.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2009-07-22 04:44:57 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2006-04-19 01:23:15 +04:00
|
|
|
#include "nsTransform2D.h"
|
|
|
|
|
2009-04-09 00:27:20 +04:00
|
|
|
#include "gfxContext.h"
|
2009-03-05 16:43:45 +03:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
|
|
|
|
static nsHTMLCanvasElement *
|
|
|
|
CanvasElementFromContent(nsIContent *content)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMHTMLCanvasElement> domCanvas(do_QueryInterface(content));
|
|
|
|
return domCanvas ? static_cast<nsHTMLCanvasElement*>(domCanvas.get()) : nsnull;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
PRBool* aForceTransparentSurface = nsnull) {
|
2010-10-19 21:02:25 +04:00
|
|
|
if (aForceTransparentSurface) {
|
|
|
|
*aForceTransparentSurface = PR_FALSE;
|
|
|
|
}
|
2009-03-05 16:43:45 +03:00
|
|
|
nsIFrame* f = GetUnderlyingFrame();
|
2010-05-18 08:04:22 +04:00
|
|
|
nsHTMLCanvasElement *canvas = CanvasElementFromContent(f->GetContent());
|
2011-01-03 04:48:09 +03:00
|
|
|
nsRegion result;
|
|
|
|
if (canvas->GetIsOpaque()) {
|
|
|
|
result = GetBounds(aBuilder);
|
|
|
|
}
|
|
|
|
return result;
|
2009-03-05 16:43:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder) {
|
|
|
|
nsHTMLCanvasFrame* f = static_cast<nsHTMLCanvasFrame*>(GetUnderlyingFrame());
|
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,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
2010-07-16 01:07:46 +04:00
|
|
|
return static_cast<nsHTMLCanvasFrame*>(mFrame)->
|
|
|
|
BuildLayer(aBuilder, aManager, this);
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
2010-07-16 01:08:05 +04:00
|
|
|
virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
|
|
|
|
LayerManager* aManager)
|
|
|
|
{
|
|
|
|
// XXX we should have some kind of activity timeout here so that
|
|
|
|
// inactive canvases can be composited into the background
|
|
|
|
return mozilla::LAYER_ACTIVE;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-09-12 20:49:24 +04:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsHTMLCanvasFrame)
|
|
|
|
|
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);
|
|
|
|
nsHTMLCanvasElement *canvas = CanvasElementFromContent(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();
|
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
|
|
|
|
nsHTMLCanvasFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2007-02-07 10:46:44 +03: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 08:38:33 +03:00
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
nsHTMLCanvasFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
// XXX The caller doesn't account for constraints of the height,
|
|
|
|
// min-height, and max-height properties.
|
2007-02-07 10:46:44 +03: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 08:38:33 +03:00
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-06-12 22:27:09 +04:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsHTMLCanvasFrame::GetIntrinsicRatio()
|
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntSize size(GetCanvasSize());
|
|
|
|
return nsSize(nsPresContext::CSSPixelsToAppUnits(size.width),
|
|
|
|
nsPresContext::CSSPixelsToAppUnits(size.height));
|
2007-06-12 22:27:09 +04: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 08:38:33 +03:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsHTMLCanvasFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
|
|
|
PRBool aShrinkWrap)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
return nsLayoutUtils::ComputeSizeWithIntrinsicDimensions(
|
2007-11-18 15:09:03 +03: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 08:38:33 +03:00
|
|
|
}
|
2005-04-18 10:33:23 +04: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 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",
|
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight));
|
|
|
|
|
|
|
|
NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
|
|
|
|
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
|
2007-01-26 03:05:12 +03:00
|
|
|
aMetrics.width = aReflowState.ComputedWidth();
|
2007-08-02 22:08:05 +04:00
|
|
|
aMetrics.height = aReflowState.ComputedHeight();
|
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
|
|
|
|
mBorderPadding = aReflowState.mComputedBorderPadding;
|
|
|
|
|
|
|
|
aMetrics.width += mBorderPadding.left + mBorderPadding.right;
|
|
|
|
aMetrics.height += mBorderPadding.top + mBorderPadding.bottom;
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if (GetPrevInFlow()) {
|
2005-04-18 10:33:23 +04:00
|
|
|
nscoord y = GetContinuationOffset(&aMetrics.width);
|
|
|
|
aMetrics.height -= y + mBorderPadding.top;
|
2009-09-16 19:01:36 +04:00
|
|
|
aMetrics.height = NS_MAX(0, aMetrics.height);
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
|
2010-10-07 08:25:46 +04:00
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2005-04-18 10:33:23 +04:00
|
|
|
FinishAndStoreOverflow(&aMetrics);
|
|
|
|
|
|
|
|
if (mRect.width != aMetrics.width || mRect.height != aMetrics.height) {
|
2008-09-18 13:47:21 +04:00
|
|
|
Invalidate(nsRect(0, 0, mRect.width, mRect.height));
|
2005-04-18 10:33:23 +04: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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-07 07:45:06 +04: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 08:04:22 +04:00
|
|
|
already_AddRefed<Layer>
|
|
|
|
nsHTMLCanvasFrame::BuildLayer(nsDisplayListBuilder* aBuilder,
|
2010-07-16 01:07:46 +04:00
|
|
|
LayerManager* aManager,
|
|
|
|
nsDisplayItem* aItem)
|
2006-01-26 05:29:17 +03:00
|
|
|
{
|
2010-08-13 14:01:58 +04:00
|
|
|
nsRect area = GetContentRect() - GetPosition() + aItem->ToReferenceFrame();
|
2010-05-18 08:04:22 +04:00
|
|
|
nsHTMLCanvasElement* element = static_cast<nsHTMLCanvasElement*>(GetContent());
|
|
|
|
nsIntSize canvasSize = GetCanvasSize();
|
2009-05-07 00:02:59 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
if (canvasSize.width <= 0 || canvasSize.height <= 0 || area.IsEmpty())
|
|
|
|
return nsnull;
|
2007-01-17 05:41:47 +03:00
|
|
|
|
2010-07-16 01:07:46 +04:00
|
|
|
CanvasLayer* oldLayer = static_cast<CanvasLayer*>
|
|
|
|
(aBuilder->LayerBuilder()->GetLeafLayerFor(aBuilder, aManager, aItem));
|
|
|
|
nsRefPtr<CanvasLayer> layer = element->GetCanvasLayer(oldLayer, aManager);
|
2010-05-18 08:04:22 +04:00
|
|
|
if (!layer)
|
|
|
|
return nsnull;
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
element->MarkContextClean();
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
gfxRect r = gfxRect(presContext->AppUnitsToGfxUnits(area.x),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.y),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.width),
|
|
|
|
presContext->AppUnitsToGfxUnits(area.height));
|
2006-04-19 01:23:15 +04:00
|
|
|
|
2010-05-18 08:04:22 +04:00
|
|
|
// Transform the canvas into the right place
|
|
|
|
gfxMatrix transform;
|
|
|
|
transform.Translate(r.pos);
|
|
|
|
transform.Scale(r.Width()/canvasSize.width, r.Height()/canvasSize.height);
|
|
|
|
layer->SetTransform(gfx3DMatrix::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
|
|
|
}
|
|
|
|
|
2005-04-18 10:33:23 +04:00
|
|
|
NS_IMETHODIMP
|
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))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv = DisplayBorderBackgroundOutline(aBuilder, aLists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-09-09 19:21:47 +04:00
|
|
|
nsDisplayList replacedContent;
|
|
|
|
|
|
|
|
rv = replacedContent.AppendNewToTop(
|
2010-08-13 14:01:13 +04:00
|
|
|
new (aBuilder) nsDisplayCanvas(aBuilder, this));
|
2006-04-19 01:23:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-04-18 10:33:23 +04:00
|
|
|
|
2010-09-09 19:21:47 +04:00
|
|
|
rv = DisplaySelectionOverlay(aBuilder, &replacedContent,
|
|
|
|
nsISelectionDisplay::DISPLAY_IMAGES);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
WrapReplacedContentForBorderRadius(aBuilder, &replacedContent, aLists);
|
|
|
|
|
|
|
|
return NS_OK;
|
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;
|
|
|
|
}
|
|
|
|
offset -= mBorderPadding.top;
|
2009-09-16 19:01:36 +04:00
|
|
|
offset = NS_MAX(0, offset);
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2010-06-28 16:02:03 +04:00
|
|
|
already_AddRefed<nsAccessible>
|
|
|
|
nsHTMLCanvasFrame::CreateAccessible()
|
2005-04-18 10:33:23 +04:00
|
|
|
{
|
2010-06-28 16:02:03 +04:00
|
|
|
return nsnull;
|
2005-04-18 10:33:23 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2005-05-07 07:45:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLCanvasFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("HTMLCanvas"), aResult);
|
|
|
|
}
|
2005-04-18 10:33:23 +04:00
|
|
|
#endif
|
|
|
|
|