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
|
1999-05-12 02:03:29 +04:00
|
|
|
NS_NewAreaFrame(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;
|
|
|
|
}
|
1998-12-18 20:54:54 +03:00
|
|
|
nsAreaFrame* it = new nsAreaFrame;
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
1999-07-03 02:45:07 +04:00
|
|
|
if (!mSpaceManager) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-01-17 01:18:08 +03:00
|
|
|
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-06-29 07:41:58 +04:00
|
|
|
nsresult rv = mAbsoluteContainer.GetPositionedInfo(aXMost, aYMost);
|
|
|
|
|
|
|
|
// If we have child frames that stick outside of our box, and they should
|
|
|
|
// be visible, then include them too so the total size is correct
|
|
|
|
if (mState & NS_FRAME_OUTSIDE_CHILDREN) {
|
|
|
|
const nsStyleDisplay* display = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
if (NS_STYLE_OVERFLOW_VISIBLE == display->mOverflow) {
|
|
|
|
if (mCombinedArea.XMost() > aXMost) {
|
|
|
|
aXMost = mCombinedArea.XMost();
|
|
|
|
}
|
|
|
|
if (mCombinedArea.YMost() > aYMost) {
|
|
|
|
aYMost = mCombinedArea.YMost();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
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-06-29 07:41:58 +04:00
|
|
|
// If we have a space manager, then set it in the reflow state
|
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-06-29 07:41:58 +04:00
|
|
|
// Compute our desired size taking into account floaters and child frames
|
|
|
|
// that stick outside our box. Note that if this frame has a height specified
|
|
|
|
// by CSS then we don't do this
|
1999-05-12 02:03:29 +04:00
|
|
|
if ((mFlags & NS_AREA_WRAP_HEIGHT) &&
|
|
|
|
(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-06-29 07:41:58 +04:00
|
|
|
// If we have children that stick outside our box, then remember the
|
|
|
|
// combined area, because we'll need it later when sizing our view
|
|
|
|
if (mState & NS_FRAME_OUTSIDE_CHILDREN) {
|
|
|
|
mCombinedArea = aDesiredSize.mCombinedArea;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-06-29 07:41:58 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::DidReflow(nsIPresContext& aPresContext,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
|
|
|
|
// If we should position our view, and we have child frames that stick
|
|
|
|
// outside our box, then we need to size our view large enough to include
|
|
|
|
// those child frames
|
|
|
|
if ((mState & NS_FRAME_SYNC_FRAME_AND_VIEW) &&
|
|
|
|
(mState & NS_FRAME_OUTSIDE_CHILDREN)) {
|
|
|
|
|
|
|
|
nsIView* view;
|
|
|
|
const nsStyleDisplay* display = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
|
|
|
GetView(&view);
|
|
|
|
if (view && (NS_STYLE_OVERFLOW_VISIBLE == display->mOverflow)) {
|
|
|
|
// Don't let our base class position the view since we're doing it
|
|
|
|
mState &= ~NS_FRAME_SYNC_FRAME_AND_VIEW;
|
|
|
|
|
|
|
|
// Set the view's bit that indicates that it has transparent content
|
|
|
|
nsIViewManager* vm;
|
|
|
|
|
|
|
|
view->GetViewManager(vm);
|
|
|
|
vm->SetViewContentTransparency(view, PR_TRUE);
|
|
|
|
|
|
|
|
// Position and size view relative to its parent, not relative to our
|
|
|
|
// parent frame (our parent frame may not have a view).
|
|
|
|
nsIView* parentWithView;
|
|
|
|
nsPoint origin;
|
|
|
|
|
|
|
|
// XXX We need to handle the case where child frames stick out on the
|
|
|
|
// left and top edges as well...
|
|
|
|
GetOffsetFromView(origin, &parentWithView);
|
|
|
|
vm->ResizeView(view, mCombinedArea.XMost(), mCombinedArea.YMost());
|
|
|
|
vm->MoveViewTo(view, origin.x, origin.y);
|
|
|
|
NS_RELEASE(vm);
|
|
|
|
|
|
|
|
// Call our base class
|
|
|
|
nsresult rv = nsBlockFrame::DidReflow(aPresContext, aStatus);
|
|
|
|
|
|
|
|
// Set the flag again...
|
|
|
|
mState |= NS_FRAME_SYNC_FRAME_AND_VIEW;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsBlockFrame::DidReflow(aPresContext, aStatus);
|
|
|
|
}
|
|
|
|
|
1998-12-18 20:54:54 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Diagnostics
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAreaFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("Area", aResult);
|
|
|
|
}
|