2002-01-25 02:07:03 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-01-25 02:07:03 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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/
|
2002-01-25 02:07:03 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-01-25 02:07:03 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* 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"),
|
2002-01-25 02:07:03 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-01-25 02:07:03 +00:00
|
|
|
* 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
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-01-25 02:07:03 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsPageContentFrame.h"
|
2007-07-26 04:03:29 +00:00
|
|
|
#include "nsPageFrame.h"
|
2008-02-24 12:19:17 +00:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2007-07-26 04:03:29 +00:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
2011-12-27 20:18:48 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2002-01-25 02:07:03 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIContent.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2002-01-25 02:07:03 +00:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2002-09-19 21:45:07 +00:00
|
|
|
#include "nsSimplePageSequence.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2002-01-25 02:07:03 +00:00
|
|
|
|
2005-11-04 02:38:33 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2002-01-31 14:24:06 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsPageContentFrame(aContext);
|
2002-01-31 14:24:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame)
|
|
|
|
|
2008-02-09 02:54:55 +00:00
|
|
|
/* virtual */ nsSize
|
2011-04-08 01:04:40 +00:00
|
|
|
nsPageContentFrame::ComputeSize(nsRenderingContext *aRenderingContext,
|
2008-02-09 02:54:55 +00:00
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aShrinkWrap)
|
2008-02-09 02:54:55 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mPD, "Pages are supposed to have page data");
|
|
|
|
nscoord height = (!mPD || mPD->mReflowSize.height == NS_UNCONSTRAINEDSIZE)
|
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: (mPD->mReflowSize.height - mPD->mReflowMargin.TopBottom());
|
|
|
|
return nsSize(aAvailableWidth, height);
|
|
|
|
}
|
|
|
|
|
2007-07-26 04:03:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageContentFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2002-01-25 02:07:03 +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
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
|
2002-01-25 02:07:03 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
2008-02-24 12:19:17 +00:00
|
|
|
nsresult rv = NS_OK;
|
2002-01-25 02:07:03 +00:00
|
|
|
|
2008-09-08 08:13:17 +00:00
|
|
|
if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) {
|
2007-08-07 16:06:56 +00:00
|
|
|
nsresult rv = aPresContext->PresShell()->FrameConstructor()
|
|
|
|
->ReplicateFixedFrames(this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-26 04:03:29 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 21:59:36 +00:00
|
|
|
// Set our size up front, since some parts of reflow depend on it
|
|
|
|
// being already set. Note that the computed height may be
|
|
|
|
// unconstrained; that's ok. Consumers should watch out for that.
|
|
|
|
SetSize(nsSize(aReflowState.availableWidth, aReflowState.availableHeight));
|
|
|
|
|
2008-09-08 08:13:17 +00:00
|
|
|
// A PageContentFrame must always have one child: the canvas frame.
|
2006-04-01 01:19:28 +00:00
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* frame = mFrames.FirstChild();
|
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
|
2008-09-08 08:13:17 +00:00
|
|
|
kidReflowState.SetComputedHeight(aReflowState.availableHeight);
|
2006-04-01 01:19:28 +00:00
|
|
|
|
|
|
|
mPD->mPageContentSize = aReflowState.availableWidth;
|
|
|
|
|
2008-02-24 12:19:17 +00:00
|
|
|
// Reflow the page content area
|
|
|
|
rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-04-01 01:19:28 +00:00
|
|
|
// The document element's background should cover the entire canvas, so
|
|
|
|
// take into account the combined area and any space taken up by
|
|
|
|
// absolutely positioned elements
|
|
|
|
nsMargin padding(0,0,0,0);
|
|
|
|
|
|
|
|
// XXXbz this screws up percentage padding (sets padding to zero
|
|
|
|
// in the percentage padding case)
|
|
|
|
kidReflowState.mStylePadding->GetPadding(padding);
|
|
|
|
|
2010-10-07 04:25:47 +00:00
|
|
|
// This is for shrink-to-fit, and therefore we want to use the
|
|
|
|
// scrollable overflow, since the purpose of shrink to fit is to
|
|
|
|
// make the content that ought to be reachable (represented by the
|
|
|
|
// scrollable overflow) fit in the page.
|
|
|
|
if (frame->HasOverflowAreas()) {
|
2006-04-01 01:19:28 +00:00
|
|
|
// The background covers the content area and padding area, so check
|
|
|
|
// for children sticking outside the child frame's padding edge
|
2010-10-07 04:25:47 +00:00
|
|
|
nscoord xmost = aDesiredSize.ScrollableOverflow().XMost();
|
|
|
|
if (xmost > aDesiredSize.width) {
|
2006-04-01 01:19:28 +00:00
|
|
|
mPD->mPageContentXMost =
|
2010-10-07 04:25:47 +00:00
|
|
|
xmost +
|
2008-07-17 06:30:25 +00:00
|
|
|
kidReflowState.mStyleBorder->GetActualBorderWidth(NS_SIDE_RIGHT) +
|
2006-04-01 01:19:28 +00:00
|
|
|
padding.right;
|
2002-09-19 21:45:07 +00:00
|
|
|
}
|
2006-04-01 01:19:28 +00:00
|
|
|
}
|
2002-09-19 21:45:07 +00:00
|
|
|
|
2006-04-01 01:19:28 +00:00
|
|
|
// Place and size the child
|
|
|
|
FinishReflowChild(frame, aPresContext, &kidReflowState, aDesiredSize, 0, 0, 0);
|
2002-01-25 02:07:03 +00:00
|
|
|
|
2007-07-26 04:03:29 +00:00
|
|
|
NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) ||
|
2006-04-01 01:19:28 +00:00
|
|
|
!frame->GetNextInFlow(), "bad child flow list");
|
|
|
|
}
|
2011-04-29 23:02:33 +00:00
|
|
|
|
|
|
|
// Reflow our fixed frames
|
2008-04-22 17:24:28 +00:00
|
|
|
nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
|
2011-04-29 23:02:33 +00:00
|
|
|
ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, fixedStatus);
|
2008-04-22 17:24:28 +00:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete");
|
2006-04-01 01:19:28 +00:00
|
|
|
|
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
2002-01-25 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
2010-08-27 23:15:08 +00:00
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
|
|
|
|
2002-05-28 22:50:43 +00:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2002-01-25 02:07:03 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-31 20:19:18 +00:00
|
|
|
nsIAtom*
|
|
|
|
nsPageContentFrame::GetType() const
|
2002-01-25 02:07:03 +00:00
|
|
|
{
|
2006-12-26 17:47:52 +00:00
|
|
|
return nsGkAtoms::pageContentFrame;
|
2002-01-25 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageContentFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|