1998-12-18 20:54:54 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-12-18 20:54:54 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03: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.
|
1998-12-18 20:54:54 +03:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-12-18 20:54:54 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:40:37 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-12-18 20:54:54 +03:00
|
|
|
*/
|
|
|
|
#include "nsAreaFrame.h"
|
1999-04-10 21:30:46 +04:00
|
|
|
#include "nsBlockBandData.h"
|
1998-12-18 20:54:54 +03:00
|
|
|
#include "nsIReflowCommand.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIViewManager.h"
|
|
|
|
#include "nsSpaceManager.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
|
|
|
#include "nsHTMLValue.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
1999-10-02 04:52:01 +04:00
|
|
|
#include "nsISizeOfHandler.h"
|
1998-12-18 20:54:54 +03:00
|
|
|
|
1999-07-14 21:26:12 +04:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1999-09-15 04:25:51 +04:00
|
|
|
#undef NOISY_SPACEMANAGER
|
1999-09-18 03:15:53 +04:00
|
|
|
#undef NOISY_FINAL_SIZE
|
1998-12-18 20:54:54 +03:00
|
|
|
|
|
|
|
nsresult
|
1999-12-05 02:49:50 +03:00
|
|
|
NS_NewAreaFrame(nsIPresShell* aPresShell, nsIFrame** aNewFrame, PRUint32 aFlags)
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_PRECONDITION(aNewFrame, "null OUT ptr");
|
|
|
|
if (nsnull == aNewFrame) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1999-12-05 02:49:50 +03:00
|
|
|
nsAreaFrame* it = new (aPresShell) nsAreaFrame;
|
1998-12-18 20:54:54 +03:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetFlags(aFlags);
|
1999-05-12 02:03:29 +04:00
|
|
|
*aNewFrame = it;
|
1998-12-18 20:54:54 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAreaFrame::nsAreaFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIFrame
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::Destroy(nsIPresContext* aPresContext)
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
1999-07-24 06:37:45 +04:00
|
|
|
mAbsoluteContainer.DestroyFrames(this, aPresContext);
|
1999-07-22 06:24:52 +04:00
|
|
|
return nsBlockFrame::Destroy(aPresContext);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::SetInitialChildList(nsIPresContext* aPresContext,
|
1998-12-29 06:38:16 +03:00
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::absoluteList == aListName) {
|
1999-07-24 06:37:45 +04:00
|
|
|
rv = mAbsoluteContainer.SetInitialChildList(this, aPresContext, aListName, aChildList);
|
1998-12-29 06:38:16 +03:00
|
|
|
} else {
|
|
|
|
rv = nsBlockFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-07-24 06:37:45 +04:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::AppendFrames(nsIPresContext* aPresContext,
|
1999-07-24 06:37:45 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::absoluteList == aListName) {
|
|
|
|
rv = mAbsoluteContainer.AppendFrames(this, aPresContext, aPresShell, aListName,
|
|
|
|
aFrameList);
|
|
|
|
} else {
|
|
|
|
rv = nsBlockFrame::AppendFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::InsertFrames(nsIPresContext* aPresContext,
|
1999-07-24 06:37:45 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::absoluteList == aListName) {
|
|
|
|
rv = mAbsoluteContainer.InsertFrames(this, aPresContext, aPresShell, aListName,
|
|
|
|
aPrevFrame, aFrameList);
|
|
|
|
} else {
|
|
|
|
rv = nsBlockFrame::InsertFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aPrevFrame, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::RemoveFrame(nsIPresContext* aPresContext,
|
1999-07-24 06:37:45 +04:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::absoluteList == aListName) {
|
|
|
|
rv = mAbsoluteContainer.RemoveFrame(this, aPresContext, aPresShell, aListName, aOldFrame);
|
|
|
|
} else {
|
|
|
|
rv = nsBlockFrame::RemoveFrame(aPresContext, aPresShell, aListName, aOldFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetAdditionalChildListName(PRInt32 aIndex,
|
1999-02-10 05:25:01 +03:00
|
|
|
nsIAtom** aListName) const
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
|
1998-12-18 20:54:54 +03:00
|
|
|
if (aIndex <= NS_BLOCK_FRAME_LAST_LIST_INDEX) {
|
|
|
|
return nsBlockFrame::GetAdditionalChildListName(aIndex, aListName);
|
|
|
|
}
|
|
|
|
|
1999-02-10 05:25:01 +03:00
|
|
|
*aListName = nsnull;
|
1998-12-18 20:54:54 +03:00
|
|
|
if (NS_AREA_FRAME_ABSOLUTE_LIST_INDEX == aIndex) {
|
1999-02-10 05:25:01 +03:00
|
|
|
*aListName = nsLayoutAtoms::absoluteList;
|
|
|
|
NS_ADDREF(*aListName);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-22 04:16:50 +03:00
|
|
|
nsAreaFrame::FirstChild(nsIPresContext* aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame** aFirstChild) const
|
1998-12-18 20:54:54 +03:00
|
|
|
{
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_PRECONDITION(nsnull != aFirstChild, "null OUT parameter pointer");
|
1998-12-18 20:54:54 +03:00
|
|
|
if (aListName == nsLayoutAtoms::absoluteList) {
|
1999-07-24 06:37:45 +04:00
|
|
|
return mAbsoluteContainer.FirstChild(this, aListName, aFirstChild);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
2000-01-22 04:16:50 +03:00
|
|
|
return nsBlockFrame::FirstChild(aPresContext, aListName, aFirstChild);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
static void
|
|
|
|
CalculateContainingBlock(const nsHTMLReflowState& aReflowState,
|
|
|
|
nscoord aFrameWidth,
|
|
|
|
nscoord aFrameHeight,
|
|
|
|
nscoord& aContainingBlockWidth,
|
|
|
|
nscoord& aContainingBlockHeight)
|
|
|
|
{
|
|
|
|
aContainingBlockWidth = -1; // have reflow state calculate
|
|
|
|
aContainingBlockHeight = -1; // have reflow state calculate
|
|
|
|
|
1999-10-14 08:56:50 +04:00
|
|
|
// The issue there is that for a 'height' of 'auto' the reflow state code
|
|
|
|
// won't know how to calculate the containing block height because it's
|
|
|
|
// calculated bottom up. We don't really want to do this for the initial
|
|
|
|
// containing block so that's why we have the check for if the element
|
|
|
|
// is absolutely or relatively positioned
|
|
|
|
if (aReflowState.mStylePosition->IsAbsolutelyPositioned() ||
|
|
|
|
(NS_STYLE_POSITION_RELATIVE == aReflowState.mStylePosition->mPosition)) {
|
1999-09-16 18:33:19 +04:00
|
|
|
aContainingBlockWidth = aFrameWidth;
|
|
|
|
aContainingBlockHeight = aFrameHeight;
|
|
|
|
|
|
|
|
// Containing block is relative to the padding edge
|
|
|
|
nsMargin border;
|
|
|
|
if (!aReflowState.mStyleSpacing->GetBorder(border)) {
|
|
|
|
NS_NOTYETIMPLEMENTED("percentage border");
|
|
|
|
}
|
|
|
|
aContainingBlockWidth -= border.left + border.right;
|
|
|
|
aContainingBlockHeight -= border.top + border.bottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-24 09:03:41 +03:00
|
|
|
nsAreaFrame::Reflow(nsIPresContext* aPresContext,
|
1999-12-06 18:49:53 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
1998-12-18 20:54:54 +03:00
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsAreaFrame::Reflow: maxSize=%d,%d reason=%d",
|
1999-01-06 02:31:18 +03:00
|
|
|
aReflowState.availableWidth,
|
|
|
|
aReflowState.availableHeight,
|
1998-12-18 20:54:54 +03:00
|
|
|
aReflowState.reason));
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-01-22 03:30:27 +03:00
|
|
|
// See if it's an incremental reflow command
|
1998-12-29 06:38:16 +03:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
1999-04-16 04:08:59 +04:00
|
|
|
// Give the absolute positioning code a chance to handle it
|
1999-09-16 18:33:19 +04:00
|
|
|
nscoord containingBlockWidth;
|
|
|
|
nscoord containingBlockHeight;
|
1999-04-16 04:08:59 +04:00
|
|
|
PRBool handled;
|
1999-12-06 18:49:53 +03:00
|
|
|
nsRect childBounds;
|
1999-09-16 18:33:19 +04:00
|
|
|
|
|
|
|
CalculateContainingBlock(aReflowState, mRect.width, mRect.height,
|
|
|
|
containingBlockWidth, containingBlockHeight);
|
1999-04-16 04:08:59 +04:00
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
mAbsoluteContainer.IncrementalReflow(this, aPresContext, aReflowState,
|
|
|
|
containingBlockWidth, containingBlockHeight,
|
1999-12-06 18:49:53 +03:00
|
|
|
handled, childBounds);
|
1999-01-22 03:30:27 +03:00
|
|
|
|
1999-04-16 04:08:59 +04:00
|
|
|
// If the incremental reflow command was handled by the absolute positioning
|
|
|
|
// code, then we're all done
|
1999-01-22 03:30:27 +03:00
|
|
|
if (handled) {
|
1999-12-06 18:49:53 +03:00
|
|
|
// Just return our current size as our desired size.
|
|
|
|
// XXX We need to know the overflow area for the flowed content, and
|
|
|
|
// we don't have a way to get that currently so for the time being pretend
|
|
|
|
// a resize reflow occured
|
|
|
|
#if 0
|
|
|
|
aMetrics.width = mRect.width;
|
|
|
|
aMetrics.height = mRect.height;
|
|
|
|
aMetrics.ascent = mRect.height;
|
|
|
|
aMetrics.descent = 0;
|
1999-01-22 03:30:27 +03:00
|
|
|
|
|
|
|
// Whether or not we're complete hasn't changed
|
|
|
|
aStatus = (nsnull != mNextInFlow) ? NS_FRAME_NOT_COMPLETE : NS_FRAME_COMPLETE;
|
1999-12-06 18:49:53 +03:00
|
|
|
#else
|
|
|
|
nsHTMLReflowState reflowState(aReflowState);
|
|
|
|
reflowState.reason = eReflowReason_Resize;
|
|
|
|
reflowState.reflowCommand = nsnull;
|
|
|
|
rv = nsBlockFrame::Reflow(aPresContext, aMetrics, reflowState, aStatus);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Factor the absolutely positioned child bounds into the overflow area
|
|
|
|
aMetrics.mOverflowArea.UnionRect(aMetrics.mOverflowArea, childBounds);
|
|
|
|
|
|
|
|
// Make sure the NS_FRAME_OUTSIDE_CHILDREN flag is set correctly
|
|
|
|
if ((aMetrics.mOverflowArea.x < 0) ||
|
|
|
|
(aMetrics.mOverflowArea.y < 0) ||
|
|
|
|
(aMetrics.mOverflowArea.XMost() > aMetrics.width) ||
|
|
|
|
(aMetrics.mOverflowArea.YMost() > aMetrics.height)) {
|
|
|
|
mState |= NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
} else {
|
|
|
|
mState &= ~NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
}
|
1999-01-22 03:30:27 +03:00
|
|
|
return rv;
|
|
|
|
}
|
1998-12-29 06:38:16 +03:00
|
|
|
}
|
|
|
|
|
1999-04-16 04:08:59 +04:00
|
|
|
// Let the block frame do its reflow first
|
1999-12-06 18:49:53 +03:00
|
|
|
rv = nsBlockFrame::Reflow(aPresContext, aMetrics, aReflowState, aStatus);
|
1999-01-22 03:30:27 +03:00
|
|
|
|
1999-09-16 18:33:19 +04:00
|
|
|
// Let the absolutely positioned container reflow any absolutely positioned
|
|
|
|
// child frames that need to be reflowed, e.g., elements with a percentage
|
|
|
|
// based width/height
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nscoord containingBlockWidth;
|
|
|
|
nscoord containingBlockHeight;
|
1999-12-06 18:49:53 +03:00
|
|
|
nsRect childBounds;
|
1999-09-16 18:33:19 +04:00
|
|
|
|
1999-12-06 18:49:53 +03:00
|
|
|
CalculateContainingBlock(aReflowState, aMetrics.width, aMetrics.height,
|
1999-09-16 18:33:19 +04:00
|
|
|
containingBlockWidth, containingBlockHeight);
|
|
|
|
|
|
|
|
rv = mAbsoluteContainer.Reflow(this, aPresContext, aReflowState,
|
1999-12-06 18:49:53 +03:00
|
|
|
containingBlockWidth, containingBlockHeight,
|
|
|
|
childBounds);
|
|
|
|
|
|
|
|
// Factor the absolutely positioned child bounds into the overflow area
|
|
|
|
aMetrics.mOverflowArea.UnionRect(aMetrics.mOverflowArea, childBounds);
|
|
|
|
|
|
|
|
// Make sure the NS_FRAME_OUTSIDE_CHILDREN flag is set correctly
|
|
|
|
if ((aMetrics.mOverflowArea.x < 0) ||
|
|
|
|
(aMetrics.mOverflowArea.y < 0) ||
|
|
|
|
(aMetrics.mOverflowArea.XMost() > aMetrics.width) ||
|
|
|
|
(aMetrics.mOverflowArea.YMost() > aMetrics.height)) {
|
|
|
|
mState |= NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
} else {
|
|
|
|
mState &= ~NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
}
|
1999-09-16 18:33:19 +04:00
|
|
|
}
|
|
|
|
|
1999-07-14 21:26:12 +04:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": maxElementSize=%d,%d desiredSize=%d,%d\n",
|
1999-12-06 18:49:53 +03:00
|
|
|
aMetrics.maxElementSize ? aMetrics.maxElementSize->width : 0,
|
|
|
|
aMetrics.maxElementSize ? aMetrics.maxElementSize->height : 0,
|
|
|
|
aMetrics.width, aMetrics.height);
|
1999-07-14 21:26:12 +04:00
|
|
|
#endif
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-14 06:47:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsLayoutAtoms::areaFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Diagnostics
|
|
|
|
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef NS_DEBUG
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("Area", aResult);
|
|
|
|
}
|
1999-08-31 07:09:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const
|
|
|
|
{
|
1999-09-01 05:02:16 +04:00
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-08-31 07:09:40 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
nsBlockFrame::SizeOf(aHandler, aResult);
|
|
|
|
*aResult += sizeof(*this) - sizeof(nsBlockFrame);
|
1999-10-02 04:52:01 +04:00
|
|
|
|
1999-09-01 05:02:16 +04:00
|
|
|
return NS_OK;
|
1999-08-31 07:09:40 +04:00
|
|
|
}
|
1999-09-01 05:02:16 +04:00
|
|
|
#endif
|