gecko-dev/layout/generic/nsLineLayout.h
1998-04-30 23:32:32 +00:00

202 lines
5.5 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsLineLayout_h___
#define nsLineLayout_h___
#include "nsIFrame.h"
#include "nsCoord.h"
#include "nsSize.h"
class nsIPresContext;
class nsBlockFrame;
struct nsBlockReflowState;
/**
* Persistent per-line data
*/
struct nsLineData {
nsLineData();
~nsLineData();
nsIFrame* GetLastChild();
nsresult Verify() const;
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
void UnlinkLine();
PRIntn GetLineNumber() const;
nsLineData* mNextLine;
nsLineData* mPrevLine;
nsIFrame* mFirstChild;
PRInt32 mChildCount;
PRInt32 mFirstContentOffset;
PRInt32 mLastContentOffset;
nsRect mBounds;
PRPackedBool mLastContentIsComplete;
};
//----------------------------------------------------------------------
/**
* Transient state used during line reflow.
*/
struct nsLineLayoutReflowData {
nscoord mX;
nscoord mAvailWidth;
nsSize mMaxElementSize;
nscoord mMaxAscent;
nscoord mMaxDescent;
};
struct nsLineLayout {
nsLineLayout();
~nsLineLayout();
nsresult Initialize(nsBlockReflowState& aState,
nsLineData* aLine,
const nsRect& aAvailSpace);
/**
* <h2>Rules of order</h2>
*
* Lines are disassociated from the block frame's state
* (mLastContentIsComplete, mLastContentOffset, mChildCount). Upon
* completion of this routine the block frame is responsible for
* updating it's own state.<p>
*
* ReflowLine can return the following status:
*
* <dl>
* <dt>NS_LINE_LAYOUT_BREAK_BEFORE</dt>
*
* <dd>mKidFrame and mKidIndex indicate the child to break
* before. Note that we will always have a child frame created which
* means we must not lose it!</dd>
*
* <dt>NS_LINE_LAYOUT_OK</dt>
*
* <dd>This means that the line should be flushed out as is</dd>
*
* </dl>
*/
nsresult ReflowLine();
// The presentation context
nsIPresContext* mPresContext;
// The block behind the line
nsBlockFrame* mBlock;
PRBool mBlockIsPseudo;
nsIContent* mBlockContent;
PRInt32 mKidIndex;
// The line we are reflowing
nsLineData* mLine;
nsIFrame* mKidPrevInFlow;
// Whenever the line layout creates a frame this slot is incremented
PRInt32 mNewFrames;
// Current reflow data indicating where we are in the line, how much
// width remains and the maximum element size so far.
nsLineLayoutReflowData mReflowData;
PRPackedBool mUnconstrainedWidth;
PRPackedBool mUnconstrainedHeight;
nscoord mY;
nscoord mLineHeight;
nscoord mAvailHeight;
nsSize* mMaxElementSizePointer;
nscoord mX0;
nscoord* mAscents;
nscoord mAscentBuf[20];
nscoord mMaxAscents;
// The current type of reflow in progress. Normally, this value is
// set to NS_LINE_LAYOUT_NORMAL_REFLOW. However, in the special case
// of needing to chop off some frames because of a soft-line-break
// that was triggered by a word-wrap, the value will be set to
// NS_LINE_LAYOUT_WORD_WRAP_REFLOW. nsInlineFrame's and text know
// about this flag and respond to it appropriately.
PRInt32 mReflowType;
// A value set by line-layout cognizant frames. Frames that are not
// aware of line layout leave the value unchanged and can thus be
// detected by the line-layout algorithm.
PRInt32 mReflowResult;
// The current child frame being reflowed
nsIFrame* mKidFrame;
// The previous child frame that was just reflowed
nsIFrame* mPrevKidFrame;
// When a span of text ends in non-whitespace then we need to track
// the start of the word in case we need to word break at that word.
// Note that mWordStart may not be a direct child; instead it may be
// several levels down in inline frames. It may or may not be the
// first child of a contained inline.
nsIFrame* mWordStart;
nsIFrame* mWordStartParent;
PRInt32 mWordStartOffset;
nsLineLayoutReflowData mWordStartReflowData;
PRBool mSkipLeadingWhiteSpace;
protected:
nsresult WordBreakReflow();
nsresult ReflowChild();
nsresult ReflowMapped();
nsresult SplitLine(PRInt32 aChildReflowStatus, PRInt32 aRemainingKids);
nsresult PushChildren();
nsresult CreateNextInFlow(nsIFrame* aFrame);
nsresult PullUpChildren();
nsresult CreateFrameFor(nsIContent* aKid);
nsresult ReflowUnmapped();
nsresult AlignChildren();
nsIFrame* GetWordStartParent();
};
// Value's for nsLineLayout.mReflowType
#define NS_LINE_LAYOUT_REFLOW_TYPE_NORMAL 0
#define NS_LINE_LAYOUT_REFLOW_TYPE_WORD_WRAP 1
// Value's for nsLineLayout.mReflowResult
#define NS_LINE_LAYOUT_REFLOW_RESULT_NOT_AWARE 0
// Return value's from nsLineLayout reflow methods
#define NS_LINE_LAYOUT_COMPLETE 0
#define NS_LINE_LAYOUT_NOT_COMPLETE 1
#define NS_LINE_LAYOUT_BREAK_BEFORE 2
#define NS_LINE_LAYOUT_BREAK_AFTER 3
#define NS_LINE_LAYOUT_PSEUDO_BREAK_BEFORE_BLOCK 4
#endif /* nsLineLayout_h___ */