1998-06-18 20:25:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "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-09-15 04:19:49 +04:00
|
|
|
#ifndef nsLineLayout_h___
|
|
|
|
#define nsLineLayout_h___
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsFrame.h"
|
1998-06-18 20:25:41 +04:00
|
|
|
#include "nsVoidArray.h"
|
1998-10-20 04:22:48 +04:00
|
|
|
#include "nsTextReflow.h"
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
class nsISpaceManager;
|
1998-12-05 19:05:52 +03:00
|
|
|
class nsBlockReflowState;
|
1998-08-05 01:17:56 +04:00
|
|
|
class nsPlaceholderFrame;
|
1999-03-19 00:03:25 +03:00
|
|
|
struct nsStyleText;
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
// If your machine has a limited size stack, you'll want to adjust
|
|
|
|
// these numbers. Note that it will force the line layout code to use
|
|
|
|
// the heap more so layout will be slower!
|
|
|
|
#if defined(XP_MAC)
|
|
|
|
#define NS_LINELAYOUT_NUM_FRAMES 15
|
|
|
|
#define NS_LINELAYOUT_NUM_SPANS 5
|
|
|
|
#else
|
|
|
|
#define NS_LINELAYOUT_NUM_FRAMES 50
|
|
|
|
#define NS_LINELAYOUT_NUM_SPANS 20
|
|
|
|
#endif
|
|
|
|
|
1998-09-15 04:19:49 +04:00
|
|
|
class nsLineLayout {
|
1998-06-18 20:25:41 +04:00
|
|
|
public:
|
1998-09-23 06:31:00 +04:00
|
|
|
nsLineLayout(nsIPresContext& aPresContext,
|
1999-03-19 00:03:25 +03:00
|
|
|
nsISpaceManager* aSpaceManager,
|
|
|
|
const nsHTMLReflowState* aOuterReflowState,
|
|
|
|
PRBool aComputeMaxElementSize);
|
|
|
|
nsLineLayout(nsIPresContext& aPresContext);
|
1998-09-15 04:19:49 +04:00
|
|
|
~nsLineLayout();
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void Init(nsBlockReflowState* aState) {
|
|
|
|
mBlockRS = aState;
|
1998-08-05 01:17:56 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRInt32 GetColumn() {
|
|
|
|
return mColumn;
|
1999-02-18 06:28:00 +03:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void SetColumn(PRInt32 aNewColumn) {
|
|
|
|
mColumn = aNewColumn;
|
1998-09-23 06:31:00 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void AdvanceToNextLine() {
|
|
|
|
mLineNumber++;
|
1998-09-23 06:31:00 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
PRInt32 GetLineNumber() const {
|
|
|
|
return mLineNumber;
|
1998-09-23 06:31:00 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void BeginLineReflow(nscoord aX, nscoord aY,
|
|
|
|
nscoord aWidth, nscoord aHeight,
|
1999-03-21 04:14:05 +03:00
|
|
|
PRBool aImpactedByFloaters,
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool aIsTopOfPage);
|
1998-10-27 19:52:10 +03:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void EndLineReflow();
|
1998-09-30 02:32:04 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void UpdateBand(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
|
|
|
PRBool aPlacedLeftFloater);
|
1998-09-30 02:32:04 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult BeginSpan(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowState* aSpanReflowState,
|
|
|
|
nscoord aLeftEdge,
|
|
|
|
nscoord aRightEdge);
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void EndSpan(nsIFrame* aFrame, nsSize& aSizeResult,
|
|
|
|
nsSize* aMaxElementSize);
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRInt32 GetCurrentSpanCount() const;
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void SplitLineTo(PRInt32 aNewCount);
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool IsZeroHeight();
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult ReflowFrame(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNextRCFrame,
|
|
|
|
nsReflowStatus& aReflowStatus);
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord GetCarriedOutBottomMargin() const {
|
1999-03-25 06:49:47 +03:00
|
|
|
return mCarriedOutBottomMargin;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult AddBulletFrame(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aMetrics);
|
1998-10-20 04:22:48 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void RemoveBulletFrame(nsIFrame* aFrame) {
|
|
|
|
PushFrame(aFrame);
|
1998-10-10 08:35:01 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void VerticalAlignFrames(nsRect& aLineBoxResult,
|
|
|
|
nsSize& aMaxElementSizeResult);
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void TrimTrailingWhiteSpace(nsRect& aLineBounds);
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void HorizontalAlignFrames(nsRect& aLineBounds, PRBool aAllowJustify);
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void RelativePositionFrames(nsRect& aCombinedArea);
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
//----------------------------------------
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Support methods for white-space compression and word-wrapping
|
|
|
|
// during line reflow
|
|
|
|
|
|
|
|
void SetEndsInWhiteSpace(PRBool aState) {
|
|
|
|
mEndsInWhiteSpace = aState;
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool GetEndsInWhiteSpace() const {
|
|
|
|
return mEndsInWhiteSpace;
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void SetUnderstandsWhiteSpace(PRBool aSetting) {
|
|
|
|
mUnderstandsWhiteSpace = aSetting;
|
1998-06-25 20:33:10 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
void RecordWordFrame(nsIFrame* aWordFrame) {
|
|
|
|
mWordFrames.AppendElement(aWordFrame);
|
1998-10-17 05:06:17 +04:00
|
|
|
}
|
1998-06-25 20:33:10 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool InWord() const {
|
|
|
|
return 0 != mWordFrames.Count();
|
|
|
|
}
|
1998-07-22 22:38:57 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void ForgetWordFrame(nsIFrame* aFrame);
|
1999-02-01 20:32:33 +03:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void ForgetWordFrames() {
|
|
|
|
mWordFrames.Clear();
|
|
|
|
}
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsIFrame* FindNextText(nsIFrame* aFrame);
|
1998-11-10 21:04:19 +03:00
|
|
|
|
1999-03-24 18:41:17 +03:00
|
|
|
PRBool CanPlaceFloaterNow() const;
|
1998-10-10 08:35:01 +04:00
|
|
|
|
1999-03-24 18:41:17 +03:00
|
|
|
PRBool LineIsEmpty() const;
|
|
|
|
|
|
|
|
PRBool LineIsBreakable() const;
|
1999-03-21 04:14:05 +03:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
//----------------------------------------
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Inform the line-layout engine about the presence of a BR frame
|
|
|
|
// XXX get rid of this: use get-frame-type?
|
|
|
|
void SetBRFrame(nsIFrame* aFrame) {
|
|
|
|
mBRFrame = aFrame;
|
1998-11-01 01:48:56 +03:00
|
|
|
}
|
1998-06-18 20:25:41 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Return the line's BR frame if any
|
|
|
|
nsIFrame* GetBRFrame() const {
|
|
|
|
return mBRFrame;
|
1998-11-01 01:48:56 +03:00
|
|
|
}
|
1998-06-25 20:33:10 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
//----------------------------------------
|
|
|
|
// Inform the line-layout about the presence of a floating frame
|
|
|
|
// XXX get rid of this: use get-frame-type?
|
|
|
|
void InitFloater(nsPlaceholderFrame* aFrame);
|
|
|
|
void AddFloater(nsPlaceholderFrame* aFrame);
|
1998-06-25 20:33:10 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
//----------------------------------------
|
1998-06-28 02:56:09 +04:00
|
|
|
|
1998-11-05 22:30:31 +03:00
|
|
|
PRBool GetFirstLetterStyleOK() const {
|
|
|
|
return mFirstLetterStyleOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFirstLetterStyleOK(PRBool aSetting) {
|
|
|
|
mFirstLetterStyleOK = aSetting;
|
|
|
|
}
|
|
|
|
|
1999-03-26 03:41:36 +03:00
|
|
|
void SetFirstLetterFrame(nsIFrame* aFrame) {
|
|
|
|
mFirstLetterFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
//----------------------------------------
|
|
|
|
// Text run usage methods. These methods are using during reflow to
|
|
|
|
// track the current text run and to advance through text runs.
|
|
|
|
|
|
|
|
void SetReflowTextRuns(nsTextRun* aTextRuns) {
|
|
|
|
mReflowTextRuns = aTextRuns;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
static PRBool TreatFrameAsBlock(nsIFrame* aFrame);
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
// XXX Move this out of line-layout; make some little interface to
|
|
|
|
// deal with it...
|
|
|
|
|
|
|
|
// Add another piece of text to a text-run during FindTextRuns.
|
|
|
|
// Note: continuation frames must NOT add themselves; just the
|
|
|
|
// first-in-flow
|
|
|
|
nsresult AddText(nsIFrame* aTextFrame);
|
|
|
|
|
|
|
|
// Close out a text-run during FindTextRuns.
|
|
|
|
void EndTextRun();
|
|
|
|
|
|
|
|
// This returns the first nsTextRun found during a FindTextRuns. The
|
|
|
|
// internal text-run state is reset.
|
|
|
|
nsTextRun* TakeTextRuns();
|
|
|
|
|
|
|
|
nsIPresContext& mPresContext;
|
|
|
|
|
1998-06-28 02:56:09 +04:00
|
|
|
protected:
|
1999-03-19 00:03:25 +03:00
|
|
|
// This state is constant for a given block frame doing line layout
|
|
|
|
nsISpaceManager* mSpaceManager;
|
|
|
|
const nsStyleText* mStyleText;
|
|
|
|
const nsHTMLReflowState* mBlockReflowState;
|
|
|
|
nsBlockReflowState* mBlockRS;/* XXX hack! */
|
|
|
|
nscoord mMinLineHeight;
|
|
|
|
PRBool mComputeMaxElementSize;
|
|
|
|
PRUint8 mTextAlign;
|
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
// This state varies during the reflow of a line but is line
|
|
|
|
// "global" state not span "local" state.
|
1998-09-30 02:32:04 +04:00
|
|
|
nsIFrame* mBRFrame;
|
1999-03-26 03:41:36 +03:00
|
|
|
nsIFrame* mFirstLetterFrame;
|
1999-03-19 00:03:25 +03:00
|
|
|
PRInt32 mLineNumber;
|
|
|
|
PRInt32 mColumn;
|
1998-11-01 01:48:56 +03:00
|
|
|
PRBool mEndsInWhiteSpace;
|
|
|
|
PRBool mUnderstandsWhiteSpace;
|
1998-11-05 22:30:31 +03:00
|
|
|
PRBool mFirstLetterStyleOK;
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool mIsTopOfPage;
|
|
|
|
PRBool mUpdatedBand;
|
1999-03-21 04:14:05 +03:00
|
|
|
PRBool mImpactedByFloaters;
|
1999-03-24 18:41:17 +03:00
|
|
|
PRBool mCanPlaceFloater;
|
1999-03-19 00:03:25 +03:00
|
|
|
PRUint8 mPlacedFloaters;
|
1998-09-23 06:31:00 +04:00
|
|
|
PRInt32 mTotalPlacedFrames;
|
1998-10-10 08:35:01 +04:00
|
|
|
nsVoidArray mWordFrames;
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord mTopEdge;
|
|
|
|
nscoord mBottomEdge;
|
|
|
|
nscoord mMaxTopBoxHeight;
|
|
|
|
nscoord mMaxBottomBoxHeight;
|
1999-03-25 06:49:47 +03:00
|
|
|
nscoord mCarriedOutBottomMargin;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
nsTextRun* mReflowTextRuns;
|
|
|
|
nsTextRun* mTextRun;
|
1998-10-10 02:58:25 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Per-frame data recorded by the line-layout reflow logic. This
|
|
|
|
// state is the state needed to post-process the line after reflow
|
|
|
|
// has completed (vertical alignment, horizontal alignment,
|
|
|
|
// justification and relative positioning).
|
|
|
|
struct PerSpanData;
|
|
|
|
struct PerFrameData {
|
|
|
|
// link to next/prev frame in same span
|
|
|
|
PerFrameData* mNext;
|
|
|
|
PerFrameData* mPrev;
|
|
|
|
|
|
|
|
// pointer to child span data if this is an inline container frame
|
|
|
|
PerSpanData* mSpan;
|
|
|
|
|
|
|
|
// The frame and its type
|
|
|
|
nsIFrame* mFrame;
|
|
|
|
nsCSSFrameType mFrameType;
|
|
|
|
|
|
|
|
// From metrics
|
|
|
|
nscoord mAscent, mDescent;
|
|
|
|
nsRect mBounds;
|
|
|
|
nsSize mMaxElementSize;
|
|
|
|
nsRect mCombinedArea;
|
|
|
|
|
|
|
|
// From reflow-state
|
|
|
|
nsMargin mMargin;
|
|
|
|
nsMargin mBorderPadding;
|
|
|
|
nsMargin mOffsets;
|
|
|
|
PRBool mRelativePos;
|
|
|
|
|
|
|
|
// Other state we use
|
|
|
|
PRUint8 mVerticalAlign;
|
|
|
|
};
|
1999-03-30 03:46:34 +04:00
|
|
|
PerFrameData mFrameDataBuf[NS_LINELAYOUT_NUM_FRAMES];
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* mFrameFreeList;
|
1999-03-30 03:46:34 +04:00
|
|
|
PRInt32 mInitialFramesFreed;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
struct PerSpanData {
|
1999-03-30 03:46:34 +04:00
|
|
|
union {
|
|
|
|
PerSpanData* mParent;
|
|
|
|
PerSpanData* mNextFreeSpan;
|
|
|
|
};
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* mFrame;
|
|
|
|
PerFrameData* mFirstFrame;
|
|
|
|
PerFrameData* mLastFrame;
|
|
|
|
|
|
|
|
const nsHTMLReflowState* mReflowState;
|
1999-03-22 23:45:09 +03:00
|
|
|
PRBool mNoWrap;
|
|
|
|
PRUint8 mDirection;
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord mLeftEdge;
|
|
|
|
nscoord mX;
|
|
|
|
nscoord mRightEdge;
|
|
|
|
|
|
|
|
nscoord mTopLeading, mBottomLeading;
|
|
|
|
nscoord mLogicalHeight;
|
|
|
|
nscoord mMinY, mMaxY;
|
|
|
|
|
|
|
|
void AppendFrame(PerFrameData* pfd) {
|
|
|
|
if (nsnull == mLastFrame) {
|
|
|
|
mFirstFrame = pfd;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLastFrame->mNext = pfd;
|
|
|
|
pfd->mPrev = mLastFrame;
|
|
|
|
}
|
|
|
|
mLastFrame = pfd;
|
|
|
|
}
|
|
|
|
};
|
1999-03-30 03:46:34 +04:00
|
|
|
PerSpanData mSpanDataBuf[NS_LINELAYOUT_NUM_SPANS];
|
1999-03-19 00:03:25 +03:00
|
|
|
PerSpanData* mSpanFreeList;
|
1999-03-30 03:46:34 +04:00
|
|
|
PRInt32 mInitialSpansFreed;
|
1999-03-19 00:03:25 +03:00
|
|
|
PerSpanData* mRootSpan;
|
|
|
|
PerSpanData* mCurrentSpan;
|
|
|
|
PRInt32 mSpanDepth;
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRInt32 mSpansAllocated, mSpansFreed;
|
|
|
|
PRInt32 mFramesAllocated, mFramesFreed;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// XXX These slots are used ONLY during FindTextRuns
|
1998-09-15 04:19:49 +04:00
|
|
|
nsTextRun* mTextRuns;
|
|
|
|
nsTextRun** mTextRunP;
|
|
|
|
nsTextRun* mNewTextRun;
|
1998-06-28 02:56:09 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult NewPerFrameData(PerFrameData** aResult);
|
|
|
|
|
|
|
|
nsresult NewPerSpanData(PerSpanData** aResult);
|
|
|
|
|
|
|
|
void FreeSpan(PerSpanData* psd);
|
|
|
|
|
|
|
|
PRBool InBlockContext() const {
|
|
|
|
return mSpanDepth == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushFrame(nsIFrame* aFrame);
|
|
|
|
|
|
|
|
void ApplyLeftMargin(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowState& aReflowState);
|
|
|
|
|
|
|
|
PRBool CanPlaceFrame(PerFrameData* pfd,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
1999-03-22 23:45:09 +03:00
|
|
|
PRBool aNotSafeToBreak,
|
1999-03-19 00:03:25 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
nsReflowStatus& aStatus);
|
|
|
|
|
|
|
|
void PlaceFrame(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowMetrics& aMetrics);
|
|
|
|
|
|
|
|
void UpdateFrames();
|
|
|
|
|
|
|
|
void VerticalAlignFrames(PerSpanData* psd);
|
|
|
|
|
|
|
|
void PlaceTopBottomFrames(PerSpanData* psd,
|
|
|
|
nscoord aDistanceFromTop,
|
|
|
|
nscoord aLineHeight);
|
|
|
|
|
|
|
|
void RelativePositionFrames(PerSpanData* psd, nsRect& aCombinedArea);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void DumpPerSpanData(PerSpanData* psd, PRInt32 aIndent);
|
|
|
|
#endif
|
1998-06-18 20:25:41 +04:00
|
|
|
};
|
|
|
|
|
1998-09-15 04:19:49 +04:00
|
|
|
#endif /* nsLineLayout_h___ */
|