1998-12-18 20:54:54 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#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-01-18 20:27:27 +03:00
|
|
|
static NS_DEFINE_IID(kAreaFrameIID, NS_IAREAFRAME_IID);
|
1998-12-18 20:54:54 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewAreaFrame(nsIFrame*& aResult, PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
nsAreaFrame* it = new nsAreaFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetFlags(aFlags);
|
|
|
|
aResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAreaFrame::nsAreaFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAreaFrame::~nsAreaFrame()
|
|
|
|
{
|
1999-01-17 01:18:08 +03:00
|
|
|
NS_IF_RELEASE(mSpaceManager);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
1999-01-18 20:27:27 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
if (aIID.Equals(kAreaFrameIID)) {
|
|
|
|
nsIAreaFrame* tmp = (nsIAreaFrame*)this;
|
|
|
|
*aInstancePtr = (void*)tmp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsBlockFrame::QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIFrame
|
|
|
|
|
1999-01-17 01:18:08 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::Init(nsIPresContext& aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
1999-02-25 06:27:57 +03:00
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
1999-01-17 01:18:08 +03:00
|
|
|
{
|
1999-02-25 08:31:15 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Let the block frame do its initialization
|
|
|
|
rv = nsBlockFrame::Init(aPresContext, aContent, aParent, aContext, aPrevInFlow);
|
|
|
|
|
1999-01-17 01:18:08 +03:00
|
|
|
// Create a space manager if requested
|
|
|
|
if (0 == (mFlags & NS_AREA_NO_SPACE_MGR)) {
|
|
|
|
mSpaceManager = new nsSpaceManager(this);
|
|
|
|
NS_ADDREF(mSpaceManager);
|
|
|
|
}
|
|
|
|
|
1999-02-25 08:31:15 +03:00
|
|
|
return rv;
|
1999-01-17 01:18:08 +03:00
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::DeleteFrame(nsIPresContext& aPresContext)
|
|
|
|
{
|
1999-04-16 04:08:59 +04:00
|
|
|
mAbsoluteContainer.DeleteFrames(aPresContext);
|
1998-12-18 20:54:54 +03:00
|
|
|
return nsBlockFrame::DeleteFrame(aPresContext);
|
|
|
|
}
|
|
|
|
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::absoluteList == aListName) {
|
1999-04-16 04:08:59 +04:00
|
|
|
rv = mAbsoluteContainer.SetInitialChildList(aPresContext, aListName, aChildList);
|
1998-12-29 06:38:16 +03:00
|
|
|
} else {
|
|
|
|
rv = nsBlockFrame::SetInitialChildList(aPresContext, aListName, aChildList);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
1999-02-10 05:25:01 +03:00
|
|
|
nsAreaFrame::FirstChild(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-04-16 04:08:59 +04:00
|
|
|
return mAbsoluteContainer.FirstChild(aListName, aFirstChild);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsBlockFrame::FirstChild(aListName, aFirstChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
|
|
|
{
|
|
|
|
// Note: all absolutely positioned elements have views so we don't
|
|
|
|
// need to worry about painting them
|
|
|
|
nsresult rv = nsBlockFrame::Paint(aPresContext, aRenderingContext,
|
|
|
|
aDirtyRect, aWhichLayer);
|
|
|
|
|
1999-03-26 03:39:35 +03:00
|
|
|
if ((NS_FRAME_PAINT_LAYER_DEBUG == aWhichLayer) && GetShowFrameBorders()) {
|
1998-12-18 20:54:54 +03:00
|
|
|
// Render the bands in the spacemanager
|
|
|
|
nsISpaceManager* sm = mSpaceManager;
|
1999-01-17 01:18:08 +03:00
|
|
|
|
|
|
|
if (nsnull != sm) {
|
1999-04-10 21:30:46 +04:00
|
|
|
nsBlockBandData band;
|
|
|
|
band.Init(sm, nsSize(mRect.width, mRect.height));
|
1999-01-17 01:18:08 +03:00
|
|
|
nscoord y = 0;
|
|
|
|
while (y < mRect.height) {
|
1999-04-10 21:30:46 +04:00
|
|
|
nsRect availArea;
|
|
|
|
band.GetAvailableSpace(y, availArea);
|
1999-01-17 01:18:08 +03:00
|
|
|
|
|
|
|
// Render a box and a diagonal line through the band
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,255,0));
|
1999-04-10 21:30:46 +04:00
|
|
|
aRenderingContext.DrawRect(0, availArea.y,
|
|
|
|
mRect.width, availArea.height);
|
|
|
|
aRenderingContext.DrawLine(0, availArea.y,
|
|
|
|
mRect.width, availArea.YMost());
|
1999-01-17 01:18:08 +03:00
|
|
|
|
|
|
|
// Render boxes and opposite diagonal lines around the
|
|
|
|
// unavailable parts of the band.
|
|
|
|
PRInt32 i;
|
1999-04-10 21:30:46 +04:00
|
|
|
for (i = 0; i < band.GetTrapezoidCount(); i++) {
|
|
|
|
const nsBandTrapezoid* trapezoid = band.GetTrapezoid(i);
|
1999-01-17 01:18:08 +03:00
|
|
|
if (nsBandTrapezoid::Available != trapezoid->state) {
|
|
|
|
nsRect r;
|
|
|
|
trapezoid->GetRect(r);
|
|
|
|
if (nsBandTrapezoid::OccupiedMultiple == trapezoid->state) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0,255,128));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(128,255,0));
|
|
|
|
}
|
|
|
|
aRenderingContext.DrawRect(r);
|
|
|
|
aRenderingContext.DrawLine(r.x, r.YMost(), r.XMost(), r.y);
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
}
|
1999-04-10 21:30:46 +04:00
|
|
|
y = availArea.YMost();
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-18 20:27:27 +03:00
|
|
|
// Return the x-most and y-most for the child absolutely positioned
|
|
|
|
// elements
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetPositionedInfo(nscoord& aXMost, nscoord& aYMost) const
|
|
|
|
{
|
1999-04-16 04:08:59 +04:00
|
|
|
return mAbsoluteContainer.GetPositionedInfo(aXMost, aYMost);
|
1999-01-22 03:30:27 +03:00
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
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
|
|
|
|
PRBool handled;
|
|
|
|
|
|
|
|
mAbsoluteContainer.IncrementalReflow(aPresContext, aReflowState, handled);
|
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) {
|
|
|
|
// Just return our current size as our desired size
|
|
|
|
aDesiredSize.width = mRect.width;
|
|
|
|
aDesiredSize.height = mRect.height;
|
|
|
|
aDesiredSize.ascent = mRect.height;
|
|
|
|
aDesiredSize.descent = 0;
|
|
|
|
|
|
|
|
// Whether or not we're complete hasn't changed
|
|
|
|
aStatus = (nsnull != mNextInFlow) ? NS_FRAME_NOT_COMPLETE : NS_FRAME_COMPLETE;
|
|
|
|
return rv;
|
|
|
|
}
|
1998-12-29 06:38:16 +03:00
|
|
|
}
|
|
|
|
|
1999-04-16 04:08:59 +04:00
|
|
|
// If we have one then set the space manager
|
1999-01-22 03:30:27 +03:00
|
|
|
if (nsnull != mSpaceManager) {
|
1999-04-13 06:55:54 +04:00
|
|
|
// Modify the reflow state and set the space manager
|
|
|
|
nsHTMLReflowState& reflowState = (nsHTMLReflowState&)aReflowState;
|
1999-01-22 03:30:27 +03:00
|
|
|
reflowState.spaceManager = mSpaceManager;
|
|
|
|
|
|
|
|
// Clear the spacemanager's regions.
|
|
|
|
mSpaceManager->ClearRegions();
|
1998-12-29 06:38:16 +03:00
|
|
|
}
|
1998-12-18 20:54:54 +03:00
|
|
|
|
1999-04-16 04:08:59 +04:00
|
|
|
// Let the block frame do its reflow first
|
1999-04-13 06:55:54 +04:00
|
|
|
rv = nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
|
1999-01-22 03:30:27 +03:00
|
|
|
|
1999-04-16 04:08:59 +04:00
|
|
|
// Let the absolutely positioned container reflow any absolutely positioned
|
|
|
|
// child frames that need to be reflowed
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mAbsoluteContainer.Reflow(aPresContext, aReflowState);
|
|
|
|
}
|
1998-12-18 20:54:54 +03:00
|
|
|
|
1999-04-13 06:55:54 +04:00
|
|
|
// Compute our desired size taking into account floaters that stick outside
|
|
|
|
// our box. Note that if this frame has a height specified by CSS then we
|
|
|
|
// don't do this
|
|
|
|
if ((NS_UNCONSTRAINEDSIZE == aReflowState.computedHeight) &&
|
1999-03-23 07:25:03 +03:00
|
|
|
(NS_FRAME_OUTSIDE_CHILDREN & mState)) {
|
1999-03-25 06:48:30 +03:00
|
|
|
nscoord contentYMost = aDesiredSize.height;
|
1999-03-23 07:25:03 +03:00
|
|
|
nscoord yMost = aDesiredSize.mCombinedArea.YMost();
|
|
|
|
if (yMost > contentYMost) {
|
1999-03-25 06:48:30 +03:00
|
|
|
// retain the border+padding for this element after the bottom
|
|
|
|
// most object.
|
|
|
|
aDesiredSize.height = yMost;
|
1998-12-18 20:54:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX This code is really temporary; the lower level frame
|
|
|
|
// classes need to contribute to the area that needs damage
|
|
|
|
// repair. This class should only worry about damage repairing
|
|
|
|
// it's border+padding area.
|
|
|
|
nsRect damageArea(0, 0, 0, 0);
|
|
|
|
|
|
|
|
// Decide how much to repaint based on the reflow type.
|
|
|
|
// Note: we don't have to handle the initial reflow case and the
|
|
|
|
// resize reflow case, because they're handled by the scroll frame
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
nsIReflowCommand::ReflowType reflowType;
|
|
|
|
aReflowState.reflowCommand->GetType(reflowType);
|
|
|
|
|
|
|
|
// For append reflow commands that target the flowed frames just
|
|
|
|
// repaint the newly added part of the frame.
|
|
|
|
if (nsIReflowCommand::FrameAppended == reflowType) {
|
|
|
|
//this blows. we're repainting everything, but we have no choice
|
|
|
|
//since we don't know how we got here. see the XXX above for a
|
|
|
|
//real fix.
|
|
|
|
#if 1
|
|
|
|
damageArea.y = 0;
|
|
|
|
damageArea.height = aDesiredSize.height;
|
|
|
|
damageArea.width = aDesiredSize.width;
|
|
|
|
#else
|
|
|
|
// It's an append reflow command
|
|
|
|
damageArea.y = mRect.YMost();
|
|
|
|
damageArea.width = aDesiredSize.width;
|
|
|
|
damageArea.height = aDesiredSize.height - mRect.height;
|
|
|
|
if ((damageArea.height < 0) ||
|
|
|
|
(aDesiredSize.height == mRect.height)) {
|
|
|
|
// Since we don't know what changed, assume it all changed.
|
|
|
|
damageArea.y = 0;
|
|
|
|
damageArea.height = aDesiredSize.height;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
// Ideally the frame that is the target of the reflow command
|
|
|
|
// (or its parent frame) would generate a damage rect, but
|
|
|
|
// since none of the frame classes know how to do this then
|
|
|
|
// for the time being just repaint the entire frame
|
|
|
|
damageArea.width = aDesiredSize.width;
|
|
|
|
// If the new height is smaller than the old height then make
|
|
|
|
// sure we erase whatever used to be displayed
|
|
|
|
damageArea.height = PR_MAX(aDesiredSize.height, mRect.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is really the body, force a repaint of the damage area
|
1999-01-12 19:42:03 +03:00
|
|
|
if ((NS_BLOCK_DOCUMENT_ROOT & mFlags) && !damageArea.IsEmpty()) {
|
1998-12-18 20:54:54 +03:00
|
|
|
Invalidate(damageArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("Area", aResult);
|
|
|
|
}
|