1998-06-18 16:25:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2001-10-25 01:08:40 +00:00
|
|
|
* vim:cindent:ts=2:et:sw=2:
|
1998-06-18 16:25:41 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-18 16:25:41 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
1998-06-18 16:25:41 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* Contributor(s):
|
2000-04-17 14:40:46 +00:00
|
|
|
* Steve Clark <buster@netscape.com>
|
2004-04-18 14:30:37 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK *****
|
2000-05-02 23:07:11 +00:00
|
|
|
* This Original Code has been modified by IBM Corporation. Modifications made by IBM
|
|
|
|
* described herein are Copyright (c) International Business Machines Corporation, 2000.
|
|
|
|
* Modifications to Mozilla code or documentation identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
|
1998-06-18 16:25:41 +00:00
|
|
|
*/
|
2006-03-29 18:29:03 +00:00
|
|
|
|
|
|
|
/* state and methods used while laying out a single line of a block frame */
|
|
|
|
|
1998-09-15 00:19:49 +00:00
|
|
|
#ifndef nsLineLayout_h___
|
|
|
|
#define nsLineLayout_h___
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
#include "nsFrame.h"
|
2002-03-19 21:57:45 +00:00
|
|
|
#include "nsDeque.h"
|
2000-02-15 04:26:44 +00:00
|
|
|
#include "nsLineBox.h"
|
2001-05-01 04:22:57 +00:00
|
|
|
#include "nsBlockReflowState.h"
|
2004-07-15 17:50:34 +00:00
|
|
|
#include "plarena.h"
|
2008-07-24 07:16:18 +00:00
|
|
|
#include "gfxTypes.h"
|
1998-06-18 16:25:41 +00:00
|
|
|
|
2006-10-19 01:47:47 +00:00
|
|
|
class nsBlockFrame;
|
|
|
|
|
2009-01-05 00:39:54 +00:00
|
|
|
class nsFloatManager;
|
1998-08-04 21:17:56 +00:00
|
|
|
class nsPlaceholderFrame;
|
1999-03-18 21:03:25 +00:00
|
|
|
struct nsStyleText;
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1998-09-15 00:19:49 +00:00
|
|
|
class nsLineLayout {
|
1998-06-18 16:25:41 +00:00
|
|
|
public:
|
2004-07-31 23:15:21 +00:00
|
|
|
nsLineLayout(nsPresContext* aPresContext,
|
2009-01-05 00:39:54 +00:00
|
|
|
nsFloatManager* aFloatManager,
|
2007-01-18 01:20:09 +00:00
|
|
|
const nsHTMLReflowState* aOuterReflowState,
|
|
|
|
const nsLineList::iterator* aLine);
|
1998-09-15 00:19:49 +00:00
|
|
|
~nsLineLayout();
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-08-27 21:49:12 +00:00
|
|
|
void Init(nsBlockReflowState* aState, nscoord aMinLineHeight,
|
|
|
|
PRInt32 aLineNumber) {
|
1999-03-18 21:03:25 +00:00
|
|
|
mBlockRS = aState;
|
1999-08-27 21:49:12 +00:00
|
|
|
mMinLineHeight = aMinLineHeight;
|
|
|
|
mLineNumber = aLineNumber;
|
1998-08-04 21:17:56 +00:00
|
|
|
}
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
PRInt32 GetLineNumber() const {
|
|
|
|
return mLineNumber;
|
1998-09-23 02:31:00 +00:00
|
|
|
}
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
void BeginLineReflow(nscoord aX, nscoord aY,
|
|
|
|
nscoord aWidth, nscoord aHeight,
|
2003-10-13 21:51:02 +00:00
|
|
|
PRBool aImpactedByFloats,
|
1999-03-18 21:03:25 +00:00
|
|
|
PRBool aIsTopOfPage);
|
1998-10-27 16:52:10 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
void EndLineReflow();
|
1998-09-29 22:32:04 +00:00
|
|
|
|
2008-06-10 23:53:22 +00:00
|
|
|
/**
|
|
|
|
* Called when a float has been placed. This method updates the
|
|
|
|
* inline frame and span data to account for any change in positions
|
|
|
|
* due to available space for the line boxes changing.
|
|
|
|
* @param aX/aY/aWidth/aHeight are the new available
|
|
|
|
* space rectangle, relative to the containing block.
|
|
|
|
* @param aFloatFrame the float frame that was placed.
|
|
|
|
*/
|
|
|
|
void UpdateBand(const nsRect& aNewAvailableSpace,
|
2003-10-13 21:51:02 +00:00
|
|
|
nsIFrame* aFloatFrame);
|
1998-09-29 22:32:04 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
nsresult BeginSpan(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowState* aSpanReflowState,
|
|
|
|
nscoord aLeftEdge,
|
2011-08-03 18:30:58 +00:00
|
|
|
nscoord aRightEdge,
|
|
|
|
nscoord* aBaseline);
|
1998-10-09 22:58:25 +00:00
|
|
|
|
2007-12-12 21:51:18 +00:00
|
|
|
// Returns the width of the span
|
|
|
|
nscoord EndSpan(nsIFrame* aFrame);
|
1999-09-03 03:47:49 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
PRInt32 GetCurrentSpanCount() const;
|
1998-10-09 22:58:25 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
void SplitLineTo(PRInt32 aNewCount);
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
PRBool IsZeroHeight();
|
1998-06-18 16:25:41 +00:00
|
|
|
|
2000-01-03 04:32:13 +00:00
|
|
|
// Reflows the frame and returns the reflow status. aPushedFrame is PR_TRUE
|
|
|
|
// if the frame is pushed to the next line because it doesn't fit
|
1999-03-18 21:03:25 +00:00
|
|
|
nsresult ReflowFrame(nsIFrame* aFrame,
|
1999-10-29 14:33:26 +00:00
|
|
|
nsReflowStatus& aReflowStatus,
|
2000-01-03 04:32:13 +00:00
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
|
|
|
PRBool& aPushedFrame);
|
1998-06-18 16:25:41 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
nsresult AddBulletFrame(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aMetrics);
|
1998-10-20 00:22:48 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
void RemoveBulletFrame(nsIFrame* aFrame) {
|
|
|
|
PushFrame(aFrame);
|
1998-10-10 04:35:01 +00:00
|
|
|
}
|
|
|
|
|
2007-01-18 01:20:09 +00:00
|
|
|
void VerticalAlignLine();
|
1998-10-10 04:35:01 +00:00
|
|
|
|
1999-10-12 23:27:32 +00:00
|
|
|
PRBool TrimTrailingWhiteSpace();
|
1998-10-10 04:35:01 +00:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
void HorizontalAlignFrames(nsRect& aLineBounds, PRBool aAllowJustify);
|
1998-10-10 04:35:01 +00:00
|
|
|
|
2003-07-23 00:14:16 +00:00
|
|
|
/**
|
|
|
|
* Handle all the relative positioning in the line, compute the
|
|
|
|
* combined area (== overflow area) for the line, and handle view
|
2009-04-06 00:31:50 +00:00
|
|
|
* sizing/positioning and the setting of the overflow rect.
|
2003-07-23 00:14:16 +00:00
|
|
|
*/
|
2010-10-07 04:25:45 +00:00
|
|
|
void RelativePositionFrames(nsOverflowAreas& aOverflowAreas);
|
1998-10-10 04:35:01 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
//----------------------------------------
|
1998-10-10 04:35:01 +00:00
|
|
|
|
2000-04-17 14:40:46 +00:00
|
|
|
// Supporting methods and data for flags
|
|
|
|
protected:
|
|
|
|
#define LL_FIRSTLETTERSTYLEOK 0x00000008
|
|
|
|
#define LL_ISTOPOFPAGE 0x00000010
|
2003-10-13 21:51:02 +00:00
|
|
|
#define LL_IMPACTEDBYFLOATS 0x00000040
|
|
|
|
#define LL_LASTFLOATWASLETTERFRAME 0x00000080
|
2008-06-14 08:28:07 +00:00
|
|
|
#define LL_LINEISEMPTY 0x00000100
|
2002-06-25 21:16:17 +00:00
|
|
|
#define LL_LINEENDSINBR 0x00000200
|
2007-10-20 07:30:26 +00:00
|
|
|
#define LL_NEEDBACKUP 0x00000400
|
|
|
|
#define LL_INFIRSTLINE 0x00000800
|
|
|
|
#define LL_GOTLINEBOX 0x00001000
|
2009-01-05 00:36:56 +00:00
|
|
|
#define LL_INFIRSTLETTER 0x00002000
|
2009-08-11 02:48:42 +00:00
|
|
|
#define LL_HASBULLET 0x00004000
|
2009-10-27 01:43:56 +00:00
|
|
|
#define LL_DIRTYNEXTLINE 0x00008000
|
2010-03-10 00:14:14 +00:00
|
|
|
#define LL_LINEATSTART 0x00010000
|
|
|
|
#define LL_LASTFLAG LL_LINEATSTART
|
2000-04-17 14:40:46 +00:00
|
|
|
|
|
|
|
void SetFlag(PRUint32 aFlag, PRBool aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=LL_LASTFLAG, "bad flag");
|
|
|
|
NS_ASSERTION(aValue==PR_FALSE || aValue==PR_TRUE, "bad value");
|
|
|
|
if (aValue) { // set flag
|
|
|
|
mFlags |= aFlag;
|
|
|
|
}
|
|
|
|
else { // unset flag
|
|
|
|
mFlags &= ~aFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool GetFlag(PRUint32 aFlag) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=LL_LASTFLAG, "bad flag");
|
2007-10-10 00:00:05 +00:00
|
|
|
return !!(mFlags & aFlag);
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2007-10-02 02:36:26 +00:00
|
|
|
// Support methods for word-wrapping during line reflow
|
2000-04-17 14:40:46 +00:00
|
|
|
|
|
|
|
void SetTextJustificationWeights(PRInt32 aNumSpaces, PRInt32 aNumLetters) {
|
|
|
|
mTextJustificationNumSpaces = aNumSpaces;
|
|
|
|
mTextJustificationNumLetters = aNumLetters;
|
1998-06-25 16:33:10 +00:00
|
|
|
}
|
1999-03-18 21:03:25 +00:00
|
|
|
|
2008-06-14 08:28:07 +00:00
|
|
|
/**
|
|
|
|
* @return true if so far during reflow no non-empty content has been
|
2010-03-10 00:14:14 +00:00
|
|
|
* placed in the line (according to nsIFrame::IsEmpty())
|
2008-06-14 08:28:07 +00:00
|
|
|
*/
|
|
|
|
PRBool LineIsEmpty() const
|
|
|
|
{
|
|
|
|
return GetFlag(LL_LINEISEMPTY);
|
|
|
|
}
|
1998-10-10 04:35:01 +00:00
|
|
|
|
2010-03-10 00:14:14 +00:00
|
|
|
/**
|
|
|
|
* @return true if so far during reflow no non-empty leaf content
|
|
|
|
* (non-collapsed whitespace, replaced element, inline-block, etc) has been
|
|
|
|
* placed in the line
|
|
|
|
*/
|
|
|
|
PRBool LineAtStart() const
|
|
|
|
{
|
|
|
|
return GetFlag(LL_LINEATSTART);
|
|
|
|
}
|
|
|
|
|
1999-03-24 15:41:17 +00:00
|
|
|
PRBool LineIsBreakable() const;
|
1999-03-21 01:14:05 +00:00
|
|
|
|
2000-04-17 14:40:46 +00:00
|
|
|
PRBool GetLineEndsInBR() const
|
|
|
|
{
|
|
|
|
return GetFlag(LL_LINEENDSINBR);
|
|
|
|
}
|
1999-10-29 14:33:26 +00:00
|
|
|
|
2000-04-17 14:40:46 +00:00
|
|
|
void SetLineEndsInBR(PRBool aOn)
|
|
|
|
{
|
|
|
|
SetFlag(LL_LINEENDSINBR, aOn);
|
|
|
|
}
|
1999-10-29 14:33:26 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
//----------------------------------------
|
|
|
|
// Inform the line-layout about the presence of a floating frame
|
|
|
|
// XXX get rid of this: use get-frame-type?
|
2010-08-06 04:59:20 +00:00
|
|
|
PRBool AddFloat(nsIFrame* aFloat, nscoord aAvailableWidth)
|
2009-08-31 18:25:35 +00:00
|
|
|
{
|
2010-08-06 04:59:20 +00:00
|
|
|
return mBlockRS->AddFloat(this, aFloat, aAvailableWidth);
|
2001-05-01 04:22:57 +00:00
|
|
|
}
|
1998-06-25 16:33:10 +00:00
|
|
|
|
2007-10-20 07:30:26 +00:00
|
|
|
void SetTrimmableWidth(nscoord aTrimmableWidth) {
|
|
|
|
mTrimmableWidth = aTrimmableWidth;
|
2006-10-19 01:47:47 +00:00
|
|
|
}
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
//----------------------------------------
|
1998-06-27 22:56:09 +00:00
|
|
|
|
1998-11-05 19:30:31 +00:00
|
|
|
PRBool GetFirstLetterStyleOK() const {
|
2000-04-17 14:40:46 +00:00
|
|
|
return GetFlag(LL_FIRSTLETTERSTYLEOK);
|
1998-11-05 19:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetFirstLetterStyleOK(PRBool aSetting) {
|
2000-04-17 14:40:46 +00:00
|
|
|
SetFlag(LL_FIRSTLETTERSTYLEOK, aSetting);
|
1998-11-05 19:30:31 +00:00
|
|
|
}
|
|
|
|
|
2009-01-05 00:36:56 +00:00
|
|
|
PRBool GetInFirstLetter() const {
|
|
|
|
return GetFlag(LL_INFIRSTLETTER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetInFirstLetter(PRBool aSetting) {
|
|
|
|
SetFlag(LL_INFIRSTLETTER, aSetting);
|
|
|
|
}
|
|
|
|
|
2007-01-18 01:20:09 +00:00
|
|
|
PRBool GetInFirstLine() const {
|
|
|
|
return GetFlag(LL_INFIRSTLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetInFirstLine(PRBool aSetting) {
|
|
|
|
SetFlag(LL_INFIRSTLINE, aSetting);
|
|
|
|
}
|
|
|
|
|
2009-10-27 01:43:56 +00:00
|
|
|
// Calling this during block reflow ensures that the next line of inlines
|
|
|
|
// will be marked dirty, if there is one.
|
|
|
|
void SetDirtyNextLine() {
|
|
|
|
SetFlag(LL_DIRTYNEXTLINE, PR_TRUE);
|
|
|
|
}
|
|
|
|
PRBool GetDirtyNextLine() {
|
|
|
|
return GetFlag(LL_DIRTYNEXTLINE);
|
|
|
|
}
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
//----------------------------------------
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
nsPresContext* mPresContext;
|
1999-03-18 21:03:25 +00:00
|
|
|
|
2006-10-19 01:47:47 +00:00
|
|
|
/**
|
|
|
|
* Record where an optional break could have been placed. During line reflow,
|
|
|
|
* frames containing optional break points (e.g., whitespace in text frames)
|
|
|
|
* can call SetLastOptionalBreakPosition to record where a break could
|
2007-02-21 01:52:03 +00:00
|
|
|
* have been made, but wasn't because we decided to place more content on
|
|
|
|
* the line. For non-text frames, offset 0 means
|
2006-10-19 01:47:47 +00:00
|
|
|
* before the content, offset PR_INT32_MAX means after the content.
|
|
|
|
*
|
|
|
|
* Currently this is used to handle cases where a single word comprises
|
|
|
|
* multiple frames, and the first frame fits on the line but the whole word
|
|
|
|
* doesn't. We look back to the last optional break position and
|
|
|
|
* reflow the whole line again, forcing a break at that position. The last
|
|
|
|
* optional break position could be in a text frame or else after a frame
|
|
|
|
* that cannot be part of a text run, so those are the positions we record.
|
|
|
|
*
|
2007-02-21 01:52:03 +00:00
|
|
|
* @param aFits set to true if the break position is within the available width.
|
2006-10-19 01:47:47 +00:00
|
|
|
*
|
2008-07-24 07:16:18 +00:00
|
|
|
* @param aPriority the priority of the break opportunity. If we are
|
|
|
|
* prioritizing break opportunities, we will not set a break if we have
|
|
|
|
* already set a break with a higher priority. @see gfxBreakPriority.
|
|
|
|
*
|
2006-10-19 01:47:47 +00:00
|
|
|
* @return PR_TRUE if we are actually reflowing with forced break position and we
|
|
|
|
* should break here
|
|
|
|
*/
|
2007-02-21 01:52:03 +00:00
|
|
|
PRBool NotifyOptionalBreakPosition(nsIContent* aContent, PRInt32 aOffset,
|
2008-07-24 07:16:18 +00:00
|
|
|
PRBool aFits, gfxBreakPriority aPriority) {
|
2007-12-07 09:17:19 +00:00
|
|
|
NS_ASSERTION(!aFits || !GetFlag(LL_NEEDBACKUP),
|
|
|
|
"Shouldn't be updating the break position with a break that fits after we've already flagged an overrun");
|
2007-02-21 01:52:03 +00:00
|
|
|
// Remember the last break position that fits; if there was no break that fit,
|
|
|
|
// just remember the first break
|
2008-07-24 07:16:18 +00:00
|
|
|
if ((aFits && aPriority >= mLastOptionalBreakPriority) ||
|
|
|
|
!mLastOptionalBreakContent) {
|
2007-02-21 01:52:03 +00:00
|
|
|
mLastOptionalBreakContent = aContent;
|
|
|
|
mLastOptionalBreakContentOffset = aOffset;
|
2008-07-24 07:16:18 +00:00
|
|
|
mLastOptionalBreakPriority = aPriority;
|
2007-02-21 01:52:03 +00:00
|
|
|
}
|
2006-10-19 01:47:47 +00:00
|
|
|
return aContent && mForceBreakContent == aContent &&
|
|
|
|
mForceBreakContentOffset == aOffset;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Like NotifyOptionalBreakPosition, but here it's OK for LL_NEEDBACKUP
|
|
|
|
* to be set, because the caller is merely pruning some saved break position(s)
|
|
|
|
* that are actually not feasible.
|
|
|
|
*/
|
2008-07-24 07:16:18 +00:00
|
|
|
void RestoreSavedBreakPosition(nsIContent* aContent, PRInt32 aOffset,
|
|
|
|
gfxBreakPriority aPriority) {
|
2006-10-19 01:47:47 +00:00
|
|
|
mLastOptionalBreakContent = aContent;
|
|
|
|
mLastOptionalBreakContentOffset = aOffset;
|
2008-07-24 07:16:18 +00:00
|
|
|
mLastOptionalBreakPriority = aPriority;
|
2006-10-19 01:47:47 +00:00
|
|
|
}
|
2007-02-21 01:52:03 +00:00
|
|
|
/**
|
|
|
|
* Signal that no backing up will be required after all.
|
|
|
|
*/
|
2006-10-19 01:47:47 +00:00
|
|
|
void ClearOptionalBreakPosition() {
|
2007-02-21 01:52:03 +00:00
|
|
|
SetFlag(LL_NEEDBACKUP, PR_FALSE);
|
2006-10-19 01:47:47 +00:00
|
|
|
mLastOptionalBreakContent = nsnull;
|
|
|
|
mLastOptionalBreakContentOffset = -1;
|
2008-07-24 07:16:18 +00:00
|
|
|
mLastOptionalBreakPriority = eNoBreak;
|
2006-10-19 01:47:47 +00:00
|
|
|
}
|
|
|
|
// Retrieve last set optional break position. When this returns null, no
|
|
|
|
// optional break has been recorded (which means that the line can't break yet).
|
2008-07-24 07:16:18 +00:00
|
|
|
nsIContent* GetLastOptionalBreakPosition(PRInt32* aOffset,
|
|
|
|
gfxBreakPriority* aPriority) {
|
2006-10-19 01:47:47 +00:00
|
|
|
*aOffset = mLastOptionalBreakContentOffset;
|
2008-07-24 07:16:18 +00:00
|
|
|
*aPriority = mLastOptionalBreakPriority;
|
2006-10-19 01:47:47 +00:00
|
|
|
return mLastOptionalBreakContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether frames overflowed the available width and CanPlaceFrame
|
|
|
|
* requested backing up to a saved break position.
|
|
|
|
*/
|
|
|
|
PRBool NeedsBackup() { return GetFlag(LL_NEEDBACKUP); }
|
|
|
|
|
|
|
|
// Line layout may place too much content on a line, overflowing its available
|
|
|
|
// width. When that happens, if SetLastOptionalBreakPosition has been
|
|
|
|
// used to record an optional break that wasn't taken, we can reflow the line
|
|
|
|
// again and force the break to happen at that point (i.e., backtracking
|
|
|
|
// to the last choice point).
|
|
|
|
|
|
|
|
// Record that we want to break at the given content+offset (which
|
|
|
|
// should have been previously returned by GetLastOptionalBreakPosition
|
|
|
|
// from another nsLineLayout).
|
|
|
|
void ForceBreakAtPosition(nsIContent* aContent, PRInt32 aOffset) {
|
|
|
|
mForceBreakContent = aContent;
|
|
|
|
mForceBreakContentOffset = aOffset;
|
|
|
|
}
|
|
|
|
PRBool HaveForcedBreakPosition() { return mForceBreakContent != nsnull; }
|
|
|
|
PRInt32 GetForcedBreakPosition(nsIContent* aContent) {
|
|
|
|
return mForceBreakContent == aContent ? mForceBreakContentOffset : -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This can't be null. It usually returns a block frame but may return
|
|
|
|
* some other kind of frame when inline frames are reflowed in a non-block
|
2008-07-30 05:11:26 +00:00
|
|
|
* context (e.g. MathML or floating first-letter).
|
2006-10-19 01:47:47 +00:00
|
|
|
*/
|
2007-01-18 01:20:09 +00:00
|
|
|
nsIFrame* GetLineContainerFrame() const { return mBlockReflowState->frame; }
|
|
|
|
const nsLineList::iterator* GetLine() const {
|
|
|
|
return GetFlag(LL_GOTLINEBOX) ? &mLineBox : nsnull;
|
|
|
|
}
|
2010-08-06 04:59:20 +00:00
|
|
|
nsLineList::iterator* GetLine() {
|
|
|
|
return GetFlag(LL_GOTLINEBOX) ? &mLineBox : nsnull;
|
|
|
|
}
|
2007-05-21 03:44:26 +00:00
|
|
|
|
|
|
|
/**
|
2008-06-20 04:39:56 +00:00
|
|
|
* Returns the accumulated advance width of frames before the current frame
|
|
|
|
* on the line, plus the line container's left border+padding.
|
|
|
|
* This is always positive, the advance width is measured from
|
2007-05-21 03:44:26 +00:00
|
|
|
* the right edge for RTL blocks and from the left edge for LTR blocks.
|
2008-06-20 04:39:56 +00:00
|
|
|
* In other words, the current frame's distance from the line container's
|
|
|
|
* start content edge is:
|
|
|
|
* <code>GetCurrentFrameXDistanceFromBlock() - lineContainer->GetUsedBorderAndPadding().left</code>
|
|
|
|
* Note the use of <code>.left</code> for both LTR and RTL line containers.
|
2007-05-21 03:44:26 +00:00
|
|
|
*/
|
|
|
|
nscoord GetCurrentFrameXDistanceFromBlock();
|
2007-01-18 01:20:09 +00:00
|
|
|
|
1998-06-27 22:56:09 +00:00
|
|
|
protected:
|
1999-03-18 21:03:25 +00:00
|
|
|
// This state is constant for a given block frame doing line layout
|
2009-01-05 00:39:54 +00:00
|
|
|
nsFloatManager* mFloatManager;
|
2001-10-25 01:08:40 +00:00
|
|
|
const nsStyleText* mStyleText; // for the block
|
1999-03-18 21:03:25 +00:00
|
|
|
const nsHTMLReflowState* mBlockReflowState;
|
2002-09-24 22:13:20 +00:00
|
|
|
|
2006-10-19 01:47:47 +00:00
|
|
|
nsIContent* mLastOptionalBreakContent;
|
|
|
|
nsIContent* mForceBreakContent;
|
|
|
|
|
2002-09-24 22:13:20 +00:00
|
|
|
// XXX remove this when landing bug 154892 (splitting absolute positioned frames)
|
|
|
|
friend class nsInlineFrame;
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
nsBlockReflowState* mBlockRS;/* XXX hack! */
|
2000-04-17 14:40:46 +00:00
|
|
|
|
2007-01-18 01:20:09 +00:00
|
|
|
nsLineList::iterator mLineBox;
|
2000-04-17 14:40:46 +00:00
|
|
|
|
1999-03-18 21:03:25 +00: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).
|
1999-03-31 04:21:53 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
struct PerSpanData;
|
1999-04-12 20:12:15 +00:00
|
|
|
struct PerFrameData;
|
|
|
|
friend struct PerSpanData;
|
|
|
|
friend struct PerFrameData;
|
1999-03-18 21:03:25 +00:00
|
|
|
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;
|
|
|
|
|
2009-02-19 21:55:48 +00:00
|
|
|
// The frame
|
1999-03-18 21:03:25 +00:00
|
|
|
nsIFrame* mFrame;
|
|
|
|
|
|
|
|
// From metrics
|
2007-01-23 04:06:56 +00:00
|
|
|
nscoord mAscent;
|
1999-03-18 21:03:25 +00:00
|
|
|
nsRect mBounds;
|
2010-10-07 04:25:45 +00:00
|
|
|
nsOverflowAreas mOverflowAreas;
|
1999-03-18 21:03:25 +00:00
|
|
|
|
|
|
|
// From reflow-state
|
|
|
|
nsMargin mMargin;
|
|
|
|
nsMargin mBorderPadding;
|
|
|
|
nsMargin mOffsets;
|
|
|
|
|
2000-04-17 14:40:46 +00:00
|
|
|
// state for text justification
|
|
|
|
PRInt32 mJustificationNumSpaces;
|
|
|
|
PRInt32 mJustificationNumLetters;
|
2002-11-06 02:03:43 +00:00
|
|
|
|
|
|
|
// Other state we use
|
|
|
|
PRUint8 mVerticalAlign;
|
2000-04-17 14:40:46 +00:00
|
|
|
|
|
|
|
// PerFrameData flags
|
|
|
|
#define PFD_RELATIVEPOS 0x00000001
|
|
|
|
#define PFD_ISTEXTFRAME 0x00000002
|
|
|
|
#define PFD_ISNONEMPTYTEXTFRAME 0x00000004
|
|
|
|
#define PFD_ISNONWHITESPACETEXTFRAME 0x00000008
|
|
|
|
#define PFD_ISLETTERFRAME 0x00000010
|
2007-09-24 02:19:14 +00:00
|
|
|
#define PFD_RECOMPUTEOVERFLOW 0x00000020
|
2000-04-17 14:40:46 +00:00
|
|
|
#define PFD_ISBULLET 0x00000040
|
2006-04-21 01:31:35 +00:00
|
|
|
#define PFD_SKIPWHENTRIMMINGWHITESPACE 0x00000080
|
|
|
|
#define PFD_LASTFLAG PFD_SKIPWHENTRIMMINGWHITESPACE
|
2000-04-17 14:40:46 +00:00
|
|
|
|
2006-04-21 01:31:35 +00:00
|
|
|
PRUint8 mFlags;
|
2000-04-17 14:40:46 +00:00
|
|
|
|
|
|
|
void SetFlag(PRUint32 aFlag, PRBool aValue)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=PFD_LASTFLAG, "bad flag");
|
2006-04-21 01:31:35 +00:00
|
|
|
NS_ASSERTION(aFlag<=PR_UINT8_MAX, "bad flag");
|
2000-04-17 14:40:46 +00:00
|
|
|
NS_ASSERTION(aValue==PR_FALSE || aValue==PR_TRUE, "bad value");
|
|
|
|
if (aValue) { // set flag
|
|
|
|
mFlags |= aFlag;
|
|
|
|
}
|
|
|
|
else { // unset flag
|
|
|
|
mFlags &= ~aFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool GetFlag(PRUint32 aFlag) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFlag<=PFD_LASTFLAG, "bad flag");
|
2007-10-10 00:00:05 +00:00
|
|
|
return !!(mFlags & aFlag);
|
2000-04-17 14:40:46 +00:00
|
|
|
}
|
|
|
|
|
1999-09-21 00:14:22 +00:00
|
|
|
|
|
|
|
PerFrameData* Last() {
|
|
|
|
PerFrameData* pfd = this;
|
|
|
|
while (pfd->mNext) {
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
return pfd;
|
|
|
|
}
|
1999-03-18 21:03:25 +00:00
|
|
|
};
|
2002-08-14 13:00:16 +00:00
|
|
|
PerFrameData* mFrameFreeList;
|
1999-03-18 21:03:25 +00:00
|
|
|
|
|
|
|
struct PerSpanData {
|
2002-08-14 13:00:16 +00:00
|
|
|
union {
|
|
|
|
PerSpanData* mParent;
|
|
|
|
PerSpanData* mNextFreeSpan;
|
|
|
|
};
|
1999-03-18 21:03:25 +00:00
|
|
|
PerFrameData* mFrame;
|
|
|
|
PerFrameData* mFirstFrame;
|
|
|
|
PerFrameData* mLastFrame;
|
|
|
|
|
|
|
|
const nsHTMLReflowState* mReflowState;
|
2000-01-04 02:59:35 +00:00
|
|
|
PRPackedBool mNoWrap;
|
1999-03-22 20:45:09 +00:00
|
|
|
PRUint8 mDirection;
|
2000-01-04 02:59:35 +00:00
|
|
|
PRPackedBool mChangedFrameDirection;
|
|
|
|
PRPackedBool mZeroEffectiveSpanBox;
|
2003-10-13 21:51:02 +00:00
|
|
|
PRPackedBool mContainsFloat;
|
2008-02-14 09:08:33 +00:00
|
|
|
PRPackedBool mHasNonemptyContent;
|
1999-03-22 20:45:09 +00:00
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
nscoord mLeftEdge;
|
|
|
|
nscoord mX;
|
|
|
|
nscoord mRightEdge;
|
|
|
|
|
|
|
|
nscoord mTopLeading, mBottomLeading;
|
|
|
|
nscoord mLogicalHeight;
|
|
|
|
nscoord mMinY, mMaxY;
|
2011-08-03 18:30:58 +00:00
|
|
|
nscoord* mBaseline;
|
1999-03-18 21:03:25 +00:00
|
|
|
|
|
|
|
void AppendFrame(PerFrameData* pfd) {
|
|
|
|
if (nsnull == mLastFrame) {
|
|
|
|
mFirstFrame = pfd;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mLastFrame->mNext = pfd;
|
|
|
|
pfd->mPrev = mLastFrame;
|
|
|
|
}
|
|
|
|
mLastFrame = pfd;
|
|
|
|
}
|
|
|
|
};
|
2002-08-14 13:00:16 +00:00
|
|
|
PerSpanData* mSpanFreeList;
|
1999-03-18 21:03:25 +00:00
|
|
|
PerSpanData* mRootSpan;
|
|
|
|
PerSpanData* mCurrentSpan;
|
2009-05-12 08:53:06 +00:00
|
|
|
|
|
|
|
gfxBreakPriority mLastOptionalBreakPriority;
|
|
|
|
PRInt32 mLastOptionalBreakContentOffset;
|
|
|
|
PRInt32 mForceBreakContentOffset;
|
|
|
|
|
|
|
|
nscoord mMinLineHeight;
|
|
|
|
|
|
|
|
// The amount of text indent that we applied to this line, needed for
|
|
|
|
// max-element-size calculation.
|
|
|
|
nscoord mTextIndent;
|
|
|
|
|
|
|
|
// This state varies during the reflow of a line but is line
|
|
|
|
// "global" state not span "local" state.
|
|
|
|
PRInt32 mLineNumber;
|
|
|
|
PRInt32 mTextJustificationNumSpaces;
|
|
|
|
PRInt32 mTextJustificationNumLetters;
|
|
|
|
|
|
|
|
PRInt32 mTotalPlacedFrames;
|
|
|
|
|
|
|
|
nscoord mTopEdge;
|
|
|
|
nscoord mMaxTopBoxHeight;
|
|
|
|
nscoord mMaxBottomBoxHeight;
|
|
|
|
|
|
|
|
// Final computed line-height value after VerticalAlignFrames for
|
|
|
|
// the block has been called.
|
|
|
|
nscoord mFinalLineHeight;
|
|
|
|
|
|
|
|
// Amount of trimmable whitespace width for the trailing text frame, if any
|
|
|
|
nscoord mTrimmableWidth;
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
PRInt32 mSpanDepth;
|
2002-08-14 13:00:16 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
PRInt32 mSpansAllocated, mSpansFreed;
|
|
|
|
PRInt32 mFramesAllocated, mFramesFreed;
|
|
|
|
#endif
|
2009-05-12 08:53:06 +00:00
|
|
|
PLArenaPool mArena; // Per span and per frame data, 4 byte aligned
|
|
|
|
|
2010-03-10 00:14:14 +00:00
|
|
|
PRUint32 mFlags;
|
2009-05-12 08:53:06 +00:00
|
|
|
|
|
|
|
PRUint8 mTextAlign;
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
nsresult NewPerFrameData(PerFrameData** aResult);
|
|
|
|
|
|
|
|
nsresult NewPerSpanData(PerSpanData** aResult);
|
|
|
|
|
2002-08-14 13:00:16 +00:00
|
|
|
void FreeSpan(PerSpanData* psd);
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
PRBool InBlockContext() const {
|
|
|
|
return mSpanDepth == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PushFrame(nsIFrame* aFrame);
|
|
|
|
|
2002-01-30 23:28:56 +00:00
|
|
|
void ApplyStartMargin(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowState& aReflowState);
|
1999-03-18 21:03:25 +00:00
|
|
|
|
|
|
|
PRBool CanPlaceFrame(PerFrameData* pfd,
|
2010-08-25 18:54:47 +00:00
|
|
|
PRUint8 aFrameDirection,
|
1999-03-22 20:45:09 +00:00
|
|
|
PRBool aNotSafeToBreak,
|
2006-10-19 01:47:47 +00:00
|
|
|
PRBool aFrameCanContinueTextRun,
|
2007-05-21 03:44:26 +00:00
|
|
|
PRBool aCanRollBackBeforeFrame,
|
1999-03-18 21:03:25 +00:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
2007-12-07 09:17:19 +00:00
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
PRBool* aOptionalBreakAfterFits);
|
1999-03-18 21:03:25 +00:00
|
|
|
|
|
|
|
void PlaceFrame(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowMetrics& aMetrics);
|
|
|
|
|
|
|
|
void VerticalAlignFrames(PerSpanData* psd);
|
|
|
|
|
|
|
|
void PlaceTopBottomFrames(PerSpanData* psd,
|
|
|
|
nscoord aDistanceFromTop,
|
|
|
|
nscoord aLineHeight);
|
|
|
|
|
2010-10-07 04:25:45 +00:00
|
|
|
void RelativePositionFrames(PerSpanData* psd, nsOverflowAreas& aOverflowAreas);
|
1999-03-18 21:03:25 +00:00
|
|
|
|
1999-09-21 00:14:22 +00:00
|
|
|
PRBool TrimTrailingWhiteSpaceIn(PerSpanData* psd, nscoord* aDeltaWidth);
|
|
|
|
|
2000-04-17 14:40:46 +00:00
|
|
|
void ComputeJustificationWeights(PerSpanData* psd, PRInt32* numSpaces, PRInt32* numLetters);
|
|
|
|
|
|
|
|
struct FrameJustificationState {
|
|
|
|
PRInt32 mTotalNumSpaces;
|
|
|
|
PRInt32 mTotalNumLetters;
|
|
|
|
nscoord mTotalWidthForSpaces;
|
|
|
|
nscoord mTotalWidthForLetters;
|
|
|
|
PRInt32 mNumSpacesProcessed;
|
|
|
|
PRInt32 mNumLettersProcessed;
|
|
|
|
nscoord mWidthForSpacesProcessed;
|
|
|
|
nscoord mWidthForLettersProcessed;
|
|
|
|
};
|
2006-04-12 01:07:01 +00:00
|
|
|
|
|
|
|
// Apply justification. The return value is the amount by which the width of
|
|
|
|
// the span corresponding to aPSD got increased due to justification.
|
|
|
|
nscoord ApplyFrameJustification(PerSpanData* aPSD,
|
|
|
|
FrameJustificationState* aState);
|
2000-04-17 14:40:46 +00:00
|
|
|
|
|
|
|
|
1999-03-18 21:03:25 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void DumpPerSpanData(PerSpanData* psd, PRInt32 aIndent);
|
|
|
|
#endif
|
1998-06-18 16:25:41 +00:00
|
|
|
};
|
|
|
|
|
1998-09-15 00:19:49 +00:00
|
|
|
#endif /* nsLineLayout_h___ */
|