1998-10-01 01:35:29 +04: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 "nsContainerFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsISpaceManager.h"
|
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsRect.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsVoidArray.h"
|
|
|
|
#include "nsISizeOfHandler.h"
|
1999-01-16 01:53:39 +03:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-10-01 01:35:29 +04:00
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#undef NOISY
|
|
|
|
#else
|
|
|
|
#undef NOISY
|
|
|
|
#endif
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsContainerFrame::nsContainerFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsContainerFrame::~nsContainerFrame()
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-11-10 09:05:32 +03:00
|
|
|
nsContainerFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1999-01-16 01:53:39 +03:00
|
|
|
NS_PRECONDITION(mFrames.IsEmpty(), "already initialized");
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsresult result;
|
|
|
|
if (nsnull != mFrames.FirstChild()) {
|
1998-11-10 09:05:32 +03:00
|
|
|
result = NS_ERROR_UNEXPECTED;
|
|
|
|
} else if (nsnull != aListName) {
|
|
|
|
result = NS_ERROR_INVALID_ARG;
|
|
|
|
} else {
|
1999-01-16 01:53:39 +03:00
|
|
|
mFrames.SetFrames(aChildList);
|
1998-11-10 09:05:32 +03:00
|
|
|
result = NS_OK;
|
|
|
|
}
|
|
|
|
return result;
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContainerFrame::DeleteFrame(nsIPresContext& aPresContext)
|
|
|
|
{
|
1998-11-14 22:25:34 +03:00
|
|
|
// Prevent event dispatch during destruction
|
1999-01-16 01:53:39 +03:00
|
|
|
nsIView* view;
|
1999-02-10 08:38:18 +03:00
|
|
|
GetView(&view);
|
1998-10-31 02:38:03 +03:00
|
|
|
if (nsnull != view) {
|
|
|
|
view->SetClientData(nsnull);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
1998-11-14 22:25:34 +03:00
|
|
|
// Delete the primary child list
|
1999-01-16 01:53:39 +03:00
|
|
|
mFrames.DeleteFrames(aPresContext);
|
1998-11-14 22:25:34 +03:00
|
|
|
|
|
|
|
// Base class will delete the frame
|
|
|
|
return nsFrame::DeleteFrame(aPresContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-10-01 01:35:29 +04:00
|
|
|
nsContainerFrame::DidReflow(nsIPresContext& aPresContext,
|
|
|
|
nsDidReflowStatus aStatus)
|
|
|
|
{
|
|
|
|
NS_FRAME_TRACE_MSG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("enter nsContainerFrame::DidReflow: status=%d",
|
|
|
|
aStatus));
|
|
|
|
if (NS_FRAME_REFLOW_FINISHED == aStatus) {
|
1998-11-14 22:25:34 +03:00
|
|
|
// Apply DidReflow to each and every list that this frame implements
|
|
|
|
nsIAtom* listName = nsnull;
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
do {
|
|
|
|
nsIFrame* kid;
|
1999-02-10 05:25:01 +03:00
|
|
|
FirstChild(listName, &kid);
|
1998-11-14 22:25:34 +03:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsresult rv;
|
|
|
|
rv = kid->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
htmlReflow->DidReflow(aPresContext, aStatus);
|
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-11-14 22:25:34 +03:00
|
|
|
NS_IF_RELEASE(listName);
|
1999-02-10 05:25:01 +03:00
|
|
|
GetAdditionalChildListName(listIndex++, &listName);
|
1998-11-14 22:25:34 +03:00
|
|
|
} while(nsnull != listName);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_FRAME_TRACE_OUT("nsContainerFrame::DidReflow");
|
|
|
|
|
|
|
|
// Let nsFrame position and size our view (if we have one), and clear
|
|
|
|
// the NS_FRAME_IN_REFLOW bit
|
|
|
|
return nsFrame::DidReflow(aPresContext, aStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Child frame enumeration
|
|
|
|
|
1998-11-14 22:25:34 +03:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 05:25:01 +03:00
|
|
|
nsContainerFrame::FirstChild(nsIAtom* aListName, nsIFrame** aFirstChild) const
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1999-02-10 05:25:01 +03:00
|
|
|
NS_PRECONDITION(nsnull != aFirstChild, "null OUT parameter pointer");
|
1998-11-09 22:40:27 +03:00
|
|
|
// We only know about the unnamed principal child list
|
|
|
|
if (nsnull == aListName) {
|
1999-02-10 05:25:01 +03:00
|
|
|
*aFirstChild = mFrames.FirstChild();
|
1998-11-09 22:40:27 +03:00
|
|
|
return NS_OK;
|
|
|
|
} else {
|
1999-02-10 05:25:01 +03:00
|
|
|
*aFirstChild = nsnull;
|
1998-11-09 22:40:27 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
1998-11-03 23:23:15 +03:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Style support
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContainerFrame::ReResolveStyleContext(nsIPresContext* aPresContext,
|
1998-11-04 00:29:14 +03:00
|
|
|
nsIStyleContext* aParentContext)
|
1998-11-03 23:23:15 +03:00
|
|
|
{
|
|
|
|
nsIStyleContext* oldContext = mStyleContext;
|
1998-11-04 00:29:14 +03:00
|
|
|
nsresult result = nsFrame::ReResolveStyleContext(aPresContext, aParentContext);
|
1998-11-03 23:23:15 +03:00
|
|
|
if (oldContext != mStyleContext) {
|
1998-11-05 22:31:59 +03:00
|
|
|
// Update primary child list
|
1998-12-05 19:02:43 +03:00
|
|
|
nsIFrame* child;
|
1999-02-10 05:25:01 +03:00
|
|
|
result = FirstChild(nsnull, &child);
|
1998-11-03 23:23:15 +03:00
|
|
|
while ((NS_SUCCEEDED(result)) && (nsnull != child)) {
|
1998-11-04 00:29:14 +03:00
|
|
|
result = child->ReResolveStyleContext(aPresContext, mStyleContext);
|
1999-02-10 09:13:38 +03:00
|
|
|
child->GetNextSibling(&child);
|
1998-11-03 23:23:15 +03:00
|
|
|
}
|
1998-11-05 22:31:59 +03:00
|
|
|
|
|
|
|
// Update overflow list too
|
1999-01-16 01:53:39 +03:00
|
|
|
child = mOverflowFrames.FirstChild();
|
1998-11-05 22:31:59 +03:00
|
|
|
while ((NS_SUCCEEDED(result)) && (nsnull != child)) {
|
|
|
|
result = child->ReResolveStyleContext(aPresContext, mStyleContext);
|
1999-02-10 09:13:38 +03:00
|
|
|
child->GetNextSibling(&child);
|
1998-11-05 22:31:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// And just to be complete, update our prev-in-flows overflow list
|
|
|
|
// too (since in theory, those frames will become our frames)
|
|
|
|
if (nsnull != mPrevInFlow) {
|
1999-01-16 01:53:39 +03:00
|
|
|
child = ((nsContainerFrame*)mPrevInFlow)->mOverflowFrames.FirstChild();
|
1998-11-05 22:31:59 +03:00
|
|
|
while ((NS_SUCCEEDED(result)) && (nsnull != child)) {
|
|
|
|
result = child->ReResolveStyleContext(aPresContext, mStyleContext);
|
1999-02-10 09:13:38 +03:00
|
|
|
child->GetNextSibling(&child);
|
1998-11-05 22:31:59 +03:00
|
|
|
}
|
|
|
|
}
|
1998-11-03 23:23:15 +03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-10-01 01:35:29 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-01-16 01:53:39 +03:00
|
|
|
// Painting/Events
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1998-10-31 01:11:06 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContainerFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1998-12-18 18:54:23 +03:00
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1998-10-01 01:35:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-10-31 01:11:06 +03:00
|
|
|
// Paint the children of a container, assuming nothing about the
|
|
|
|
// childrens spatial arrangement. Given relative positioning, negative
|
|
|
|
// margins, etc, that's probably a good thing.
|
|
|
|
//
|
|
|
|
// Note: aDirtyRect is in our coordinate system (and of course, child
|
|
|
|
// rect's are also in our coordinate system)
|
|
|
|
void
|
|
|
|
nsContainerFrame::PaintChildren(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 18:54:23 +03:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1998-10-31 01:11:06 +03:00
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
|
|
|
|
1998-11-19 06:52:29 +03:00
|
|
|
// Child elements have the opportunity to override the visibility property
|
|
|
|
// of their parent and display even if the parent is hidden
|
|
|
|
PRBool clipState;
|
1998-10-31 01:11:06 +03:00
|
|
|
|
1998-11-19 06:52:29 +03:00
|
|
|
// If overflow is hidden then set the clip rect so that children
|
|
|
|
// don't leak out of us
|
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(nsRect(0, 0, mRect.width, mRect.height),
|
|
|
|
nsClipCombine_kIntersect, clipState);
|
|
|
|
}
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
1998-11-19 06:52:29 +03:00
|
|
|
while (nsnull != kid) {
|
1998-12-18 18:54:23 +03:00
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect, kid, aWhichLayer);
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-11-19 06:52:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
|
|
|
|
aRenderingContext.PopState(clipState);
|
1998-10-07 01:00:58 +04:00
|
|
|
}
|
1998-10-31 01:11:06 +03:00
|
|
|
}
|
1998-10-07 01:00:58 +04:00
|
|
|
|
1998-10-31 01:11:06 +03:00
|
|
|
// Paint one child frame
|
|
|
|
void
|
|
|
|
nsContainerFrame::PaintChild(nsIPresContext& aPresContext,
|
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
1998-12-18 18:54:23 +03:00
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-10-31 01:11:06 +03:00
|
|
|
{
|
|
|
|
nsIView *pView;
|
1999-02-10 08:38:18 +03:00
|
|
|
aFrame->GetView(&pView);
|
1998-10-31 01:11:06 +03:00
|
|
|
if (nsnull == pView) {
|
|
|
|
nsRect kidRect;
|
|
|
|
aFrame->GetRect(kidRect);
|
|
|
|
nsFrameState state;
|
1999-02-10 07:17:06 +03:00
|
|
|
aFrame->GetFrameState(&state);
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1998-10-31 01:11:06 +03:00
|
|
|
// Compute the constrained damage area; set the overlap flag to
|
|
|
|
// PR_TRUE if any portion of the child frame intersects the
|
|
|
|
// dirty rect.
|
|
|
|
nsRect damageArea;
|
|
|
|
PRBool overlap;
|
|
|
|
if (NS_FRAME_OUTSIDE_CHILDREN & state) {
|
|
|
|
// If the child frame has children that leak out of our box
|
|
|
|
// then we don't constrain the damageArea to just the childs
|
|
|
|
// bounding rect.
|
|
|
|
damageArea = aDirtyRect;
|
|
|
|
overlap = PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Compute the intersection of the dirty rect and the childs
|
|
|
|
// rect (both are in our coordinate space). This limits the
|
|
|
|
// damageArea to just the portion that intersects the childs
|
|
|
|
// rect.
|
|
|
|
overlap = damageArea.IntersectRect(aDirtyRect, kidRect);
|
1998-10-10 02:58:25 +04:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
if (!overlap && (0 == kidRect.width) && (0 == kidRect.height)) {
|
|
|
|
overlap = PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
1998-10-31 01:11:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (overlap) {
|
|
|
|
// Translate damage area into the kids coordinate
|
|
|
|
// system. Translate rendering context into the kids
|
|
|
|
// coordinate system.
|
|
|
|
damageArea.x -= kidRect.x;
|
|
|
|
damageArea.y -= kidRect.y;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.Translate(kidRect.x, kidRect.y);
|
|
|
|
|
|
|
|
// Paint the kid
|
1998-12-18 18:54:23 +03:00
|
|
|
aFrame->Paint(aPresContext, aRenderingContext, damageArea, aWhichLayer);
|
1998-10-31 01:11:06 +03:00
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.PopState(clipState);
|
|
|
|
|
1998-10-01 01:35:29 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-10-31 01:11:06 +03:00
|
|
|
// Draw a border around the child
|
|
|
|
if (nsIFrame::GetShowFrameBorders() && !kidRect.IsEmpty()) {
|
|
|
|
aRenderingContext.SetColor(NS_RGB(255,0,0));
|
|
|
|
aRenderingContext.DrawRect(kidRect);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1998-10-31 01:11:06 +03:00
|
|
|
#endif
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-18 08:25:26 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsContainerFrame::GetFrameForPoint(const nsPoint& aPoint,
|
|
|
|
nsIFrame** aFrame)
|
1998-11-19 21:09:03 +03:00
|
|
|
{
|
|
|
|
return GetFrameForPointUsing(aPoint, nsnull, aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsContainerFrame::GetFrameForPointUsing(const nsPoint& aPoint,
|
|
|
|
nsIAtom* aList,
|
|
|
|
nsIFrame** aFrame)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
nsIFrame* kid;
|
1998-11-18 08:25:26 +03:00
|
|
|
nsRect kidRect;
|
|
|
|
nsPoint tmp;
|
|
|
|
*aFrame = nsnull;
|
|
|
|
|
1999-02-10 05:25:01 +03:00
|
|
|
FirstChild(aList, &kid);
|
1998-10-01 01:35:29 +04:00
|
|
|
while (nsnull != kid) {
|
|
|
|
kid->GetRect(kidRect);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (kidRect.Contains(aPoint)) {
|
|
|
|
tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y);
|
|
|
|
return kid->GetFrameForPoint(tmp, aFrame);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
1999-02-10 05:25:01 +03:00
|
|
|
FirstChild(aList, &kid);
|
1998-10-01 01:35:29 +04:00
|
|
|
while (nsnull != kid) {
|
1998-11-18 08:25:26 +03:00
|
|
|
nsFrameState state;
|
1999-02-10 07:17:06 +03:00
|
|
|
kid->GetFrameState(&state);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (NS_FRAME_OUTSIDE_CHILDREN & state) {
|
1998-11-24 23:31:21 +03:00
|
|
|
kid->GetRect(kidRect);
|
1998-10-01 01:35:29 +04:00
|
|
|
tmp.MoveTo(aPoint.x - kidRect.x, aPoint.y - kidRect.y);
|
1998-11-18 08:25:26 +03:00
|
|
|
if (NS_OK == kid->GetFrameForPoint(tmp, aFrame)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1998-11-18 08:25:26 +03:00
|
|
|
*aFrame = this;
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Helper member functions
|
|
|
|
|
|
|
|
/**
|
1998-10-06 04:27:22 +04:00
|
|
|
* Queries the child frame for the nsIHTMLReflow interface and if it's
|
|
|
|
* supported invokes the WillReflow() and Reflow() member functions. If
|
|
|
|
* the reflow succeeds and the child frame is complete, deletes any
|
|
|
|
* next-in-flows using DeleteChildsNextInFlow()
|
1998-10-01 01:35:29 +04:00
|
|
|
*/
|
1998-10-06 04:27:22 +04:00
|
|
|
nsresult
|
|
|
|
nsContainerFrame::ReflowChild(nsIFrame* aKidFrame,
|
|
|
|
nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aReflowState.frame == aKidFrame, "bad reflow state");
|
|
|
|
|
1998-10-06 04:27:22 +04:00
|
|
|
// Query for the nsIHTMLReflow interface
|
1998-10-01 08:46:11 +04:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
1998-10-06 04:27:22 +04:00
|
|
|
nsresult result;
|
|
|
|
result = aKidFrame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow);
|
|
|
|
if (NS_FAILED(result)) {
|
|
|
|
return result;
|
1998-10-01 08:46:11 +04:00
|
|
|
}
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1998-10-06 04:27:22 +04:00
|
|
|
// Send the WillReflow notification, and reflow the child frame
|
|
|
|
htmlReflow->WillReflow(aPresContext);
|
1999-01-16 01:53:39 +03:00
|
|
|
result = htmlReflow->Reflow(aPresContext, aDesiredSize, aReflowState,
|
|
|
|
aStatus);
|
1998-10-06 04:27:22 +04:00
|
|
|
|
|
|
|
// If the reflow was successful and the child frame is complete, delete any
|
|
|
|
// next-in-flows
|
|
|
|
if (NS_SUCCEEDED(result) && NS_FRAME_IS_COMPLETE(aStatus)) {
|
1998-10-01 01:35:29 +04:00
|
|
|
nsIFrame* kidNextInFlow;
|
1999-02-24 07:48:08 +03:00
|
|
|
aKidFrame->GetNextInFlow(&kidNextInFlow);
|
1998-10-01 01:35:29 +04:00
|
|
|
if (nsnull != kidNextInFlow) {
|
|
|
|
// Remove all of the childs next-in-flows. Make sure that we ask
|
|
|
|
// the right parent to do the removal (it's possible that the
|
|
|
|
// parent is not this because we are executing pullup code)
|
|
|
|
nsIFrame* parent;
|
1999-02-10 04:36:30 +03:00
|
|
|
aKidFrame->GetParent(&parent);
|
1999-01-16 01:53:39 +03:00
|
|
|
((nsContainerFrame*)parent)->DeleteChildsNextInFlow(aPresContext,
|
|
|
|
aKidFrame);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
1998-10-06 04:27:22 +04:00
|
|
|
return result;
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and delete aChild's next-in-flow(s). Updates the sibling and flow
|
|
|
|
* pointers
|
|
|
|
*
|
|
|
|
* Updates the child count and content offsets of all containers that are
|
|
|
|
* affected
|
|
|
|
*
|
|
|
|
* @param aChild child this child's next-in-flow
|
|
|
|
* @return PR_TRUE if successful and PR_FALSE otherwise
|
|
|
|
*/
|
1999-01-16 01:53:39 +03:00
|
|
|
void
|
|
|
|
nsContainerFrame::DeleteChildsNextInFlow(nsIPresContext& aPresContext,
|
|
|
|
nsIFrame* aChild)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(IsChild(aChild), "bad geometric parent");
|
|
|
|
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
nsContainerFrame* parent;
|
|
|
|
|
1999-02-24 07:48:08 +03:00
|
|
|
aChild->GetNextInFlow(&nextInFlow);
|
1998-10-01 01:35:29 +04:00
|
|
|
NS_PRECONDITION(nsnull != nextInFlow, "null next-in-flow");
|
1999-02-10 04:36:30 +03:00
|
|
|
nextInFlow->GetParent((nsIFrame**)&parent);
|
1998-10-01 01:35:29 +04:00
|
|
|
|
|
|
|
// If the next-in-flow has a next-in-flow then delete it, too (and
|
|
|
|
// delete it first).
|
|
|
|
nsIFrame* nextNextInFlow;
|
|
|
|
|
1999-02-24 07:48:08 +03:00
|
|
|
nextInFlow->GetNextInFlow(&nextNextInFlow);
|
1998-10-01 01:35:29 +04:00
|
|
|
if (nsnull != nextNextInFlow) {
|
|
|
|
parent->DeleteChildsNextInFlow(aPresContext, nextInFlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disconnect the next-in-flow from the flow list
|
|
|
|
nextInFlow->BreakFromPrevFlow();
|
|
|
|
|
|
|
|
// Take the next-in-flow out of the parent's child list
|
1999-02-21 21:59:00 +03:00
|
|
|
PRBool result = parent->mFrames.RemoveFrame(nextInFlow);
|
|
|
|
NS_ASSERTION(result, "failed to remove frame");
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1998-10-06 04:27:22 +04:00
|
|
|
// Delete the next-in-flow frame
|
1998-10-01 01:35:29 +04:00
|
|
|
nextInFlow->DeleteFrame(aPresContext);
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
1999-02-24 07:48:08 +03:00
|
|
|
aChild->GetNextInFlow(&nextInFlow);
|
1998-10-01 01:35:29 +04:00
|
|
|
NS_POSTCONDITION(nsnull == nextInFlow, "non null next-in-flow");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Push aFromChild and its next siblings to the next-in-flow. Change the
|
|
|
|
* geometric parent of each frame that's pushed. If there is no next-in-flow
|
|
|
|
* the frames are placed on the overflow list (and the geometric parent is
|
|
|
|
* left unchanged).
|
|
|
|
*
|
|
|
|
* Updates the next-in-flow's child count. Does <b>not</b> update the
|
|
|
|
* pusher's child count.
|
|
|
|
*
|
|
|
|
* @param aFromChild the first child frame to push. It is disconnected from
|
|
|
|
* aPrevSibling
|
|
|
|
* @param aPrevSibling aFromChild's previous sibling. Must not be null. It's
|
|
|
|
* an error to push a parent's first child frame
|
|
|
|
*/
|
1999-01-16 01:53:39 +03:00
|
|
|
void
|
|
|
|
nsContainerFrame::PushChildren(nsIFrame* aFromChild, nsIFrame* aPrevSibling)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFromChild, "null pointer");
|
|
|
|
NS_PRECONDITION(nsnull != aPrevSibling, "pushing first child");
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIFrame* prevNextSibling;
|
1999-02-10 09:13:38 +03:00
|
|
|
aPrevSibling->GetNextSibling(&prevNextSibling);
|
1998-10-01 01:35:29 +04:00
|
|
|
NS_PRECONDITION(prevNextSibling == aFromChild, "bad prev sibling");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Disconnect aFromChild from its previous sibling
|
|
|
|
aPrevSibling->SetNextSibling(nsnull);
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
if (nsnull != mNextInFlow) {
|
1999-02-01 20:29:58 +03:00
|
|
|
// XXX This is not a very good thing to do. If it gets removed
|
|
|
|
// then remove the copy of this routine that doesn't do this from
|
|
|
|
// nsInlineFrame.
|
1999-01-16 01:53:39 +03:00
|
|
|
nsContainerFrame* nextInFlow = (nsContainerFrame*)mNextInFlow;
|
|
|
|
nextInFlow->mFrames.InsertFrames(mNextInFlow, nsnull, aFromChild);
|
|
|
|
}
|
|
|
|
else {
|
1998-10-01 01:35:29 +04:00
|
|
|
// Add the frames to our overflow list
|
1999-01-16 01:53:39 +03:00
|
|
|
NS_ASSERTION(mOverflowFrames.IsEmpty(), "bad overflow list");
|
|
|
|
mOverflowFrames.SetFrames(aFromChild);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moves any frames on the overflwo lists (the prev-in-flow's overflow list and
|
|
|
|
* the receiver's overflow list) to the child list.
|
|
|
|
*
|
|
|
|
* Updates this frame's child count and content mapping.
|
|
|
|
*
|
|
|
|
* @return PR_TRUE if any frames were moved and PR_FALSE otherwise
|
|
|
|
*/
|
1999-01-16 01:53:39 +03:00
|
|
|
PRBool
|
|
|
|
nsContainerFrame::MoveOverflowToChildList()
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1999-01-16 01:53:39 +03:00
|
|
|
PRBool result = PR_FALSE;
|
1998-10-01 01:35:29 +04:00
|
|
|
|
|
|
|
// Check for an overflow list with our prev-in-flow
|
|
|
|
nsContainerFrame* prevInFlow = (nsContainerFrame*)mPrevInFlow;
|
|
|
|
if (nsnull != prevInFlow) {
|
1999-01-16 01:53:39 +03:00
|
|
|
if (prevInFlow->mOverflowFrames.NotEmpty()) {
|
|
|
|
NS_ASSERTION(mFrames.IsEmpty(), "bad overflow list");
|
|
|
|
mFrames.Join(this, prevInFlow->mOverflowFrames);
|
1998-10-01 01:35:29 +04:00
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's also possible that we have an overflow list for ourselves
|
1999-01-16 01:53:39 +03:00
|
|
|
if (mOverflowFrames.NotEmpty()) {
|
|
|
|
NS_ASSERTION(mFrames.NotEmpty(), "overflow list w/o frames");
|
|
|
|
mFrames.Join(nsnull, mOverflowFrames);
|
1998-10-01 01:35:29 +04:00
|
|
|
result = PR_TRUE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-01-16 01:53:39 +03:00
|
|
|
nsresult
|
|
|
|
nsContainerFrame::AddFrame(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIFrame * aAddedFrame)
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
1999-01-16 01:53:39 +03:00
|
|
|
nsresult rv=NS_OK;
|
|
|
|
nsIReflowCommand::ReflowType type;
|
|
|
|
aReflowState.reflowCommand->GetType(type);
|
|
|
|
|
|
|
|
// we have a generic frame that gets inserted but doesn't effect
|
|
|
|
// reflow hook it up then ignore it
|
|
|
|
if (nsIReflowCommand::FrameAppended == type) {
|
|
|
|
// Append aAddedFrame to the list of frames
|
|
|
|
mFrames.AppendFrame(nsnull, aAddedFrame);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1999-01-16 01:53:39 +03:00
|
|
|
else if (nsIReflowCommand::FrameInserted == type) {
|
|
|
|
// Insert aAddedFrame into the list of frames
|
|
|
|
nsIFrame *prevSibling=nsnull;
|
|
|
|
rv = aReflowState.reflowCommand->GetPrevSiblingFrame(prevSibling);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mFrames.InsertFrame(nsnull, prevSibling, aAddedFrame);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
1999-01-16 01:53:39 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ASSERTION(PR_FALSE, "bad reflow type");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-02-04 19:27:18 +03:00
|
|
|
nsContainerFrame::RemoveAFrame(nsIFrame* aRemovedFrame)
|
1999-01-16 01:53:39 +03:00
|
|
|
{
|
|
|
|
PRBool zap = mFrames.RemoveFrame(aRemovedFrame);
|
|
|
|
NS_ASSERTION(zap, "failure to remove a frame");
|
|
|
|
return NS_OK;
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Debugging
|
|
|
|
|
1998-11-19 20:22:29 +03:00
|
|
|
NS_IMETHODIMP
|
1999-01-16 03:00:50 +03:00
|
|
|
nsContainerFrame::List(FILE* out, PRInt32 aIndent) const
|
1998-10-01 01:35:29 +04:00
|
|
|
{
|
|
|
|
nsAutoString tagString;
|
1998-11-13 02:03:35 +03:00
|
|
|
if (nsnull != mContent) {
|
|
|
|
nsIAtom* tag;
|
|
|
|
mContent->GetTag(tag);
|
|
|
|
if (tag != nsnull) {
|
|
|
|
tag->ToString(tagString);
|
|
|
|
NS_RELEASE(tag);
|
|
|
|
}
|
|
|
|
}
|
1998-11-19 20:22:29 +03:00
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
// Indent
|
|
|
|
IndentBy(out, aIndent);
|
1998-11-19 20:22:29 +03:00
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
// Output the tag
|
|
|
|
ListTag(out);
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
nsIView* view;
|
1999-02-10 08:38:18 +03:00
|
|
|
GetView(&view);
|
1999-01-16 03:00:50 +03:00
|
|
|
if (nsnull != view) {
|
|
|
|
fprintf(out, " [view=%p]", view);
|
|
|
|
}
|
1998-10-01 01:35:29 +04:00
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
if (nsnull != mPrevInFlow) {
|
1999-02-01 20:29:58 +03:00
|
|
|
fprintf(out, " prev-in-flow=%p", mPrevInFlow);
|
1999-01-16 03:00:50 +03:00
|
|
|
}
|
|
|
|
if (nsnull != mNextInFlow) {
|
1999-02-01 20:29:58 +03:00
|
|
|
fprintf(out, " next-in-flow=%p", mNextInFlow);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
1999-01-16 03:00:50 +03:00
|
|
|
// Output the rect
|
|
|
|
out << mRect;
|
|
|
|
|
1999-01-16 03:19:10 +03:00
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
|
|
|
}
|
|
|
|
|
1998-10-01 01:35:29 +04:00
|
|
|
// Output the children
|
1999-01-16 03:19:10 +03:00
|
|
|
nsIAtom* listName = nsnull;
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
PRBool outputOneList = PR_FALSE;
|
|
|
|
do {
|
|
|
|
nsIFrame* kid;
|
1999-02-10 05:25:01 +03:00
|
|
|
FirstChild(listName, &kid);
|
1999-01-16 03:19:10 +03:00
|
|
|
if (nsnull != kid) {
|
1999-02-01 20:29:58 +03:00
|
|
|
if (outputOneList) {
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
}
|
1999-01-16 03:19:10 +03:00
|
|
|
outputOneList = PR_TRUE;
|
|
|
|
nsAutoString tmp;
|
|
|
|
if (nsnull != listName) {
|
|
|
|
listName->ToString(tmp);
|
|
|
|
fputs(tmp, out);
|
|
|
|
}
|
|
|
|
fputs("<\n", out);
|
|
|
|
while (nsnull != kid) {
|
|
|
|
kid->List(out, aIndent + 1);
|
1999-02-10 09:13:38 +03:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-16 03:19:10 +03:00
|
|
|
}
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
fputs(">\n", out);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
1999-01-16 03:19:10 +03:00
|
|
|
NS_IF_RELEASE(listName);
|
1999-02-10 05:25:01 +03:00
|
|
|
GetAdditionalChildListName(listIndex++, &listName);
|
1999-01-16 03:19:10 +03:00
|
|
|
} while(nsnull != listName);
|
|
|
|
|
|
|
|
if (!outputOneList) {
|
1999-01-16 03:00:50 +03:00
|
|
|
fputs("<>\n", out);
|
1998-10-01 01:35:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|