1998-06-18 16:25:41 +00: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 "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/
|
|
|
|
*
|
|
|
|
* 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 Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
1998-11-16 17:11:12 +00:00
|
|
|
#include "nsBlockFrame.h"
|
1998-12-05 16:02:08 +00:00
|
|
|
#include "nsBlockReflowContext.h"
|
1998-12-08 21:43:15 +00:00
|
|
|
#include "nsBlockBandData.h"
|
1998-12-05 16:02:08 +00:00
|
|
|
#include "nsBulletFrame.h"
|
|
|
|
#include "nsLineBox.h"
|
|
|
|
|
1998-09-15 00:19:49 +00:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-23 02:25:26 +00:00
|
|
|
#include "nsInlineReflow.h"
|
1998-06-18 16:25:41 +00:00
|
|
|
#include "nsPlaceholderFrame.h"
|
|
|
|
#include "nsStyleConsts.h"
|
1998-06-18 23:16:00 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-06-24 17:52:42 +00:00
|
|
|
#include "nsCSSRendering.h"
|
1998-06-18 16:25:41 +00:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIReflowCommand.h"
|
1998-09-23 20:10:40 +00:00
|
|
|
#include "nsISpaceManager.h"
|
1998-06-18 16:25:41 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsIView.h"
|
1998-07-10 20:30:23 +00:00
|
|
|
#include "nsIFontMetrics.h"
|
1998-09-23 02:25:26 +00:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsHTMLAtoms.h"
|
|
|
|
#include "nsHTMLValue.h"
|
1998-11-14 21:01:26 +00:00
|
|
|
#include "nsDOMEvent.h"
|
1998-09-23 20:10:40 +00:00
|
|
|
#include "nsIHTMLContent.h"
|
1998-11-14 21:01:26 +00:00
|
|
|
#include "prprf.h"
|
1998-12-09 05:30:17 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-02-23 19:22:53 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-11-05 19:33:01 +00:00
|
|
|
// XXX temporary for :first-letter support
|
|
|
|
#include "nsITextContent.h"
|
|
|
|
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID);/* XXX */
|
|
|
|
|
1999-01-05 23:01:54 +00:00
|
|
|
// XXX for IsEmptyLine
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// XXX TODO:
|
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
// XXX get rid of the need for this
|
|
|
|
#define SLOW_INCREMENTAL_REFLOW
|
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// If I can add in IsAPlaceHolder then we can remove the mFloaters
|
|
|
|
// void array from the nsLineBox
|
|
|
|
|
1998-11-05 19:33:01 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
#undef NOISY_FIRST_LINE
|
|
|
|
#undef REALLY_NOISY_FIRST_LINE
|
1998-11-14 21:01:26 +00:00
|
|
|
#undef NOISY_FIRST_LETTER
|
1998-12-17 19:10:53 +00:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1998-11-11 03:55:55 +00:00
|
|
|
#undef NOISY_RUNIN
|
1998-11-17 22:28:51 +00:00
|
|
|
#undef NOISY_FLOATER_CLEARING
|
1998-12-05 16:02:08 +00:00
|
|
|
#undef NOISY_INCREMENTAL_REFLOW
|
|
|
|
#undef REFLOW_STATUS_COVERAGE
|
1999-03-08 19:24:07 +00:00
|
|
|
#undef NOISY_FINAL_SIZE
|
1999-03-16 19:36:00 +00:00
|
|
|
#undef NOISY_REMOVE_FRAME
|
1998-11-05 19:33:01 +00:00
|
|
|
#else
|
|
|
|
#undef NOISY_FIRST_LINE
|
1998-11-09 17:54:37 +00:00
|
|
|
#undef REALLY_NOISY_FIRST_LINE
|
1998-11-12 16:32:56 +00:00
|
|
|
#undef NOISY_FIRST_LETTER
|
1998-11-09 17:54:37 +00:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
1998-11-11 03:55:55 +00:00
|
|
|
#undef NOISY_RUNIN
|
1998-11-17 22:28:51 +00:00
|
|
|
#undef NOISY_FLOATER_CLEARING
|
1998-12-05 16:02:08 +00:00
|
|
|
#undef NOISY_INCREMENTAL_REFLOW
|
|
|
|
#undef REFLOW_STATUS_COVERAGE
|
1999-03-08 19:24:07 +00:00
|
|
|
#undef NOISY_FINAL_SIZE
|
1999-03-16 19:36:00 +00:00
|
|
|
#undef NOISY_REMOVE_FRAME
|
1998-11-05 19:33:01 +00:00
|
|
|
#endif
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//----------------------------------------------------------------------
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Debugging support code
|
|
|
|
|
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
|
|
|
static PRInt32 gNoiseIndent;
|
|
|
|
static const char* kReflowCommandType[] = {
|
|
|
|
"FrameAppended",
|
|
|
|
"FrameInserted",
|
|
|
|
"FrameRemoved",
|
|
|
|
"ContentChanged",
|
|
|
|
"StyleChanged",
|
|
|
|
"PullupReflow",
|
|
|
|
"PushReflow",
|
|
|
|
"CheckPullupReflow",
|
1999-03-05 04:21:32 +00:00
|
|
|
"ReflowDirty",
|
1998-12-05 16:02:08 +00:00
|
|
|
"UserDefined",
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_FIRST_LINE
|
|
|
|
static void
|
|
|
|
DumpStyleGeneaology(nsIFrame* aFrame, const char* gap)
|
|
|
|
{
|
|
|
|
fputs(gap, stdout);
|
1999-03-05 04:21:32 +00:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
printf(": ");
|
|
|
|
nsIStyleContext* sc;
|
1999-03-05 04:21:32 +00:00
|
|
|
aFrame->GetStyleContext(&sc);
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != sc) {
|
|
|
|
nsIStyleContext* psc;
|
|
|
|
printf("%p ", sc);
|
|
|
|
psc = sc->GetParent();
|
|
|
|
NS_RELEASE(sc);
|
|
|
|
sc = psc;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef REFLOW_STATUS_COVERAGE
|
|
|
|
static void
|
1999-02-09 17:31:33 +00:00
|
|
|
RecordReflowStatus(PRBool aChildIsBlock, nsReflowStatus aFrameReflowStatus)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-09 17:31:33 +00:00
|
|
|
static PRUint32 record[2];
|
1998-12-05 16:02:08 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// 0: child-is-block
|
|
|
|
// 1: child-is-inline
|
1998-12-05 16:02:08 +00:00
|
|
|
PRIntn index = 0;
|
|
|
|
if (!aChildIsBlock) index |= 1;
|
|
|
|
|
|
|
|
// Compute new status
|
|
|
|
PRUint32 newS = record[index];
|
|
|
|
if (NS_INLINE_IS_BREAK(aFrameReflowStatus)) {
|
|
|
|
if (NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
|
|
|
|
newS |= 1;
|
|
|
|
}
|
|
|
|
else if (NS_FRAME_IS_NOT_COMPLETE(aFrameReflowStatus)) {
|
|
|
|
newS |= 2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newS |= 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NS_FRAME_IS_NOT_COMPLETE(aFrameReflowStatus)) {
|
|
|
|
newS |= 8;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newS |= 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Log updates to the status that yield different values
|
|
|
|
if (record[index] != newS) {
|
|
|
|
record[index] = newS;
|
1999-02-09 17:31:33 +00:00
|
|
|
printf("record(%d): %02x %02x\n", index, record[0], record[1]);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
class nsBlockReflowState {
|
1998-12-05 16:02:08 +00:00
|
|
|
public:
|
1999-03-05 04:21:32 +00:00
|
|
|
nsBlockReflowState(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIPresContext& aPresContext,
|
|
|
|
nsBlockFrame* aFrame,
|
1998-12-05 16:02:08 +00:00
|
|
|
const nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsLineLayout* aLineLayout);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
|
|
|
~nsBlockReflowState();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the mCurrentBand data based on the current mY position.
|
|
|
|
*/
|
|
|
|
void GetAvailableSpace();
|
|
|
|
|
1998-11-10 18:03:29 +00:00
|
|
|
void InitFloater(nsPlaceholderFrame* aPlaceholderFrame);
|
|
|
|
|
1998-12-15 04:20:54 +00:00
|
|
|
void AddFloater(nsPlaceholderFrame* aPlaceholderFrame,
|
|
|
|
PRBool aInitialReflow);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-10-09 22:58:25 +00:00
|
|
|
void PlaceFloater(nsPlaceholderFrame* aFloater, PRBool& aIsLeftFloater);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
void PlaceBelowCurrentLineFloaters(nsVoidArray* aFloaters);
|
|
|
|
|
|
|
|
void PlaceCurrentLineFloaters(nsVoidArray* aFloaters);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void ClearFloaters(nscoord aY, PRUint8 aBreakType);
|
|
|
|
|
1998-09-23 20:10:40 +00:00
|
|
|
PRBool IsLeftMostChild(nsIFrame* aFrame);
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool IsAdjacentWithTop() const {
|
1999-03-05 04:21:32 +00:00
|
|
|
return mY == mReflowState.mComputedBorderPadding.top;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool ShouldApplyTopMargin() const {
|
|
|
|
return mIsMarginRoot || !IsAdjacentWithTop();
|
|
|
|
}
|
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& BorderPadding() const {
|
|
|
|
return mReflowState.mComputedBorderPadding;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPresContext& mPresContext;
|
|
|
|
const nsHTMLReflowState& mReflowState;
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineLayout* mLineLayout;
|
1998-09-23 20:10:40 +00:00
|
|
|
nsInlineReflow* mInlineReflow;
|
|
|
|
|
|
|
|
nsISpaceManager* mSpaceManager;
|
1998-09-28 18:50:59 +00:00
|
|
|
nscoord mSpaceManagerX, mSpaceManagerY;
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* mBlock;
|
|
|
|
nsBlockFrame* mNextInFlow;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsReflowStatus mReflowStatus;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* mRunInFromFrame;
|
|
|
|
nsBlockFrame* mRunInToFrame;
|
1998-11-11 03:55:55 +00:00
|
|
|
|
1998-09-23 20:10:40 +00:00
|
|
|
nscoord mBottomEdge; // maximum Y
|
|
|
|
|
|
|
|
PRBool mUnconstrainedWidth;
|
|
|
|
PRBool mUnconstrainedHeight;
|
|
|
|
nscoord mY;
|
|
|
|
nscoord mKidXMost;
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Previous child. This is used when pulling up a frame to update
|
|
|
|
// the sibling list.
|
1998-09-23 20:10:40 +00:00
|
|
|
nsIFrame* mPrevChild;
|
|
|
|
|
|
|
|
nsVoidArray mPendingFloaters;
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* mCurrentLine;
|
|
|
|
nsLineBox* mPrevLine;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsBlockBandData mCurrentBand;
|
1998-12-08 21:43:15 +00:00
|
|
|
nsRect mAvailSpaceRect;
|
1999-02-23 19:32:00 +00:00
|
|
|
|
|
|
|
nscoord mMinLineHeight;
|
1999-03-05 04:21:32 +00:00
|
|
|
|
|
|
|
PRBool mComputeMaxElementSize;
|
|
|
|
nsSize mMaxElementSize;
|
|
|
|
|
|
|
|
// The content area to reflow child frames within. The x/y
|
|
|
|
// coordinates are known to be mBorderPadding.left and
|
|
|
|
// mBorderPadding.top. The width/height may be NS_UNCONSTRAINEDSIZE
|
|
|
|
// if the container reflowing this frame has given the frame an
|
|
|
|
// unconstrained area.
|
|
|
|
nsSize mContentArea;
|
|
|
|
|
|
|
|
// Our wrapping behavior
|
|
|
|
PRBool mNoWrap;
|
|
|
|
|
|
|
|
// The previous child frames collapsed bottom margin value.
|
|
|
|
nscoord mPrevBottomMargin;
|
|
|
|
|
|
|
|
nsIFrame* mNextRCFrame;
|
|
|
|
|
|
|
|
// Is this frame a root for margin collapsing?
|
|
|
|
PRBool mIsMarginRoot;
|
|
|
|
|
|
|
|
// The computed collapsed top margin value that the frame did not
|
|
|
|
// apply but is passing out to the frames parent so that the parent
|
|
|
|
// can perform generational margin collapsing. This value ends up
|
|
|
|
// being copied into the nsHTMLReflowMetrics.mCarriedOutTopMargin.
|
|
|
|
nscoord mCarriedOutTopMargin;
|
1998-09-23 20:10:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// XXX This is vile. Make it go away
|
|
|
|
void
|
1998-11-10 18:03:29 +00:00
|
|
|
nsLineLayout::InitFloater(nsPlaceholderFrame* aFrame)
|
|
|
|
{
|
|
|
|
mBlockReflowState->InitFloater(aFrame);
|
|
|
|
}
|
|
|
|
void
|
1998-09-23 20:10:40 +00:00
|
|
|
nsLineLayout::AddFloater(nsPlaceholderFrame* aFrame)
|
|
|
|
{
|
1998-12-15 04:20:54 +00:00
|
|
|
mBlockReflowState->AddFloater(aFrame, PR_FALSE);
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
nsBlockReflowState::nsBlockReflowState(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsIPresContext& aPresContext,
|
|
|
|
nsBlockFrame* aFrame,
|
1998-12-05 16:02:08 +00:00
|
|
|
const nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsLineLayout* aLineLayout)
|
1999-03-05 04:21:32 +00:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mReflowState(aReflowState),
|
|
|
|
mBlock(aFrame),
|
|
|
|
mPrevBottomMargin(0),
|
|
|
|
mNextRCFrame(nsnull),
|
|
|
|
mIsMarginRoot(PR_FALSE),
|
|
|
|
mCarriedOutTopMargin(0)
|
1998-11-14 21:01:26 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
mInlineReflow = nsnull;
|
1998-11-14 21:01:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
mLineLayout = aLineLayout;
|
1998-11-14 21:01:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
mSpaceManager = aReflowState.spaceManager;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Translate into our content area and then save the
|
|
|
|
// coordinate system origin for later.
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
mSpaceManager->Translate(borderPadding.left, borderPadding.top);
|
1998-12-05 16:02:08 +00:00
|
|
|
mSpaceManager->GetTranslation(mSpaceManagerX, mSpaceManagerY);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
mReflowStatus = NS_FRAME_COMPLETE;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
mPresContext = aPresContext;
|
1999-02-24 04:48:08 +00:00
|
|
|
mBlock->GetNextInFlow((nsIFrame**)&mNextInFlow);
|
1998-12-05 16:02:08 +00:00
|
|
|
mKidXMost = 0;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
mRunInFromFrame = nsnull;
|
|
|
|
mRunInToFrame = nsnull;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
#if 0
|
|
|
|
// Compute "content area"
|
|
|
|
mUnconstrainedWidth = aReflowState.computedWidth == NS_UNCONSTRAINEDSIZE;
|
|
|
|
mUnconstrainedHeight = aReflowState.computedHeight == NS_UNCONSTRAINEDSIZE;
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NS_DEBUG
|
1999-03-05 04:21:32 +00:00
|
|
|
if ((!mUnconstrainedWidth && (aReflowState.computedWidth > 200000)) ||
|
|
|
|
(!mUnconstrainedHeight && (aReflowState.computedHeight > 200000))) {
|
1998-12-05 16:02:08 +00:00
|
|
|
mBlock->ListTag(stdout);
|
1999-03-05 04:21:32 +00:00
|
|
|
printf(": bad parent: computed size is %d(0x%x),%d(0x%x)\n",
|
|
|
|
aReflowState.computedWidth, aReflowState.computedWidth,
|
|
|
|
aReflowState.computedHeight, aReflowState.computedHeight);
|
|
|
|
if (aReflowState.computedWidth > 200000) {
|
1998-12-11 15:49:07 +00:00
|
|
|
mUnconstrainedWidth = PR_TRUE;
|
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aReflowState.computedHeight > 200000) {
|
1998-12-11 15:49:07 +00:00
|
|
|
mUnconstrainedHeight = PR_TRUE;
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
// Compute content area width (the content area is inside the border
|
|
|
|
// and padding)
|
|
|
|
mUnconstrainedWidth = PR_FALSE;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.computedWidth) {
|
|
|
|
mContentArea.width = aReflowState.computedWidth;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-03-05 04:21:32 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableWidth) {
|
1998-12-05 16:02:08 +00:00
|
|
|
mContentArea.width = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:21:32 +00:00
|
|
|
mUnconstrainedWidth = PR_TRUE;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-03-05 04:21:32 +00:00
|
|
|
nscoord lr = borderPadding.left + borderPadding.right;
|
|
|
|
mContentArea.width = aReflowState.availableWidth - lr;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-30 17:50:00 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
// Compute content area height. Unlike the width, if we have a
|
|
|
|
// specified style height we ignore it since extra content is
|
|
|
|
// managed by the "overflow" property. When we don't have a
|
|
|
|
// specified style height then we may end up limiting our height if
|
|
|
|
// the availableHeight is constrained (this situation occurs when we
|
|
|
|
// are paginated).
|
|
|
|
mUnconstrainedHeight = PR_FALSE;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.availableHeight) {
|
|
|
|
mContentArea.height = aReflowState.availableHeight;
|
|
|
|
mUnconstrainedHeight = PR_TRUE;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
else {
|
|
|
|
// Use constrained height
|
|
|
|
nscoord tb = borderPadding.top + borderPadding.bottom;
|
|
|
|
mContentArea.height = aReflowState.availableHeight - tb;
|
|
|
|
}
|
|
|
|
|
|
|
|
mY = borderPadding.top;
|
|
|
|
mBottomEdge = mContentArea.height;
|
1998-12-08 21:43:15 +00:00
|
|
|
mCurrentBand.Init(mSpaceManager, mContentArea);
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
mPrevChild = nsnull;
|
1999-02-09 17:31:33 +00:00
|
|
|
mCurrentLine = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
mPrevLine = nsnull;
|
1999-03-05 04:21:32 +00:00
|
|
|
|
|
|
|
const nsStyleText* styleText;
|
|
|
|
mBlock->GetStyleData(eStyleStruct_Text,
|
|
|
|
(const nsStyleStruct*&) styleText);
|
|
|
|
switch (styleText->mWhiteSpace) {
|
|
|
|
case NS_STYLE_WHITESPACE_PRE:
|
|
|
|
case NS_STYLE_WHITESPACE_NOWRAP:
|
|
|
|
mNoWrap = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mNoWrap = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mComputeMaxElementSize = nsnull != aMetrics.maxElementSize;;
|
|
|
|
mMaxElementSize.SizeTo(0, 0);
|
|
|
|
|
|
|
|
if ((0 != borderPadding.top) || (0 != borderPadding.bottom)) {
|
|
|
|
mIsMarginRoot = PR_TRUE;
|
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsBlockReflowState::~nsBlockReflowState()
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Restore the coordinate system
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
mSpaceManager->Translate(-borderPadding.left, -borderPadding.top);
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Get the available reflow space for the current y coordinate. The
|
|
|
|
// available space is relative to our coordinate system (0,0) is our
|
|
|
|
// upper left corner.
|
|
|
|
void
|
|
|
|
nsBlockReflowState::GetAvailableSpace()
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsISpaceManager* sm = mSpaceManager;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NS_DEBUG
|
|
|
|
// Verify that the caller setup the coordinate system properly
|
|
|
|
nscoord wx, wy;
|
|
|
|
sm->GetTranslation(wx, wy);
|
|
|
|
NS_ASSERTION((wx == mSpaceManagerX) && (wy == mSpaceManagerY),
|
|
|
|
"bad coord system");
|
|
|
|
#endif
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
mCurrentBand.GetAvailableSpace(mY - BorderPadding().top, mAvailSpaceRect);
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CALLS,
|
|
|
|
("nsBlockReflowState::GetAvailableSpace: band={%d,%d,%d,%d} count=%d",
|
1998-12-08 21:43:15 +00:00
|
|
|
mAvailSpaceRect.x, mAvailSpaceRect.y,
|
|
|
|
mAvailSpaceRect.width, mAvailSpaceRect.height,
|
|
|
|
mCurrentBand.GetTrapezoidCount()));
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("GetAvailableSpace: band=%d,%d,%d,%d count=%d\n",
|
1998-12-08 21:43:15 +00:00
|
|
|
mAvailSpaceRect.x, mAvailSpaceRect.y,
|
|
|
|
mAvailSpaceRect.width, mAvailSpaceRect.height,
|
|
|
|
mCurrentBand.GetTrapezoidCount());
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//----------------------------------------------------------------------
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#define NS_BLOCK_FRAME_CID \
|
1999-02-01 17:29:37 +00:00
|
|
|
{ 0xa6cf90df, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
static const nsIID kBlockFrameCID = NS_BLOCK_FRAME_CID;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
nsresult
|
|
|
|
NS_NewBlockFrame(nsIFrame*& aNewFrame, PRUint32 aFlags)
|
|
|
|
{
|
|
|
|
nsBlockFrame* it = new nsBlockFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
it->SetFlags(aFlags);
|
|
|
|
aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBlockFrame::nsBlockFrame()
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::~nsBlockFrame()
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1999-02-09 17:31:33 +00:00
|
|
|
NS_IF_RELEASE(mFirstLineStyle);
|
|
|
|
NS_IF_RELEASE(mFirstLetterStyle);
|
|
|
|
nsTextRun::DeleteTextRuns(mTextRuns);
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DeleteFrame(nsIPresContext& aPresContext)
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1999-02-18 22:22:55 +00:00
|
|
|
// Outside bullets are not in our child-list so check for them here
|
|
|
|
// and delete them when present.
|
|
|
|
if (HaveOutsideBullet()) {
|
1999-02-09 17:31:33 +00:00
|
|
|
mBullet->DeleteFrame(aPresContext);
|
|
|
|
mBullet = nsnull;
|
|
|
|
}
|
|
|
|
|
1999-02-10 18:12:24 +00:00
|
|
|
nsLineBox::DeleteLineList(aPresContext, mLines);
|
|
|
|
nsLineBox::DeleteLineList(aPresContext, mOverflowLines);
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
mFloaters.DeleteFrames(aPresContext);
|
|
|
|
|
|
|
|
return nsBlockFrameSuper::DeleteFrame(aPresContext);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-09-26 20:05:09 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
if (NULL == aInstancePtr) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
if (aIID.Equals(kBlockFrameCID)) {
|
|
|
|
nsBlockFrame* tmp = this;
|
|
|
|
*aInstancePtr = (void*) tmp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return nsBlockFrameSuper::QueryInterface(aIID, aInstancePtr);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-09-26 18:36:01 +00:00
|
|
|
static nsresult
|
1998-12-05 16:02:08 +00:00
|
|
|
ReResolveLineList(nsIPresContext* aPresContext,
|
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIStyleContext* aStyleContext)
|
1998-09-26 18:36:01 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != aLine) {
|
|
|
|
nsIFrame* child = aLine->mFirstChild;
|
|
|
|
PRInt32 n = aLine->mChildCount;
|
|
|
|
while ((--n >= 0) && NS_SUCCEEDED(rv)) {
|
|
|
|
rv = child->ReResolveStyleContext(aPresContext, aStyleContext);
|
1999-02-10 06:13:38 +00:00
|
|
|
child->GetNextSibling(&child);
|
1998-09-26 18:36:01 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine = aLine->mNext;
|
1998-09-26 18:36:01 +00:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReResolveStyleContext(nsIPresContext* aPresContext,
|
|
|
|
nsIStyleContext* aParentContext)
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIStyleContext* oldContext = mStyleContext;
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// NOTE: using nsFrame's ReResolveStyleContext method to avoid
|
|
|
|
// useless version in base classes.
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = nsFrame::ReResolveStyleContext(aPresContext, aParentContext);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (oldContext != mStyleContext) {
|
1999-02-09 17:31:33 +00:00
|
|
|
// Re-resolve the :first-line pseudo style context
|
|
|
|
if (nsnull == mPrevInFlow) {
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIStyleContext* newFirstLineStyle;
|
|
|
|
aPresContext->ProbePseudoStyleContextFor(mContent,
|
|
|
|
nsHTMLAtoms::firstLinePseudo,
|
|
|
|
mStyleContext,
|
|
|
|
PR_FALSE,
|
|
|
|
&newFirstLineStyle);
|
1999-02-09 17:31:33 +00:00
|
|
|
if (newFirstLineStyle != mFirstLineStyle) {
|
|
|
|
NS_IF_RELEASE(mFirstLineStyle);
|
|
|
|
mFirstLineStyle = newFirstLineStyle;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_IF_RELEASE(newFirstLineStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-resolve the :first-letter pseudo style context
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIStyleContext* newFirstLetterStyle;
|
|
|
|
aPresContext->ProbePseudoStyleContextFor(mContent,
|
|
|
|
nsHTMLAtoms::firstLetterPseudo,
|
|
|
|
(nsnull != mFirstLineStyle
|
|
|
|
? mFirstLineStyle
|
|
|
|
: mStyleContext),
|
|
|
|
PR_FALSE,
|
|
|
|
&newFirstLetterStyle);
|
1999-02-09 17:31:33 +00:00
|
|
|
if (newFirstLetterStyle != mFirstLetterStyle) {
|
|
|
|
NS_IF_RELEASE(mFirstLetterStyle);
|
|
|
|
mFirstLetterStyle = newFirstLetterStyle;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_IF_RELEASE(newFirstLetterStyle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the child frames on each line
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
nsIFrame* child = line->mFirstChild;
|
|
|
|
PRInt32 n = line->mChildCount;
|
|
|
|
while ((--n >= 0) && NS_SUCCEEDED(rv)) {
|
|
|
|
if (line == mLines) {
|
|
|
|
rv = child->ReResolveStyleContext(aPresContext,
|
|
|
|
(nsnull != mFirstLineStyle
|
|
|
|
? mFirstLineStyle
|
|
|
|
: mStyleContext));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = child->ReResolveStyleContext(aPresContext, mStyleContext);
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
child->GetNextSibling(&child);
|
1999-02-09 17:31:33 +00:00
|
|
|
}
|
|
|
|
line = line->mNext;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != mOverflowLines)) {
|
|
|
|
rv = ReResolveLineList(aPresContext, mOverflowLines, mStyleContext);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != mPrevInFlow)) {
|
1999-02-09 17:31:33 +00:00
|
|
|
nsLineBox* lines = ((nsBlockFrame*)mPrevInFlow)->mOverflowLines;
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != lines) {
|
|
|
|
rv = ReResolveLineList(aPresContext, lines, mStyleContext);
|
|
|
|
}
|
|
|
|
}
|
1999-02-25 19:14:35 +00:00
|
|
|
|
|
|
|
// XXX Need to check if the bullet is inside and hence
|
|
|
|
// in the line list. If so, we don't need to do this.
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != mBullet)) {
|
|
|
|
nsIStyleContext* bulletSC;
|
|
|
|
aPresContext->ResolvePseudoStyleContextFor(mContent,
|
|
|
|
nsHTMLAtoms::mozListBulletPseudo,
|
|
|
|
mStyleContext,
|
|
|
|
PR_FALSE, &bulletSC);
|
|
|
|
rv = mBullet->SetStyleContext(aPresContext, bulletSC);
|
|
|
|
NS_RELEASE(bulletSC);
|
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::IsSplittable(nsSplittableType& aIsSplittable) const
|
1998-09-23 20:10:40 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
aIsSplittable = NS_FRAME_SPLITTABLE_NON_RECTANGULAR;
|
1998-10-03 04:28:05 +00:00
|
|
|
return NS_OK;
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
static void
|
|
|
|
ListTextRuns(FILE* out, PRInt32 aIndent, nsTextRun* aRuns)
|
|
|
|
{
|
|
|
|
while (nsnull != aRuns) {
|
|
|
|
aRuns->List(out, aIndent);
|
|
|
|
aRuns = aRuns->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_METHOD
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::List(FILE* out, PRInt32 aIndent) const
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-03-05 04:21:32 +00:00
|
|
|
IndentBy(out, aIndent);
|
1999-01-16 00:00:50 +00:00
|
|
|
ListTag(out);
|
|
|
|
nsIView* view;
|
1999-02-10 05:38:18 +00:00
|
|
|
GetView(&view);
|
1999-01-16 00:00:50 +00:00
|
|
|
if (nsnull != view) {
|
|
|
|
fprintf(out, " [view=%p]", view);
|
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1999-01-16 00:00:50 +00:00
|
|
|
// Output the flow linkage
|
|
|
|
if (nsnull != mPrevInFlow) {
|
|
|
|
fprintf(out, " prev-in-flow=%p", mPrevInFlow);
|
|
|
|
}
|
|
|
|
if (nsnull != mNextInFlow) {
|
|
|
|
fprintf(out, " next-in-flow=%p", mNextInFlow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output the rect and state
|
1999-03-05 04:21:32 +00:00
|
|
|
fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
|
1999-01-16 00:00:50 +00:00
|
|
|
if (0 != mState) {
|
|
|
|
fprintf(out, " [state=%08x]", mState);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1999-01-16 00:00:50 +00:00
|
|
|
fputs("<\n", out);
|
|
|
|
aIndent++;
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Output the lines
|
|
|
|
if (nsnull != mLines) {
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
1999-01-16 00:00:50 +00:00
|
|
|
line->List(out, aIndent);
|
1998-12-05 16:02:08 +00:00
|
|
|
line = line->mNext;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-16 00:19:10 +00:00
|
|
|
nsIAtom* listName = nsnull;
|
|
|
|
PRInt32 listIndex = 0;
|
|
|
|
for (;;) {
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
GetAdditionalChildListName(listIndex++, &listName);
|
1999-01-16 00:19:10 +00:00
|
|
|
if (nsnull == listName) {
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 02:25:01 +00:00
|
|
|
FirstChild(listName, &kid);
|
1999-01-16 00:19:10 +00:00
|
|
|
if (nsnull != kid) {
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
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 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1999-01-16 00:19:10 +00:00
|
|
|
}
|
|
|
|
IndentBy(out, aIndent);
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE(listName);
|
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// Output the text-runs
|
|
|
|
if (nsnull != mTextRuns) {
|
1999-03-05 04:21:32 +00:00
|
|
|
IndentBy(out, aIndent);
|
1999-02-09 17:31:33 +00:00
|
|
|
fputs("text-runs <\n", out);
|
|
|
|
|
|
|
|
ListTextRuns(out, aIndent + 1, mTextRuns);
|
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
IndentBy(out, aIndent);
|
1999-02-09 17:31:33 +00:00
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
1999-01-16 00:00:50 +00:00
|
|
|
aIndent--;
|
1999-03-05 04:21:32 +00:00
|
|
|
IndentBy(out, aIndent);
|
1999-01-16 00:00:50 +00:00
|
|
|
fputs(">\n", out);
|
1998-06-30 23:51:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-30 23:51:26 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::GetFrameName(nsString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName("Block", aResult);
|
|
|
|
}
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::GetFrameType(nsIAtom** aType) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aType, "null OUT parameter pointer");
|
|
|
|
*aType = nsHTMLAtoms::blockFrame;
|
|
|
|
NS_ADDREF(*aType);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Child frame enumeration
|
1998-08-03 17:07:44 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-10 02:25:01 +00:00
|
|
|
nsBlockFrame::FirstChild(nsIAtom* aListName, nsIFrame** aFirstChild) const
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-10 02:25:01 +00:00
|
|
|
NS_PRECONDITION(nsnull != aFirstChild, "null OUT parameter pointer");
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull == aListName) {
|
1999-02-10 02:25:01 +00:00
|
|
|
*aFirstChild = (nsnull != mLines) ? mLines->mFirstChild : nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
1998-08-03 17:07:44 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
else if (aListName == nsLayoutAtoms::floaterList) {
|
1999-02-10 02:25:01 +00:00
|
|
|
*aFirstChild = mFloaters.FirstChild();
|
1999-02-09 17:31:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (aListName == nsLayoutAtoms::bulletList) {
|
1999-02-10 02:25:01 +00:00
|
|
|
*aFirstChild = mBullet;
|
1999-02-09 17:31:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-02-10 02:25:01 +00:00
|
|
|
*aFirstChild = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1998-08-03 17:07:44 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::GetAdditionalChildListName(PRInt32 aIndex,
|
1999-02-10 02:25:01 +00:00
|
|
|
nsIAtom** aListName) const
|
1999-02-09 17:31:33 +00:00
|
|
|
{
|
1999-02-10 02:25:01 +00:00
|
|
|
NS_PRECONDITION(nsnull != aListName, "null OUT parameter pointer");
|
1999-02-09 17:31:33 +00:00
|
|
|
if (aIndex < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
1999-02-10 02:25:01 +00:00
|
|
|
*aListName = nsnull;
|
1999-02-09 17:31:33 +00:00
|
|
|
switch (aIndex) {
|
|
|
|
case NS_BLOCK_FRAME_FLOATER_LIST_INDEX:
|
1999-02-10 02:25:01 +00:00
|
|
|
*aListName = nsLayoutAtoms::floaterList;
|
|
|
|
NS_ADDREF(*aListName);
|
1999-02-09 17:31:33 +00:00
|
|
|
break;
|
|
|
|
case NS_BLOCK_FRAME_BULLET_LIST_INDEX:
|
1999-02-10 02:25:01 +00:00
|
|
|
*aListName = nsLayoutAtoms::bulletList;
|
|
|
|
NS_ADDREF(*aListName);
|
1999-02-09 17:31:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::IsPercentageBase(PRBool& aBase) const
|
|
|
|
{
|
|
|
|
aBase = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-12 16:42:03 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Frame structure methods
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Reflow methods
|
1998-08-03 17:07:44 +00:00
|
|
|
|
1999-01-05 23:01:54 +00:00
|
|
|
#if 0
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ComputeCollapsedMargins(nsIPresContext& aPresContext,
|
1999-01-05 23:01:54 +00:00
|
|
|
const nsReflowState* aParentReflowState,
|
|
|
|
nscoord* aTopMarginResult,
|
|
|
|
nscoord* aBottomMarginResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION((nsnull != aTopMarginResult) &&
|
|
|
|
(nsnull != aBottomMarginResult), "null ptr");
|
|
|
|
if ((nsnull != aTopMarginResult) || (nsnull != aBottomMarginResult)) {
|
|
|
|
nsMargin myMargin(0, 0, 0, 0);
|
|
|
|
if (0 == (BLOCK_IS_INLINE & mFlags)) {
|
|
|
|
nsHTMLReflowState::ComputeMarginFor(this, aParentReflowState, myMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the first appropriate line (skipping over an empty line if
|
|
|
|
// present) that contains a block that can be used for a
|
|
|
|
// parent-child margin collapse.
|
|
|
|
nsLineBox* firstLine = nsnull;
|
|
|
|
nscoord firstLineTopMargin = 0;
|
|
|
|
if (nsnull != aTopMarginResult) {
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
if (nsnull != line) {
|
|
|
|
if (line->IsEmptyLine()) {
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
if ((nsnull != line) && line->IsBlock()) {
|
|
|
|
firstLine = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the last appropriate line (skipping over an empty line)...
|
|
|
|
nsLineBox* lastLine = nsnull;
|
|
|
|
nscoord lastLineBottomMargin = 0;
|
|
|
|
if (nsnull != aBottomMarginResult) {
|
|
|
|
// Find the last line (line) and the previous to the last line
|
|
|
|
// (prevLine)
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
nsLineBox* prevLine = nsnull;
|
|
|
|
while (nsnull != line) {
|
|
|
|
nsLineBox* next = line->mNext;
|
|
|
|
if (nsnull == next) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevLine = line;
|
|
|
|
line = next;
|
|
|
|
}
|
|
|
|
if (nsnull != line) {
|
|
|
|
if (line->IsEmptyLine()) {
|
|
|
|
line = prevLine;
|
|
|
|
}
|
|
|
|
if ((nsnull != line) && line->IsBlock()) {
|
|
|
|
lastLine = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsnull != firstLine) {
|
|
|
|
if (lastLine == firstLine) {
|
|
|
|
ComputeCollapsedMargins(aPresContext, nsnull,
|
|
|
|
&firstLineTopMargin,
|
|
|
|
&lastLineBottomMargin);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ComputeCollapsedMargins(aPresContext, nsnull,
|
|
|
|
&firstLineTopMargin,
|
|
|
|
nsnull);
|
|
|
|
}
|
|
|
|
firstLineTopMargin
|
|
|
|
}
|
|
|
|
else if (nsnull != lastLine) {
|
|
|
|
ComputeCollapsedMargins(aPresContext, nsnull,
|
|
|
|
nsnull,
|
|
|
|
&lastLineBottomMargin);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nsnull != aTopMarginResult) && (nsnull != aBottomMarginResult)) {
|
|
|
|
nscoord topMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(myMargin.top, firstLineTopMargin);
|
|
|
|
*aTopMarginResult = topMargin;
|
|
|
|
nscoord bottomMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(myMargin.bottom, lastLineBottomMargin);
|
|
|
|
*aBottomMarginResult = bottomMargin;
|
|
|
|
}
|
|
|
|
else if (nsnull != aTopMarginResult) {
|
|
|
|
nscoord topMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(myMargin.top, firstLineTopMargin);
|
|
|
|
*aTopMarginResult = topMargin;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nscoord bottomMargin =
|
|
|
|
nsBlockReflowContext::MaxMargin(myMargin.bottom, lastLineBottomMargin);
|
|
|
|
*aBottomMarginResult = bottomMargin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::Reflow(nsIPresContext& aPresContext,
|
1999-03-05 04:21:32 +00:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
// Replace parent provided reflow state with our own significantly
|
|
|
|
// more extensive version.
|
|
|
|
nsLineLayout ll(aPresContext, aReflowState.spaceManager);
|
|
|
|
nsLineLayout* lineLayout = ≪
|
1999-03-05 04:21:32 +00:00
|
|
|
nsBlockReflowState state(aReflowState, aPresContext, this, aMetrics,
|
|
|
|
lineLayout);
|
1999-01-12 16:42:03 +00:00
|
|
|
if (NS_BLOCK_MARGIN_ROOT & mFlags) {
|
|
|
|
state.mIsMarginRoot = PR_TRUE;
|
1998-10-30 22:10:10 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
lineLayout->Init(&state);
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1999-02-23 19:32:00 +00:00
|
|
|
// Prepare inline-reflow engine. Note that we will almost always use
|
|
|
|
// the inline reflow engine so this setup is not wasted work:
|
|
|
|
// because most content has compressed white-space in it, we will
|
|
|
|
// use the inline reflow engine to get rid of it.
|
1999-03-05 04:21:32 +00:00
|
|
|
nsInlineReflow inlineReflow(ll, aReflowState, this, PR_TRUE,
|
|
|
|
state.mComputeMaxElementSize);
|
1998-12-05 16:02:08 +00:00
|
|
|
state.mInlineReflow = &inlineReflow;
|
|
|
|
lineLayout->PushInline(&inlineReflow);
|
1998-07-18 21:45:17 +00:00
|
|
|
|
1999-02-23 19:32:00 +00:00
|
|
|
// Compute the blocks minimum line-height the first time that its
|
|
|
|
// needed (which is now).
|
1999-03-05 04:21:32 +00:00
|
|
|
nscoord minLineHeight = nsHTMLReflowState::CalcLineHeight(aPresContext, this);
|
1999-02-23 19:32:00 +00:00
|
|
|
inlineReflow.SetMinLineHeight(minLineHeight);
|
|
|
|
|
1999-03-05 19:25:44 +00:00
|
|
|
if (eReflowReason_Resize != aReflowState.reason) {
|
|
|
|
RenumberLists();
|
|
|
|
ComputeTextRuns(aPresContext);
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsIFrame* target;
|
1999-03-05 04:21:32 +00:00
|
|
|
switch (aReflowState.reason) {
|
1998-12-05 16:02:08 +00:00
|
|
|
case eReflowReason_Initial:
|
1999-02-26 17:04:44 +00:00
|
|
|
DrainOverflowLines();
|
1998-12-05 16:02:08 +00:00
|
|
|
rv = PrepareInitialReflow(state);
|
|
|
|
mState &= ~NS_FRAME_FIRST_REFLOW;
|
|
|
|
break;
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
case eReflowReason_Incremental:
|
1999-03-05 04:21:32 +00:00
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (this == target) {
|
|
|
|
nsIReflowCommand::ReflowType type;
|
1999-03-05 04:21:32 +00:00
|
|
|
aReflowState.reflowCommand->GetType(type);
|
1998-12-05 16:02:08 +00:00
|
|
|
switch (type) {
|
|
|
|
case nsIReflowCommand::FrameAppended:
|
|
|
|
case nsIReflowCommand::FrameInserted:
|
|
|
|
case nsIReflowCommand::FrameRemoved:
|
|
|
|
break;
|
|
|
|
case nsIReflowCommand::StyleChanged:
|
|
|
|
rv = PrepareStyleChangedReflow(state);
|
|
|
|
break;
|
1999-02-03 19:09:24 +00:00
|
|
|
case nsIReflowCommand::ReflowDirty:
|
|
|
|
break;
|
1998-12-05 16:02:08 +00:00
|
|
|
default:
|
|
|
|
// Map any other incremental operations into full reflows
|
|
|
|
rv = PrepareResizeReflow(state);
|
|
|
|
break;
|
|
|
|
}
|
1998-10-06 00:38:56 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// Get next frame in reflow command chain
|
1999-03-05 04:21:32 +00:00
|
|
|
aReflowState.reflowCommand->GetNext(state.mNextRCFrame);
|
|
|
|
inlineReflow.SetNextRCFrame(state.mNextRCFrame);
|
1998-10-06 00:38:56 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now do the reflow
|
|
|
|
rv = PrepareChildIncrementalReflow(state);
|
1998-10-16 20:22:39 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eReflowReason_Resize:
|
|
|
|
default:
|
|
|
|
DrainOverflowLines();
|
|
|
|
rv = PrepareResizeReflow(state);
|
|
|
|
break;
|
1998-10-16 20:22:39 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now reflow...
|
|
|
|
rv = ReflowDirtyLines(state);
|
|
|
|
aStatus = state.mReflowStatus;
|
1999-02-12 17:45:58 +00:00
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) {
|
1999-03-05 04:21:32 +00:00
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == aReflowState.mStyleDisplay->mOverflow) {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
|
|
|
else {
|
1999-03-05 19:25:44 +00:00
|
|
|
#ifdef DEBUG_kipp
|
1999-03-05 04:21:32 +00:00
|
|
|
ListTag(stdout); printf(": block is not complete\n");
|
1999-03-05 19:25:44 +00:00
|
|
|
#endif
|
1999-03-05 04:21:32 +00:00
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// XXX get rid of this!
|
|
|
|
BuildFloaterList();
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute our final size
|
1999-03-05 04:21:32 +00:00
|
|
|
ComputeFinalSize(aReflowState, state, aMetrics);
|
1998-12-05 16:02:08 +00:00
|
|
|
lineLayout->PopInline();
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1999-03-08 19:24:07 +00:00
|
|
|
#ifdef NOISY_FINAL_SIZE
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": availSize=%d,%d computed=%d,%d metrics=%d,%d carriedMargin=%d,%d\n",
|
|
|
|
aReflowState.availableWidth, aReflowState.availableHeight,
|
|
|
|
aReflowState.computedWidth, aReflowState.computedHeight,
|
|
|
|
aMetrics.width, aMetrics.height,
|
|
|
|
aMetrics.mCarriedOutTopMargin, aMetrics.mCarriedOutBottomMargin);
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-03-05 04:21:32 +00:00
|
|
|
nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState,
|
|
|
|
nsBlockReflowState& aState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics)
|
1998-06-25 16:33:10 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute final width
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = aState.BorderPadding();
|
|
|
|
if (!aState.mUnconstrainedWidth && aReflowState.HaveFixedContentWidth()) {
|
1998-12-05 16:02:08 +00:00
|
|
|
// Use style defined width
|
1999-03-05 04:21:32 +00:00
|
|
|
aMetrics.width = borderPadding.left + aReflowState.computedWidth +
|
|
|
|
borderPadding.right;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
1999-03-05 04:21:32 +00:00
|
|
|
nscoord computedWidth = aState.mKidXMost + borderPadding.right;
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool compact = PR_FALSE;
|
1999-03-05 04:21:32 +00:00
|
|
|
if (NS_STYLE_DISPLAY_COMPACT == aReflowState.mStyleDisplay->mDisplay) {
|
1998-12-05 16:02:08 +00:00
|
|
|
// If we are display: compact AND we have no lines or we have
|
|
|
|
// exactly one line and that line is not a block line AND that
|
|
|
|
// line doesn't end in a BR of any sort THEN we remain a compact
|
|
|
|
// frame.
|
|
|
|
if ((nsnull == mLines) ||
|
|
|
|
((nsnull == mLines->mNext) && !mLines->IsBlock() &&
|
1999-03-05 04:21:32 +00:00
|
|
|
(NS_STYLE_CLEAR_NONE == mLines->mBreakType)
|
|
|
|
/*XXX && (computedWidth <= aState.mCompactMarginWidth) */
|
|
|
|
)) {
|
1998-12-05 16:02:08 +00:00
|
|
|
compact = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// There are two options here. We either shrink wrap around our
|
1999-03-05 04:21:32 +00:00
|
|
|
// contents or we fluff out to the maximum block width. Note:
|
1998-12-05 16:02:08 +00:00
|
|
|
// We always shrink wrap when given an unconstrained width.
|
1999-01-12 16:42:03 +00:00
|
|
|
if ((0 == (NS_BLOCK_SHRINK_WRAP & mFlags)) &&
|
1998-12-05 16:02:08 +00:00
|
|
|
!aState.mUnconstrainedWidth &&
|
|
|
|
!compact) {
|
1999-03-05 04:21:32 +00:00
|
|
|
// Set our width to the max width if we aren't already that
|
|
|
|
// wide. Note that the max-width has nothing to do with our
|
|
|
|
// contents (CSS2 section XXX)
|
|
|
|
nscoord maxWidth = borderPadding.left + aState.mContentArea.width +
|
|
|
|
borderPadding.right;
|
|
|
|
computedWidth = maxWidth;
|
1998-09-02 21:59:54 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aMetrics.width = computedWidth;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
NS_ASSERTION((aMetrics.width > -200000) && (aMetrics.width < 200000), "oy");
|
|
|
|
#endif
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute final height
|
1999-03-05 04:21:32 +00:00
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.computedHeight) {
|
1998-12-05 16:02:08 +00:00
|
|
|
// Use style defined height
|
1999-03-05 04:21:32 +00:00
|
|
|
aMetrics.height = borderPadding.top + aReflowState.computedHeight +
|
|
|
|
borderPadding.bottom;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// Shrink wrap our height around our contents.
|
|
|
|
if (aState.mIsMarginRoot) {
|
|
|
|
// When we are a margin root make sure that our last childs
|
|
|
|
// bottom margin is fully applied.
|
|
|
|
// XXX check for a fit
|
|
|
|
aState.mY += aState.mPrevBottomMargin;
|
1998-07-02 00:04:12 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
aState.mY += borderPadding.bottom;
|
1998-12-05 16:02:08 +00:00
|
|
|
aMetrics.height = aState.mY;
|
1998-07-02 00:04:12 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
NS_ASSERTION((aMetrics.height > -200000) && (aMetrics.height < 200000), "oy");
|
|
|
|
#endif
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Return top and bottom margin information
|
|
|
|
if (aState.mIsMarginRoot) {
|
|
|
|
aMetrics.mCarriedOutTopMargin = 0;
|
|
|
|
aMetrics.mCarriedOutBottomMargin = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMetrics.mCarriedOutTopMargin = aState.mCarriedOutTopMargin;
|
|
|
|
aMetrics.mCarriedOutBottomMargin = aState.mPrevBottomMargin;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Special check for zero sized content: If our content is zero
|
|
|
|
// sized then we collapse into nothingness.
|
1998-12-17 18:52:10 +00:00
|
|
|
PRBool emptyFrame = PR_FALSE;
|
1998-12-30 17:50:00 +00:00
|
|
|
// We need to check the specified width and see if it's 'auto'
|
1999-03-05 04:21:32 +00:00
|
|
|
PRIntn specifiedWidthUnit = aReflowState.mStylePosition->mWidth.GetUnit();
|
1999-03-08 19:24:07 +00:00
|
|
|
// XXX bug: what about inherit?
|
1998-12-30 17:50:00 +00:00
|
|
|
if ((eStyleUnit_Auto == specifiedWidthUnit) &&
|
1999-03-05 04:21:32 +00:00
|
|
|
(NS_AUTOHEIGHT == aReflowState.computedHeight) &&
|
|
|
|
((0 == aState.mKidXMost - borderPadding.left) &&
|
|
|
|
(0 == aState.mY - borderPadding.top))) {
|
1998-12-05 16:02:08 +00:00
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.height = 0;
|
1998-12-17 18:52:10 +00:00
|
|
|
emptyFrame = PR_TRUE;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
aMetrics.ascent = aMetrics.height;
|
|
|
|
aMetrics.descent = 0;
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (aState.mComputeMaxElementSize) {
|
|
|
|
nscoord maxWidth, maxHeight;
|
1998-12-17 18:52:10 +00:00
|
|
|
if (emptyFrame) {
|
|
|
|
// When a frame is empty it must not provide any
|
|
|
|
// max-element-size information.
|
|
|
|
maxWidth = maxHeight = 0;
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
1998-12-17 18:52:10 +00:00
|
|
|
if (aState.mNoWrap) {
|
|
|
|
// When no-wrap is true the max-element-size.width is the
|
|
|
|
// width of the widest line plus the right border. Note that
|
|
|
|
// aState.mKidXMost already has the left border factored into
|
|
|
|
// it
|
1999-03-05 04:21:32 +00:00
|
|
|
maxWidth = aState.mKidXMost + borderPadding.right;
|
1998-12-17 18:52:10 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Add in border and padding dimensions to already computed
|
|
|
|
// max-element-size values.
|
|
|
|
maxWidth = aState.mMaxElementSize.width +
|
1999-03-05 04:21:32 +00:00
|
|
|
borderPadding.left + borderPadding.right;
|
1998-12-17 18:52:10 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
maxHeight = aState.mMaxElementSize.height +
|
1999-03-05 04:21:32 +00:00
|
|
|
borderPadding.top + borderPadding.bottom;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Store away the final value
|
|
|
|
aMetrics.maxElementSize->width = maxWidth;
|
|
|
|
aMetrics.maxElementSize->height = maxHeight;
|
1999-03-05 19:25:44 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
if ((maxWidth > aMetrics.width) || (maxHeight > aMetrics.height)) {
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": WARNING: max-element-size:%d,%d desired:%d,%d maxSize:%d,%d\n",
|
|
|
|
maxWidth, maxHeight, aMetrics.width, aMetrics.height,
|
|
|
|
aState.mReflowState.availableWidth,
|
|
|
|
aState.mReflowState.availableHeight);
|
|
|
|
}
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
ListTag(stdout);
|
1998-12-17 18:52:10 +00:00
|
|
|
printf(": max-element-size:%d,%d desired:%d,%d maxSize:%d,%d\n",
|
|
|
|
maxWidth, maxHeight, aMetrics.width, aMetrics.height,
|
1999-03-05 04:21:32 +00:00
|
|
|
aState.mReflowState.availableWidth,
|
|
|
|
aState.mReflowState.availableHeight);
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute the combined area of our children
|
|
|
|
// XXX take into account the overflow->clip property!
|
|
|
|
nscoord x0 = 0, y0 = 0, x1 = aMetrics.width, y1 = aMetrics.height;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
// Compute min and max x/y values for the reflowed frame's
|
|
|
|
// combined areas
|
|
|
|
nscoord x = line->mCombinedArea.x;
|
|
|
|
nscoord y = line->mCombinedArea.y;
|
|
|
|
nscoord xmost = x + line->mCombinedArea.width;
|
|
|
|
nscoord ymost = y + line->mCombinedArea.height;
|
|
|
|
if (x < x0) x0 = x;
|
|
|
|
if (xmost > x1) x1 = xmost;
|
|
|
|
if (y < y0) y0 = y;
|
|
|
|
if (ymost > y1) y1 = ymost;
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If the line has floaters, factor those in as well
|
|
|
|
nsVoidArray* floaters = line->mFloaters;
|
|
|
|
if (nsnull != floaters) {
|
|
|
|
PRInt32 i, n = floaters->Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) floaters->ElementAt(i);
|
|
|
|
nsIFrame* frame = ph->GetAnchoredItem();
|
|
|
|
// XXX This is wrong! The floater may have a combined area
|
|
|
|
// that exceeds its bounding box!
|
|
|
|
nsRect r;
|
|
|
|
frame->GetRect(r);
|
1999-03-08 19:24:07 +00:00
|
|
|
x = r.x;
|
|
|
|
y = r.y;
|
|
|
|
xmost = x + r.width;
|
|
|
|
ymost = y + r.height;
|
|
|
|
if (x < x0) x0 = x;
|
|
|
|
if (xmost > x1) x1 = xmost;
|
|
|
|
if (y < y0) y0 = y;
|
|
|
|
if (ymost > y1) y1 = ymost;
|
1998-07-09 18:14:19 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
line = line->mNext;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
if (nsnull != mBullet) {
|
|
|
|
nsRect r;
|
|
|
|
mBullet->GetRect(r);
|
1999-03-08 19:24:07 +00:00
|
|
|
nscoord x = r.x;
|
|
|
|
nscoord y = r.y;
|
|
|
|
nscoord xmost = x + r.width;
|
|
|
|
nscoord ymost = y + r.height;
|
|
|
|
if (x < x0) x0 = x;
|
|
|
|
if (xmost > x1) x1 = xmost;
|
|
|
|
if (y < y0) y0 = y;
|
|
|
|
if (ymost > y1) y1 = ymost;
|
1999-02-09 17:31:33 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If the combined area of our children exceeds our bounding box
|
|
|
|
// then set the NS_FRAME_OUTSIDE_CHILDREN flag, otherwise clear it.
|
1999-03-08 19:24:07 +00:00
|
|
|
aMetrics.mCombinedArea.x = x0;
|
|
|
|
aMetrics.mCombinedArea.y = y0;
|
|
|
|
aMetrics.mCombinedArea.width = x1 - x0;
|
|
|
|
aMetrics.mCombinedArea.height = y1 - y0;
|
1998-12-05 16:02:08 +00:00
|
|
|
if ((aMetrics.mCombinedArea.x < 0) ||
|
|
|
|
(aMetrics.mCombinedArea.y < 0) ||
|
|
|
|
(aMetrics.mCombinedArea.XMost() > aMetrics.width) ||
|
|
|
|
(aMetrics.mCombinedArea.YMost() > aMetrics.height)) {
|
|
|
|
mState |= NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mState &= ~NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
}
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PrepareInitialReflow(nsBlockReflowState& aState)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1999-03-05 04:21:32 +00:00
|
|
|
if ((nsnull == mPrevInFlow) && (nsnull != aState.mReflowState.mRunInFrame)) {
|
1999-02-09 17:31:33 +00:00
|
|
|
#ifdef NOISY_RUNIN
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": run-in from: ");
|
1999-03-05 04:21:32 +00:00
|
|
|
aState.mReflowState.mRunInFrame->ListTag(stdout);
|
1999-02-09 17:31:33 +00:00
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
// Take frames away from the run-in frame
|
1999-03-05 04:21:32 +00:00
|
|
|
TakeRunInFrames(aState.mReflowState.mRunInFrame);
|
1999-02-09 17:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PrepareResizeReflow(aState);
|
|
|
|
return NS_OK;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-08-04 21:18:16 +00:00
|
|
|
|
1998-06-24 17:52:42 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PrepareChildIncrementalReflow(nsBlockReflowState& aState)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// If by chance we are inside a table, then give up and reflow
|
|
|
|
// everything because we don't cache max-element-size information in
|
|
|
|
// the lines.
|
|
|
|
if (aState.mComputeMaxElementSize) {
|
|
|
|
return PrepareResizeReflow(aState);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Determine the line being impacted
|
|
|
|
PRBool isFloater;
|
|
|
|
nsLineBox* line = FindLineFor(aState.mNextRCFrame, isFloater);
|
|
|
|
if (nsnull == line) {
|
|
|
|
// This can't happen, but just in case it does...
|
|
|
|
return PrepareResizeReflow(aState);
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// XXX: temporary: If the child frame is a floater then punt
|
|
|
|
if (isFloater) {
|
|
|
|
return PrepareResizeReflow(aState);
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX need code for run-in/compact
|
|
|
|
|
|
|
|
// Mark (at least) the affected line dirty.
|
|
|
|
line->MarkDirty();
|
|
|
|
if (aState.mNoWrap || line->IsBlock()) {
|
|
|
|
// If we aren't wrapping then we know for certain that any changes
|
|
|
|
// to a childs reflow can't affect the line that follows. This is
|
|
|
|
// also true if the line is a block line.
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXX: temporary: For now we are conservative and mark this line
|
|
|
|
// and any inline lines that follow it dirty.
|
|
|
|
line = line->mNext;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
line->MarkDirty();
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
void
|
|
|
|
nsBlockFrame::UpdateBulletPosition()
|
|
|
|
{
|
1999-03-05 19:25:44 +00:00
|
|
|
if (nsnull == mBullet) {
|
|
|
|
// Don't bother if there is no bullet
|
|
|
|
return;
|
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsStyleList* styleList;
|
|
|
|
GetStyleData(eStyleStruct_List, (const nsStyleStruct*&) styleList);
|
|
|
|
if (NS_STYLE_LIST_STYLE_POSITION_INSIDE == styleList->mListStylePosition) {
|
|
|
|
if (HaveOutsideBullet()) {
|
|
|
|
// We now have an inside bullet, but used to have an outside
|
|
|
|
// bullet. Adjust the frame lists and mark the first line
|
|
|
|
// dirty.
|
|
|
|
if (nsnull != mLines) {
|
|
|
|
mBullet->SetNextSibling(mLines->mFirstChild);
|
|
|
|
mLines->mFirstChild = mBullet;
|
|
|
|
mLines->mChildCount++;
|
|
|
|
mLines->MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mState &= ~NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!HaveOutsideBullet()) {
|
|
|
|
// We now have an outside bullet, but used to have an inside
|
|
|
|
// bullet. Take the bullet frame out of the first lines frame
|
|
|
|
// list.
|
|
|
|
if ((nsnull != mLines) && (mBullet == mLines->mFirstChild)) {
|
|
|
|
nsIFrame* next;
|
|
|
|
mBullet->GetNextSibling(&next);
|
|
|
|
mBullet->SetNextSibling(nsnull);
|
|
|
|
if (--mLines->mChildCount == 0) {
|
|
|
|
nsLineBox* nextLine = mLines->mNext;
|
|
|
|
delete mLines;
|
|
|
|
mLines = nextLine;
|
|
|
|
if (nsnull != nextLine) {
|
|
|
|
nextLine->MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLines->mFirstChild = next;
|
|
|
|
mLines->MarkDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mState |= NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET;
|
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-03-05 04:21:32 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PrepareStyleChangedReflow(nsBlockReflowState& aState)
|
1998-11-12 16:32:56 +00:00
|
|
|
{
|
1999-03-05 04:21:32 +00:00
|
|
|
UpdateBulletPosition();
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX temporary
|
1998-12-15 04:20:54 +00:00
|
|
|
return PrepareResizeReflow(aState);
|
1998-11-12 16:32:56 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PrepareResizeReflow(nsBlockReflowState& aState)
|
1998-11-05 19:33:01 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Mark everything dirty
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
line->MarkDirty();
|
|
|
|
line = line->mNext;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//----------------------------------------
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox*
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::FindLineFor(nsIFrame* aFrame, PRBool& aIsFloaterResult)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
aIsFloaterResult = PR_FALSE;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (line->Contains(aFrame)) {
|
|
|
|
return line;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != line->mFloaters) {
|
|
|
|
nsVoidArray& a = *line->mFloaters;
|
|
|
|
PRInt32 i, n = a.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) a[i];
|
|
|
|
if (aFrame == ph->GetAnchoredItem()) {
|
|
|
|
aIsFloaterResult = PR_TRUE;
|
|
|
|
return line;
|
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
line = line->mNext;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return line;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::RecoverStateFrom(nsBlockReflowState& aState,
|
1998-12-12 19:19:11 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nscoord aDeltaY)
|
1998-09-10 19:32:14 +00:00
|
|
|
{
|
1999-02-09 17:31:33 +00:00
|
|
|
aState.mCurrentLine = aLine;
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Recover xmost
|
|
|
|
nscoord xmost = aLine->mBounds.XMost();
|
|
|
|
if (xmost > aState.mKidXMost) {
|
1999-03-05 04:21:32 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
NS_ASSERTION((xmost > -200000) && (xmost < 200000), "oy");
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mKidXMost = xmost;
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Recover the natural (un-collapsed margins) for the child
|
|
|
|
nsMargin childMargins(0, 0, 0, 0);
|
|
|
|
if (aLine->IsBlock()) {
|
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
frame->GetStyleData(eStyleStruct_Spacing, (const nsStyleStruct*&)spacing);
|
1999-03-05 04:21:32 +00:00
|
|
|
// XXX use a reflow-state to do the necessary computations for blocks
|
|
|
|
#if XXX_fix_me
|
1998-12-05 16:02:08 +00:00
|
|
|
nsBlockReflowContext::ComputeMarginsFor(aState.mPresContext, frame,
|
1999-03-05 04:21:32 +00:00
|
|
|
spacing, aState.mReflowState,
|
|
|
|
childMargins);
|
|
|
|
#endif
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Recompute running margin value (aState.mPrevBottomMargin). Also
|
1999-02-12 17:45:58 +00:00
|
|
|
// recover the aState.carriedOutTopMargin, when appropriate.
|
1998-12-05 16:02:08 +00:00
|
|
|
nscoord topMargin, bottomMargin;
|
|
|
|
nsBlockReflowContext::CollapseMargins(childMargins,
|
|
|
|
aLine->GetCarriedOutTopMargin(),
|
|
|
|
aLine->GetCarriedOutBottomMargin(),
|
|
|
|
aLine->GetHeight(),
|
|
|
|
aState.mPrevBottomMargin,
|
|
|
|
topMargin, bottomMargin);
|
|
|
|
aState.mPrevBottomMargin = bottomMargin;
|
|
|
|
if (!aState.ShouldApplyTopMargin()) {
|
|
|
|
aState.mCarriedOutTopMargin = topMargin;
|
|
|
|
}
|
|
|
|
|
1998-12-12 19:19:11 +00:00
|
|
|
if (0 != aDeltaY) {
|
|
|
|
// Move this lines frames by the current delta value
|
|
|
|
SlideFrames(aState.mPresContext, aState.mSpaceManager, aLine, aDeltaY);
|
|
|
|
SlideFloaters(aState.mPresContext, aState.mSpaceManager, aLine, aDeltaY,
|
|
|
|
PR_FALSE);
|
|
|
|
}
|
|
|
|
if (nsnull != aLine->mFloaters) {
|
|
|
|
aState.mY = aLine->mBounds.y;
|
1999-02-09 17:31:33 +00:00
|
|
|
aState.PlaceCurrentLineFloaters(aLine->mFloaters);
|
|
|
|
aState.mY = aLine->mBounds.YMost();
|
|
|
|
aState.PlaceBelowCurrentLineFloaters(aLine->mFloaters);
|
1998-12-12 19:19:11 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Advance Y to be below the line.
|
|
|
|
aState.mY = aLine->mBounds.YMost();
|
|
|
|
|
|
|
|
// XXX_fix_me: if the line has clear-before semantics then figure out
|
|
|
|
// if we need to do anything here or not!
|
|
|
|
|
|
|
|
// Apply any clear before/after semantics the line might have
|
|
|
|
if (!aLine->IsBlock() && (NS_STYLE_CLEAR_NONE != aLine->mBreakType)) {
|
|
|
|
// Apply clear
|
|
|
|
switch (aLine->mBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
|
|
|
// XXX_fix_me is this the right y value to use? or should we use
|
|
|
|
// the previous aState.mY?
|
|
|
|
aState.ClearFloaters(aState.mY, aLine->mBreakType);
|
|
|
|
break;
|
1998-11-12 16:32:56 +00:00
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
|
|
|
|
1998-09-23 20:10:40 +00:00
|
|
|
return NS_OK;
|
1998-09-10 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Propogate reflow "damage" from the just reflowed line (aLine) to
|
|
|
|
* any subsequent lines that were affected. The only thing that causes
|
|
|
|
* damage is a change to the impact that floaters make.
|
|
|
|
*/
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PropogateReflowDamage(nsBlockReflowState& aState,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nscoord aDeltaY)
|
1998-08-28 03:02:39 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
if (aLine->mCombinedArea.YMost() > aLine->mBounds.YMost()) {
|
|
|
|
// The line has an object that extends outside of its bounding box.
|
|
|
|
nscoord impactY0 = aLine->mCombinedArea.y;
|
|
|
|
nscoord impactY1 = aLine->mCombinedArea.YMost();
|
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("impactY0=%d impactY1=%d deltaY=%d\n",
|
|
|
|
impactY0, impactY1, aDeltaY);
|
|
|
|
}
|
|
|
|
#endif
|
1998-09-26 00:37:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX Because we don't know what it is (it might be a floater; it
|
|
|
|
// might be something that is just relatively positioned) we
|
|
|
|
// *assume* that it's a floater and that lines that follow will
|
|
|
|
// need reflowing.
|
1998-08-28 03:02:39 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Note: we cannot stop after the first non-intersecting line
|
|
|
|
// because lines might be overlapping because of negative margins.
|
|
|
|
nsLineBox* next = aLine->mNext;
|
|
|
|
while (nsnull != next) {
|
|
|
|
nscoord lineY0 = next->mBounds.y + aDeltaY;
|
|
|
|
nscoord lineY1 = lineY0 + next->mBounds.height;
|
|
|
|
if ((lineY0 < impactY1) && (impactY0 < lineY1)) {
|
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("line=%p setting dirty\n", next);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
next->MarkDirty();
|
|
|
|
}
|
|
|
|
next = next->mNext;
|
|
|
|
}
|
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Reflow the dirty lines
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReflowDirtyLines(nsBlockReflowState& aState)
|
1998-06-24 17:52:42 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool keepGoing = PR_TRUE;
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// Inform line layout of where the text runs are
|
|
|
|
aState.mLineLayout->SetReflowTextRuns(mTextRuns);
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIReflowCommand::ReflowType type;
|
1999-03-05 04:21:32 +00:00
|
|
|
aState.mReflowState.reflowCommand->GetType(type);
|
1998-12-05 16:02:08 +00:00
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": incrementally reflowing dirty lines: type=%s(%d)\n",
|
|
|
|
kReflowCommandType[type], type);
|
|
|
|
gNoiseIndent++;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-11-14 19:28:11 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Reflow the lines that are already ours
|
|
|
|
aState.mPrevLine = nsnull;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
nscoord deltaY = 0;
|
|
|
|
while (nsnull != line) {
|
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("line=%p mY=%d dirty=%s oldBounds=%d,%d,%d,%d deltaY=%d\n",
|
|
|
|
line, aState.mY, line->IsDirty() ? "yes" : "no",
|
1999-03-05 04:21:32 +00:00
|
|
|
line->mBounds.x, line->mBounds.y,
|
|
|
|
line->mBounds.width, line->mBounds.height,
|
|
|
|
deltaY);
|
1998-12-05 16:02:08 +00:00
|
|
|
gNoiseIndent++;
|
1998-11-12 23:03:35 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
|
|
|
if (line->IsDirty()) {
|
|
|
|
// Compute the dirty lines "before" YMost, after factoring in
|
|
|
|
// the running deltaY value - the running value is implicit in
|
|
|
|
// aState.mY.
|
|
|
|
nscoord oldHeight = line->mBounds.height;
|
|
|
|
|
|
|
|
// Reflow the dirty line
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = ReflowLine(aState, line, &keepGoing);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
DidReflowLine(aState, line, keepGoing);
|
|
|
|
if (!keepGoing) {
|
1998-12-07 22:28:55 +00:00
|
|
|
if (0 == line->ChildCount()) {
|
|
|
|
DeleteLine(aState, line);
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
nscoord newHeight = line->mBounds.height;
|
|
|
|
deltaY += newHeight - oldHeight;
|
|
|
|
|
|
|
|
// If the next line is clean then check and see if reflowing the
|
|
|
|
// current line "damaged" the next line. Damage occurs when the
|
|
|
|
// current line contains floaters that intrude upon the
|
|
|
|
// subsequent lines.
|
|
|
|
nsLineBox* next = line->mNext;
|
|
|
|
if ((nsnull != next) && !next->IsDirty()) {
|
|
|
|
PropogateReflowDamage(aState, line, deltaY);
|
|
|
|
}
|
1998-09-02 21:59:54 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// XXX what if the slid line doesn't fit because we are in a
|
|
|
|
// vertically constrained situation?
|
|
|
|
// Recover state as if we reflowed this line
|
1998-12-12 19:19:11 +00:00
|
|
|
RecoverStateFrom(aState, line, deltaY);
|
1998-09-02 21:59:54 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
gNoiseIndent--;
|
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("line=%p mY=%d newBounds=%d,%d,%d,%d deltaY=%d\n",
|
1999-03-05 04:21:32 +00:00
|
|
|
line, aState.mY,
|
|
|
|
line->mBounds.x, line->mBounds.y,
|
|
|
|
line->mBounds.width, line->mBounds.height,
|
|
|
|
deltaY);
|
1998-09-02 21:59:54 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If this is an inline frame then its time to stop
|
|
|
|
aState.mPrevLine = line;
|
|
|
|
line = line->mNext;
|
|
|
|
aState.mLineLayout->NextLine();
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Pull data from a next-in-flow if we can
|
|
|
|
while (keepGoing && (nsnull != aState.mNextInFlow)) {
|
|
|
|
// Grab first line from our next-in-flow
|
|
|
|
line = aState.mNextInFlow->mLines;
|
|
|
|
if (nsnull == line) {
|
1999-02-09 17:31:33 +00:00
|
|
|
aState.mNextInFlow = (nsBlockFrame*) aState.mNextInFlow->mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
continue;
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX See if the line is not dirty; if it's not maybe we can
|
|
|
|
// avoid the pullup if it can't fit?
|
|
|
|
aState.mNextInFlow->mLines = line->mNext;
|
|
|
|
line->mNext = nsnull;
|
|
|
|
if (0 == line->ChildCount()) {
|
|
|
|
// The line is empty. Try the next one.
|
|
|
|
NS_ASSERTION(nsnull == line->mFirstChild, "bad empty line");
|
|
|
|
delete line;
|
|
|
|
continue;
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX move to a subroutine: run-in, overflow, pullframe and this do this
|
|
|
|
// Make the children in the line ours.
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
nsIFrame* lastFrame = nsnull;
|
|
|
|
PRInt32 n = line->ChildCount();
|
|
|
|
while (--n >= 0) {
|
1999-01-14 05:16:23 +00:00
|
|
|
frame->SetParent(this);
|
1998-12-05 16:02:08 +00:00
|
|
|
lastFrame = frame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
lastFrame->SetNextSibling(nsnull);
|
1998-11-14 19:28:11 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Add line to our line list
|
|
|
|
if (nsnull == aState.mPrevLine) {
|
|
|
|
NS_ASSERTION(nsnull == mLines, "bad aState.mPrevLine");
|
|
|
|
mLines = line;
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
NS_ASSERTION(nsnull == aState.mPrevLine->mNext, "bad aState.mPrevLine");
|
|
|
|
aState.mPrevLine->mNext = line;
|
|
|
|
aState.mPrevChild->SetNextSibling(line->mFirstChild);
|
1998-09-02 21:59:54 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now reflow it and any lines that it makes during it's reflow
|
|
|
|
// (we have to loop here because reflowing the line may case a new
|
|
|
|
// line to be created; see SplitLine's callers for examples of
|
|
|
|
// when this happens).
|
|
|
|
while (nsnull != line) {
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = ReflowLine(aState, line, &keepGoing);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
DidReflowLine(aState, line, keepGoing);
|
|
|
|
if (!keepGoing) {
|
1998-12-07 22:28:55 +00:00
|
|
|
if (0 == line->ChildCount()) {
|
|
|
|
DeleteLine(aState, line);
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-11-14 19:28:11 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If this is an inline frame then its time to stop
|
|
|
|
aState.mPrevLine = line;
|
|
|
|
line = line->mNext;
|
|
|
|
aState.mLineLayout->NextLine();
|
|
|
|
}
|
|
|
|
}
|
1998-11-14 19:28:11 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (aState.mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
gNoiseIndent--;
|
|
|
|
IndentBy(stdout, gNoiseIndent);
|
|
|
|
ListTag(stdout);
|
1999-03-05 04:21:32 +00:00
|
|
|
printf(": done reflowing dirty lines (status=%x)\n",
|
|
|
|
aState.mReflowStatus);
|
1998-06-27 22:56:09 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-06-27 22:56:09 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-07 22:28:55 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DeleteLine(nsBlockReflowState& aState,
|
1999-02-12 17:45:58 +00:00
|
|
|
nsLineBox* aLine)
|
1998-12-07 22:28:55 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(0 == aLine->ChildCount(), "can't delete !empty line");
|
|
|
|
if (0 == aLine->ChildCount()) {
|
|
|
|
if (nsnull == aState.mPrevLine) {
|
|
|
|
NS_ASSERTION(aLine == mLines, "huh");
|
|
|
|
mLines = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERTION(aState.mPrevLine->mNext == aLine, "bad prev-line");
|
|
|
|
aState.mPrevLine->mNext = aLine->mNext;
|
|
|
|
}
|
|
|
|
delete aLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::WillReflowLine(nsBlockReflowState& aState,
|
|
|
|
nsLineBox* aLine)
|
1998-11-14 19:28:11 +00:00
|
|
|
{
|
1999-02-09 17:31:33 +00:00
|
|
|
// Setup the first-letter-style-ok flag
|
|
|
|
nsLineLayout& lineLayout = *aState.mLineLayout;
|
|
|
|
if (mFirstLetterStyle && (0 == lineLayout.GetLineNumber())) {
|
|
|
|
lineLayout.SetFirstLetterStyleOK(PR_TRUE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lineLayout.SetFirstLetterStyleOK(PR_FALSE);
|
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Reflow a line. The line will either contain a single block frame
|
|
|
|
* or contain 1 or more inline frames. aLineReflowStatus indicates
|
|
|
|
* whether or not the caller should continue to reflow more lines.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReflowLine(nsBlockReflowState& aState,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* aLine,
|
1999-02-12 17:45:58 +00:00
|
|
|
PRBool* aKeepReflowGoing)
|
1998-11-19 18:09:57 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
|
1999-02-09 17:31:33 +00:00
|
|
|
("nsBlockFrame::ReflowLine: line=%p", aLine));
|
1998-11-19 18:09:57 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-11-11 03:55:55 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If the line already has floaters on it from last time, remove
|
|
|
|
// them from the spacemanager now.
|
|
|
|
if (nsnull != aLine->mFloaters) {
|
|
|
|
aLine->mFloaters->Clear();
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If the line is empty then first pull a frame into it so that we
|
|
|
|
// know what kind of line it is (block or inline).
|
|
|
|
if (0 == aLine->ChildCount()) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
rv = PullFrame(aState, aLine, frame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (nsnull == frame) {
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// Setup the line-layout for the new line
|
|
|
|
aState.mLineLayout->Reset();
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mCurrentLine = aLine;
|
|
|
|
aLine->ClearDirty();
|
|
|
|
aLine->SetNeedDidReflow();
|
1998-11-11 03:55:55 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now that we know what kind of line we have, reflow it
|
|
|
|
if (aLine->IsBlock()) {
|
|
|
|
// When reflowing a block frame we always get the available space
|
|
|
|
aState.GetAvailableSpace();
|
1998-11-11 03:55:55 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
#if XXX_dead_code
|
1998-12-05 16:02:08 +00:00
|
|
|
if ((nsnull != aState.lineLayout) &&
|
|
|
|
(0 != aState.lineLayout->GetPlacedFrames())) {
|
|
|
|
// Blocks are not allowed on the same line as anything else
|
|
|
|
aState.mReflowStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Notify observers that we are about to reflow the line
|
|
|
|
WillReflowLine(aState, aLine);
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = ReflowBlockFrame(aState, aLine, aKeepReflowGoing);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-12-05 16:02:08 +00:00
|
|
|
// When this class is an inline frame and we are reflowing inline
|
|
|
|
// frames then there is no point in getting available space.
|
|
|
|
nscoord x, availWidth, availHeight;
|
1999-02-09 17:31:33 +00:00
|
|
|
aState.GetAvailableSpace();
|
1998-12-05 16:02:08 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// Setup initial coordinate system for reflowing the inline frames
|
|
|
|
// into.
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = aState.BorderPadding();
|
|
|
|
x = aState.mAvailSpaceRect.x + borderPadding.left;
|
1999-02-09 17:31:33 +00:00
|
|
|
availWidth = aState.mAvailSpaceRect.width;
|
1998-12-05 16:02:08 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
if (aState.mUnconstrainedHeight) {
|
|
|
|
availHeight = NS_UNCONSTRAINEDSIZE;
|
1998-07-17 16:16:19 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-02-09 17:31:33 +00:00
|
|
|
/* XXX get the height right! */
|
|
|
|
availHeight = aState.mAvailSpaceRect.height;
|
1998-07-17 16:16:19 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mInlineReflow->Init(x, aState.mY, availWidth, availHeight);
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Notify observers that we are about to reflow the line
|
|
|
|
WillReflowLine(aState, aLine);
|
1998-09-25 16:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Reflow the frames that are already on the line first
|
|
|
|
PRBool keepLineGoing = PR_TRUE;
|
|
|
|
PRInt32 i;
|
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
for (i = 0; i < aLine->ChildCount(); i++) {
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = ReflowInlineFrame(aState, aLine, frame, &keepLineGoing);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (!keepLineGoing) {
|
|
|
|
// It is possible that one or more of next lines are empty
|
|
|
|
// (because of DeleteNextInFlowsFor). If so, delete them now
|
|
|
|
// in case we are finished.
|
|
|
|
nsLineBox* nextLine = aLine->mNext;
|
|
|
|
while ((nsnull != nextLine) && (0 == nextLine->ChildCount())) {
|
|
|
|
// Discard empty lines immediately. Empty lines can happen
|
|
|
|
// here because of DeleteNextInFlowsFor not being able to
|
|
|
|
// delete lines.
|
|
|
|
aLine->mNext = nextLine->mNext;
|
|
|
|
NS_ASSERTION(nsnull == nextLine->mFirstChild, "bad empty line");
|
|
|
|
delete nextLine;
|
|
|
|
nextLine = aLine->mNext;
|
|
|
|
}
|
1998-07-06 21:37:08 +00:00
|
|
|
break;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-07-06 21:37:08 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Pull frames and reflow them until we can't
|
|
|
|
while (keepLineGoing) {
|
|
|
|
nsIFrame* frame;
|
|
|
|
rv = PullFrame(aState, aLine, frame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (nsnull == frame) {
|
1998-09-25 16:10:10 +00:00
|
|
|
break;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
while (keepLineGoing) {
|
|
|
|
PRInt32 oldCount = aLine->ChildCount();
|
|
|
|
rv = ReflowInlineFrame(aState, aLine, frame, &keepLineGoing);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (aLine->ChildCount() != oldCount) {
|
|
|
|
// We just created a continuation for aFrame AND its going
|
|
|
|
// to end up on this line (e.g. :first-letter
|
|
|
|
// situation). Therefore we have to loop here before trying
|
|
|
|
// to pull another frame.
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
break;
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-06-25 20:51:04 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If we are propogating out a break-before status then there is
|
|
|
|
// no point in placing the line.
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aState.mReflowStatus)) {
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = PlaceLine(aState, aLine, aKeepReflowGoing);
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-14 19:28:11 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Pull frame from the next available location (one of our lines or
|
|
|
|
* one of our next-in-flows lines).
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PullFrame(nsBlockReflowState& aState,
|
1999-03-16 19:36:00 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame*& aFrameResult)
|
1998-11-14 19:28:11 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRBool stopPulling;
|
|
|
|
aFrameResult = nsnull;
|
|
|
|
|
|
|
|
// First check our remaining lines
|
|
|
|
while (nsnull != aLine->mNext) {
|
|
|
|
rv = PullFrame(aState, aLine, &aLine->mNext, PR_FALSE,
|
|
|
|
aFrameResult, stopPulling);
|
|
|
|
if (NS_FAILED(rv) || stopPulling) {
|
|
|
|
return rv;
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
|
|
|
}
|
1998-11-17 01:04:45 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Pull frames from the next-in-flow(s) until we can't
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* nextInFlow = aState.mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != nextInFlow) {
|
|
|
|
nsLineBox* line = nextInFlow->mLines;
|
|
|
|
if (nsnull == line) {
|
1999-02-09 17:31:33 +00:00
|
|
|
nextInFlow = (nsBlockFrame*) nextInFlow->mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mNextInFlow = nextInFlow;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
rv = PullFrame(aState, aLine, &nextInFlow->mLines, PR_TRUE,
|
|
|
|
aFrameResult, stopPulling);
|
|
|
|
if (NS_FAILED(rv) || stopPulling) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-17 01:04:45 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-11-14 19:28:11 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Try to pull a frame out a line pointed at by aFromList. If a frame
|
|
|
|
* is pulled then aPulled will be set to PR_TRUE. In addition, if
|
|
|
|
* aUpdateGeometricParent is set then the pulled frames geometric
|
|
|
|
* parent will be updated (e.g. when pulling from a next-in-flows line
|
|
|
|
* list).
|
|
|
|
*
|
|
|
|
* Note: pulling a frame from a line that is a place-holder frame
|
|
|
|
* doesn't automatically remove the corresponding floater from the
|
|
|
|
* line's floater array. This happens indirectly: either the line gets
|
|
|
|
* emptied (and destroyed) or the line gets reflowed (because we mark
|
|
|
|
* it dirty) and the code at the top of ReflowLine empties the
|
|
|
|
* array. So eventually, it will be removed, just not right away.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PullFrame(nsBlockReflowState& aState,
|
1999-02-18 18:25:45 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsLineBox** aFromList,
|
|
|
|
PRBool aUpdateGeometricParent,
|
|
|
|
nsIFrame*& aFrameResult,
|
|
|
|
PRBool& aStopPulling)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* fromLine = *aFromList;
|
|
|
|
NS_ASSERTION(nsnull != fromLine, "bad line to pull from");
|
|
|
|
if (0 == fromLine->ChildCount()) {
|
|
|
|
// Discard empty lines immediately. Empty lines can happen here
|
|
|
|
// because of DeleteChildsNextInFlow not being able to delete
|
|
|
|
// lines. Don't stop pulling - there may be more frames around.
|
|
|
|
*aFromList = fromLine->mNext;
|
|
|
|
NS_ASSERTION(nsnull == fromLine->mFirstChild, "bad empty line");
|
|
|
|
delete fromLine;
|
|
|
|
aStopPulling = PR_FALSE;
|
|
|
|
aFrameResult = nsnull;
|
|
|
|
}
|
|
|
|
else if ((0 != aLine->ChildCount()) && fromLine->IsBlock()) {
|
|
|
|
// If our line is not empty and the child in aFromLine is a block
|
|
|
|
// then we cannot pull up the frame into this line. In this case
|
|
|
|
// we stop pulling.
|
|
|
|
aStopPulling = PR_TRUE;
|
|
|
|
aFrameResult = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Take frame from fromLine
|
|
|
|
nsIFrame* frame = fromLine->mFirstChild;
|
|
|
|
if (0 == aLine->mChildCount++) {
|
|
|
|
aLine->mFirstChild = frame;
|
|
|
|
aLine->SetIsBlock(fromLine->IsBlock());
|
|
|
|
NS_ASSERTION(aLine->CheckIsBlock(), "bad line isBlock");
|
|
|
|
}
|
|
|
|
if (0 != --fromLine->mChildCount) {
|
|
|
|
// Mark line dirty now that we pulled a child
|
|
|
|
fromLine->MarkDirty();
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&fromLine->mFirstChild);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Free up the fromLine now that it's empty
|
|
|
|
*aFromList = fromLine->mNext;
|
|
|
|
delete fromLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change geometric parents
|
|
|
|
if (aUpdateGeometricParent) {
|
1999-01-14 05:16:23 +00:00
|
|
|
frame->SetParent(this);
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// The frame is being pulled from a next-in-flow; therefore we
|
|
|
|
// need to add it to our sibling list.
|
|
|
|
if (nsnull != aState.mPrevChild) {
|
|
|
|
aState.mPrevChild->SetNextSibling(frame);
|
|
|
|
}
|
|
|
|
frame->SetNextSibling(nsnull);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Stop pulling because we found a frame to pull
|
|
|
|
aStopPulling = PR_TRUE;
|
|
|
|
aFrameResult = frame;
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1998-09-23 20:10:40 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-09-23 20:10:40 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DidReflowLine(nsBlockReflowState& aState,
|
1999-02-18 18:25:45 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
PRBool aLineReflowStatus)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
// If the line no longer needs a floater array, get rid of it and
|
|
|
|
// save some memory
|
|
|
|
nsVoidArray* array = aLine->mFloaters;
|
|
|
|
if (nsnull != array) {
|
|
|
|
if (0 == array->Count()) {
|
|
|
|
delete array;
|
|
|
|
aLine->mFloaters = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
array->Compact();
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::SlideFrames(nsIPresContext& aPresContext,
|
1999-02-18 18:25:45 +00:00
|
|
|
nsISpaceManager* aSpaceManager,
|
|
|
|
nsLineBox* aLine, nscoord aDY)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-11-20 22:24:20 +00:00
|
|
|
#if 0
|
1998-12-05 16:02:08 +00:00
|
|
|
ListTag(stdout); printf(": SlideFrames: line=%p dy=%d\n", aDY);
|
1998-11-20 22:24:20 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
// Adjust the Y coordinate of the frames in the line
|
1998-12-12 19:19:11 +00:00
|
|
|
nsRect r;
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* kid = aLine->mFirstChild;
|
|
|
|
PRInt32 n = aLine->ChildCount();
|
|
|
|
while (--n >= 0) {
|
|
|
|
kid->GetRect(r);
|
|
|
|
r.y += aDY;
|
|
|
|
kid->SetRect(r);
|
1998-11-20 22:24:20 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If the child has any floaters that impact the space manager,
|
1998-12-12 19:19:11 +00:00
|
|
|
// slide them now.
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIHTMLReflow* ihr;
|
|
|
|
if (NS_OK == kid->QueryInterface(kIHTMLReflowIID, (void**)&ihr)) {
|
|
|
|
ihr->MoveInSpaceManager(aPresContext, aSpaceManager, 0, aDY);
|
1998-11-12 16:32:56 +00:00
|
|
|
}
|
|
|
|
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-09-23 02:25:26 +00:00
|
|
|
}
|
|
|
|
|
1998-12-12 19:19:11 +00:00
|
|
|
// Adjust line state
|
|
|
|
aLine->mBounds.y += aDY;
|
|
|
|
aLine->mCombinedArea.y += aDY;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::SlideFloaters(nsIPresContext& aPresContext,
|
1999-02-18 18:25:45 +00:00
|
|
|
nsISpaceManager* aSpaceManager,
|
|
|
|
nsLineBox* aLine, nscoord aDY,
|
|
|
|
PRBool aUpdateSpaceManager)
|
1998-12-12 19:19:11 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsVoidArray* floaters = aLine->mFloaters;
|
|
|
|
if (nsnull != floaters) {
|
1998-12-12 19:19:11 +00:00
|
|
|
nsRect r;
|
|
|
|
PRInt32 i, n = floaters->Count();
|
1998-12-05 16:02:08 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) floaters->ElementAt(i);
|
1998-12-12 19:19:11 +00:00
|
|
|
nsIFrame* floater = ph->GetAnchoredItem();
|
|
|
|
floater->GetRect(r);
|
1998-12-05 16:02:08 +00:00
|
|
|
r.y += aDY;
|
1998-12-12 19:19:11 +00:00
|
|
|
floater->SetRect(r);
|
|
|
|
|
|
|
|
if (aUpdateSpaceManager) {
|
|
|
|
// Adjust placement in space manager by the same amount
|
|
|
|
aSpaceManager->OffsetRegion(floater, 0, aDY);
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-09-23 02:25:26 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::MoveInSpaceManager(nsIPresContext& aPresContext,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsISpaceManager* aSpaceManager,
|
|
|
|
nscoord aDeltaX, nscoord aDeltaY)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
ListTag(stdout); printf(": MoveInSpaceManager: d=%d,%d\n", aDeltaX, aDeltaY);
|
|
|
|
#endif
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
// Move the floaters in the spacemanager
|
|
|
|
nsVoidArray* floaters = line->mFloaters;
|
|
|
|
if (nsnull != floaters) {
|
1998-12-12 19:19:11 +00:00
|
|
|
PRInt32 i, n = floaters->Count();
|
1998-12-05 16:02:08 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) floaters->ElementAt(i);
|
1998-12-12 19:19:11 +00:00
|
|
|
nsIFrame* floater = ph->GetAnchoredItem();
|
|
|
|
aSpaceManager->OffsetRegion(floater, aDeltaX, aDeltaY);
|
1998-12-05 16:02:08 +00:00
|
|
|
#if 0
|
|
|
|
((nsFrame*)kid)->ListTag(stdout); printf(": offset=%d,%d\n", aDeltaX, aDeltaY);
|
|
|
|
#endif
|
1998-10-06 00:38:56 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tell kids about the move too
|
1998-12-12 19:19:11 +00:00
|
|
|
PRInt32 n = line->ChildCount();
|
|
|
|
nsIFrame* kid = line->mFirstChild;
|
1998-12-05 16:02:08 +00:00
|
|
|
while (--n >= 0) {
|
|
|
|
nsIHTMLReflow* ihr;
|
|
|
|
if (NS_OK == kid->QueryInterface(kIHTMLReflowIID, (void**)&ihr)) {
|
|
|
|
ihr->MoveInSpaceManager(aPresContext, aSpaceManager, aDeltaX, aDeltaY);
|
1998-10-06 00:38:56 +00:00
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
line = line->mNext;
|
1998-09-23 02:25:26 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-23 19:18:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::AttributeChanged(nsIPresContext* aPresContext,
|
|
|
|
nsIContent* aChild,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
PRInt32 aHint)
|
|
|
|
{
|
|
|
|
nsresult rv = nsBlockFrameSuper::AttributeChanged(aPresContext, aChild,
|
|
|
|
aAttribute, aHint);
|
|
|
|
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (nsHTMLAtoms::start == aAttribute) {
|
1999-03-05 19:25:44 +00:00
|
|
|
// XXX Not sure if this is necessary anymore
|
1999-02-23 19:18:12 +00:00
|
|
|
RenumberLists();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this,
|
|
|
|
nsIReflowCommand::ContentChanged,
|
|
|
|
nsnull,
|
|
|
|
aAttribute);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsHTMLAtoms::value == aAttribute) {
|
|
|
|
const nsStyleDisplay* styleDisplay;
|
|
|
|
GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) styleDisplay);
|
|
|
|
if (NS_STYLE_DISPLAY_LIST_ITEM == styleDisplay->mDisplay) {
|
|
|
|
nsIFrame* nextAncestor = mParent;
|
|
|
|
nsBlockFrame* blockParent = nsnull;
|
|
|
|
|
|
|
|
// Search for the closest ancestor that's a block frame. We
|
|
|
|
// make the assumption that all related list items share a
|
|
|
|
// common block parent.
|
|
|
|
while (nextAncestor != nsnull) {
|
|
|
|
if (NS_OK == nextAncestor->QueryInterface(kBlockFrameCID,
|
|
|
|
(void**)&blockParent)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nextAncestor->GetParent(&nextAncestor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the enclosing block frame to renumber list items within
|
|
|
|
// itself
|
|
|
|
if (nsnull != blockParent) {
|
1999-03-05 19:25:44 +00:00
|
|
|
// XXX Not sure if this is necessary anymore
|
1999-02-23 19:18:12 +00:00
|
|
|
blockParent->RenumberLists();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
|
|
|
|
|
|
|
nsIReflowCommand* reflowCmd;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, blockParent,
|
|
|
|
nsIReflowCommand::ContentChanged,
|
|
|
|
nsnull,
|
|
|
|
aAttribute);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
shell->AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame*
|
|
|
|
nsBlockFrame::FindFollowingBlockFrame(nsIFrame* aFrame)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* followingBlockFrame = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* frame = aFrame;
|
|
|
|
for (;;) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&nextFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != nextFrame) {
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
nextFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
if (NS_STYLE_DISPLAY_BLOCK == display->mDisplay) {
|
|
|
|
#ifdef NOISY_RUNIN
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": frame: ");
|
1999-03-05 04:21:32 +00:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
printf(" followed by: ");
|
1999-03-05 04:21:32 +00:00
|
|
|
nsFrame::ListTag(stdout, nextFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
printf("\n");
|
|
|
|
#endif
|
1999-02-09 17:31:33 +00:00
|
|
|
followingBlockFrame = (nsBlockFrame*) nextFrame;
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (NS_STYLE_DISPLAY_INLINE == display->mDisplay) {
|
|
|
|
// If it's a text-frame and it's just whitespace and we are
|
|
|
|
// in a normal whitespace situation THEN skip it and keep
|
|
|
|
// going...
|
|
|
|
// XXX WRITE ME!
|
|
|
|
}
|
|
|
|
frame = nextFrame;
|
1998-10-06 00:38:56 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else
|
|
|
|
break;
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return followingBlockFrame;
|
|
|
|
}
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
#if XXX
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::WillReflowFrame(nsBlockReflowState& aState,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
aFrame->GetStyleContext(kidSC);
|
|
|
|
if (nsnull != kidSC) {
|
|
|
|
nsIStyleContext* kidParentSC;
|
|
|
|
kidParentSC = kidSC->GetParent();
|
|
|
|
if (nsnull != kidParentSC) {
|
|
|
|
if (kidParentSC != mStyleContext) {
|
|
|
|
// The frame has changed situations so re-resolve its style
|
|
|
|
// context in the new situation.
|
|
|
|
aFrame->ReResolveStyleContext(&aState.mPresContext, mStyleContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(kidParentSC);
|
|
|
|
}
|
|
|
|
NS_RELEASE(kidSC);
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
#endif
|
|
|
|
|
1999-02-12 17:45:58 +00:00
|
|
|
// XXX This should be a no-op when there is no first-line/letter style
|
|
|
|
// in force!
|
1999-02-09 17:31:33 +00:00
|
|
|
void
|
|
|
|
nsBlockFrame::WillReflowFrame(nsBlockReflowState& aState,
|
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
PRBool repairStyleContext = PR_TRUE;
|
|
|
|
|
|
|
|
// When reflowing a frame that is on the first-line, check and see
|
|
|
|
// if a special style context should be placed in the context chain.
|
|
|
|
if ((nsnull == mPrevInFlow) &&
|
|
|
|
(0 == aState.mLineLayout->GetLineNumber())) {
|
|
|
|
if (nsnull != mFirstLineStyle) {
|
|
|
|
// Update the child frames style to inherit from the first-line
|
|
|
|
// style.
|
|
|
|
|
|
|
|
// XXX add code to check first and only do it if it needs doing!
|
|
|
|
#ifdef REALLY_NOISY_FIRST_LINE
|
|
|
|
DumpStyleGeneaology(aFrame, "");
|
|
|
|
#endif
|
|
|
|
#ifdef NOISY_FIRST_LINE
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": ");
|
|
|
|
((nsFrame*)aFrame)->ListTag(stdout);
|
|
|
|
printf(" adding in first-line style\n");
|
|
|
|
#endif
|
|
|
|
aFrame->ReResolveStyleContext(&aState.mPresContext, mFirstLineStyle);
|
|
|
|
repairStyleContext = PR_FALSE;
|
|
|
|
#ifdef REALLY_NOISY_FIRST_LINE
|
|
|
|
DumpStyleGeneaology(aFrame, " ");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if ((nsnull != mFirstLetterStyle) &&
|
|
|
|
aState.mLineLayout->GetFirstLetterStyleOK()) {
|
|
|
|
aFrame->ReResolveStyleContext(&aState.mPresContext, mFirstLetterStyle);
|
|
|
|
repairStyleContext = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (repairStyleContext) {
|
|
|
|
// Update style context when appropriate
|
|
|
|
nsIStyleContext* kidSC;
|
1999-02-10 00:42:56 +00:00
|
|
|
aFrame->GetStyleContext(&kidSC);
|
1999-02-09 17:31:33 +00:00
|
|
|
if (nsnull != kidSC) {
|
|
|
|
nsIStyleContext* kidParentSC;
|
|
|
|
kidParentSC = kidSC->GetParent();
|
|
|
|
if (nsnull != kidParentSC) {
|
|
|
|
if (kidParentSC != mStyleContext) {
|
|
|
|
aFrame->ReResolveStyleContext(&aState.mPresContext, mStyleContext);
|
|
|
|
}
|
|
|
|
NS_RELEASE(kidParentSC);
|
|
|
|
}
|
|
|
|
NS_RELEASE(kidSC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReflowBlockFrame(nsBlockReflowState& aState,
|
1999-02-12 17:45:58 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
PRBool* aKeepReflowGoing)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(*aKeepReflowGoing, "bad caller");
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_PRECONDITION(0 == aState.mLineLayout->GetPlacedFrames(),
|
|
|
|
"non-empty line with a block");
|
1998-07-10 21:45:30 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
|
|
|
|
// Prepare the inline reflow engine
|
1999-03-05 04:21:32 +00:00
|
|
|
//XXX nsBlockFrame* runInToFrame;
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* compactWithFrame;
|
1998-12-05 16:02:08 +00:00
|
|
|
nscoord compactMarginWidth = 0;
|
|
|
|
PRBool isCompactFrame = PR_FALSE;
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
frame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
switch (display->mDisplay) {
|
1999-03-05 04:21:32 +00:00
|
|
|
#if XXX_runin
|
1998-12-05 16:02:08 +00:00
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
#ifdef NOISY_RUNIN
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": trying to see if ");
|
|
|
|
aFrame->ListTag(stdout);
|
|
|
|
printf(" is a run-in candidate\n");
|
|
|
|
#endif
|
|
|
|
runInToFrame = FindFollowingBlockFrame(frame);
|
|
|
|
if (nsnull != runInToFrame) {
|
|
|
|
// XXX run-in frame should be pushed to the next-in-flow too if the
|
|
|
|
// run-in-to frame is pushed.
|
|
|
|
nsRect r(0, aState.mY, 0, 0);
|
|
|
|
aLine->mBounds = r;
|
|
|
|
aLine->mCombinedArea = r;
|
|
|
|
aLine->mCarriedOutTopMargin = 0;
|
|
|
|
aLine->mCarriedOutBottomMargin = 0;
|
|
|
|
aLine->SetMarginFlags(0);
|
1998-12-15 00:14:09 +00:00
|
|
|
#if XXX_need_line_outside_children
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine->ClearOutsideChildren();
|
1998-12-15 00:14:09 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine->mBreakType = NS_STYLE_CLEAR_NONE;
|
|
|
|
//XXX aFrame->WillReflow(aState.mPresContext);
|
|
|
|
frame->SetRect(r);
|
|
|
|
aState.mPrevChild = frame;
|
|
|
|
aState.mRunInToFrame = runInToFrame;
|
|
|
|
aState.mRunInFrame = (nsBlockFrame*) frame;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
break;
|
1999-03-05 04:21:32 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
|
|
|
compactWithFrame = FindFollowingBlockFrame(frame);
|
|
|
|
if (nsnull != compactWithFrame) {
|
|
|
|
const nsStyleSpacing* spacing;
|
|
|
|
nsMargin margin;
|
|
|
|
nsresult rv;
|
|
|
|
rv = compactWithFrame->GetStyleData(eStyleStruct_Spacing,
|
|
|
|
(const nsStyleStruct*&) spacing);
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != spacing)) {
|
1999-03-05 04:21:32 +00:00
|
|
|
nsHTMLReflowState::ComputeMarginFor(compactWithFrame,
|
|
|
|
&aState.mReflowState,
|
1998-12-05 16:02:08 +00:00
|
|
|
margin);
|
|
|
|
compactMarginWidth = margin.left;
|
1998-11-06 02:09:21 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
isCompactFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
nsBlockReflowContext brc(aState.mPresContext, aState.mReflowState,
|
|
|
|
aState.mComputeMaxElementSize);
|
1998-12-05 16:02:08 +00:00
|
|
|
brc.SetCompactMarginWidth(compactMarginWidth);
|
1999-03-05 04:21:32 +00:00
|
|
|
brc.SetNextRCFrame(aState.mNextRCFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Clear floaters before the block if the clear style is not none
|
|
|
|
aLine->mBreakType = display->mBreakType;
|
|
|
|
if (NS_STYLE_CLEAR_NONE != display->mBreakType) {
|
|
|
|
switch (display->mBreakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
|
|
|
aState.ClearFloaters(aState.mY, display->mBreakType);
|
|
|
|
// XXX: ?If we just advanced Y then we need to factor that amount
|
|
|
|
// into the next margin calculation and reduce the amount of Y
|
|
|
|
// margin applied by the amount just moved.
|
|
|
|
break;
|
1998-11-06 02:09:21 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-08-04 21:18:16 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
#if XXX_runin
|
1998-12-05 16:02:08 +00:00
|
|
|
// Set run-in frame if this is the run-in-to frame. That way the
|
|
|
|
// target block frame knows to pick up the children from the run-in
|
|
|
|
// frame.
|
|
|
|
if (frame == aState.mRunInToFrame) {
|
|
|
|
brc.SetRunInFrame(aState.mRunInFrame);
|
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Compute the available space for the block
|
|
|
|
nscoord availHeight = aState.mUnconstrainedHeight
|
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: aState.mBottomEdge - aState.mY;
|
|
|
|
|
|
|
|
// Now setup the availSpace rect. If the block frame we are
|
|
|
|
// reflowing is one of "ours" (block, run-in, compact, list-item)
|
|
|
|
// then we get it an available space that is *NOT* affected by
|
|
|
|
// floaters. Otherwise we position the block outside of the
|
|
|
|
// floaters.
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = aState.BorderPadding();
|
1998-12-05 16:02:08 +00:00
|
|
|
nscoord availX, availWidth;
|
1998-12-08 21:43:15 +00:00
|
|
|
nsSplittableType splitType;
|
1998-12-05 16:02:08 +00:00
|
|
|
switch (display->mDisplay) {
|
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
1998-12-08 21:43:15 +00:00
|
|
|
if (NS_SUCCEEDED(frame->IsSplittable(splitType)) &&
|
|
|
|
(NS_FRAME_SPLITTABLE_NON_RECTANGULAR == splitType)) {
|
1999-03-05 04:21:32 +00:00
|
|
|
availX = borderPadding.left;
|
1998-12-08 21:43:15 +00:00
|
|
|
availWidth = aState.mUnconstrainedWidth
|
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: aState.mContentArea.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Assume the frame is clueless about the space manager
|
|
|
|
// FALLTHROUGH
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
default:
|
1999-03-05 04:21:32 +00:00
|
|
|
availX = aState.mAvailSpaceRect.x + borderPadding.left;
|
1998-12-08 21:43:15 +00:00
|
|
|
availWidth = aState.mAvailSpaceRect.width;
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Reflow the block into the available space
|
|
|
|
nsRect availSpace(availX, aState.mY, availWidth, availHeight);
|
|
|
|
WillReflowFrame(aState, aLine, frame);
|
|
|
|
nsReflowStatus frameReflowStatus;
|
1999-01-16 20:58:17 +00:00
|
|
|
nsMargin computedOffsets;
|
1999-02-12 17:45:58 +00:00
|
|
|
PRBool applyTopMargin = aState.ShouldApplyTopMargin();
|
1999-02-26 17:04:44 +00:00
|
|
|
if (!applyTopMargin) {
|
|
|
|
// XXX clarify the IsAdjacentWithTop
|
|
|
|
|
1999-03-08 19:24:07 +00:00
|
|
|
// XXX rationalize this with the box model....
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (line != aLine) {
|
|
|
|
if ((nsnull != line->mFloaters) && (0 != line->mFloaters->Count())) {
|
1999-02-26 17:04:44 +00:00
|
|
|
applyTopMargin = PR_TRUE;
|
1999-03-08 19:24:07 +00:00
|
|
|
break;
|
1999-02-26 17:04:44 +00:00
|
|
|
}
|
1999-03-08 19:24:07 +00:00
|
|
|
if (line->IsBlock()) {
|
|
|
|
applyTopMargin = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
line = line->mNext;
|
1999-02-26 17:04:44 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
rv = brc.ReflowBlock(frame, availSpace,
|
|
|
|
#ifdef SPECULATIVE_TOP_MARGIN
|
|
|
|
applyTopMargin, aState.mPrevBottomMargin,
|
|
|
|
#endif
|
|
|
|
aState.IsAdjacentWithTop(),
|
1999-01-16 20:58:17 +00:00
|
|
|
computedOffsets, frameReflowStatus);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
aState.mPrevChild = frame;
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#if defined(REFLOW_STATUS_COVERAGE)
|
1999-02-09 17:31:33 +00:00
|
|
|
RecordReflowStatus(PR_TRUE, frameReflowStatus);
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_INLINE_IS_BREAK_BEFORE(frameReflowStatus)) {
|
|
|
|
// None of the child block fits.
|
|
|
|
PushLines(aState);
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mReflowStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
else {
|
1998-12-11 15:49:07 +00:00
|
|
|
// Note: line-break-after a block is a nop
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Try to place the child block
|
|
|
|
PRBool isAdjacentWithTop = aState.IsAdjacentWithTop();
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = brc.PlaceBlock(isAdjacentWithTop,
|
|
|
|
#ifndef SPECULATIVE_TOP_MARGIN
|
|
|
|
applyTopMargin,
|
|
|
|
aState.mPrevBottomMargin,
|
|
|
|
#endif
|
|
|
|
computedOffsets,
|
|
|
|
aLine->mBounds, aLine->mCombinedArea);
|
|
|
|
if (*aKeepReflowGoing) {
|
1998-12-05 16:02:08 +00:00
|
|
|
// Some of the child block fit
|
|
|
|
|
|
|
|
// Set carry out top margin value when margin is not being applied
|
|
|
|
if (!applyTopMargin) {
|
|
|
|
aState.mCarriedOutTopMargin = brc.GetCollapsedTopMargin();
|
|
|
|
}
|
1998-11-20 17:18:58 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Advance to new Y position
|
|
|
|
nscoord newY = aLine->mBounds.YMost();
|
|
|
|
if (isCompactFrame) {
|
|
|
|
// For compact frames, we don't adjust the Y coordinate at all IF
|
|
|
|
// the compact frame ended up fitting in the margin space
|
|
|
|
// allocated for it.
|
|
|
|
nsRect r;
|
|
|
|
frame->GetRect(r);
|
|
|
|
if (r.width <= compactMarginWidth) {
|
|
|
|
// XXX margins will be wrong
|
|
|
|
// XXX ltr/rtl for horizontal placement within the margin area
|
|
|
|
// XXX vertical alignment with the compactWith frame's *first line*
|
|
|
|
newY = aState.mY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aState.mY = newY;
|
|
|
|
aLine->mCarriedOutTopMargin = brc.GetCarriedOutTopMargin();
|
|
|
|
aLine->mCarriedOutBottomMargin = brc.GetCarriedOutBottomMargin();
|
|
|
|
|
|
|
|
// Continue the block frame now if it didn't completely fit in
|
|
|
|
// the available space.
|
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(frameReflowStatus)) {
|
|
|
|
PRBool madeContinuation;
|
|
|
|
rv = CreateContinuationFor(aState, aLine, frame, madeContinuation);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-11-20 17:18:58 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Push continuation to a new line, but only if we actually
|
|
|
|
// made one.
|
|
|
|
if (madeContinuation) {
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* line = new nsLineBox(frame, 1, LINE_IS_BLOCK);
|
|
|
|
if (nsnull == line) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-10-16 20:22:39 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
line->mNext = aLine->mNext;
|
|
|
|
aLine->mNext = line;
|
1998-11-17 22:28:51 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Do not count the continuation child on the line it used
|
|
|
|
// to be on
|
|
|
|
aLine->mChildCount--;
|
1998-08-04 21:18:16 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Advance to next line since some of the block fit. That way
|
|
|
|
// only the following lines will be pushed.
|
|
|
|
aState.mPrevLine = aLine;
|
|
|
|
PushLines(aState);
|
|
|
|
aState.mReflowStatus = NS_FRAME_NOT_COMPLETE;
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// The bottom margin for a block is only applied on the last
|
|
|
|
// flow block. Since we just continued the child block frame,
|
|
|
|
// we know that line->mFirstChild is not the last flow block
|
|
|
|
// therefore zero out the running margin value.
|
|
|
|
aState.mPrevBottomMargin = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aState.mPrevBottomMargin = brc.GetCollapsedBottomMargin();
|
1998-11-06 02:09:21 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Post-process the "line"
|
|
|
|
PostPlaceLine(aState, aLine, brc.GetMaxElementSize());
|
|
|
|
|
1999-02-18 22:22:55 +00:00
|
|
|
// Place the "marker" (bullet) frame.
|
|
|
|
//
|
|
|
|
// According to the CSS2 spec, section 12.6.1, the "marker" box
|
|
|
|
// participates in the height calculation of the list-item box's
|
|
|
|
// first line box.
|
|
|
|
//
|
|
|
|
// There are exactly two places a bullet can be placed: near the
|
|
|
|
// first or second line. Its only placed on the second line in a
|
|
|
|
// rare case: an empty first line followed by a second line that
|
|
|
|
// contains a block (example: <LI>\n<P>... ). This is where
|
|
|
|
// the second case can happen.
|
|
|
|
if (HaveOutsideBullet() &&
|
|
|
|
((aLine == mLines) ||
|
|
|
|
((0 == mLines->mBounds.height) && (aLine == mLines->mNext)))) {
|
|
|
|
// Reflow the bullet
|
|
|
|
nsHTMLReflowMetrics metrics(nsnull);
|
|
|
|
ReflowBullet(aState, metrics);
|
|
|
|
|
|
|
|
// For bullets that are placed next to a child block, there will
|
|
|
|
// be no correct ascent value. Therefore, make one up...
|
|
|
|
nscoord ascent = 0;
|
|
|
|
const nsStyleFont* font;
|
|
|
|
nsresult rv;
|
|
|
|
rv = frame->GetStyleData(eStyleStruct_Font,
|
|
|
|
(const nsStyleStruct*&) font);
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != font)) {
|
1999-03-05 04:21:32 +00:00
|
|
|
nsIRenderingContext& rc = *aState.mReflowState.rendContext;
|
1999-02-18 22:22:55 +00:00
|
|
|
rc.SetFont(font->mFont);
|
|
|
|
nsIFontMetrics* fm;
|
|
|
|
rv = rc.GetFontMetrics(fm);
|
|
|
|
if (NS_SUCCEEDED(rv) && (nsnull != fm)) {
|
|
|
|
fm->GetMaxAscent(ascent);
|
|
|
|
NS_RELEASE(fm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tall bullets won't look particularly nice here...
|
|
|
|
nsRect bbox;
|
|
|
|
mBullet->GetRect(bbox);
|
|
|
|
nscoord topMargin = applyTopMargin ? brc.GetCollapsedTopMargin() : 0;
|
1999-03-05 04:21:32 +00:00
|
|
|
bbox.y = borderPadding.top + ascent - metrics.ascent +
|
1999-02-18 22:22:55 +00:00
|
|
|
topMargin;
|
|
|
|
mBullet->SetRect(bbox);
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// None of the block fits. Determine the correct reflow status.
|
|
|
|
if (aLine == mLines) {
|
|
|
|
// If it's our very first line then we need to be pushed to
|
|
|
|
// our parents next-in-flow. Therefore, return break-before
|
|
|
|
// status for our reflow status.
|
|
|
|
aState.mReflowStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Push the line that didn't fit and any lines that follow it
|
|
|
|
// to our next-in-flow.
|
|
|
|
PushLines(aState);
|
|
|
|
aState.mReflowStatus = NS_FRAME_NOT_COMPLETE;
|
|
|
|
}
|
|
|
|
}
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Reflow an inline frame. The reflow status is mapped from the frames
|
|
|
|
* reflow status to the lines reflow status (not to our reflow status).
|
|
|
|
* The line reflow status is simple: PR_TRUE means keep placing frames
|
|
|
|
* on the line; PR_FALSE means don't (the line is done). If the line
|
|
|
|
* has some sort of breaking affect then aLine->mBreakType will be set
|
|
|
|
* to something other than NS_STYLE_CLEAR_NONE.
|
|
|
|
*/
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReflowInlineFrame(nsBlockReflowState& aState,
|
1999-02-12 17:45:58 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
PRBool* aKeepLineGoing)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_PRECONDITION(*aKeepLineGoing, "bad caller");
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Send pre-reflow notification
|
|
|
|
WillReflowFrame(aState, aLine, aFrame);
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// If it's currently ok to be reflowing in first-letter style then
|
|
|
|
// we must be about to reflow a frame that has first-letter style.
|
|
|
|
PRBool reflowingFirstLetter = aState.mLineLayout->GetFirstLetterStyleOK();
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Reflow the inline frame
|
|
|
|
nsReflowStatus frameReflowStatus;
|
1998-12-12 17:59:30 +00:00
|
|
|
nsresult rv = aState.mInlineReflow->ReflowFrame(aFrame, aState.IsAdjacentWithTop(),
|
|
|
|
frameReflowStatus);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-09-10 19:32:14 +00:00
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef REALLY_NOISY_REFLOW_CHILD
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
|
|
|
printf(": status=%x\n", frameReflowStatus);
|
|
|
|
#endif
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#if defined(REFLOW_STATUS_COVERAGE)
|
1999-02-09 17:31:33 +00:00
|
|
|
RecordReflowStatus(PR_FALSE, frameReflowStatus);
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Send post-reflow notification
|
|
|
|
aState.mPrevChild = aFrame;
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Process the child frames reflow status. There are 5 cases:
|
|
|
|
// complete, not-complete, break-before, break-after-complete,
|
|
|
|
// break-after-not-complete. There are two situations: we are a
|
|
|
|
// block or we are an inline. This makes a total of 10 cases
|
|
|
|
// (fortunately, there is some overlap).
|
|
|
|
aLine->mBreakType = NS_STYLE_CLEAR_NONE;
|
|
|
|
if (NS_INLINE_IS_BREAK(frameReflowStatus)) {
|
|
|
|
// Always abort the line reflow (because a line break is the
|
|
|
|
// minimal amount of break we do).
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepLineGoing = PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// XXX what should aLine->mBreakType be set to in all these cases?
|
|
|
|
PRUint8 breakType = NS_INLINE_GET_BREAK_TYPE(frameReflowStatus);
|
|
|
|
NS_ASSERTION(breakType != NS_STYLE_CLEAR_NONE, "bad break type");
|
|
|
|
NS_ASSERTION(NS_STYLE_CLEAR_PAGE != breakType, "no page breaks yet");
|
|
|
|
|
|
|
|
if (NS_INLINE_IS_BREAK_BEFORE(frameReflowStatus)) {
|
|
|
|
// Break-before cases.
|
|
|
|
if (aFrame == aLine->mFirstChild) {
|
1999-02-12 17:45:58 +00:00
|
|
|
NS_NOTREACHED("can't get here, can we?");
|
|
|
|
#if 0
|
1998-12-05 16:02:08 +00:00
|
|
|
// All break-before's that occur at the first child on a
|
|
|
|
// line stop the overall reflow.
|
|
|
|
if (mLines == aLine) {
|
|
|
|
// If it's our first child on our first line then propogate
|
|
|
|
// outward the break-before reflow status unmodified.
|
|
|
|
aState.mReflowStatus = frameReflowStatus;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Its not our first line; push the remaining lines to a
|
|
|
|
// next-in-flow
|
|
|
|
PushLines(aState);
|
|
|
|
|
|
|
|
// Adjust the reflow status to indicate a
|
|
|
|
// break-after-not-complete; because we need to be continued
|
|
|
|
// and we need to force a line break (or something stronger)
|
|
|
|
// upstream.
|
|
|
|
aState.mReflowStatus = NS_FRAME_NOT_COMPLETE | NS_INLINE_BREAK |
|
|
|
|
NS_INLINE_BREAK_AFTER | NS_INLINE_MAKE_BREAK_TYPE(breakType);
|
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// It's not the first child on this line so go ahead and split
|
|
|
|
// the line. We will see the frame again on the next-line.
|
|
|
|
rv = SplitLine(aState, aLine, aFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-09-10 19:32:14 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// Break-after cases
|
|
|
|
aLine->mBreakType = breakType;
|
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(frameReflowStatus)) {
|
|
|
|
// Create a continuation for the incomplete frame. Note that the
|
|
|
|
// frame may already have a continuation.
|
|
|
|
PRBool madeContinuation;
|
|
|
|
rv = CreateContinuationFor(aState, aLine, aFrame, madeContinuation);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Split line, but after the frame just reflowed
|
1999-03-16 19:36:00 +00:00
|
|
|
nsIFrame* nextFrame;
|
|
|
|
aFrame->GetNextSibling(&nextFrame);
|
|
|
|
rv = SplitLine(aState, aLine, nextFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
1998-09-11 04:13:29 +00:00
|
|
|
}
|
|
|
|
|
1999-02-09 17:31:33 +00:00
|
|
|
// Mark next line dirty in case SplitLine didn't end up
|
|
|
|
// pushing any frames.
|
|
|
|
nsLineBox* next = aLine->mNext;
|
|
|
|
if ((nsnull != next) && !next->IsBlock()) {
|
|
|
|
next->MarkDirty();
|
1999-01-05 23:01:54 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NS_FRAME_IS_NOT_COMPLETE(frameReflowStatus)) {
|
|
|
|
// Frame is not-complete, no special breaking status
|
1998-09-10 19:32:14 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Create a continuation for the incomplete frame. Note that the
|
|
|
|
// frame may already have a continuation.
|
|
|
|
PRBool madeContinuation;
|
|
|
|
rv = CreateContinuationFor(aState, aLine, aFrame, madeContinuation);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool needSplit = PR_FALSE;
|
1999-02-09 17:31:33 +00:00
|
|
|
if (!reflowingFirstLetter) {
|
1998-12-05 16:02:08 +00:00
|
|
|
needSplit = PR_TRUE;
|
1998-09-10 19:32:14 +00:00
|
|
|
}
|
1998-09-11 04:13:29 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (needSplit) {
|
|
|
|
// Split line after the current frame
|
1999-02-12 18:18:34 +00:00
|
|
|
*aKeepLineGoing = PR_FALSE;
|
1999-02-10 06:13:38 +00:00
|
|
|
aFrame->GetNextSibling(&aFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
rv = SplitLine(aState, aLine, aFrame);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
// Mark next line dirty in case SplitLine didn't end up
|
|
|
|
// pushing any frames.
|
|
|
|
nsLineBox* next = aLine->mNext;
|
|
|
|
if ((nsnull != next) && !next->IsBlock()) {
|
|
|
|
next->MarkDirty();
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
1998-09-10 19:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Create a continuation, if necessary, for aFrame. Place it on the
|
|
|
|
* same line that aFrame is on. Set aMadeNewFrame to PR_TRUE if a
|
|
|
|
* new frame is created.
|
|
|
|
*/
|
1998-06-30 20:14:04 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::CreateContinuationFor(nsBlockReflowState& aState,
|
1999-03-16 19:36:00 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
PRBool& aMadeNewFrame)
|
1998-06-30 20:14:04 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
aMadeNewFrame = PR_FALSE;
|
|
|
|
nsresult rv;
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
rv = CreateNextInFlow(aState.mPresContext, this, aFrame, nextInFlow);
|
|
|
|
if (NS_FAILED(rv)) {
|
1998-06-30 20:14:04 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != nextInFlow) {
|
|
|
|
aMadeNewFrame = PR_TRUE;
|
|
|
|
aLine->mChildCount++;
|
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
1998-06-30 20:14:04 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::SplitLine(nsBlockReflowState& aState,
|
1999-01-05 23:01:54 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsIFrame* aFrame)
|
1998-10-02 21:50:53 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
PRInt32 pushCount = aLine->ChildCount() -
|
|
|
|
aState.mInlineReflow->GetCurrentFrameNum();
|
1999-03-16 19:36:00 +00:00
|
|
|
//printf("BEFORE (pushCount=%d):\n", pushCount);
|
|
|
|
//aLine->List(stdout, 0);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (0 != pushCount) {
|
|
|
|
NS_ASSERTION(aLine->ChildCount() > pushCount, "bad push");
|
|
|
|
NS_ASSERTION(nsnull != aFrame, "whoops");
|
|
|
|
nsLineBox* to = aLine->mNext;
|
|
|
|
if (nsnull != to) {
|
|
|
|
// Only push into the next line if it's empty; otherwise we can
|
|
|
|
// end up pushing a frame which is continued into the same frame
|
|
|
|
// as it's continuation. This causes all sorts of bad side
|
|
|
|
// effects so we don't allow it.
|
|
|
|
if (0 != to->ChildCount()) {
|
|
|
|
nsLineBox* insertedLine = new nsLineBox(aFrame, pushCount, 0);
|
|
|
|
if (nsnull == insertedLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aLine->mNext = insertedLine;
|
|
|
|
insertedLine->mNext = to;
|
|
|
|
to = insertedLine;
|
|
|
|
} else {
|
|
|
|
to->mFirstChild = aFrame;
|
1999-03-16 19:36:00 +00:00
|
|
|
to->mChildCount = pushCount;
|
1998-12-05 16:02:08 +00:00
|
|
|
to->MarkDirty();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
to = new nsLineBox(aFrame, pushCount, 0);
|
|
|
|
if (nsnull == to) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine->mNext = to;
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
to->SetIsBlock(aLine->IsBlock());
|
|
|
|
aLine->mChildCount -= pushCount;
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Let inline reflow know that some frames are no longer part of
|
|
|
|
// its state.
|
|
|
|
if (!aLine->IsBlock()) {
|
|
|
|
aState.mInlineReflow->ChangeFrameCount(aLine->ChildCount());
|
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ShouldJustifyLine(nsBlockReflowState& aState, nsLineBox* aLine)
|
1998-06-24 17:52:42 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* next = aLine->mNext;
|
|
|
|
while (nsnull != next) {
|
|
|
|
// There is another line
|
|
|
|
if (0 != next->ChildCount()) {
|
|
|
|
// If the next line is a block line then we must not justify
|
|
|
|
// this line because it means that this line is the last in a
|
|
|
|
// group of inline lines.
|
|
|
|
return !next->IsBlock();
|
|
|
|
}
|
1998-06-30 20:14:04 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// The next line is empty, try the next one
|
|
|
|
next = next->mNext;
|
1998-06-30 20:14:04 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX Not sure about this part
|
|
|
|
// Try our next-in-flows lines to answer the question
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* nextInFlow = (nsBlockFrame*) mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != nextInFlow) {
|
|
|
|
nsLineBox* line = nextInFlow->mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (0 != line->ChildCount()) {
|
1998-12-11 15:49:07 +00:00
|
|
|
return !line->IsBlock();
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
line = line->mNext;
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
nextInFlow = (nsBlockFrame*) nextInFlow->mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-11-11 03:55:55 +00:00
|
|
|
|
1998-12-11 15:49:07 +00:00
|
|
|
// This is the last line - so don't allow justification
|
|
|
|
return PR_FALSE;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PlaceLine(nsBlockReflowState& aState,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* aLine,
|
1999-02-12 17:45:58 +00:00
|
|
|
PRBool* aKeepReflowGoing)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-02-18 22:22:55 +00:00
|
|
|
// Vertically align the frames on this line.
|
|
|
|
//
|
|
|
|
// According to the CSS2 spec, section 12.6.1, the "marker" box
|
|
|
|
// participates in the height calculation of the list-item box's
|
|
|
|
// first line box.
|
|
|
|
//
|
|
|
|
// There are exactly two places a bullet can be placed: near the
|
|
|
|
// first or second line. Its only placed on the second line in a
|
|
|
|
// rare case: an empty first line followed by a second line that
|
|
|
|
// contains a block (example: <LI>\n<P>... ).
|
|
|
|
//
|
|
|
|
// For this code, only the first case is possible because this
|
|
|
|
// method is used for placing a line of inline frames. If the rare
|
|
|
|
// case is happening then the worst that will happen is that the
|
|
|
|
// bullet frame will be reflowed twice.
|
1998-12-05 16:02:08 +00:00
|
|
|
nsInlineReflow& ir = *aState.mInlineReflow;
|
1999-02-18 22:22:55 +00:00
|
|
|
PRBool addedBullet = PR_FALSE;
|
|
|
|
if (HaveOutsideBullet() && (aLine == mLines) && !ir.IsZeroHeight()) {
|
|
|
|
nsHTMLReflowMetrics metrics(nsnull);
|
|
|
|
ReflowBullet(aState, metrics);
|
|
|
|
ir.AddFrame(mBullet, metrics);
|
|
|
|
addedBullet = PR_TRUE;
|
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
nscoord a, d;
|
|
|
|
ir.VerticalAlignFrames(aLine->mBounds, a, d);
|
1999-02-18 22:22:55 +00:00
|
|
|
if (addedBullet) {
|
|
|
|
ir.RemoveFrame(mBullet);
|
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
NS_ASSERTION((aLine->mBounds.YMost()) < 200000 && (aLine->mBounds.y > -200000), "oy");
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Only block frames horizontally align their children because
|
|
|
|
// inline frames "shrink-wrap" around their children (therefore
|
|
|
|
// there is no extra horizontal space).
|
1999-03-05 04:21:32 +00:00
|
|
|
#if XXX_fix_me
|
1999-02-09 17:31:33 +00:00
|
|
|
PRBool allowJustify = PR_TRUE;
|
|
|
|
if (NS_STYLE_TEXT_ALIGN_JUSTIFY == aState.mStyleText->mTextAlign) {
|
|
|
|
allowJustify = ShouldJustifyLine(aState, aLine);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
#else
|
|
|
|
PRBool allowJustify = PR_FALSE;
|
|
|
|
#endif
|
1999-02-09 17:31:33 +00:00
|
|
|
ir.TrimTrailingWhiteSpace(aLine->mBounds);
|
|
|
|
ir.HorizontalAlignFrames(aLine->mBounds, allowJustify);
|
1998-12-05 16:02:08 +00:00
|
|
|
ir.RelativePositionFrames(aLine->mCombinedArea);
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Calculate the bottom margin for the line.
|
|
|
|
nscoord lineBottomMargin = 0;
|
|
|
|
if (0 == aLine->mBounds.height) {
|
|
|
|
nsIFrame* brFrame = aState.mLineLayout->GetBRFrame();
|
|
|
|
if (nsnull != brFrame) {
|
|
|
|
// If a line ends in a BR, and the line is empty of height, then
|
|
|
|
// we make sure that the line ends up with some height
|
|
|
|
// anyway. Note that the height looks like vertical margin so
|
|
|
|
// that it can compress with other block margins.
|
|
|
|
nsIStyleContext* brSC;
|
|
|
|
nsIPresContext& px = aState.mPresContext;
|
1999-02-10 00:42:56 +00:00
|
|
|
nsresult rv = brFrame->GetStyleContext(&brSC);
|
1998-12-05 16:02:08 +00:00
|
|
|
if ((NS_OK == rv) && (nsnull != brSC)) {
|
|
|
|
const nsStyleFont* font = (const nsStyleFont*)
|
|
|
|
brSC->GetStyleData(eStyleStruct_Font);
|
1999-02-12 17:45:58 +00:00
|
|
|
nsIFontMetrics* fm = nsnull;
|
|
|
|
px.GetMetricsFor(font->mFont, &fm);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != fm) {
|
|
|
|
fm->GetHeight(lineBottomMargin);
|
|
|
|
NS_RELEASE(fm);
|
|
|
|
}
|
|
|
|
NS_RELEASE(brSC);
|
|
|
|
}
|
1998-07-09 17:06:35 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aState.mRunInFromFrame = nsnull;
|
|
|
|
aState.mRunInToFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the lines top and bottom margin values. The margin will
|
|
|
|
// come from an embedded block frame, not from inline
|
|
|
|
// frames. Because this is an "inline" line, the child margins are
|
|
|
|
// all effectively zero so we pass in nsMargin(0, 0, 0, 0).
|
|
|
|
nscoord topMargin, bottomMargin;
|
|
|
|
nsBlockReflowContext::CollapseMargins(nsMargin(0, 0, 0, 0),
|
|
|
|
ir.GetCarriedOutTopMargin(),
|
|
|
|
ir.GetCarriedOutBottomMargin(),
|
|
|
|
aLine->mBounds.height,
|
|
|
|
aState.mPrevBottomMargin,
|
|
|
|
topMargin, bottomMargin);
|
|
|
|
|
|
|
|
#if XXX
|
|
|
|
ListTag(stdout);
|
|
|
|
printf(": ");
|
|
|
|
((nsFrame*)(aLine->mFirstChild))->ListTag(stdout);
|
|
|
|
printf(" mY=%d carried=%d,%d top=%d bottom=%d prev=%d shouldApply=%s\n",
|
|
|
|
aState.mY, ir.GetCarriedOutTopMargin(), ir.GetCarriedOutBottomMargin(),
|
|
|
|
topMargin, bottomMargin, aState.mPrevBottomMargin,
|
|
|
|
aState.ShouldApplyTopMargin() ? "yes" : "no");
|
|
|
|
#endif
|
|
|
|
if (!aState.ShouldApplyTopMargin()) {
|
|
|
|
aState.mCarriedOutTopMargin = topMargin;
|
|
|
|
topMargin = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if the line fit. If it doesn't we need to push it. Our first
|
|
|
|
// line will always fit.
|
|
|
|
nscoord newY = aLine->mBounds.YMost() + topMargin + lineBottomMargin;
|
|
|
|
NS_FRAME_TRACE(NS_FRAME_TRACE_CHILD_REFLOW,
|
1999-02-09 17:31:33 +00:00
|
|
|
("nsBlockFrame::PlaceLine: newY=%d limit=%d lineHeight=%d",
|
1998-12-05 16:02:08 +00:00
|
|
|
newY, aState.mBottomEdge, aLine->mBounds.height));
|
|
|
|
if ((mLines != aLine) && (newY > aState.mBottomEdge)) {
|
|
|
|
// Push this line and all of it's children and anything else that
|
|
|
|
// follows to our next-in-flow
|
|
|
|
PushLines(aState);
|
|
|
|
|
|
|
|
// Stop reflow and whack the reflow status if reflow hasn't
|
|
|
|
// already been stopped.
|
1999-02-12 17:45:58 +00:00
|
|
|
if (*aKeepReflowGoing) {
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_ASSERTION(NS_FRAME_COMPLETE == aState.mReflowStatus,
|
|
|
|
"lost reflow status");
|
|
|
|
aState.mReflowStatus = NS_FRAME_NOT_COMPLETE;
|
1999-02-12 17:45:58 +00:00
|
|
|
*aKeepReflowGoing = PR_FALSE;
|
1998-10-06 00:38:56 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine->mCarriedOutTopMargin = ir.GetCarriedOutTopMargin();
|
|
|
|
aLine->mCarriedOutBottomMargin = ir.GetCarriedOutBottomMargin();
|
|
|
|
aState.mPrevBottomMargin = bottomMargin;
|
|
|
|
if (0 != topMargin) {
|
|
|
|
// Apply collapsed top-margin value
|
|
|
|
SlideFrames(aState.mPresContext, aState.mSpaceManager, aLine, topMargin);
|
1998-12-12 19:19:11 +00:00
|
|
|
SlideFloaters(aState.mPresContext, aState.mSpaceManager, aLine, topMargin,
|
|
|
|
PR_TRUE);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
aState.mY = newY;
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
PostPlaceLine(aState, aLine, ir.GetMaxElementSize());
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Any below current line floaters to place?
|
|
|
|
if (0 != aState.mPendingFloaters.Count()) {
|
1999-02-09 17:31:33 +00:00
|
|
|
aState.PlaceBelowCurrentLineFloaters(&aState.mPendingFloaters);
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mPendingFloaters.Clear();
|
1998-06-30 23:51:26 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Apply break-after clearing if necessary
|
|
|
|
PRUint8 breakType = aLine->mBreakType;
|
|
|
|
switch (breakType) {
|
|
|
|
case NS_STYLE_CLEAR_LEFT:
|
|
|
|
case NS_STYLE_CLEAR_RIGHT:
|
|
|
|
case NS_STYLE_CLEAR_LEFT_AND_RIGHT:
|
|
|
|
aState.ClearFloaters(aState.mY, breakType);
|
|
|
|
break;
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return rv;
|
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
// Compute the line's max-element-size by adding into the raw value
|
|
|
|
// computed by reflowing the contents of the line (aMaxElementSize)
|
|
|
|
// the impact of floaters on this line or the preceeding lines.
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ComputeLineMaxElementSize(nsBlockReflowState& aState,
|
1998-12-17 18:52:10 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
nsSize* aMaxElementSize)
|
|
|
|
{
|
|
|
|
nscoord maxWidth, maxHeight;
|
|
|
|
aState.mCurrentBand.GetMaxElementSize(&maxWidth, &maxHeight);
|
|
|
|
|
|
|
|
// Add in the maximum width of any floaters in the band because we
|
|
|
|
// always place some non-floating content with a floater.
|
|
|
|
aMaxElementSize->width += maxWidth;
|
|
|
|
|
|
|
|
// If the maximum-height of the tallest floater is larger than the
|
|
|
|
// maximum-height of the content then update the max-element-size
|
|
|
|
// height
|
|
|
|
if (maxHeight > aMaxElementSize->height) {
|
|
|
|
aMaxElementSize->height = maxHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PostPlaceLine(nsBlockReflowState& aState,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* aLine,
|
|
|
|
const nsSize& aMaxElementSize)
|
|
|
|
{
|
|
|
|
// Update max-element-size
|
|
|
|
if (aState.mComputeMaxElementSize) {
|
1998-12-17 18:52:10 +00:00
|
|
|
nsSize lineMaxElementSize(aMaxElementSize);
|
1999-02-09 17:31:33 +00:00
|
|
|
if (0 != aState.mCurrentBand.GetFloaterCount()) {
|
1998-12-17 18:52:10 +00:00
|
|
|
// Add in floater impacts to the lines max-element-size
|
|
|
|
ComputeLineMaxElementSize(aState, aLine, &lineMaxElementSize);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-12-17 18:52:10 +00:00
|
|
|
if (lineMaxElementSize.width > aState.mMaxElementSize.width) {
|
1999-03-05 19:25:44 +00:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
ListTag(stdout); printf(": old max-element-size.width=%d new=%d\n",
|
|
|
|
aState.mMaxElementSize.width,
|
|
|
|
lineMaxElementSize.width);
|
|
|
|
#endif
|
1998-12-17 18:52:10 +00:00
|
|
|
aState.mMaxElementSize.width = lineMaxElementSize.width;
|
|
|
|
}
|
|
|
|
if (lineMaxElementSize.height > aState.mMaxElementSize.height) {
|
1999-03-05 19:25:44 +00:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
ListTag(stdout); printf(": old max-element-size.height=%d new=%d\n",
|
|
|
|
aState.mMaxElementSize.height,
|
|
|
|
lineMaxElementSize.height);
|
|
|
|
#endif
|
1998-12-17 18:52:10 +00:00
|
|
|
aState.mMaxElementSize.height = lineMaxElementSize.height;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-15 00:14:09 +00:00
|
|
|
#if XXX_need_line_outside_children
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute LINE_OUTSIDE_CHILDREN state for this line. The bit is set
|
|
|
|
// if any child frame has outside children.
|
1998-12-15 00:14:09 +00:00
|
|
|
if ((aLine->mCombinedArea.x < aLine->mBounds.x) ||
|
|
|
|
(aLine->mCombinedArea.XMost() > aLine->mBounds.XMost()) ||
|
|
|
|
(aLine->mCombinedArea.y < aLine->mBounds.y) ||
|
|
|
|
(aLine->mCombinedArea.YMost() > aLine->mBounds.YMost())) {
|
|
|
|
aLine->SetOutsideChildren();
|
1998-06-30 23:51:26 +00:00
|
|
|
}
|
1998-12-15 00:14:09 +00:00
|
|
|
else {
|
|
|
|
aLine->ClearOutsideChildren();
|
|
|
|
}
|
|
|
|
#endif
|
1998-07-09 17:06:35 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Update xmost
|
|
|
|
nscoord xmost = aLine->mBounds.XMost();
|
|
|
|
if (xmost > aState.mKidXMost) {
|
1999-03-05 04:21:32 +00:00
|
|
|
#ifdef DEBUG_kipp
|
|
|
|
NS_ASSERTION((xmost > -200000) && (xmost < 200000), "oy");
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
aState.mKidXMost = xmost;
|
|
|
|
}
|
1998-06-30 20:14:04 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
static nsresult
|
|
|
|
FindFloatersIn(nsIFrame* aFrame, nsVoidArray*& aArray)
|
|
|
|
{
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
if (NS_STYLE_FLOAT_NONE != display->mFloats) {
|
|
|
|
if (nsnull == aArray) {
|
|
|
|
aArray = new nsVoidArray();
|
|
|
|
if (nsnull == aArray) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-06-27 22:56:09 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aArray->AppendElement(aFrame);
|
1998-06-27 22:56:09 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_STYLE_DISPLAY_INLINE == display->mDisplay) {
|
|
|
|
nsIFrame* kid;
|
1999-02-10 02:25:01 +00:00
|
|
|
aFrame->FirstChild(nsnull, &kid);
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != kid) {
|
|
|
|
nsresult rv = FindFloatersIn(kid, aArray);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
1998-06-27 22:56:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::FindFloaters(nsLineBox* aLine)
|
1998-07-02 00:04:12 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsVoidArray* floaters = aLine->mFloaters;
|
|
|
|
if (nsnull != floaters) {
|
|
|
|
// Empty floater array before proceeding
|
|
|
|
floaters->Clear();
|
|
|
|
}
|
1998-09-18 17:18:37 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
PRInt32 n = aLine->ChildCount();
|
|
|
|
while (--n >= 0) {
|
|
|
|
FindFloatersIn(frame, floaters);
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-09-18 17:18:37 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
aLine->mFloaters = floaters;
|
1998-09-18 17:18:37 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Get rid of floater array if we don't need it
|
|
|
|
if (nsnull != floaters) {
|
|
|
|
if (0 == floaters->Count()) {
|
|
|
|
delete floaters;
|
|
|
|
aLine->mFloaters = nsnull;
|
1998-07-02 00:04:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PushLines(nsBlockReflowState& aState)
|
1998-07-06 21:37:08 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_ASSERTION(nsnull != aState.mPrevLine, "bad push");
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox* lastLine = aState.mPrevLine;
|
|
|
|
nsLineBox* nextLine = lastLine->mNext;
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
lastLine->mNext = nsnull;
|
|
|
|
mOverflowLines = nextLine;
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Mark all the overflow lines dirty so that they get reflowed when
|
|
|
|
// they are pulled up by our next-in-flow.
|
|
|
|
while (nsnull != nextLine) {
|
|
|
|
nextLine->MarkDirty();
|
|
|
|
nextLine = nextLine->mNext;
|
1998-09-25 05:13:06 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Break frame sibling list
|
|
|
|
nsIFrame* lastFrame = lastLine->LastChild();
|
|
|
|
lastFrame->SetNextSibling(nsnull);
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyOverflowSituation();
|
1998-09-25 05:13:06 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DrainOverflowLines()
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyOverflowSituation();
|
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool drained = PR_FALSE;
|
1998-11-17 01:04:45 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// First grab the prev-in-flows overflow lines
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* prevBlock = (nsBlockFrame*) mPrevInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != prevBlock) {
|
|
|
|
nsLineBox* line = prevBlock->mOverflowLines;
|
|
|
|
if (nsnull != line) {
|
|
|
|
drained = PR_TRUE;
|
|
|
|
prevBlock->mOverflowLines = nsnull;
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Make all the frames on the mOverflowLines list mine
|
|
|
|
nsIFrame* lastFrame = nsnull;
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
1999-01-14 05:16:23 +00:00
|
|
|
frame->SetParent(this);
|
1998-12-05 16:02:08 +00:00
|
|
|
lastFrame = frame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-09-25 05:13:06 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Join the line lists
|
|
|
|
if (nsnull == mLines) {
|
|
|
|
mLines = line;
|
1998-09-25 05:13:06 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-12-05 16:02:08 +00:00
|
|
|
// Join the sibling lists together
|
|
|
|
lastFrame->SetNextSibling(mLines->mFirstChild);
|
1998-09-25 05:13:06 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Place overflow lines at the front of our line list
|
|
|
|
nsLineBox* lastLine = nsLineBox::LastLine(line);
|
|
|
|
lastLine->mNext = mLines;
|
|
|
|
mLines = line;
|
|
|
|
}
|
1998-09-25 05:13:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now grab our own overflow lines
|
|
|
|
if (nsnull != mOverflowLines) {
|
|
|
|
// This can happen when we reflow and not everything fits and then
|
|
|
|
// we are told to reflow again before a next-in-flow is created
|
|
|
|
// and reflows.
|
|
|
|
nsLineBox* lastLine = nsLineBox::LastLine(mLines);
|
|
|
|
if (nsnull == lastLine) {
|
|
|
|
mLines = mOverflowLines;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastLine->mNext = mOverflowLines;
|
|
|
|
nsIFrame* lastFrame = lastLine->LastChild();
|
|
|
|
lastFrame->SetNextSibling(mOverflowLines->mFirstChild);
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Update our last-content-index now that we have a new last child
|
|
|
|
lastLine = nsLineBox::LastLine(mOverflowLines);
|
|
|
|
}
|
|
|
|
mOverflowLines = nsnull;
|
|
|
|
drained = PR_TRUE;
|
|
|
|
}
|
|
|
|
return drained;
|
1998-09-25 16:10:10 +00:00
|
|
|
}
|
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Frame list manipulation routines
|
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::AppendFrames(nsIPresContext& aPresContext,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
1999-02-02 17:31:09 +00:00
|
|
|
{
|
1999-02-26 17:04:44 +00:00
|
|
|
if (nsLayoutAtoms::floaterList == aListName) {
|
|
|
|
// XXX we don't *really* care about this right now because we are
|
|
|
|
// BuildFloaterList ing still
|
|
|
|
mFloaters.AppendFrames(nsnull, aFrameList);
|
|
|
|
return NS_OK;
|
1999-02-03 19:09:24 +00:00
|
|
|
}
|
1999-02-26 17:04:44 +00:00
|
|
|
else if (nsLayoutAtoms::absoluteList == aListName) {
|
|
|
|
// XXX temporary until area frame and floater code is updated
|
|
|
|
return nsFrame::AppendFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aFrameList);
|
|
|
|
}
|
|
|
|
else if (nsnull != aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
nsresult rv = AppendNewFrames(aPresContext, aFrameList);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-26 17:04:44 +00:00
|
|
|
// Generate reflow command to reflow the dirty lines
|
1999-02-02 17:31:09 +00:00
|
|
|
nsIReflowCommand* reflowCmd = nsnull;
|
|
|
|
nsresult rv;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIReflowCommand::ReflowDirty,
|
1999-02-02 17:31:09 +00:00
|
|
|
nsnull);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nsnull != aListName) {
|
|
|
|
reflowCmd->SetChildListName(aListName);
|
|
|
|
}
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::AppendNewFrames(nsIPresContext& aPresContext,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIFrame* aNewFrame)
|
1998-12-17 18:52:10 +00:00
|
|
|
{
|
|
|
|
// Get our last line and then get its last child
|
|
|
|
nsIFrame* lastFrame;
|
|
|
|
nsLineBox* lastLine = nsLineBox::LastLine(mLines);
|
|
|
|
if (nsnull != lastLine) {
|
|
|
|
lastFrame = lastLine->LastChild();
|
|
|
|
} else {
|
|
|
|
lastFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the new frames to the sibling list; wrap any frames that
|
|
|
|
// require wrapping
|
|
|
|
if (nsnull != lastFrame) {
|
|
|
|
lastFrame->SetNextSibling(aNewFrame);
|
|
|
|
}
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Make sure that new inlines go onto the end of the lastLine when
|
|
|
|
// the lastLine is mapping inline frames.
|
|
|
|
PRInt32 pendingInlines = 0;
|
|
|
|
if (nsnull != lastLine) {
|
|
|
|
if (!lastLine->IsBlock()) {
|
|
|
|
pendingInlines = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now create some lines for the new frames
|
|
|
|
nsIFrame* prevFrame = lastFrame;
|
|
|
|
for (nsIFrame* frame = aNewFrame; nsnull != frame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame)) {
|
1998-12-17 18:52:10 +00:00
|
|
|
// See if the child is a block or non-block
|
|
|
|
const nsStyleDisplay* kidDisplay;
|
|
|
|
rv = frame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) kidDisplay);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
const nsStylePosition* kidPosition;
|
|
|
|
rv = frame->GetStyleData(eStyleStruct_Position,
|
|
|
|
(const nsStyleStruct*&) kidPosition);
|
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PRBool isBlock = nsLineLayout::TreatFrameAsBlock(kidDisplay, kidPosition);
|
|
|
|
|
|
|
|
// If the child is an inline then add it to the lastLine (if it's
|
|
|
|
// an inline line, otherwise make a new line). If the child is a
|
|
|
|
// block then make a new line and put the child in that line.
|
|
|
|
if (isBlock) {
|
|
|
|
// If the previous line has pending inline data to be reflowed,
|
|
|
|
// do so now.
|
|
|
|
if (0 != pendingInlines) {
|
|
|
|
// Set this to true in case we don't end up reflowing all of the
|
|
|
|
// frames on the line (because they end up being pushed).
|
|
|
|
lastLine->MarkDirty();
|
|
|
|
pendingInlines = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a line for the block
|
|
|
|
nsLineBox* line = new nsLineBox(frame, 1, LINE_IS_BLOCK);
|
|
|
|
if (nsnull == line) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (nsnull == lastLine) {
|
|
|
|
mLines = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastLine->mNext = line;
|
|
|
|
}
|
|
|
|
lastLine = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (0 == pendingInlines) {
|
|
|
|
nsLineBox* line = new nsLineBox(frame, 0, 0);
|
|
|
|
if (nsnull == line) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
if (nsnull == lastLine) {
|
|
|
|
mLines = line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastLine->mNext = line;
|
|
|
|
}
|
|
|
|
lastLine = line;
|
|
|
|
}
|
|
|
|
lastLine->mChildCount++;
|
|
|
|
pendingInlines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember the previous frame
|
|
|
|
prevFrame = frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 != pendingInlines) {
|
|
|
|
// Set this to true in case we don't end up reflowing all of the
|
|
|
|
// frames on the line (because they end up being pushed).
|
|
|
|
lastLine->MarkDirty();
|
|
|
|
}
|
|
|
|
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-01-05 23:01:54 +00:00
|
|
|
MarkEmptyLines(aPresContext);
|
1999-02-26 17:04:44 +00:00
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::InsertFrames(nsIPresContext& aPresContext,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
1999-02-02 17:31:09 +00:00
|
|
|
{
|
1999-02-26 17:04:44 +00:00
|
|
|
if (nsLayoutAtoms::floaterList == aListName) {
|
|
|
|
// XXX we don't *really* care about this right now because we are
|
|
|
|
// BuildFloaterList ing still
|
|
|
|
mFloaters.AppendFrames(nsnull, aFrameList);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (nsLayoutAtoms::absoluteList == aListName) {
|
|
|
|
// XXX temporary until area frame and floater code is updated
|
|
|
|
return nsFrame::InsertFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aPrevFrame, aFrameList);
|
|
|
|
}
|
|
|
|
else if (nsnull != aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-02-03 19:09:24 +00:00
|
|
|
}
|
1999-02-26 17:04:44 +00:00
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
nsresult rv = InsertNewFrames(aPresContext, aFrameList, aPrevFrame);
|
1999-02-23 19:18:12 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
#ifdef SLOW_INCREMENTAL_REFLOW
|
1999-02-23 19:18:12 +00:00
|
|
|
// XXX Temporary code to ensure that that right things
|
|
|
|
// get marked direty. Kipp will replace this with better
|
|
|
|
// code.
|
|
|
|
// Mark everything dirty
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
line->MarkDirty();
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
1999-02-26 17:04:44 +00:00
|
|
|
#endif
|
1999-02-23 19:18:12 +00:00
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-26 17:04:44 +00:00
|
|
|
// Generate reflow command to reflow the dirty lines
|
1999-02-02 17:31:09 +00:00
|
|
|
nsIReflowCommand* reflowCmd = nsnull;
|
|
|
|
nsresult rv;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this,
|
1999-02-03 19:09:24 +00:00
|
|
|
nsIReflowCommand::ReflowDirty,
|
1999-02-02 17:31:09 +00:00
|
|
|
nsnull);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nsnull != aListName) {
|
|
|
|
reflowCmd->SetChildListName(aListName);
|
|
|
|
}
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// XXX rewrite to deal with a list of frames
|
1998-06-18 16:25:41 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::InsertNewFrames(nsIPresContext& aPresContext,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIFrame* aFrameList,
|
|
|
|
nsIFrame* aPrevSibling)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull == mLines) {
|
|
|
|
NS_ASSERTION(nsnull == aPrevSibling, "prev-sibling and empty line list!");
|
1999-02-01 17:29:37 +00:00
|
|
|
return AppendNewFrames(aPresContext, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* newFrame = aFrameList;
|
|
|
|
while (nsnull != newFrame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 06:13:38 +00:00
|
|
|
newFrame->GetNextSibling(&next);
|
1999-02-01 17:29:37 +00:00
|
|
|
newFrame->SetNextSibling(nsnull);
|
|
|
|
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
newFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
const nsStylePosition* position;
|
|
|
|
newFrame->GetStyleData(eStyleStruct_Position,
|
|
|
|
(const nsStyleStruct*&) position);
|
|
|
|
PRUint16 newFrameIsBlock =
|
|
|
|
nsLineLayout::TreatFrameAsBlock(display, position)
|
|
|
|
? LINE_IS_BLOCK
|
|
|
|
: 0;
|
1998-06-30 23:51:26 +00:00
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// Insert/append the frame into flows line list at the right spot
|
|
|
|
nsLineBox* newLine;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
// Insert new frame into the sibling list
|
|
|
|
newFrame->SetNextSibling(line->mFirstChild);
|
|
|
|
|
|
|
|
if (line->IsBlock() || newFrameIsBlock) {
|
|
|
|
// Create a new line
|
|
|
|
newLine = new nsLineBox(newFrame, 1, newFrameIsBlock);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull == newLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
newLine->mNext = mLines;
|
|
|
|
mLines = newLine;
|
|
|
|
} else {
|
|
|
|
// Insert frame at the front of the line
|
|
|
|
line->mFirstChild = newFrame;
|
|
|
|
line->mChildCount++;
|
|
|
|
line->MarkDirty();
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Find line containing the previous sibling to the new frame
|
|
|
|
line = nsLineBox::FindLineContaining(line, aPrevSibling);
|
|
|
|
NS_ASSERTION(nsnull != line, "no line contains the previous sibling");
|
|
|
|
if (nsnull != line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
// Create a new line just after line
|
|
|
|
newLine = new nsLineBox(newFrame, 1, newFrameIsBlock);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull == newLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
newLine->mNext = line->mNext;
|
|
|
|
line->mNext = newLine;
|
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
else if (newFrameIsBlock) {
|
|
|
|
// Split line in two, if necessary. We can't allow a block to
|
|
|
|
// end up in an inline line.
|
|
|
|
if (line->IsLastChild(aPrevSibling)) {
|
|
|
|
// The new frame goes after prevSibling and prevSibling is
|
|
|
|
// the last frame on the line. Therefore we don't need to
|
|
|
|
// split the line, just create a new line.
|
|
|
|
newLine = new nsLineBox(newFrame, 1, newFrameIsBlock);
|
|
|
|
if (nsnull == newLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
newLine->mNext = line->mNext;
|
|
|
|
line->mNext = newLine;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
else {
|
|
|
|
// The new frame goes after prevSibling and prevSibling is
|
|
|
|
// somewhere in the line, but not at the end. Split the line
|
|
|
|
// just after prevSibling.
|
|
|
|
PRInt32 i, n = line->ChildCount();
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (frame == aPrevSibling) {
|
|
|
|
nsIFrame* nextSibling;
|
1999-02-10 06:13:38 +00:00
|
|
|
aPrevSibling->GetNextSibling(&nextSibling);
|
1999-02-01 17:29:37 +00:00
|
|
|
|
|
|
|
// Create new line to hold the remaining frames
|
|
|
|
NS_ASSERTION(n - i - 1 > 0, "bad line count");
|
|
|
|
newLine = new nsLineBox(nextSibling, n - i - 1, 0);
|
|
|
|
if (nsnull == newLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
newLine->mNext = line->mNext;
|
|
|
|
line->mNext = newLine;
|
|
|
|
line->MarkDirty();
|
|
|
|
line->mChildCount = i + 1;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// Now create a new line to hold the block
|
|
|
|
newLine = new nsLineBox(newFrame, 1, newFrameIsBlock);
|
|
|
|
if (nsnull == newLine) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
newLine->mNext = line->mNext;
|
|
|
|
line->mNext = newLine;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
line->mChildCount++;
|
|
|
|
line->MarkDirty();
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
// Insert new frame into the sibling list; note: this must be done
|
|
|
|
// after the above logic because the above logic depends on the
|
|
|
|
// sibling list being in the "before insertion" state.
|
|
|
|
nsIFrame* nextSibling;
|
1999-02-10 06:13:38 +00:00
|
|
|
aPrevSibling->GetNextSibling(&nextSibling);
|
1999-02-01 17:29:37 +00:00
|
|
|
newFrame->SetNextSibling(nextSibling);
|
|
|
|
aPrevSibling->SetNextSibling(newFrame);
|
|
|
|
}
|
|
|
|
aPrevSibling = newFrame;
|
|
|
|
newFrame = next;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-01-05 23:01:54 +00:00
|
|
|
MarkEmptyLines(aPresContext);
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::RemoveFrame(nsIPresContext& aPresContext,
|
1999-02-26 17:04:44 +00:00
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
1999-02-02 17:31:09 +00:00
|
|
|
{
|
1999-02-26 17:04:44 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsLayoutAtoms::floaterList == aListName) {
|
|
|
|
// Remove floater from the floater list first
|
|
|
|
mFloaters.RemoveFrame(aOldFrame);
|
|
|
|
|
|
|
|
// Find which line contains the floater
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
nsVoidArray* floaters = line->mFloaters;
|
|
|
|
if (nsnull != floaters) {
|
|
|
|
PRInt32 i, count = floaters->Count();
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*)floaters->ElementAt(i);
|
|
|
|
if (ph->GetAnchoredItem() == aOldFrame) {
|
|
|
|
// Note: the placeholder is part of the line's child list
|
|
|
|
// and will be removed later.
|
|
|
|
// XXX stop storing pointers to the placeholder in the line list???
|
|
|
|
ph->SetAnchoredItem(nsnull);
|
|
|
|
floaters->RemoveElementAt(i);
|
|
|
|
aOldFrame->DeleteFrame(aPresContext);
|
|
|
|
goto found_it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
found_it:
|
|
|
|
|
|
|
|
// Mark every line at and below the line where the floater was dirty
|
|
|
|
while (nsnull != line) {
|
|
|
|
line->MarkDirty();
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We will reflow *after* removing the placeholder (which is done 2nd)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (nsLayoutAtoms::absoluteList == aListName) {
|
1999-02-03 19:09:24 +00:00
|
|
|
// XXX temporary until area frame code is updated
|
1999-02-26 17:04:44 +00:00
|
|
|
return nsFrame::RemoveFrame(aPresContext, aPresShell, aListName,
|
|
|
|
aOldFrame);
|
|
|
|
}
|
|
|
|
else if (nsnull != aListName) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-02-03 19:09:24 +00:00
|
|
|
}
|
1999-02-26 17:04:44 +00:00
|
|
|
else {
|
|
|
|
rv = DoRemoveFrame(aPresContext, aOldFrame);
|
1999-02-23 19:18:12 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
#ifdef SLOW_INCREMENTAL_REFLOW
|
|
|
|
// XXX Temporary code to ensure that that right things
|
|
|
|
// get marked direty. Kipp will replace this with better
|
|
|
|
// code.
|
|
|
|
// Mark everything dirty
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
line->MarkDirty();
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
#endif
|
1999-02-23 19:18:12 +00:00
|
|
|
}
|
|
|
|
|
1999-02-02 17:31:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
1999-02-26 17:04:44 +00:00
|
|
|
// Generate reflow command to reflow the dirty lines
|
1999-02-02 17:31:09 +00:00
|
|
|
nsIReflowCommand* reflowCmd = nsnull;
|
|
|
|
nsresult rv;
|
|
|
|
rv = NS_NewHTMLReflowCommand(&reflowCmd, this,
|
1999-02-03 19:09:24 +00:00
|
|
|
nsIReflowCommand::ReflowDirty,
|
1999-02-02 17:31:09 +00:00
|
|
|
nsnull);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (nsnull != aListName) {
|
|
|
|
reflowCmd->SetChildListName(aListName);
|
|
|
|
}
|
|
|
|
aPresShell.AppendReflowCommand(reflowCmd);
|
|
|
|
NS_RELEASE(reflowCmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DoRemoveFrame(nsIPresContext& aPresContext,
|
1999-02-18 18:25:45 +00:00
|
|
|
nsIFrame* aDeletedFrame)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1999-01-05 23:01:54 +00:00
|
|
|
// Find the line and the previous sibling that contains
|
|
|
|
// deletedFrame; we also find the pointer to the line.
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame* flow = this;
|
1998-12-05 16:02:08 +00:00
|
|
|
nsLineBox** linep = &flow->mLines;
|
|
|
|
nsLineBox* line = flow->mLines;
|
1999-01-05 23:01:54 +00:00
|
|
|
nsLineBox* prevLine = nsnull;
|
|
|
|
nsIFrame* prevSibling = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != line) {
|
1999-01-05 23:01:54 +00:00
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
PRInt32 n = line->ChildCount();
|
|
|
|
while (--n >= 0) {
|
|
|
|
if (frame == aDeletedFrame) {
|
|
|
|
goto found_frame;
|
|
|
|
}
|
|
|
|
prevSibling = frame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-10-16 20:22:39 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
linep = &line->mNext;
|
1999-01-05 23:01:54 +00:00
|
|
|
prevLine = line;
|
1998-12-05 16:02:08 +00:00
|
|
|
line = line->mNext;
|
1998-08-04 21:18:16 +00:00
|
|
|
}
|
1999-01-05 23:01:54 +00:00
|
|
|
found_frame:;
|
|
|
|
#ifdef NS_DEBUG
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_ASSERTION(nsnull != line, "can't find deleted frame in lines");
|
1999-01-05 23:01:54 +00:00
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
nsIFrame* tmp;
|
1999-02-10 06:13:38 +00:00
|
|
|
prevSibling->GetNextSibling(&tmp);
|
1999-01-05 23:01:54 +00:00
|
|
|
NS_ASSERTION(tmp == aDeletedFrame, "bad prevSibling");
|
|
|
|
}
|
|
|
|
#endif
|
1998-08-04 21:18:16 +00:00
|
|
|
|
1999-01-05 23:01:54 +00:00
|
|
|
// Remove frame and all of its continuations
|
1998-12-05 16:02:08 +00:00
|
|
|
while (nsnull != aDeletedFrame) {
|
|
|
|
while ((nsnull != line) && (nsnull != aDeletedFrame)) {
|
1998-06-24 17:52:42 +00:00
|
|
|
#ifdef NS_DEBUG
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
aDeletedFrame->GetParent(&parent);
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_ASSERTION(flow == parent, "messed up delete code");
|
1999-03-16 19:36:00 +00:00
|
|
|
NS_ASSERTION(line->Contains(aDeletedFrame), "frame not in line");
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
|
|
|
|
1999-03-16 19:36:00 +00:00
|
|
|
// See if the frame being deleted is the last one on the line
|
|
|
|
PRBool isLastFrameOnLine = PR_FALSE;
|
|
|
|
if (1 == line->mChildCount) {
|
|
|
|
isLastFrameOnLine = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (line->LastChild() == aDeletedFrame) {
|
|
|
|
isLastFrameOnLine = PR_TRUE;
|
|
|
|
}
|
1999-01-05 23:01:54 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Remove aDeletedFrame from the line
|
1999-03-16 19:36:00 +00:00
|
|
|
nsIFrame* nextFrame;
|
|
|
|
aDeletedFrame->GetNextSibling(&nextFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (line->mFirstChild == aDeletedFrame) {
|
|
|
|
line->mFirstChild = nextFrame;
|
1999-02-18 18:25:45 +00:00
|
|
|
}
|
|
|
|
if (!line->IsBlock() && (nsnull != prevLine) && !prevLine->IsBlock()) {
|
|
|
|
// Make sure the previous line (if it's an inline line) gets
|
|
|
|
// a reflow too so that it can pullup from the line where we
|
|
|
|
// just removed the frame.
|
|
|
|
prevLine->MarkDirty();
|
|
|
|
// XXX Note: prevLine may be in a prev-in-flow
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-01-05 23:01:54 +00:00
|
|
|
// Take aDeletedFrame out of the sibling list. Note that
|
|
|
|
// prevSibling will only be nsnull when we are deleting the very
|
|
|
|
// first frame.
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
prevSibling->SetNextSibling(nextFrame);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy frame; capture its next-in-flow first in case we need
|
|
|
|
// to destroy that too.
|
|
|
|
nsIFrame* nextInFlow;
|
1999-02-24 04:48:08 +00:00
|
|
|
aDeletedFrame->GetNextInFlow(&nextInFlow);
|
1999-03-16 19:36:00 +00:00
|
|
|
nsSplittableType st;
|
|
|
|
aDeletedFrame->IsSplittable(st);
|
|
|
|
if (NS_FRAME_NOT_SPLITTABLE != st) {
|
|
|
|
aDeletedFrame->RemoveFromFlow();
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef NOISY_REMOVE_FRAME
|
|
|
|
printf("DoRemoveFrame: prevLine=%p line=%p frame=",
|
|
|
|
prevLine, line);
|
|
|
|
nsFrame::ListTag(stdout, aDeletedFrame);
|
|
|
|
printf(" prevSibling=%p nextInFlow=%p\n", prevSibling, nextInFlow);
|
|
|
|
#endif
|
1999-02-02 17:31:09 +00:00
|
|
|
aDeletedFrame->DeleteFrame(aPresContext);
|
1998-12-05 16:02:08 +00:00
|
|
|
aDeletedFrame = nextInFlow;
|
|
|
|
|
|
|
|
// If line is empty, remove it now
|
|
|
|
nsLineBox* next = line->mNext;
|
|
|
|
if (0 == --line->mChildCount) {
|
|
|
|
*linep = next;
|
|
|
|
line->mNext = nsnull;
|
|
|
|
delete line;
|
1999-03-16 19:36:00 +00:00
|
|
|
line = next;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-03-16 19:36:00 +00:00
|
|
|
// Make the line that just lost a frame dirty
|
1999-01-05 23:01:54 +00:00
|
|
|
line->MarkDirty();
|
1999-03-16 19:36:00 +00:00
|
|
|
|
|
|
|
// If we just removed the last frame on the line then we need
|
|
|
|
// to advance to the next line.
|
|
|
|
if (isLastFrameOnLine) {
|
|
|
|
prevLine = line;
|
|
|
|
linep = &line->mNext;
|
|
|
|
line = next;
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-01-05 23:01:54 +00:00
|
|
|
|
|
|
|
// See if we should keep looking in the current flow's line list.
|
|
|
|
if (nsnull != aDeletedFrame) {
|
|
|
|
if (aDeletedFrame != nextFrame) {
|
|
|
|
// The deceased frames continuation is not the next frame in
|
|
|
|
// the current flow's frame list. Therefore we know that the
|
|
|
|
// continuation is in a different parent. So break out of
|
|
|
|
// the loop so that we advance to the next parent.
|
|
|
|
#ifdef NS_DEBUG
|
1999-01-14 05:16:23 +00:00
|
|
|
nsIFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
aDeletedFrame->GetParent(&parent);
|
1999-01-14 05:16:23 +00:00
|
|
|
NS_ASSERTION(parent != flow, "strange continuation");
|
1999-01-05 23:01:54 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Advance to next flow block if the frame has more continuations
|
|
|
|
if (nsnull != aDeletedFrame) {
|
1999-02-09 17:31:33 +00:00
|
|
|
flow = (nsBlockFrame*) flow->mNextInFlow;
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_ASSERTION(nsnull != flow, "whoops, continuation without a parent");
|
1999-01-05 23:01:54 +00:00
|
|
|
prevLine = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
line = flow->mLines;
|
1999-03-16 19:36:00 +00:00
|
|
|
linep = &flow->mLines;
|
1999-01-05 23:01:54 +00:00
|
|
|
prevSibling = nsnull;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-02-02 17:31:09 +00:00
|
|
|
MarkEmptyLines(aPresContext);
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-17 18:52:10 +00:00
|
|
|
static PRBool
|
|
|
|
IsEmptyLine(nsIPresContext& aPresContext, nsLineBox* aLine)
|
|
|
|
{
|
|
|
|
PRInt32 i, n = aLine->ChildCount();
|
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIContent* content;
|
1999-02-10 00:42:56 +00:00
|
|
|
nsresult rv = frame->GetContent(&content);
|
1998-12-17 18:52:10 +00:00
|
|
|
if (NS_FAILED(rv) || (nsnull == content)) {
|
|
|
|
// If it doesn't have any content then this can't be an empty line
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
nsITextContent* tc;
|
|
|
|
rv = content->QueryInterface(kITextContentIID, (void**) &tc);
|
|
|
|
if (NS_FAILED(rv) || (nsnull == tc)) {
|
|
|
|
// If it's not text content then this can't be an empty line
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTextFragment* frag;
|
|
|
|
PRInt32 numFrags;
|
|
|
|
rv = tc->GetText(frag, numFrags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(content);
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the text has any non-whitespace characters in it then the
|
|
|
|
// line is not an empty line.
|
|
|
|
while (--numFrags >= 0) {
|
|
|
|
PRInt32 len = frag->GetLength();
|
|
|
|
if (frag->Is2b()) {
|
|
|
|
const PRUnichar* cp = frag->Get2b();
|
|
|
|
const PRUnichar* end = cp + len;
|
|
|
|
while (cp < end) {
|
|
|
|
PRUnichar ch = *cp++;
|
|
|
|
if (!XP_IS_SPACE(ch)) {
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const char* cp = frag->Get1b();
|
|
|
|
const char* end = cp + len;
|
|
|
|
while (cp < end) {
|
|
|
|
char ch = *cp++;
|
|
|
|
if (!XP_IS_SPACE(ch)) {
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
NS_RELEASE(content);
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
frag++;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(tc);
|
|
|
|
NS_RELEASE(content);
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-17 18:52:10 +00:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::MarkEmptyLines(nsIPresContext& aPresContext)
|
1998-12-17 18:52:10 +00:00
|
|
|
{
|
1999-01-05 23:01:54 +00:00
|
|
|
// PRE-formatted content considers whitespace significant
|
1998-12-17 18:52:10 +00:00
|
|
|
const nsStyleText* text;
|
|
|
|
GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&) text);
|
|
|
|
if (NS_STYLE_WHITESPACE_PRE == text->mWhiteSpace) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool afterBlock = PR_TRUE;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (line->IsBlock()) {
|
|
|
|
afterBlock = PR_TRUE;
|
|
|
|
}
|
|
|
|
else if (afterBlock) {
|
|
|
|
afterBlock = PR_FALSE;
|
|
|
|
|
|
|
|
// This is an inline line and it is immediately after a block
|
|
|
|
// (or its our first line). See if it contains nothing but
|
|
|
|
// collapsible text.
|
1999-01-05 23:01:54 +00:00
|
|
|
PRBool isEmpty = IsEmptyLine(aPresContext, line);
|
|
|
|
line->SetIsEmptyLine(isEmpty);
|
1998-12-17 18:52:10 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-01-05 23:01:54 +00:00
|
|
|
line->SetIsEmptyLine(PR_FALSE);
|
1998-12-17 18:52:10 +00:00
|
|
|
}
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-15 22:53:39 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::DeleteChildsNextInFlow(nsIPresContext& aPresContext,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* aChild)
|
1998-09-23 02:25:26 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_PRECONDITION(IsChild(aChild), "bad geometric parent");
|
|
|
|
nsIFrame* nextInFlow;
|
1999-02-24 04:48:08 +00:00
|
|
|
aChild->GetNextInFlow(&nextInFlow);
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_PRECONDITION(nsnull != nextInFlow, "null next-in-flow");
|
1999-03-16 19:36:00 +00:00
|
|
|
nsBlockFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
nextInFlow->GetParent((nsIFrame**)&parent);
|
1999-03-16 19:36:00 +00:00
|
|
|
NS_PRECONDITION(nsnull != parent, "next-in-flow with no parent");
|
|
|
|
NS_PRECONDITION(nsnull != parent->mLines, "next-in-flow with weird parent");
|
|
|
|
NS_PRECONDITION(nsnull == parent->mOverflowLines, "parent with overflow");
|
|
|
|
parent->DoRemoveFrame(aPresContext, nextInFlow);
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Floater support
|
|
|
|
|
1998-10-02 21:50:53 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::ReflowFloater(nsIPresContext& aPresContext,
|
1998-12-05 16:02:08 +00:00
|
|
|
nsBlockReflowState& aState,
|
|
|
|
nsIFrame* aFloaterFrame,
|
|
|
|
nsHTMLReflowState& aFloaterReflowState)
|
1998-10-02 21:50:53 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// If either dimension is constrained then get the border and
|
|
|
|
// padding values in advance.
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& bp = aFloaterReflowState.mComputedBorderPadding;
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute the available width for the floater
|
|
|
|
if (aFloaterReflowState.HaveFixedContentWidth()) {
|
|
|
|
// When the floater has a contrained width, give it just enough
|
|
|
|
// space for its styled width plus its borders and paddings.
|
1999-03-05 04:21:32 +00:00
|
|
|
aFloaterReflowState.availableWidth = aFloaterReflowState.computedWidth +
|
|
|
|
bp.left + bp.right;
|
1998-10-30 22:10:10 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
1998-12-15 04:20:54 +00:00
|
|
|
// CSS2 section 10.3.5: Floating non-replaced elements with an
|
|
|
|
// auto width have the computed value of zero. Therefore, don't
|
|
|
|
// bother reflowing them.
|
1999-01-03 00:31:46 +00:00
|
|
|
if (!NS_FRAME_IS_REPLACED(aFloaterReflowState.frameType)) {
|
1998-12-15 04:20:54 +00:00
|
|
|
// XXX Tables are weird and special, so check for them here...
|
|
|
|
const nsStyleDisplay* floaterDisplay;
|
|
|
|
aFloaterFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)floaterDisplay);
|
|
|
|
if (NS_STYLE_DISPLAY_TABLE != floaterDisplay->mDisplay) {
|
|
|
|
return;
|
1998-10-30 22:10:10 +00:00
|
|
|
}
|
|
|
|
}
|
1999-01-05 23:31:18 +00:00
|
|
|
aFloaterReflowState.availableWidth = NS_UNCONSTRAINEDSIZE;
|
1998-10-30 22:10:10 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Compute the available height for the floater
|
|
|
|
if (aFloaterReflowState.HaveFixedContentHeight()) {
|
1999-01-05 23:31:18 +00:00
|
|
|
aFloaterReflowState.availableHeight = aFloaterReflowState.computedHeight + bp.top + bp.bottom;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
else {
|
1999-01-05 23:31:18 +00:00
|
|
|
aFloaterReflowState.availableHeight = NS_UNCONSTRAINEDSIZE;
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Resize reflow the anchored item into the available space
|
|
|
|
nsIHTMLReflow* floaterReflow;
|
|
|
|
if (NS_OK == aFloaterFrame->QueryInterface(kIHTMLReflowIID,
|
|
|
|
(void**)&floaterReflow)) {
|
|
|
|
nsHTMLReflowMetrics desiredSize(nsnull);
|
1998-12-15 04:20:54 +00:00
|
|
|
nsReflowStatus status;
|
1998-12-05 16:02:08 +00:00
|
|
|
floaterReflow->WillReflow(aPresContext);
|
|
|
|
floaterReflow->Reflow(aPresContext, desiredSize, aFloaterReflowState,
|
|
|
|
status);
|
|
|
|
aFloaterFrame->SizeTo(desiredSize.width, desiredSize.height);
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
|
|
|
nsBlockReflowState::InitFloater(nsPlaceholderFrame* aPlaceholder)
|
1998-09-23 02:25:26 +00:00
|
|
|
{
|
1998-12-15 04:20:54 +00:00
|
|
|
// Set the geometric parent of the floater
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* floater = aPlaceholder->GetAnchoredItem();
|
1999-01-14 05:16:23 +00:00
|
|
|
floater->SetParent(mBlock);
|
1998-10-09 22:58:25 +00:00
|
|
|
|
1998-12-15 04:20:54 +00:00
|
|
|
// Then add the floater to the current line and place it when
|
|
|
|
// appropriate
|
|
|
|
AddFloater(aPlaceholder, PR_TRUE);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// This is called by the line layout's AddFloater method when a
|
|
|
|
// place-holder frame is reflowed in a line. If the floater is a
|
|
|
|
// left-most child (it's x coordinate is at the line's left margin)
|
|
|
|
// then the floater is place immediately, otherwise the floater
|
|
|
|
// placement is deferred until the line has been reflowed.
|
|
|
|
void
|
1998-12-15 04:20:54 +00:00
|
|
|
nsBlockReflowState::AddFloater(nsPlaceholderFrame* aPlaceholder,
|
|
|
|
PRBool aInitialReflow)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
// Update the current line's floater array
|
|
|
|
NS_ASSERTION(nsnull != mCurrentLine, "null ptr");
|
|
|
|
if (nsnull == mCurrentLine->mFloaters) {
|
|
|
|
mCurrentLine->mFloaters = new nsVoidArray();
|
1998-09-25 17:50:09 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
mCurrentLine->mFloaters->AppendElement(aPlaceholder);
|
1998-09-23 02:25:26 +00:00
|
|
|
|
1998-12-15 04:20:54 +00:00
|
|
|
// Reflow the floater
|
|
|
|
nsIFrame* floater = aPlaceholder->GetAnchoredItem();
|
|
|
|
nsSize kidAvailSize(0, 0);
|
1999-03-05 04:21:32 +00:00
|
|
|
nsHTMLReflowState reflowState(mPresContext, mReflowState, floater,
|
|
|
|
kidAvailSize);
|
1998-12-15 04:20:54 +00:00
|
|
|
reflowState.lineLayout = nsnull;
|
1999-03-05 04:21:32 +00:00
|
|
|
if ((nsnull == mReflowState.reflowCommand) || (floater != mNextRCFrame)) {
|
1999-01-12 16:42:03 +00:00
|
|
|
// Stub out reflowCommand and repair reason in the reflowState
|
1998-12-15 04:20:54 +00:00
|
|
|
// when incremental reflow doesn't apply to the floater.
|
|
|
|
reflowState.reflowCommand = nsnull;
|
1999-03-05 04:21:32 +00:00
|
|
|
reflowState.reason =
|
|
|
|
((mReflowState.reason == eReflowReason_Initial) || aInitialReflow)
|
1998-12-15 04:20:54 +00:00
|
|
|
? eReflowReason_Initial
|
|
|
|
: eReflowReason_Resize;
|
|
|
|
}
|
|
|
|
mBlock->ReflowFloater(mPresContext, *this, floater, reflowState);
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Now place the floater immediately if possible. Otherwise stash it
|
|
|
|
// away in mPendingFloaters and place it later.
|
|
|
|
if (0 == mLineLayout->GetPlacedFrames()) {
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CHILD_REFLOW,
|
|
|
|
("nsBlockReflowState::AddFloater: IsLeftMostChild, placeHolder=%p",
|
|
|
|
aPlaceholder));
|
1998-09-23 02:25:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Flush out pending bottom margin before placing floater
|
|
|
|
if (0 != mPrevBottomMargin) {
|
|
|
|
mY += mPrevBottomMargin;
|
|
|
|
mPrevBottomMargin = 0;
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Because we are in the middle of reflowing a placeholder frame
|
|
|
|
// within a line (and possibly nested in an inline frame or two
|
|
|
|
// that's a child of our block) we need to restore the space
|
|
|
|
// manager's translation to the space that the block resides in
|
|
|
|
// before placing the floater.
|
|
|
|
PRBool isLeftFloater;
|
|
|
|
nscoord ox, oy;
|
|
|
|
mSpaceManager->GetTranslation(ox, oy);
|
|
|
|
nscoord dx = ox - mSpaceManagerX;
|
|
|
|
nscoord dy = oy - mSpaceManagerY;
|
|
|
|
mSpaceManager->Translate(-dx, -dy);
|
|
|
|
PlaceFloater(aPlaceholder, isLeftFloater);
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Pass on updated available space to the current inline reflow engine
|
|
|
|
GetAvailableSpace();
|
1999-03-05 04:21:32 +00:00
|
|
|
mLineLayout->UpdateInlines(mAvailSpaceRect.x + BorderPadding().left,
|
1998-12-05 16:02:08 +00:00
|
|
|
mY,
|
1998-12-08 21:43:15 +00:00
|
|
|
mAvailSpaceRect.width,
|
|
|
|
mAvailSpaceRect.height,
|
1998-12-05 16:02:08 +00:00
|
|
|
isLeftFloater);
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Restore coordinate system
|
|
|
|
mSpaceManager->Translate(dx, dy);
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// This floater will be placed after the line is done (it is a
|
|
|
|
// below current line floater).
|
|
|
|
NS_FRAME_LOG(NS_FRAME_TRACE_CHILD_REFLOW,
|
|
|
|
("nsBlockReflowState::AddFloater: pending, placeHolder=%p",
|
|
|
|
aPlaceholder));
|
|
|
|
mPendingFloaters.AppendElement(aPlaceholder);
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-25 16:33:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool
|
|
|
|
nsBlockReflowState::IsLeftMostChild(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
nsIFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
aFrame->GetParent(&parent);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (parent == mBlock) {
|
|
|
|
nsIFrame* child = mCurrentLine->mFirstChild;
|
|
|
|
PRInt32 n = mCurrentLine->ChildCount();
|
|
|
|
while ((nsnull != child) && (aFrame != child) && (--n >= 0)) {
|
|
|
|
nsSize size;
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Is the child zero-sized?
|
|
|
|
child->GetSize(size);
|
|
|
|
if (size.width > 0) {
|
|
|
|
// We found a non-zero sized child frame that precedes aFrame
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
child->GetNextSibling(&child);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
break;
|
1998-06-30 20:14:04 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// See if there are any non-zero sized child frames that precede
|
|
|
|
// aFrame in the child list
|
|
|
|
nsIFrame* child;
|
1999-02-10 02:25:01 +00:00
|
|
|
parent->FirstChild(nsnull, &child);
|
1998-12-05 16:02:08 +00:00
|
|
|
while ((nsnull != child) && (aFrame != child)) {
|
|
|
|
nsSize size;
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Is the child zero-sized?
|
|
|
|
child->GetSize(size);
|
|
|
|
if (size.width > 0) {
|
|
|
|
// We found a non-zero sized child frame that precedes aFrame
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
child->GetNextSibling(&child);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// aFrame is the left-most non-zero sized frame in its geometric parent.
|
|
|
|
// Walk up one level and check that its parent is left-most as well
|
|
|
|
aFrame = parent;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
|
|
|
nsBlockReflowState::PlaceFloater(nsPlaceholderFrame* aPlaceholder,
|
|
|
|
PRBool& aIsLeftFloater)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-12-12 19:19:11 +00:00
|
|
|
// Save away the Y coordinate before placing the floater. We will
|
|
|
|
// restore mY at the end after placing the floater. This is
|
|
|
|
// necessary because any adjustments to mY during the floater
|
|
|
|
// placement are for the floater only, not for any non-floating
|
|
|
|
// content.
|
|
|
|
nscoord saveY = mY;
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* floater = aPlaceholder->GetAnchoredItem();
|
1998-07-29 04:03:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Get the type of floater
|
|
|
|
const nsStyleDisplay* floaterDisplay;
|
|
|
|
const nsStyleSpacing* floaterSpacing;
|
|
|
|
floater->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&)floaterDisplay);
|
|
|
|
floater->GetStyleData(eStyleStruct_Spacing,
|
|
|
|
(const nsStyleStruct*&)floaterSpacing);
|
|
|
|
|
|
|
|
// See if the floater should clear any preceeding floaters...
|
|
|
|
if (NS_STYLE_CLEAR_NONE != floaterDisplay->mBreakType) {
|
|
|
|
ClearFloaters(mY, floaterDisplay->mBreakType);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Get the band of available space
|
|
|
|
GetAvailableSpace();
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-08-04 21:18:16 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Get the floaters bounding box and margin information
|
|
|
|
nsRect region;
|
|
|
|
floater->GetRect(region);
|
|
|
|
nsMargin floaterMargin;
|
1999-03-05 04:21:32 +00:00
|
|
|
// XXX sometimes when we reflow the floater we already have this value...
|
|
|
|
nsHTMLReflowState::ComputeMarginFor(floater, &mReflowState, floaterMargin);
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Adjust the floater size by its margin. That's the area that will
|
|
|
|
// impact the space manager.
|
|
|
|
region.width += floaterMargin.left + floaterMargin.right;
|
|
|
|
region.height += floaterMargin.top + floaterMargin.bottom;
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Find a place to place the floater. The CSS2 spec doesn't want
|
|
|
|
// floaters overlapping each other or sticking out of the containing
|
|
|
|
// block (CSS2 spec section 9.5.1, see the rule list).
|
|
|
|
NS_ASSERTION((NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) ||
|
|
|
|
(NS_STYLE_FLOAT_RIGHT == floaterDisplay->mFloats),
|
|
|
|
"invalid float type");
|
|
|
|
|
|
|
|
// While there is not enough room for the floater, clear past
|
|
|
|
// other floaters until there is room (or the band is not impacted
|
|
|
|
// by a floater).
|
1998-12-08 21:43:15 +00:00
|
|
|
while ((mAvailSpaceRect.width < region.width) &&
|
|
|
|
(mAvailSpaceRect.width < mContentArea.width)) {
|
1998-12-05 16:02:08 +00:00
|
|
|
// The CSS2 spec says that floaters should be placed as high as
|
|
|
|
// possible. We accomodate this easily by noting that if the band
|
|
|
|
// is not the full width of the content area then it must have
|
|
|
|
// been impacted by a floater. And we know that the height of the
|
|
|
|
// band will be the height of the shortest floater, therefore we
|
|
|
|
// adjust mY by that distance and keep trying until we have enough
|
|
|
|
// space for this floater.
|
|
|
|
#ifdef NOISY_FLOATER_CLEARING
|
|
|
|
mBlock->ListTag(stdout);
|
|
|
|
printf(": clearing floater during floater placement: ");
|
|
|
|
printf("availWidth=%d regionWidth=%d,%d(w/o margins) contentWidth=%d\n",
|
1998-12-08 21:43:15 +00:00
|
|
|
mAvailSpaceRect.width, region.width,
|
1998-12-05 16:02:08 +00:00
|
|
|
region.width - floaterMargin.left - floaterMargin.right,
|
|
|
|
mContentArea.width);
|
|
|
|
#endif
|
1998-12-08 21:43:15 +00:00
|
|
|
mY += mAvailSpaceRect.height;
|
1998-12-05 16:02:08 +00:00
|
|
|
GetAvailableSpace();
|
|
|
|
}
|
1998-11-14 21:01:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Assign an x and y coordinate to the floater. Note that the x,y
|
|
|
|
// coordinates are computed <b>relative to the translation in the
|
|
|
|
// spacemanager</b> which means that the impacted region will be
|
|
|
|
// <b>inside</b> the border/padding area.
|
|
|
|
if (NS_STYLE_FLOAT_LEFT == floaterDisplay->mFloats) {
|
|
|
|
aIsLeftFloater = PR_TRUE;
|
1998-12-08 21:43:15 +00:00
|
|
|
region.x = mAvailSpaceRect.x;
|
1998-06-27 22:56:09 +00:00
|
|
|
}
|
|
|
|
else {
|
1998-12-05 16:02:08 +00:00
|
|
|
aIsLeftFloater = PR_FALSE;
|
1998-12-08 21:43:15 +00:00
|
|
|
region.x = mAvailSpaceRect.XMost() - region.width;
|
1998-12-08 03:57:12 +00:00
|
|
|
|
|
|
|
// In case the floater is too big, don't go past the left edge
|
1998-12-08 21:43:15 +00:00
|
|
|
if (region.x < mAvailSpaceRect.x) {
|
|
|
|
region.x = mAvailSpaceRect.x;
|
1998-12-08 03:57:12 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& borderPadding = BorderPadding();
|
|
|
|
region.y = mY - borderPadding.top;
|
1998-12-05 16:02:08 +00:00
|
|
|
if (region.y < 0) {
|
|
|
|
// CSS2 spec, 9.5.1 rule [4]: A floating box's outer top may not
|
|
|
|
// be higher than the top of its containing block.
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX It's not clear if it means the higher than the outer edge
|
|
|
|
// or the border edge or the inner edge?
|
|
|
|
region.y = 0;
|
1998-06-27 22:56:09 +00:00
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Place the floater in the space manager
|
|
|
|
mSpaceManager->AddRectRegion(floater, region);
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Set the origin of the floater frame, in frame coordinates. These
|
|
|
|
// coordinates are <b>not</b> relative to the spacemanager
|
|
|
|
// translation, therefore we have to factor in our border/padding.
|
1999-03-05 04:21:32 +00:00
|
|
|
floater->MoveTo(borderPadding.left + floaterMargin.left + region.x,
|
|
|
|
borderPadding.top + floaterMargin.top + region.y);
|
1998-12-12 19:19:11 +00:00
|
|
|
|
|
|
|
// Now restore mY
|
|
|
|
mY = saveY;
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsRect r;
|
|
|
|
floater->GetRect(r);
|
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("placed floater: ");
|
|
|
|
((nsFrame*)floater)->ListTag(stdout);
|
|
|
|
printf(" %d,%d,%d,%d\n", r.x, r.y, r.width, r.height);
|
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
#endif
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
/**
|
|
|
|
* Place below-current-line floaters.
|
|
|
|
*/
|
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockReflowState::PlaceBelowCurrentLineFloaters(nsVoidArray* aFloaters)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFloaters->Count() > 0, "no floaters");
|
1998-11-05 19:33:01 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRInt32 numFloaters = aFloaters->Count();
|
|
|
|
for (PRInt32 i = 0; i < numFloaters; i++) {
|
|
|
|
nsPlaceholderFrame* placeholderFrame = (nsPlaceholderFrame*)
|
|
|
|
aFloaters->ElementAt(i);
|
1999-02-09 17:31:33 +00:00
|
|
|
if (!IsLeftMostChild(placeholderFrame)) {
|
|
|
|
PRBool isLeftFloater;
|
|
|
|
PlaceFloater(placeholderFrame, isLeftFloater);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Place current-line floaters.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsBlockReflowState::PlaceCurrentLineFloaters(nsVoidArray* aFloaters)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aFloaters->Count() > 0, "no floaters");
|
|
|
|
|
|
|
|
PRInt32 numFloaters = aFloaters->Count();
|
|
|
|
for (PRInt32 i = 0; i < numFloaters; i++) {
|
|
|
|
nsPlaceholderFrame* placeholderFrame = (nsPlaceholderFrame*)
|
|
|
|
aFloaters->ElementAt(i);
|
|
|
|
if (IsLeftMostChild(placeholderFrame)) {
|
|
|
|
PRBool isLeftFloater;
|
|
|
|
PlaceFloater(placeholderFrame, isLeftFloater);
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
|
|
|
nsBlockReflowState::ClearFloaters(nscoord aY, PRUint8 aBreakType)
|
1998-10-27 16:51:02 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
|
|
|
printf("clear floaters: in: mY=%d aY=%d(%d)\n",
|
1999-03-05 04:21:32 +00:00
|
|
|
mY, aY, aY - BorderPadding().top);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
1998-10-27 16:51:02 +00:00
|
|
|
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& bp = BorderPadding();
|
|
|
|
nscoord newY = mCurrentBand.ClearFloaters(aY - bp.top, aBreakType);
|
|
|
|
mY = newY + bp.top;
|
1998-12-05 16:02:08 +00:00
|
|
|
GetAvailableSpace();
|
1998-09-23 02:25:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_INCREMENTAL_REFLOW
|
1999-03-05 04:21:32 +00:00
|
|
|
if (mReflowState.reason == eReflowReason_Incremental) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsFrame::IndentBy(stdout, gNoiseIndent);
|
1999-03-05 04:21:32 +00:00
|
|
|
printf("clear floaters: out: mY=%d(%d)\n", mY, mY - bp.top);
|
1998-10-27 16:51:02 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
1998-10-27 16:51:02 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Painting, event handling
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRIntn
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::GetSkipSides() const
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
PRIntn skip = 0;
|
|
|
|
if (nsnull != mPrevInFlow) {
|
|
|
|
skip |= 1 << NS_SIDE_TOP;
|
1998-09-29 22:32:56 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != mNextInFlow) {
|
|
|
|
skip |= 1 << NS_SIDE_BOTTOM;
|
1998-11-11 03:55:55 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return skip;
|
|
|
|
}
|
1998-09-29 22:32:56 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::Paint(nsIPresContext& aPresContext,
|
1998-12-15 00:14:09 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
const nsStyleDisplay* disp = (const nsStyleDisplay*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Display);
|
1998-09-23 02:25:26 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Only paint the border and background if we're visible
|
1999-02-09 17:31:33 +00:00
|
|
|
if (disp->mVisible && (eFramePaintLayer_Underlay == aWhichLayer)) {
|
1998-12-05 16:02:08 +00:00
|
|
|
PRIntn skipSides = GetSkipSides();
|
|
|
|
const nsStyleColor* color = (const nsStyleColor*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Color);
|
|
|
|
const nsStyleSpacing* spacing = (const nsStyleSpacing*)
|
|
|
|
mStyleContext->GetStyleData(eStyleStruct_Spacing);
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Paint background and border
|
|
|
|
nsRect rect(0, 0, mRect.width, mRect.height);
|
|
|
|
nsCSSRendering::PaintBackground(aPresContext, aRenderingContext, this,
|
1999-01-15 18:25:58 +00:00
|
|
|
aDirtyRect, rect, *color, *spacing, 0, 0);
|
1998-12-05 16:02:08 +00:00
|
|
|
nsCSSRendering::PaintBorder(aPresContext, aRenderingContext, this,
|
1999-02-09 17:31:33 +00:00
|
|
|
aDirtyRect, rect, *spacing, mStyleContext,
|
|
|
|
skipSides);
|
1998-10-30 22:10:10 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00: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) {
|
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.PushState();
|
|
|
|
aRenderingContext.SetClipRect(nsRect(0, 0, mRect.width, mRect.height),
|
|
|
|
nsClipCombine_kIntersect, clipState);
|
1998-10-02 21:50:53 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Child elements have the opportunity to override the visibility
|
|
|
|
// property and display even if the parent is hidden
|
1998-12-18 15:54:23 +00:00
|
|
|
PaintFloaters(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
|
|
|
PaintChildren(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer);
|
1998-10-02 21:50:53 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_STYLE_OVERFLOW_HIDDEN == disp->mOverflow) {
|
|
|
|
PRBool clipState;
|
|
|
|
aRenderingContext.PopState(clipState);
|
1998-07-09 17:06:35 +00:00
|
|
|
}
|
1998-12-18 15:54:23 +00:00
|
|
|
|
|
|
|
if (eFramePaintLayer_Overlay == aWhichLayer) {
|
|
|
|
// XXX CSS2's outline handling goes here
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-07-09 17:06:35 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PaintFloaters(nsIPresContext& aPresContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
for (nsLineBox* line = mLines; nsnull != line; line = line->mNext) {
|
|
|
|
nsVoidArray* floaters = line->mFloaters;
|
|
|
|
if (nsnull == floaters) {
|
|
|
|
continue;
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
PRInt32 i, n = floaters->Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) floaters->ElementAt(i);
|
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect,
|
1998-12-18 15:54:23 +00:00
|
|
|
ph->GetAnchoredItem(), aWhichLayer);
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-25 16:33:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::PaintChildren(nsIPresContext& aPresContext,
|
1998-12-18 15:54:23 +00:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
nsFramePaintLayer aWhichLayer)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
for (nsLineBox* line = mLines; nsnull != line; line = line->mNext) {
|
|
|
|
// If the line has outside children or if the line intersects the
|
|
|
|
// dirty rect then paint the children in the line.
|
1998-12-15 00:14:09 +00:00
|
|
|
if (!((line->mCombinedArea.YMost() <= aDirtyRect.y) ||
|
|
|
|
(line->mCombinedArea.y >= aDirtyRect.YMost()))) {
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* kid = line->mFirstChild;
|
|
|
|
PRInt32 n = line->ChildCount();
|
|
|
|
while (--n >= 0) {
|
1998-12-18 15:54:23 +00:00
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect, kid,
|
|
|
|
aWhichLayer);
|
1999-02-10 06:13:38 +00:00
|
|
|
kid->GetNextSibling(&kid);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
|
|
|
|
if (eFramePaintLayer_Content == aWhichLayer) {
|
1999-02-18 22:22:55 +00:00
|
|
|
if ((nsnull != mBullet) && HaveOutsideBullet()) {
|
1999-02-09 17:31:33 +00:00
|
|
|
// Paint outside bullets manually
|
1999-02-18 22:22:55 +00:00
|
|
|
PaintChild(aPresContext, aRenderingContext, aDirtyRect, mBullet,
|
|
|
|
aWhichLayer);
|
1999-02-09 17:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::GetFrameForPoint(const nsPoint& aPoint, nsIFrame** aFrame)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
nsresult rv = GetFrameForPointUsing(aPoint, nsnull, aFrame);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
return NS_OK;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
if (nsnull != mBullet) {
|
|
|
|
rv = GetFrameForPointUsing(aPoint, nsLayoutAtoms::bulletList, aFrame);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mFloaters.NotEmpty()) {
|
|
|
|
rv = GetFrameForPointUsing(aPoint, nsLayoutAtoms::floaterList, aFrame);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
*aFrame = this;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Debugging
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
static PRBool
|
|
|
|
InLineList(nsLineBox* aLines, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
while (nsnull != aLines) {
|
|
|
|
nsIFrame* frame = aLines->mFirstChild;
|
|
|
|
PRInt32 n = aLines->ChildCount();
|
|
|
|
while (--n >= 0) {
|
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
1998-11-05 19:33:01 +00:00
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-07-16 23:30:49 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
aLines = aLines->mNext;
|
1998-07-16 23:30:49 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return PR_FALSE;
|
1998-06-18 16:25:41 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
static PRBool
|
|
|
|
InSiblingList(nsLineBox* aLine, nsIFrame* aFrame)
|
1998-11-12 18:19:22 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
if (nsnull != aLine) {
|
|
|
|
nsIFrame* frame = aLine->mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
return PR_FALSE;
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
PRBool
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::IsChild(nsIFrame* aFrame)
|
1998-11-12 18:19:22 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
aFrame->GetParent(&parent);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (parent != (nsIFrame*)this) {
|
|
|
|
return PR_FALSE;
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
if (InLineList(mLines, aFrame) && InSiblingList(mLines, aFrame)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
if (InLineList(mOverflowLines, aFrame) &&
|
|
|
|
InSiblingList(mOverflowLines, aFrame)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
1998-11-12 18:19:22 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
#endif
|
1998-11-12 18:19:22 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::VerifyTree() const
|
1998-07-18 21:45:17 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX rewrite this
|
1998-07-18 21:45:17 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
//----------------------------------------------------------------------
|
1998-07-18 21:45:17 +00:00
|
|
|
|
1999-02-25 05:31:15 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBlockFrame::Init(nsIPresContext& aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aContext,
|
|
|
|
nsIFrame* aPrevInFlow)
|
|
|
|
{
|
|
|
|
if (aPrevInFlow) {
|
|
|
|
// Copy over the block/area frame flags
|
|
|
|
nsBlockFrame* blockFrame = (nsBlockFrame*)aPrevInFlow;
|
|
|
|
|
|
|
|
SetFlags(blockFrame->mFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsBlockFrameSuper::Init(aPresContext, aContent, aParent,
|
|
|
|
aContext, aPrevInFlow);
|
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
NS_IMETHODIMP
|
1999-02-09 17:31:33 +00:00
|
|
|
nsBlockFrame::SetInitialChildList(nsIPresContext& aPresContext,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aChildList)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
1999-02-26 17:04:44 +00:00
|
|
|
nsresult rv = NS_OK;
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
if (nsLayoutAtoms::floaterList == aListName) {
|
|
|
|
mFloaters.SetFrames(aChildList);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = AppendNewFrames(aPresContext, aChildList);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
// Create list bullet if this is a list-item. Note that this is done
|
|
|
|
// here so that RenumberLists will work (it needs the bullets to
|
|
|
|
// store the bullet numbers).
|
|
|
|
const nsStyleDisplay* styleDisplay;
|
|
|
|
GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) styleDisplay);
|
|
|
|
if ((nsnull == mPrevInFlow) &&
|
|
|
|
(NS_STYLE_DISPLAY_LIST_ITEM == styleDisplay->mDisplay) &&
|
|
|
|
(nsnull == mBullet)) {
|
|
|
|
// Resolve style for the bullet frame
|
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
aPresContext.ResolvePseudoStyleContextFor(mContent,
|
|
|
|
nsHTMLAtoms::mozListBulletPseudo,
|
|
|
|
mStyleContext, PR_FALSE, &kidSC);
|
|
|
|
|
|
|
|
// Create bullet frame
|
|
|
|
mBullet = new nsBulletFrame;
|
|
|
|
if (nsnull == mBullet) {
|
|
|
|
NS_RELEASE(kidSC);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mBullet->Init(aPresContext, mContent, this, kidSC, nsnull);
|
1999-02-09 17:31:33 +00:00
|
|
|
NS_RELEASE(kidSC);
|
1998-07-02 00:04:12 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
// If the list bullet frame should be positioned inside then add
|
|
|
|
// it to the flow now.
|
|
|
|
const nsStyleList* styleList;
|
|
|
|
GetStyleData(eStyleStruct_List, (const nsStyleStruct*&) styleList);
|
|
|
|
if (NS_STYLE_LIST_STYLE_POSITION_INSIDE == styleList->mListStylePosition) {
|
|
|
|
InsertNewFrames(aPresContext, mBullet, nsnull);
|
|
|
|
mState &= ~NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mState |= NS_BLOCK_FRAME_HAS_OUTSIDE_BULLET;
|
|
|
|
}
|
1998-07-02 00:04:12 +00:00
|
|
|
}
|
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
// Lookup up the two pseudo style contexts
|
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
aPresContext.
|
|
|
|
ProbePseudoStyleContextFor(mContent, nsHTMLAtoms::firstLinePseudo,
|
|
|
|
mStyleContext, PR_FALSE, &mFirstLineStyle);
|
|
|
|
aPresContext.
|
|
|
|
ProbePseudoStyleContextFor(mContent, nsHTMLAtoms::firstLetterPseudo,
|
|
|
|
(nsnull != mFirstLineStyle
|
|
|
|
? mFirstLineStyle
|
|
|
|
: mStyleContext),
|
|
|
|
PR_FALSE, &mFirstLetterStyle);
|
1998-12-05 16:02:08 +00:00
|
|
|
#ifdef NOISY_FIRST_LETTER
|
1999-02-26 17:04:44 +00:00
|
|
|
if (nsnull != mFirstLetterStyle) {
|
|
|
|
printf("block(%d)@%p: first-letter style found\n",
|
|
|
|
ContentIndexInContainer(this), this);
|
|
|
|
}
|
1999-02-09 17:31:33 +00:00
|
|
|
#endif
|
1999-02-26 17:04:44 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
return NS_OK;
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-23 19:18:12 +00:00
|
|
|
nsBlockFrame::RenumberLists()
|
1998-06-24 17:52:42 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Setup initial list ordinal value
|
|
|
|
PRInt32 ordinal = 1;
|
|
|
|
nsIHTMLContent* hc;
|
|
|
|
if (mContent && (NS_OK == mContent->QueryInterface(kIHTMLContentIID, (void**) &hc))) {
|
|
|
|
nsHTMLValue value;
|
|
|
|
if (NS_CONTENT_ATTR_HAS_VALUE ==
|
1998-12-20 01:21:23 +00:00
|
|
|
hc->GetHTMLAttribute(nsHTMLAtoms::start, value)) {
|
1998-12-05 16:02:08 +00:00
|
|
|
if (eHTMLUnit_Integer == value.GetUnit()) {
|
|
|
|
ordinal = value.GetIntValue();
|
|
|
|
if (ordinal <= 0) {
|
|
|
|
ordinal = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_RELEASE(hc);
|
|
|
|
}
|
1998-10-09 22:58:25 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Get to first-in-flow
|
|
|
|
nsBlockFrame* block = this;
|
|
|
|
while (nsnull != block->mPrevInFlow) {
|
|
|
|
block = (nsBlockFrame*) block->mPrevInFlow;
|
|
|
|
}
|
1998-10-16 20:22:39 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// For each flow-block...
|
|
|
|
while (nsnull != block) {
|
|
|
|
// For each frame in the flow-block...
|
|
|
|
nsIFrame* frame = block->mLines ? block->mLines->mFirstChild : nsnull;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
// If the frame is a list-item and the frame implements our
|
|
|
|
// block frame API then get it's bullet and set the list item
|
|
|
|
// ordinal.
|
1998-06-24 17:52:42 +00:00
|
|
|
const nsStyleDisplay* display;
|
1998-12-05 16:02:08 +00:00
|
|
|
frame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
if (NS_STYLE_DISPLAY_LIST_ITEM == display->mDisplay) {
|
|
|
|
// Make certain that the frame isa block-frame in case
|
|
|
|
// something foriegn has crept in.
|
|
|
|
nsBlockFrame* listItem;
|
|
|
|
if (NS_OK == frame->QueryInterface(kBlockFrameCID,
|
|
|
|
(void**) &listItem)) {
|
|
|
|
if (nsnull != listItem->mBullet) {
|
1999-02-23 19:18:12 +00:00
|
|
|
ordinal =
|
|
|
|
listItem->mBullet->SetListItemOrdinal(ordinal);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-06-24 17:52:42 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
block = (nsBlockFrame*) block->mNextInFlow;
|
|
|
|
}
|
|
|
|
}
|
1998-10-16 20:22:39 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
1999-02-18 22:22:55 +00:00
|
|
|
nsBlockFrame::ReflowBullet(nsBlockReflowState& aState,
|
|
|
|
nsHTMLReflowMetrics& aMetrics)
|
1998-06-18 16:25:41 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Reflow the bullet now
|
|
|
|
nsSize availSize;
|
|
|
|
availSize.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
availSize.height = NS_UNCONSTRAINEDSIZE;
|
1999-03-05 04:21:32 +00:00
|
|
|
nsHTMLReflowState reflowState(aState.mPresContext, aState.mReflowState,
|
|
|
|
mBullet, availSize);
|
|
|
|
reflowState.lineLayout = aState.mLineLayout;
|
1998-12-05 16:02:08 +00:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsresult rv = mBullet->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsReflowStatus status;
|
|
|
|
htmlReflow->WillReflow(aState.mPresContext);
|
1999-02-18 22:22:55 +00:00
|
|
|
htmlReflow->Reflow(aState.mPresContext, aMetrics, reflowState, status);
|
1998-12-05 16:02:08 +00:00
|
|
|
htmlReflow->DidReflow(aState.mPresContext, NS_FRAME_REFLOW_FINISHED);
|
|
|
|
}
|
1998-11-19 03:52:29 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Place the bullet now; use its right margin to distance it
|
|
|
|
// from the rest of the frames in the line
|
1999-03-05 04:21:32 +00:00
|
|
|
const nsMargin& bp = aState.BorderPadding();
|
|
|
|
nscoord x = bp.left - reflowState.computedMargin.right - aMetrics.width;
|
1999-02-18 22:22:55 +00:00
|
|
|
|
|
|
|
// Approximate the bullets position; vertical alignment will provide
|
|
|
|
// the final vertical location.
|
1999-03-05 04:21:32 +00:00
|
|
|
nscoord y = bp.top;
|
1999-02-18 22:22:55 +00:00
|
|
|
mBullet->SetRect(nsRect(x, y, aMetrics.width, aMetrics.height));
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-07-22 05:02:07 +00:00
|
|
|
|
1999-02-26 17:04:44 +00:00
|
|
|
//XXX get rid of this -- its slow
|
1998-12-05 16:02:08 +00:00
|
|
|
void
|
|
|
|
nsBlockFrame::BuildFloaterList()
|
|
|
|
{
|
|
|
|
nsIFrame* head = nsnull;
|
|
|
|
nsIFrame* current = nsnull;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (nsnull != line->mFloaters) {
|
|
|
|
nsVoidArray& array = *line->mFloaters;
|
|
|
|
PRInt32 i, n = array.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsPlaceholderFrame* ph = (nsPlaceholderFrame*) array[i];
|
|
|
|
nsIFrame* floater = ph->GetAnchoredItem();
|
|
|
|
if (nsnull == head) {
|
|
|
|
current = head = floater;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
current->SetNextSibling(floater);
|
|
|
|
current = floater;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line = line->mNext;
|
1998-11-19 03:52:29 +00:00
|
|
|
}
|
1998-06-24 17:52:42 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Terminate end of floater list just in case a floater was removed
|
|
|
|
if (nsnull != current) {
|
|
|
|
current->SetNextSibling(nsnull);
|
1998-11-19 03:52:29 +00:00
|
|
|
}
|
1999-01-15 22:53:39 +00:00
|
|
|
mFloaters.SetFrames(head);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// XXX keep the text-run data in the first-in-flow of the block
|
1999-02-26 17:04:44 +00:00
|
|
|
|
|
|
|
// XXX Switch to an interface to pass to child frames -or- do the
|
|
|
|
// grovelling directly ourselves?
|
1998-12-05 16:02:08 +00:00
|
|
|
nsresult
|
1999-02-26 17:04:44 +00:00
|
|
|
nsBlockFrame::ComputeTextRuns(nsIPresContext& aPresContext)
|
1998-12-05 16:02:08 +00:00
|
|
|
{
|
|
|
|
// Destroy old run information first
|
|
|
|
nsTextRun::DeleteTextRuns(mTextRuns);
|
|
|
|
mTextRuns = nsnull;
|
1999-02-26 17:04:44 +00:00
|
|
|
|
|
|
|
nsLineLayout textRunThingy(aPresContext, nsnull);
|
1998-10-30 22:10:10 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Ask each child that implements nsIInlineReflow to find its text runs
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
while (nsnull != line) {
|
|
|
|
if (!line->IsBlock()) {
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
PRInt32 n = line->ChildCount();
|
|
|
|
while (--n >= 0) {
|
|
|
|
nsIHTMLReflow* hr;
|
|
|
|
if (NS_OK == frame->QueryInterface(kIHTMLReflowIID, (void**)&hr)) {
|
1999-02-26 17:04:44 +00:00
|
|
|
nsresult rv = hr->FindTextRuns(textRunThingy);
|
1998-12-05 16:02:08 +00:00
|
|
|
if (NS_OK != rv) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// A frame that doesn't implement nsIHTMLReflow isn't text
|
|
|
|
// therefore it will end an open text run.
|
1999-02-26 17:04:44 +00:00
|
|
|
textRunThingy.EndTextRun();
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// A frame that doesn't implement nsIInlineReflow isn't text
|
|
|
|
// therefore it will end an open text run.
|
1999-02-26 17:04:44 +00:00
|
|
|
textRunThingy.EndTextRun();
|
1998-12-05 16:02:08 +00:00
|
|
|
}
|
|
|
|
line = line->mNext;
|
1998-06-19 18:23:28 +00:00
|
|
|
}
|
1999-02-26 17:04:44 +00:00
|
|
|
textRunThingy.EndTextRun();
|
1998-12-05 16:02:08 +00:00
|
|
|
|
|
|
|
// Now take the text-runs away from the line layout engine.
|
1999-02-26 17:04:44 +00:00
|
|
|
mTextRuns = textRunThingy.TakeTextRuns();
|
1998-06-24 17:52:42 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-06-19 18:23:28 +00:00
|
|
|
|
1998-09-23 02:25:26 +00:00
|
|
|
void
|
1998-12-05 16:02:08 +00:00
|
|
|
nsBlockFrame::TakeRunInFrames(nsBlockFrame* aRunInFrame)
|
1998-09-23 02:25:26 +00:00
|
|
|
{
|
1998-12-05 16:02:08 +00:00
|
|
|
// Simply steal the run-in-frame's line list and make it our
|
|
|
|
// own. XXX Very similar to the logic in DrainOverflowLines...
|
|
|
|
nsLineBox* line = aRunInFrame->mLines;
|
1998-10-06 00:38:56 +00:00
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Make all the frames on the mOverflowLines list mine
|
|
|
|
nsIFrame* lastFrame = nsnull;
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
1999-01-14 05:16:23 +00:00
|
|
|
frame->SetParent(this);
|
1998-12-05 16:02:08 +00:00
|
|
|
lastFrame = frame;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1998-09-23 02:25:26 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
// Join the line lists
|
|
|
|
if (nsnull == mLines) {
|
|
|
|
mLines = line;
|
1998-11-19 18:09:57 +00:00
|
|
|
}
|
1998-12-05 16:02:08 +00:00
|
|
|
else {
|
|
|
|
// Join the sibling lists together
|
|
|
|
lastFrame->SetNextSibling(mLines->mFirstChild);
|
|
|
|
|
|
|
|
// Place overflow lines at the front of our line list
|
|
|
|
nsLineBox* lastLine = nsLineBox::LastLine(line);
|
|
|
|
lastLine->mNext = mLines;
|
|
|
|
mLines = line;
|
1998-11-19 18:09:57 +00:00
|
|
|
}
|
|
|
|
|
1998-12-05 16:02:08 +00:00
|
|
|
aRunInFrame->mLines = nsnull;
|
|
|
|
}
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-02-01 17:29:37 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewAnonymousBlockFrame(nsIFrame*& aNewFrame)
|
|
|
|
{
|
|
|
|
nsBlockFrame* it = new nsAnonymousBlockFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aNewFrame = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAnonymousBlockFrame::nsAnonymousBlockFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAnonymousBlockFrame::~nsAnonymousBlockFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnonymousBlockFrame::AppendFrames(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
return mParent->AppendFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnonymousBlockFrame::InsertFrames(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
return mParent->InsertFrames(aPresContext, aPresShell, aListName,
|
|
|
|
aPrevFrame, aFrameList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsAnonymousBlockFrame::RemoveFrame(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
|
|
|
return mParent->RemoveFrame(aPresContext, aPresShell, aListName,
|
|
|
|
aOldFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAnonymousBlockFrame::AppendFrames2(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-02-02 17:31:09 +00:00
|
|
|
return nsAnonymousBlockFrameSuper::AppendFrames(aPresContext, aPresShell,
|
|
|
|
aListName, aFrameList);
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAnonymousBlockFrame::InsertFrames2(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aPrevFrame,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
1999-02-02 17:31:09 +00:00
|
|
|
return nsAnonymousBlockFrameSuper::InsertFrames(aPresContext, aPresShell,
|
|
|
|
aListName, aPrevFrame,
|
|
|
|
aFrameList);
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsAnonymousBlockFrame::RemoveFrame2(nsIPresContext& aPresContext,
|
|
|
|
nsIPresShell& aPresShell,
|
|
|
|
nsIAtom* aListName,
|
|
|
|
nsIFrame* aOldFrame)
|
|
|
|
{
|
1999-02-02 17:31:09 +00:00
|
|
|
return nsAnonymousBlockFrameSuper::RemoveFrame(aPresContext, aPresShell,
|
|
|
|
aListName, aOldFrame);
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-02-02 17:31:09 +00:00
|
|
|
nsAnonymousBlockFrame::RemoveFirstFrame()
|
1999-02-01 17:29:37 +00:00
|
|
|
{
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
if (nsnull != line) {
|
|
|
|
nsIFrame* firstChild = line->mFirstChild;
|
|
|
|
|
|
|
|
// If the line has floaters on it, see if the frame being removed
|
|
|
|
// is a placeholder frame. If it is, then remove it from the lines
|
|
|
|
// floater array and from the block frames floater child list.
|
|
|
|
if (nsnull != line->mFloaters) {
|
|
|
|
// XXX UNTESTED!
|
|
|
|
nsPlaceholderFrame* placeholderFrame;
|
|
|
|
nsVoidArray& floaters = *line->mFloaters;
|
|
|
|
PRInt32 i, n = floaters.Count();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
placeholderFrame = (nsPlaceholderFrame*) floaters[i];
|
|
|
|
if (firstChild == placeholderFrame) {
|
|
|
|
// Remove placeholder from the line's floater array
|
|
|
|
floaters.RemoveElementAt(i);
|
1999-02-01 19:08:30 +00:00
|
|
|
if (0 == floaters.Count()) {
|
1999-02-01 17:29:37 +00:00
|
|
|
delete line->mFloaters;
|
|
|
|
line->mFloaters = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the floater from the block frames mFloaters list too
|
|
|
|
mFloaters.RemoveFrame(placeholderFrame->GetAnchoredItem());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (1 == line->mChildCount) {
|
|
|
|
// Remove line when last frame goes away
|
|
|
|
mLines = line->mNext;
|
|
|
|
delete line;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Remove frame from line and mark the line dirty
|
|
|
|
--line->mChildCount;
|
|
|
|
line->MarkDirty();
|
1999-02-10 06:13:38 +00:00
|
|
|
firstChild->GetNextSibling(&line->mFirstChild);
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Break linkage to next child after stolen frame
|
|
|
|
firstChild->SetNextSibling(nsnull);
|
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-02-01 17:29:37 +00:00
|
|
|
}
|
1999-02-02 17:31:09 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsAnonymousBlockFrame::RemoveFramesFrom(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
if (nsnull != line) {
|
|
|
|
// Chop the child sibling list into two pieces
|
|
|
|
nsFrameList tmp(line->mFirstChild);
|
|
|
|
nsIFrame* prevSibling = tmp.GetPrevSiblingFor(aFrame);
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
// Chop the sibling list into two pieces
|
|
|
|
prevSibling->SetNextSibling(nsnull);
|
|
|
|
|
|
|
|
nsLineBox* prevLine = nsnull;
|
|
|
|
while (nsnull != line) {
|
|
|
|
nsIFrame* frame = line->mFirstChild;
|
|
|
|
PRInt32 i, n = line->mChildCount;
|
|
|
|
PRBool done = PR_FALSE;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
if (frame == aFrame) {
|
|
|
|
// We just found the target frame (and the line its in and
|
|
|
|
// the previous line)
|
|
|
|
if (frame == line->mFirstChild) {
|
|
|
|
// No more children on this line, so let it get removed
|
|
|
|
prevLine->mNext = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The only frames that remain on this line are the
|
|
|
|
// frames preceeding aFrame. Adjust the count to
|
|
|
|
// indicate that fact.
|
|
|
|
line->mChildCount = i;
|
|
|
|
|
|
|
|
// Remove the lines that follow this line
|
|
|
|
prevLine = line;
|
|
|
|
line = line->mNext;
|
|
|
|
prevLine->mNext = nsnull;
|
|
|
|
}
|
|
|
|
done = PR_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-02 17:31:09 +00:00
|
|
|
}
|
|
|
|
if (done) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevLine = line;
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all of the remaining lines
|
|
|
|
while (nsnull != line) {
|
|
|
|
nsLineBox* next = line->mNext;
|
|
|
|
delete line;
|
|
|
|
line = next;
|
|
|
|
}
|
|
|
|
}
|
1999-03-16 19:36:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
VerifyFrameCount(mLines);
|
|
|
|
#endif
|
1999-02-02 17:31:09 +00:00
|
|
|
}
|
1999-02-12 17:45:58 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
nscoord
|
|
|
|
nsBlockFrame::ComputeCollapsedTopMargin(const nsHTMLReflowState& aReflowState)
|
|
|
|
{
|
|
|
|
nscoord myTopMargin = aReflowState.computedMargin.top;
|
|
|
|
nsLineBox* line = mLines;
|
|
|
|
if (nsnull != line) {
|
|
|
|
if (line->IsEmptyLine()) {
|
|
|
|
line = line->mNext;
|
|
|
|
if (nsnull == line) {
|
|
|
|
return myTopMargin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (1 == line->ChildCount()) {
|
|
|
|
nsHTMLReflowState rs();
|
|
|
|
nscoord topMargin = line->mFirstChild->ComputeCollapsedTopMargin(rs);
|
|
|
|
return nsBlockReflowContext::MaxMargin(topMargin, myTopMargin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return myTopMargin;
|
|
|
|
}
|
|
|
|
#endif
|
1999-03-16 19:36:00 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsBlockFrame::VerifyFrameCount(nsLineBox* line)
|
|
|
|
{
|
|
|
|
if (line) {
|
|
|
|
// First add up the counts on each line
|
|
|
|
nsLineBox* line0 = line;
|
|
|
|
PRInt32 count = 0;
|
|
|
|
while (nsnull != line) {
|
|
|
|
count += line->mChildCount;
|
|
|
|
line = line->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then count the frames
|
|
|
|
PRInt32 frameCount = 0;
|
|
|
|
nsIFrame* frame = line0->mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frameCount++;
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(count == frameCount, "bad line list");
|
|
|
|
|
|
|
|
// Next: test that each line has right number of frames on it
|
|
|
|
line = line0;
|
|
|
|
nsLineBox* prevLine = nsnull;
|
|
|
|
while (nsnull != line) {
|
|
|
|
count = line->mChildCount;
|
|
|
|
frame = line->mFirstChild;
|
|
|
|
while (--count >= 0) {
|
|
|
|
frame->GetNextSibling(&frame);
|
|
|
|
}
|
|
|
|
prevLine = line;
|
|
|
|
line = line->mNext;
|
|
|
|
if ((nsnull != line) && (0 != line->mChildCount)) {
|
|
|
|
NS_ASSERTION(frame == line->mFirstChild, "bad line list");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Its possible that a frame can have some frames on an overflow
|
|
|
|
// list. But its never possible for multiple frames to have overflow
|
|
|
|
// lists. Check that this fact is actually true.
|
|
|
|
void
|
|
|
|
nsBlockFrame::VerifyOverflowSituation()
|
|
|
|
{
|
|
|
|
PRBool haveOverflow = PR_FALSE;
|
|
|
|
nsBlockFrame* flow = (nsBlockFrame*) GetFirstInFlow();
|
|
|
|
while (nsnull != flow) {
|
|
|
|
if (nsnull != flow->mOverflowLines) {
|
|
|
|
NS_ASSERTION(nsnull != flow->mOverflowLines->mFirstChild,
|
|
|
|
"bad overflow list");
|
|
|
|
NS_ASSERTION(!haveOverflow, "two frames with overflow lists");
|
|
|
|
haveOverflow = PR_TRUE;
|
|
|
|
}
|
|
|
|
flow = (nsBlockFrame*) flow->mNextInFlow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|