2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-18 20:25:41 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-06-18 20:25:41 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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 20:25:41 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04: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 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
2000-04-17 18:40:46 +04:00
|
|
|
* Steve Clark <buster@netscape.com>
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2000-02-15 07:26:44 +03:00
|
|
|
* L. David Baron <dbaron@fas.harvard.edu>
|
2000-04-17 18:40:46 +04:00
|
|
|
* Robert O'Callahan <roc+moz@cs.cmu.edu>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either 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 NPL, 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 NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
2000-08-24 08:26:43 +04:00
|
|
|
#include "nsBlockFrame.h"
|
2000-09-12 00:46:44 +04:00
|
|
|
#include "nsInlineFrame.h"
|
1998-07-22 22:38:57 +04:00
|
|
|
#include "nsStyleConsts.h"
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsHTMLContainerFrame.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
2001-10-26 09:06:07 +04:00
|
|
|
#include "nsSpaceManager.h"
|
1998-06-18 20:25:41 +04:00
|
|
|
#include "nsIStyleContext.h"
|
1998-09-23 06:31:16 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIFontMetrics.h"
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
1999-04-23 19:15:53 +04:00
|
|
|
#include "nsLayoutAtoms.h"
|
1999-04-25 21:01:07 +04:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2001-12-18 01:39:59 +03:00
|
|
|
#include "nsHTMLReflowCommand.h"
|
1999-09-03 07:47:49 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIContent.h"
|
2000-02-15 07:26:44 +03:00
|
|
|
#include "nsITextContent.h"
|
1999-11-19 18:33:29 +03:00
|
|
|
#include "nsIView.h"
|
|
|
|
#include "nsIViewManager.h"
|
2000-02-15 07:26:44 +03:00
|
|
|
#include "nsHTMLAtoms.h"
|
2000-04-17 18:40:46 +04:00
|
|
|
#include "nsTextFragment.h"
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2001-04-12 03:32:21 +04:00
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
#include "nsITextFrame.h"
|
|
|
|
#define FIX_FOR_BUG_40882
|
|
|
|
#endif // IBMBIDI
|
1999-09-03 07:47:49 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#undef NOISY_HORIZONTAL_ALIGN
|
|
|
|
#undef NOISY_VERTICAL_ALIGN
|
2001-04-20 01:54:35 +04:00
|
|
|
#undef REALLY_NOISY_VERTICAL_ALIGN
|
1999-03-19 00:03:25 +03:00
|
|
|
#undef NOISY_REFLOW
|
2000-04-17 18:40:46 +04:00
|
|
|
#undef REALLY_NOISY_REFLOW
|
1999-03-19 00:03:25 +03:00
|
|
|
#undef NOISY_PUSHING
|
2001-04-20 01:54:35 +04:00
|
|
|
#undef REALLY_NOISY_PUSHING
|
|
|
|
#undef DEBUG_ADD_TEXT
|
1999-03-20 22:38:50 +03:00
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
2001-04-20 01:54:35 +04:00
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 18:41:49 +03:00
|
|
|
#undef NOISY_CAN_PLACE_FRAME
|
2001-04-20 01:54:35 +04:00
|
|
|
#undef NOISY_TRIM
|
|
|
|
#undef REALLY_NOISY_TRIM
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
1998-06-18 20:25:41 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
#define FIX_BUG_50257
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
#define PLACED_LEFT 0x1
|
|
|
|
#define PLACED_RIGHT 0x2
|
|
|
|
|
2001-08-30 02:59:09 +04:00
|
|
|
#define HACK_MEW
|
2001-09-08 23:26:34 +04:00
|
|
|
//#undef HACK_MEW
|
2001-08-30 02:59:09 +04:00
|
|
|
#ifdef HACK_MEW
|
2001-09-29 01:42:03 +04:00
|
|
|
static nscoord AccumulateImageSizes(nsIPresContext& aPresContext, nsIFrame& aFrame)
|
2001-08-30 02:59:09 +04:00
|
|
|
{
|
|
|
|
nscoord sizes = 0;
|
|
|
|
|
|
|
|
// see if aFrame is an image frame first
|
|
|
|
nsCOMPtr<nsIAtom> type;
|
|
|
|
aFrame.GetFrameType(getter_AddRefs(type));
|
|
|
|
if(type.get() == nsLayoutAtoms::imageFrame) {
|
|
|
|
nsSize size;
|
|
|
|
aFrame.GetSize(size);
|
|
|
|
sizes += NS_STATIC_CAST(nscoord,size.width);
|
|
|
|
} else {
|
|
|
|
// see if there are children to process
|
|
|
|
nsIFrame* child = nsnull;
|
|
|
|
// XXX: process alternate child lists?
|
|
|
|
aFrame.FirstChild(&aPresContext,nsnull,&child);
|
|
|
|
while(child) {
|
|
|
|
// recurse: note that we already know we are in a child frame, so no need to track further
|
2001-09-29 01:42:03 +04:00
|
|
|
sizes += AccumulateImageSizes(aPresContext, *child);
|
2001-08-30 02:59:09 +04:00
|
|
|
// now next sibling
|
|
|
|
child->GetNextSibling(&child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sizes;
|
|
|
|
}
|
2001-09-08 23:26:34 +04:00
|
|
|
|
|
|
|
static PRBool InUnconstrainedTableCell(const nsHTMLReflowState& aBlockReflowState)
|
|
|
|
{
|
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
|
|
|
// get the parent reflow state
|
|
|
|
const nsHTMLReflowState* parentReflowState = aBlockReflowState.parentReflowState;
|
|
|
|
if (parentReflowState) {
|
|
|
|
// check if the frame is a tablecell
|
|
|
|
NS_ASSERTION(parentReflowState->mStyleDisplay, "null styleDisplay in parentReflowState unexpected");
|
|
|
|
if (parentReflowState->mStyleDisplay &&
|
|
|
|
parentReflowState->mStyleDisplay->mDisplay == NS_STYLE_DISPLAY_TABLE_CELL) {
|
|
|
|
// see if width is unconstrained or percent
|
|
|
|
NS_ASSERTION(parentReflowState->mStylePosition, "null stylePosition in parentReflowState unexpected");
|
|
|
|
if(parentReflowState->mStylePosition) {
|
|
|
|
switch(parentReflowState->mStylePosition->mWidth.GetUnit()) {
|
|
|
|
case eStyleUnit_Auto :
|
|
|
|
case eStyleUnit_Null :
|
|
|
|
result = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-08-30 02:59:09 +04:00
|
|
|
#endif
|
|
|
|
|
2001-01-28 02:06:33 +03:00
|
|
|
MOZ_DECL_CTOR_COUNTER(nsLineLayout)
|
1999-10-09 00:41:19 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsLineLayout::nsLineLayout(nsIPresContext* aPresContext,
|
2001-10-26 09:06:07 +04:00
|
|
|
nsSpaceManager* aSpaceManager,
|
1999-03-19 00:03:25 +03:00
|
|
|
const nsHTMLReflowState* aOuterReflowState,
|
|
|
|
PRBool aComputeMaxElementSize)
|
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mSpaceManager(aSpaceManager),
|
|
|
|
mBlockReflowState(aOuterReflowState),
|
1999-04-28 02:13:06 +04:00
|
|
|
mBlockRS(nsnull),/* XXX temporary */
|
1999-08-28 01:50:06 +04:00
|
|
|
mMinLineHeight(0),
|
2002-03-20 00:57:45 +03:00
|
|
|
mComputeMaxElementSize(aComputeMaxElementSize),
|
|
|
|
mWordFrames(0)
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsLineLayout);
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Stash away some style data that we need
|
|
|
|
aOuterReflowState->frame->GetStyleData(eStyleStruct_Text,
|
|
|
|
(const nsStyleStruct*&) mStyleText);
|
|
|
|
mTextAlign = mStyleText->mTextAlign;
|
1998-06-18 20:25:41 +04:00
|
|
|
mLineNumber = 0;
|
|
|
|
mColumn = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
mFlags = 0; // default all flags to false except those that follow here...
|
|
|
|
SetFlag(LL_ENDSINWHITESPACE, PR_TRUE);
|
1999-03-19 00:03:25 +03:00
|
|
|
mPlacedFloaters = 0;
|
|
|
|
mTotalPlacedFrames = 0;
|
|
|
|
mTopEdge = mBottomEdge = 0;
|
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
// Instead of always pre-initializing the free-lists for frames and
|
|
|
|
// spans, we do it on demand so that situations that only use a few
|
|
|
|
// frames and spans won't waste alot of time in unneeded
|
|
|
|
// initialization.
|
|
|
|
mInitialFramesFreed = mInitialSpansFreed = 0;
|
|
|
|
mFrameFreeList = nsnull;
|
|
|
|
mSpanFreeList = nsnull;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
mCurrentSpan = mRootSpan = nsnull;
|
1999-03-19 00:03:25 +03:00
|
|
|
mSpanDepth = 0;
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_KNOWSTRICTMODE, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1998-06-28 02:56:09 +04:00
|
|
|
|
1999-11-24 09:03:41 +03:00
|
|
|
nsLineLayout::nsLineLayout(nsIPresContext* aPresContext)
|
2002-03-20 00:57:45 +03:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mWordFrames(0)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_CTOR(nsLineLayout);
|
2000-04-17 18:40:46 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
mRootSpan = nsnull;
|
|
|
|
mSpanFreeList = nsnull;
|
|
|
|
mFrameFreeList = nsnull;
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
1998-09-15 04:19:49 +04:00
|
|
|
nsLineLayout::~nsLineLayout()
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
1999-10-09 00:41:19 +04:00
|
|
|
MOZ_COUNT_DTOR(nsLineLayout);
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
NS_ASSERTION(nsnull == mRootSpan, "bad line-layout user");
|
|
|
|
|
|
|
|
// Free up all of the per-span-data items that were allocated on the heap
|
|
|
|
PerSpanData* psd = mSpanFreeList;
|
|
|
|
while (nsnull != psd) {
|
1999-03-30 03:46:34 +04:00
|
|
|
PerSpanData* nextSpan = psd->mNextFreeSpan;
|
|
|
|
if ((psd < &mSpanDataBuf[0]) ||
|
|
|
|
(psd >= &mSpanDataBuf[NS_LINELAYOUT_NUM_SPANS])) {
|
1999-03-19 00:03:25 +03:00
|
|
|
delete psd;
|
|
|
|
}
|
|
|
|
psd = nextSpan;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free up all of the per-frame-data items that were allocated on the heap
|
|
|
|
PerFrameData* pfd = mFrameFreeList;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
PerFrameData* nextFrame = pfd->mNext;
|
1999-03-30 03:46:34 +04:00
|
|
|
if ((pfd < &mFrameDataBuf[0]) ||
|
|
|
|
(pfd >= &mFrameDataBuf[NS_LINELAYOUT_NUM_FRAMES])) {
|
1999-03-19 00:03:25 +03:00
|
|
|
delete pfd;
|
|
|
|
}
|
|
|
|
pfd = nextFrame;
|
|
|
|
}
|
1998-06-28 02:56:09 +04:00
|
|
|
}
|
|
|
|
|
1999-09-03 07:47:49 +04:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::InStrictMode()
|
|
|
|
{
|
2000-04-17 18:40:46 +04:00
|
|
|
if (!GetFlag(LL_KNOWSTRICTMODE)) {
|
|
|
|
SetFlag(LL_KNOWSTRICTMODE, PR_TRUE);
|
|
|
|
SetFlag(LL_INSTRICTMODE, PR_TRUE);
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
// ask the cached presentation context for the compatibility mode
|
|
|
|
if (mPresContext) {
|
|
|
|
nsCompatibility mode;
|
|
|
|
mPresContext->GetCompatibilityMode(&mode);
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
SetFlag(LL_INSTRICTMODE, PR_FALSE);
|
1999-09-03 07:47:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
return GetFlag(LL_INSTRICTMODE);
|
1999-09-03 07:47:49 +04:00
|
|
|
}
|
|
|
|
|
1998-06-28 02:56:09 +04:00
|
|
|
void
|
1999-03-19 00:03:25 +03:00
|
|
|
nsLineLayout::BeginLineReflow(nscoord aX, nscoord aY,
|
|
|
|
nscoord aWidth, nscoord aHeight,
|
1999-03-21 04:14:43 +03:00
|
|
|
PRBool aImpactedByFloaters,
|
1999-03-19 00:03:25 +03:00
|
|
|
PRBool aIsTopOfPage)
|
1998-06-28 02:56:09 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
NS_ASSERTION(nsnull == mRootSpan, "bad linelayout user");
|
|
|
|
#ifdef DEBUG
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aWidth != NS_UNCONSTRAINEDSIZE) && CRAZY_WIDTH(aWidth)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": Init: bad caller: width WAS %d(0x%x)\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
aWidth, aWidth);
|
|
|
|
aWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aHeight != NS_UNCONSTRAINEDSIZE) && CRAZY_HEIGHT(aHeight)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": Init: bad caller: height WAS %d(0x%x)\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
aHeight, aHeight);
|
|
|
|
aHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": BeginLineReflow: %d,%d,%d,%d impacted=%s %s\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
aX, aY, aWidth, aHeight,
|
2000-04-17 18:40:46 +04:00
|
|
|
aImpactedByFloaters?"true":"false",
|
1999-03-19 00:03:25 +03:00
|
|
|
aIsTopOfPage ? "top-of-page" : "");
|
|
|
|
#endif
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
mColumn = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
|
|
|
|
SetFlag(LL_ENDSINWHITESPACE, PR_TRUE);
|
|
|
|
SetFlag(LL_UNDERSTANDSNWHITESPACE, PR_FALSE);
|
|
|
|
SetFlag(LL_TEXTSTARTSWITHNBSP, PR_FALSE);
|
|
|
|
SetFlag(LL_FIRSTLETTERSTYLEOK, PR_FALSE);
|
|
|
|
SetFlag(LL_ISTOPOFPAGE, aIsTopOfPage);
|
|
|
|
SetFlag(LL_UPDATEDBAND, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
mPlacedFloaters = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_IMPACTEDBYFLOATERS, aImpactedByFloaters);
|
1999-03-19 00:03:25 +03:00
|
|
|
mTotalPlacedFrames = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_CANPLACEFLOATER, PR_TRUE);
|
|
|
|
SetFlag(LL_LINEENDSINBR, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
mSpanDepth = 0;
|
|
|
|
mMaxTopBoxHeight = mMaxBottomBoxHeight = 0;
|
|
|
|
|
|
|
|
ForgetWordFrames();
|
|
|
|
|
|
|
|
PerSpanData* psd;
|
|
|
|
NewPerSpanData(&psd);
|
|
|
|
mCurrentSpan = mRootSpan = psd;
|
|
|
|
psd->mReflowState = mBlockReflowState;
|
|
|
|
psd->mLeftEdge = aX;
|
|
|
|
psd->mX = aX;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aWidth) {
|
|
|
|
psd->mRightEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psd->mRightEdge = aX + aWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTopEdge = aY;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aHeight) {
|
|
|
|
mBottomEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBottomEdge = aY + aHeight;
|
|
|
|
}
|
1999-03-22 23:45:09 +03:00
|
|
|
|
|
|
|
switch (mStyleText->mWhiteSpace) {
|
|
|
|
case NS_STYLE_WHITESPACE_PRE:
|
|
|
|
case NS_STYLE_WHITESPACE_NOWRAP:
|
|
|
|
psd->mNoWrap = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
psd->mNoWrap = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
psd->mDirection = mBlockReflowState->mStyleVisibility->mDirection;
|
1999-05-08 04:48:39 +04:00
|
|
|
psd->mChangedFrameDirection = PR_FALSE;
|
2001-12-11 05:45:44 +03:00
|
|
|
|
|
|
|
// If this is the first line of a block then see if the text-indent
|
|
|
|
// property amounts to anything.
|
|
|
|
|
|
|
|
if (0 == mLineNumber) {
|
|
|
|
// XXX this test is not ideal, since in print media mLineNumber is
|
|
|
|
// zero on the first line of a paragraph that has been split over a
|
|
|
|
// page break, and this causes bug 45694
|
|
|
|
nscoord indent = 0;
|
|
|
|
nsStyleUnit unit = mStyleText->mTextIndent.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
indent = mStyleText->mTextIndent.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit) {
|
|
|
|
nscoord width =
|
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState->parentReflowState);
|
|
|
|
if (0 != width) {
|
|
|
|
indent = nscoord(mStyleText->mTextIndent.GetPercentValue() * width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != psd->mRightEdge) {
|
|
|
|
psd->mRightEdge -= indent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psd->mX += indent;
|
|
|
|
}
|
|
|
|
}
|
1998-06-28 02:56:09 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void
|
|
|
|
nsLineLayout::EndLineReflow()
|
1998-06-28 02:56:09 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": EndLineReflow: width=%d\n", mRootSpan->mX - mRootSpan->mLeftEdge);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
FreeSpan(mRootSpan);
|
|
|
|
mCurrentSpan = mRootSpan = nsnull;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
NS_ASSERTION(mSpansAllocated == mSpansFreed, "leak");
|
|
|
|
NS_ASSERTION(mFramesAllocated == mFramesFreed, "leak");
|
|
|
|
|
1999-10-26 03:05:15 +04:00
|
|
|
#if 0
|
1999-03-30 03:46:34 +04:00
|
|
|
static PRInt32 maxSpansAllocated = NS_LINELAYOUT_NUM_SPANS;
|
|
|
|
static PRInt32 maxFramesAllocated = NS_LINELAYOUT_NUM_FRAMES;
|
|
|
|
if (mSpansAllocated > maxSpansAllocated) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("XXX: saw a line with %d spans\n", mSpansAllocated);
|
1999-03-30 03:46:34 +04:00
|
|
|
maxSpansAllocated = mSpansAllocated;
|
|
|
|
}
|
|
|
|
if (mFramesAllocated > maxFramesAllocated) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("XXX: saw a line with %d frames\n", mFramesAllocated);
|
1999-03-30 03:46:34 +04:00
|
|
|
maxFramesAllocated = mFramesAllocated;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1999-03-30 03:46:34 +04:00
|
|
|
#endif
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
// XXX swtich to a single mAvailLineWidth that we adjust as each frame
|
|
|
|
// on the line is placed. Each span can still have a per-span mX that
|
|
|
|
// tracks where a child frame is going in its span; they don't need a
|
|
|
|
// per-span mLeftEdge?
|
|
|
|
|
1998-06-18 20:25:41 +04:00
|
|
|
void
|
1999-03-19 00:03:25 +03:00
|
|
|
nsLineLayout::UpdateBand(nscoord aX, nscoord aY,
|
|
|
|
nscoord aWidth, nscoord aHeight,
|
1999-10-29 18:33:26 +04:00
|
|
|
PRBool aPlacedLeftFloater,
|
|
|
|
nsIFrame* aFloaterFrame)
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
2000-03-23 02:19:10 +03:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLL::UpdateBand %d, %d, %d, %d, frame=%p placedLeft=%s\n will set mImpacted to PR_TRUE\n",
|
2000-03-23 02:19:10 +03:00
|
|
|
aX, aY, aWidth, aHeight, aFloaterFrame, aPlacedLeftFloater?"true":"false");
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
NS_PRECONDITION(psd->mX == psd->mLeftEdge, "update-band called late");
|
|
|
|
#ifdef DEBUG
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aWidth != NS_UNCONSTRAINEDSIZE) && CRAZY_WIDTH(aWidth)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": UpdateBand: bad caller: width WAS %d(0x%x)\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
aWidth, aWidth);
|
|
|
|
aWidth = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aHeight != NS_UNCONSTRAINEDSIZE) && CRAZY_HEIGHT(aHeight)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": UpdateBand: bad caller: height WAS %d(0x%x)\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
aHeight, aHeight);
|
|
|
|
aHeight = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
#endif
|
1999-03-24 18:41:49 +03:00
|
|
|
|
|
|
|
// Compute the difference between last times width and the new width
|
|
|
|
nscoord deltaWidth = 0;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != psd->mRightEdge) {
|
|
|
|
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != aWidth, "switched constraints");
|
|
|
|
nscoord oldWidth = psd->mRightEdge - psd->mLeftEdge;
|
|
|
|
deltaWidth = aWidth - oldWidth;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": UpdateBand: %d,%d,%d,%d deltaWidth=%d %s floater\n",
|
1999-03-24 18:41:49 +03:00
|
|
|
aX, aY, aWidth, aHeight, deltaWidth,
|
|
|
|
aPlacedLeftFloater ? "left" : "right");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
psd->mLeftEdge = aX;
|
|
|
|
psd->mX = aX;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aWidth) {
|
|
|
|
psd->mRightEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psd->mRightEdge = aX + aWidth;
|
|
|
|
}
|
|
|
|
mTopEdge = aY;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aHeight) {
|
|
|
|
mBottomEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mBottomEdge = aY + aHeight;
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_UPDATEDBAND, PR_TRUE);
|
1999-03-19 00:03:25 +03:00
|
|
|
mPlacedFloaters |= (aPlacedLeftFloater ? PLACED_LEFT : PLACED_RIGHT);
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_IMPACTEDBYFLOATERS, PR_TRUE);
|
1999-03-24 18:41:49 +03:00
|
|
|
|
1999-10-29 18:33:26 +04:00
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aFloaterFrame->GetFrameType(getter_AddRefs(frameType));
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_LASTFLOATERWASLETTERFRAME, (nsLayoutAtoms::letterFrame == frameType.get()));
|
1999-10-29 18:33:26 +04:00
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
// Now update all of the open spans...
|
1999-11-02 18:44:57 +03:00
|
|
|
mRootSpan->mContainsFloater = PR_TRUE; // make sure mRootSpan gets updated too
|
1999-03-24 18:41:49 +03:00
|
|
|
psd = mCurrentSpan;
|
|
|
|
while (psd != mRootSpan) {
|
|
|
|
NS_ASSERTION(nsnull != psd, "null ptr");
|
|
|
|
if (nsnull == psd) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(psd->mX == psd->mLeftEdge, "bad floater placement");
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aWidth) {
|
|
|
|
psd->mRightEdge = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psd->mRightEdge += deltaWidth;
|
|
|
|
}
|
1999-11-02 18:44:57 +03:00
|
|
|
psd->mContainsFloater = PR_TRUE;
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_REFLOW
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" span %p: oldRightEdge=%d newRightEdge=%d\n",
|
1999-09-18 03:15:31 +04:00
|
|
|
psd, psd->mRightEdge - deltaWidth, psd->mRightEdge);
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
|
|
|
psd = psd->mParent;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
// Note: Only adjust the outermost frames (the ones that are direct
|
|
|
|
// children of the block), not the ones in the child spans. The reason
|
|
|
|
// is simple: the frames in the spans have coordinates local to their
|
|
|
|
// parent therefore they are moved when their parent span is moved.
|
1999-03-19 00:03:25 +03:00
|
|
|
void
|
|
|
|
nsLineLayout::UpdateFrames()
|
|
|
|
{
|
1999-03-22 23:45:09 +03:00
|
|
|
NS_ASSERTION(nsnull != mRootSpan, "UpdateFrames with no active spans");
|
|
|
|
|
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == psd->mDirection) {
|
1999-03-19 00:03:25 +03:00
|
|
|
if (PLACED_LEFT & mPlacedFloaters) {
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
pfd->mBounds.x = psd->mX;
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (PLACED_RIGHT & mPlacedFloaters) {
|
|
|
|
// XXX handle DIR=right-to-left
|
|
|
|
}
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
1999-03-19 00:03:25 +03:00
|
|
|
nsLineLayout::NewPerSpanData(PerSpanData** aResult)
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
PerSpanData* psd = mSpanFreeList;
|
|
|
|
if (nsnull == psd) {
|
1999-03-30 03:46:34 +04:00
|
|
|
if (mInitialSpansFreed < NS_LINELAYOUT_NUM_SPANS) {
|
|
|
|
// use one of the ones defined in our struct...
|
|
|
|
psd = &mSpanDataBuf[mInitialSpansFreed++];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
psd = new PerSpanData;
|
|
|
|
if (nsnull == psd) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-06-28 02:56:09 +04:00
|
|
|
}
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
else {
|
1999-03-30 03:46:34 +04:00
|
|
|
mSpanFreeList = psd->mNextFreeSpan;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
psd->mParent = nsnull;
|
|
|
|
psd->mFrame = nsnull;
|
|
|
|
psd->mFirstFrame = nsnull;
|
|
|
|
psd->mLastFrame = nsnull;
|
1999-11-02 18:44:57 +03:00
|
|
|
psd->mContainsFloater = PR_FALSE;
|
|
|
|
psd->mZeroEffectiveSpanBox = PR_FALSE;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansAllocated++;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
*aResult = psd;
|
|
|
|
return NS_OK;
|
1998-06-18 20:25:41 +04:00
|
|
|
}
|
1998-07-22 22:38:57 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult
|
|
|
|
nsLineLayout::BeginSpan(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowState* aSpanReflowState,
|
|
|
|
nscoord aLeftEdge,
|
|
|
|
nscoord aRightEdge)
|
1998-10-20 04:23:11 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth+1);
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": BeginSpan leftEdge=%d rightEdge=%d\n", aLeftEdge, aRightEdge);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
PerSpanData* psd;
|
|
|
|
nsresult rv = NewPerSpanData(&psd);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Link up span frame's pfd to point to its child span data
|
|
|
|
PerFrameData* pfd = mCurrentSpan->mLastFrame;
|
|
|
|
NS_ASSERTION(pfd->mFrame == aFrame, "huh?");
|
|
|
|
pfd->mSpan = psd;
|
|
|
|
|
|
|
|
// Init new span
|
|
|
|
psd->mFrame = pfd;
|
|
|
|
psd->mParent = mCurrentSpan;
|
|
|
|
psd->mReflowState = aSpanReflowState;
|
|
|
|
psd->mLeftEdge = aLeftEdge;
|
|
|
|
psd->mX = aLeftEdge;
|
|
|
|
psd->mRightEdge = aRightEdge;
|
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
const nsStyleText* styleText;
|
|
|
|
aSpanReflowState->frame->GetStyleData(eStyleStruct_Text,
|
|
|
|
(const nsStyleStruct*&) styleText);
|
|
|
|
switch (styleText->mWhiteSpace) {
|
|
|
|
case NS_STYLE_WHITESPACE_PRE:
|
|
|
|
case NS_STYLE_WHITESPACE_NOWRAP:
|
|
|
|
psd->mNoWrap = PR_TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
psd->mNoWrap = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
psd->mDirection = aSpanReflowState->mStyleVisibility->mDirection;
|
1999-05-08 04:48:39 +04:00
|
|
|
psd->mChangedFrameDirection = PR_FALSE;
|
1999-03-22 23:45:09 +03:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Switch to new span
|
|
|
|
mCurrentSpan = psd;
|
|
|
|
mSpanDepth++;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::EndSpan(nsIFrame* aFrame,
|
|
|
|
nsSize& aSizeResult,
|
1999-09-10 01:04:37 +04:00
|
|
|
nsSize* aMaxElementSize)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSpanDepth > 0, "end-span without begin-span");
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": EndSpan width=%d\n", mCurrentSpan->mX - mCurrentSpan->mLeftEdge);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
nscoord width = 0;
|
|
|
|
nscoord maxHeight = 0;
|
|
|
|
nscoord maxElementWidth = 0;
|
|
|
|
nscoord maxElementHeight = 0;
|
|
|
|
if (nsnull != psd->mLastFrame) {
|
|
|
|
width = psd->mX - psd->mLeftEdge;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
2000-06-15 03:15:59 +04:00
|
|
|
/* there's one oddball case we need to guard against
|
|
|
|
* if we're reflowed with NS_UNCONSTRAINEDSIZE
|
|
|
|
* then the last frame will not contribute to the max element size height
|
|
|
|
* if it is a text frame that only contains whitespace
|
|
|
|
*/
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != psd->mRightEdge || // it's not an unconstrained reflow
|
|
|
|
pfd->mNext || // or it's not the last frame in the span
|
|
|
|
!pfd->GetFlag(PFD_ISTEXTFRAME) || // or it's not a text frame
|
|
|
|
pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME) // or it contains something other than whitespace
|
|
|
|
) {
|
|
|
|
if (pfd->mBounds.height > maxHeight) maxHeight = pfd->mBounds.height;
|
|
|
|
|
|
|
|
// Compute max-element-size if necessary
|
|
|
|
if (aMaxElementSize) {
|
|
|
|
nscoord mw = pfd->mMaxElementSize.width +
|
|
|
|
pfd->mMargin.left + pfd->mMargin.right;
|
|
|
|
if (maxElementWidth < mw) {
|
|
|
|
maxElementWidth = mw;
|
|
|
|
}
|
|
|
|
nscoord mh = pfd->mMaxElementSize.height +
|
|
|
|
pfd->mMargin.top + pfd->mMargin.bottom;
|
|
|
|
if (maxElementHeight < mh) {
|
|
|
|
maxElementHeight = mh;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aSizeResult.width = width;
|
|
|
|
aSizeResult.height = maxHeight;
|
|
|
|
if (aMaxElementSize) {
|
1999-08-28 01:50:06 +04:00
|
|
|
if (psd->mNoWrap) {
|
|
|
|
// When we have a non-breakable span, it's max-element-size
|
|
|
|
// width is its entire width.
|
|
|
|
aMaxElementSize->width = width;
|
|
|
|
aMaxElementSize->height = maxHeight;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMaxElementSize->width = maxElementWidth;
|
|
|
|
aMaxElementSize->height = maxElementHeight;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mSpanDepth--;
|
|
|
|
mCurrentSpan->mReflowState = nsnull; // no longer valid so null it out!
|
|
|
|
mCurrentSpan = mCurrentSpan->mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsLineLayout::GetCurrentSpanCount() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
|
|
|
PRInt32 count = 0;
|
|
|
|
PerFrameData* pfd = mRootSpan->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
count++;
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::SplitLineTo(PRInt32 aNewCount)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_PUSHING
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SplitLineTo %d (current count=%d); before:\n", aNewCount,
|
1999-03-19 00:03:25 +03:00
|
|
|
GetCurrentSpanCount());
|
|
|
|
DumpPerSpanData(mRootSpan, 1);
|
|
|
|
#endif
|
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
if (--aNewCount == 0) {
|
|
|
|
// Truncate list at pfd (we keep pfd, but anything following is freed)
|
|
|
|
PerFrameData* next = pfd->mNext;
|
|
|
|
pfd->mNext = nsnull;
|
|
|
|
psd->mLastFrame = pfd;
|
|
|
|
|
|
|
|
// Now release all of the frames following pfd
|
|
|
|
pfd = next;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
pfd = next;
|
|
|
|
}
|
1998-10-20 04:23:11 +04:00
|
|
|
break;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd = pfd->mNext;
|
1998-10-20 04:23:11 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_PUSHING
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("SplitLineTo %d (current count=%d); after:\n", aNewCount,
|
1999-03-19 00:03:25 +03:00
|
|
|
GetCurrentSpanCount());
|
|
|
|
DumpPerSpanData(mRootSpan, 1);
|
|
|
|
#endif
|
|
|
|
}
|
1998-10-20 04:23:11 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
void
|
|
|
|
nsLineLayout::PushFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
NS_ASSERTION(psd->mLastFrame->mFrame == aFrame, "pushing non-last frame");
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_PUSHING
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("PushFrame %p, before:\n", psd);
|
1999-03-19 00:03:25 +03:00
|
|
|
DumpPerSpanData(psd, 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Take the last frame off of the span's frame list
|
|
|
|
PerFrameData* pfd = psd->mLastFrame;
|
|
|
|
if (pfd == psd->mFirstFrame) {
|
|
|
|
// We are pushing away the only frame...empty the list
|
|
|
|
psd->mFirstFrame = nsnull;
|
|
|
|
psd->mLastFrame = nsnull;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PerFrameData* prevFrame = pfd->mPrev;
|
|
|
|
prevFrame->mNext = nsnull;
|
|
|
|
psd->mLastFrame = prevFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now free it, and if it has a span, free that too
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
#ifdef NOISY_PUSHING
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("PushFrame: %p after:\n", psd);
|
1999-03-19 00:03:25 +03:00
|
|
|
DumpPerSpanData(psd, 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::FreeSpan(PerSpanData* psd)
|
|
|
|
{
|
|
|
|
// Free its frames
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
FreeSpan(pfd->mSpan);
|
1998-10-20 04:23:11 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
1999-03-30 03:46:34 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd = next;
|
|
|
|
}
|
1999-03-30 03:46:34 +04:00
|
|
|
|
|
|
|
// Now put the span on the free list since its free too
|
|
|
|
psd->mNextFreeSpan = mSpanFreeList;
|
|
|
|
mSpanFreeList = psd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansFreed++;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::IsZeroHeight()
|
|
|
|
{
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
if (0 != pfd->mBounds.height) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLineLayout::NewPerFrameData(PerFrameData** aResult)
|
|
|
|
{
|
|
|
|
PerFrameData* pfd = mFrameFreeList;
|
|
|
|
if (nsnull == pfd) {
|
1999-03-30 03:46:34 +04:00
|
|
|
if (mInitialFramesFreed < NS_LINELAYOUT_NUM_FRAMES) {
|
|
|
|
// use one of the ones defined in our struct...
|
|
|
|
pfd = &mFrameDataBuf[mInitialFramesFreed++];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd = new PerFrameData;
|
|
|
|
if (nsnull == pfd) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFrameFreeList = pfd->mNext;
|
|
|
|
}
|
|
|
|
pfd->mSpan = nsnull;
|
|
|
|
pfd->mNext = nsnull;
|
1999-09-21 04:14:22 +04:00
|
|
|
pfd->mPrev = nsnull;
|
2000-02-02 10:38:23 +03:00
|
|
|
pfd->mFrame = nsnull;
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->mFlags = 0; // all flags default to false
|
2000-02-02 10:38:23 +03:00
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
pfd->mVerticalAlign = 0xFF;
|
1999-03-30 03:46:34 +04:00
|
|
|
mFramesAllocated++;
|
1999-03-22 23:45:09 +03:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
*aResult = pfd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::CanPlaceFloaterNow() const
|
|
|
|
{
|
2000-04-17 18:40:46 +04:00
|
|
|
return GetFlag(LL_CANPLACEFLOATER);
|
1999-03-24 18:41:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::LineIsEmpty() const
|
|
|
|
{
|
|
|
|
return 0 == mTotalPlacedFrames;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::LineIsBreakable() const
|
|
|
|
{
|
2000-04-17 18:40:46 +04:00
|
|
|
if ((0 != mTotalPlacedFrames) || GetFlag(LL_IMPACTEDBYFLOATERS)) {
|
1999-03-24 18:41:49 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult
|
|
|
|
nsLineLayout::ReflowFrame(nsIFrame* aFrame,
|
|
|
|
nsIFrame** aNextRCFrame,
|
1999-10-29 18:33:26 +04:00
|
|
|
nsReflowStatus& aReflowStatus,
|
2000-01-03 07:32:13 +03:00
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
|
|
|
PRBool& aPushedFrame)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
2000-01-03 07:32:13 +03:00
|
|
|
// Initialize OUT parameter
|
|
|
|
aPushedFrame = PR_FALSE;
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* pfd;
|
|
|
|
nsresult rv = NewPerFrameData(&pfd);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
psd->AppendFrame(pfd);
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("%p: Begin ReflowFrame pfd=%p ", psd, pfd);
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Compute the available size for the frame. This available width
|
2001-12-11 05:45:44 +03:00
|
|
|
// includes room for the side margins.
|
1999-03-19 00:03:25 +03:00
|
|
|
nsSize availSize;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == psd->mRightEdge) {
|
|
|
|
availSize.width = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
availSize.width = psd->mRightEdge - psd->mX;
|
1999-03-22 23:45:09 +03:00
|
|
|
if (psd->mNoWrap) {
|
|
|
|
// Make up a width to use for reflowing into. XXX what value to
|
|
|
|
// use? for tables, we want to limit it; for other elements
|
|
|
|
// (e.g. text) it can be unlimited...
|
2001-12-06 23:14:10 +03:00
|
|
|
// especially we won't use the unlimited size for <hr> (bug 60992),
|
|
|
|
// the following code is a consequence of setting
|
|
|
|
// hr display:inline in quirks.css (bug 18754)
|
|
|
|
if (!InStrictMode()) {
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::hrFrame != frameType.get()) {
|
|
|
|
availSize.width = psd->mReflowState->availableWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
availSize.width = psd->mReflowState->availableWidth;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == mBottomEdge) {
|
|
|
|
availSize.height = NS_UNCONSTRAINEDSIZE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
availSize.height = mBottomEdge - mTopEdge;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get reflow reason set correctly. It's possible that a child was
|
|
|
|
// created and then it was decided that it could not be reflowed
|
|
|
|
// (for example, a block frame that isn't at the start of a
|
|
|
|
// line). In this case the reason will be wrong so we need to check
|
|
|
|
// the frame state.
|
|
|
|
nsReflowReason reason = eReflowReason_Resize;
|
|
|
|
nsFrameState state;
|
|
|
|
aFrame->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_FIRST_REFLOW & state) {
|
|
|
|
reason = eReflowReason_Initial;
|
2000-01-12 11:28:24 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
else if (*aNextRCFrame == aFrame) {
|
|
|
|
reason = eReflowReason_Incremental;
|
|
|
|
// Make sure we only incrementally reflow once
|
|
|
|
*aNextRCFrame = nsnull;
|
|
|
|
}
|
1999-10-22 00:44:58 +04:00
|
|
|
else if (psd->mReflowState->reason == eReflowReason_StyleChange) {
|
|
|
|
reason = eReflowReason_StyleChange;
|
|
|
|
}
|
2000-01-12 11:28:24 +03:00
|
|
|
else if (psd->mReflowState->reason == eReflowReason_Dirty) {
|
|
|
|
if (state & NS_FRAME_IS_DIRTY)
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
}
|
1999-10-22 00:44:58 +04:00
|
|
|
else {
|
1999-10-30 06:52:11 +04:00
|
|
|
const nsHTMLReflowState* rs = psd->mReflowState;
|
1999-10-22 00:44:58 +04:00
|
|
|
if (rs->reason == eReflowReason_Incremental) {
|
|
|
|
// If the incremental reflow command is a StyleChanged reflow and
|
|
|
|
// it's target is the current span, then make sure we send
|
|
|
|
// StyleChange reflow reasons down to the children so that they
|
|
|
|
// don't over-optimize their reflow.
|
2001-12-18 01:39:59 +03:00
|
|
|
nsHTMLReflowCommand* rc = rs->reflowCommand;
|
1999-10-22 00:44:58 +04:00
|
|
|
if (rc) {
|
2001-12-18 01:39:59 +03:00
|
|
|
nsReflowType type;
|
1999-10-22 00:44:58 +04:00
|
|
|
rc->GetType(type);
|
2001-12-18 01:39:59 +03:00
|
|
|
if (type == eReflowType_StyleChanged) {
|
1999-10-22 00:44:58 +04:00
|
|
|
nsIFrame* parentFrame = psd->mFrame
|
|
|
|
? psd->mFrame->mFrame
|
|
|
|
: mBlockReflowState->frame;
|
|
|
|
nsIFrame* target;
|
|
|
|
rc->GetTarget(target);
|
|
|
|
if (target == parentFrame) {
|
|
|
|
reason = eReflowReason_StyleChange;
|
|
|
|
}
|
|
|
|
}
|
2001-12-18 01:39:59 +03:00
|
|
|
else if (type == eReflowType_ReflowDirty &&
|
2000-01-12 11:28:24 +03:00
|
|
|
(state & NS_FRAME_IS_DIRTY)) {
|
|
|
|
reason = eReflowReason_Dirty;
|
|
|
|
}
|
1999-10-22 00:44:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2001-07-04 10:07:14 +04:00
|
|
|
// Unless we're doing an unconstrained reflow, compute the
|
|
|
|
// containing block's width.
|
|
|
|
nscoord containingBlockWidth =
|
|
|
|
(NS_UNCONSTRAINEDSIZE != psd->mRightEdge)
|
|
|
|
? (psd->mRightEdge - psd->mLeftEdge)
|
|
|
|
: NS_UNCONSTRAINEDSIZE;
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Setup reflow state for reflowing the frame
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
nsHTMLReflowState reflowState(mPresContext, *psd->mReflowState,
|
|
|
|
aFrame, availSize,
|
2001-07-04 10:07:14 +04:00
|
|
|
containingBlockWidth,
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
psd->mReflowState->availableHeight);
|
|
|
|
reflowState.reason = reason;
|
1999-07-20 07:51:46 +04:00
|
|
|
reflowState.mLineLayout = this;
|
2001-12-07 17:51:12 +03:00
|
|
|
reflowState.mFlags.mIsTopOfPage = GetFlag(LL_ISTOPOFPAGE);
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_UNDERSTANDSNWHITESPACE, PR_FALSE);
|
|
|
|
SetFlag(LL_TEXTSTARTSWITHNBSP, PR_FALSE);
|
|
|
|
mTextJustificationNumSpaces = 0;
|
|
|
|
mTextJustificationNumLetters = 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Stash copies of some of the computed state away for later
|
|
|
|
// (vertical alignment, for example)
|
|
|
|
pfd->mFrame = aFrame;
|
1999-07-20 07:41:03 +04:00
|
|
|
pfd->mMargin = reflowState.mComputedMargin;
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBorderPadding = reflowState.mComputedBorderPadding;
|
1999-07-20 07:41:03 +04:00
|
|
|
pfd->mFrameType = reflowState.mFrameType;
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_RELATIVEPOS,
|
2001-06-01 02:19:43 +04:00
|
|
|
(reflowState.mStyleDisplay->mPosition == NS_STYLE_POSITION_RELATIVE));
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_RELATIVEPOS)) {
|
1999-07-20 07:51:46 +04:00
|
|
|
pfd->mOffsets = reflowState.mComputedOffsets;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2001-12-11 05:45:44 +03:00
|
|
|
// NOTE: While the x coordinate remains relative to the parent span,
|
|
|
|
// the y coordinate is fixed at the top edge for the line. During
|
|
|
|
// VerticalAlignFrames we will repair this so that the y coordinate
|
|
|
|
// is properly set and relative to the appropriate span.
|
|
|
|
pfd->mBounds.x = psd->mX;
|
|
|
|
pfd->mBounds.y = mTopEdge;
|
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
// We want to guarantee that we always make progress when
|
|
|
|
// formatting. Therefore, if the object being placed on the line is
|
|
|
|
// too big for the line, but it is the only thing on the line
|
|
|
|
// (including counting floaters) then we go ahead and place it
|
|
|
|
// anyway. Its also true that if the object is a part of a larger
|
|
|
|
// object (a multiple frame word) then we will place it on the line
|
|
|
|
// too.
|
|
|
|
//
|
1999-03-19 00:03:25 +03:00
|
|
|
// Capture this state *before* we reflow the frame in case it clears
|
|
|
|
// the state out. We need to know how to treat the current frame
|
|
|
|
// when breaking.
|
1999-03-24 18:41:49 +03:00
|
|
|
PRBool notSafeToBreak = CanPlaceFloaterNow() || InWord();
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2002-01-31 02:28:56 +03:00
|
|
|
// Apply start margins (as appropriate) to the frame computing the
|
1999-03-19 00:03:25 +03:00
|
|
|
// new starting x,y coordinates for the frame.
|
2002-01-31 02:28:56 +03:00
|
|
|
ApplyStartMargin(pfd, reflowState);
|
1999-03-19 00:03:25 +03:00
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Let frame know that are reflowing it. Note that we don't bother
|
|
|
|
// positioning the frame yet, because we're probably going to end up
|
|
|
|
// moving it when we do the vertical alignment
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord x = pfd->mBounds.x;
|
|
|
|
nscoord y = pfd->mBounds.y;
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
aFrame->WillReflow(mPresContext);
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Adjust spacemanager coordinate system for the frame. The
|
|
|
|
// spacemanager coordinates are <b>inside</b> the current spans
|
|
|
|
// border+padding, but the x/y coordinates are not (recall that
|
|
|
|
// frame coordinates are relative to the parents origin and that the
|
|
|
|
// parents border/padding is <b>inside</b> the parent
|
|
|
|
// frame. Therefore we have to subtract out the parents
|
|
|
|
// border+padding before translating.
|
|
|
|
nsSize innerMaxElementSize;
|
|
|
|
nsHTMLReflowMetrics metrics(mComputeMaxElementSize
|
|
|
|
? &innerMaxElementSize
|
|
|
|
: nsnull);
|
|
|
|
#ifdef DEBUG
|
1999-03-20 02:07:17 +03:00
|
|
|
metrics.width = nscoord(0xdeadbeef);
|
|
|
|
metrics.height = nscoord(0xdeadbeef);
|
|
|
|
metrics.ascent = nscoord(0xdeadbeef);
|
|
|
|
metrics.descent = nscoord(0xdeadbeef);
|
1999-03-19 00:03:25 +03:00
|
|
|
if (mComputeMaxElementSize) {
|
|
|
|
metrics.maxElementSize->width = nscoord(0xdeadbeef);
|
|
|
|
metrics.maxElementSize->height = nscoord(0xdeadbeef);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
nscoord tx = x - psd->mReflowState->mComputedBorderPadding.left;
|
|
|
|
nscoord ty = y - psd->mReflowState->mComputedBorderPadding.top;
|
|
|
|
mSpaceManager->Translate(tx, ty);
|
1999-12-10 21:41:43 +03:00
|
|
|
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PRBool bidiEnabled;
|
2001-05-16 17:40:08 +04:00
|
|
|
mPresContext->GetBidiEnabled(&bidiEnabled);
|
2001-04-12 03:32:21 +04:00
|
|
|
PRBool visual;
|
|
|
|
PRBool setMode = PR_FALSE;
|
|
|
|
PRInt32 start, end;
|
|
|
|
|
|
|
|
if (bidiEnabled) {
|
|
|
|
if (state & NS_FRAME_IS_BIDI) {
|
|
|
|
aFrame->GetOffsets(start, end);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIFormControlFrame> formFrame(do_QueryInterface(aFrame) );
|
|
|
|
if (formFrame) {
|
|
|
|
mPresContext->IsVisualMode(visual);
|
|
|
|
|
|
|
|
PRUint32 options;
|
|
|
|
mPresContext->GetBidi(&options);
|
|
|
|
if ( (IBMBIDI_CONTROLSTEXTMODE_VISUAL == GET_BIDI_OPTION_CONTROLSTEXTMODE(options)
|
|
|
|
&& !visual)
|
|
|
|
|| (IBMBIDI_CONTROLSTEXTMODE_LOGICAL == GET_BIDI_OPTION_CONTROLSTEXTMODE(options)
|
|
|
|
&& visual) ) {
|
|
|
|
mPresContext->SetVisualMode(!visual);
|
|
|
|
setMode = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
2001-04-20 01:54:35 +04:00
|
|
|
rv = aFrame->Reflow(mPresContext, metrics, reflowState, aReflowStatus);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING( "Reflow of frame failed in nsLineLayout" );
|
|
|
|
return rv;
|
|
|
|
}
|
1999-04-23 19:15:53 +04:00
|
|
|
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (setMode) {
|
|
|
|
mPresContext->SetVisualMode(visual);
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
|
2000-08-24 08:26:43 +04:00
|
|
|
// SEC: added this next block for bug 45152
|
|
|
|
// text frames don't know how to invalidate themselves on initial reflow. Do it for them here.
|
|
|
|
// This only shows up in textareas, so do a quick check to see if we're inside one
|
|
|
|
if (eReflowReason_Initial == reflowState.reason)
|
|
|
|
{
|
|
|
|
if (frameType && nsLayoutAtoms::textFrame == frameType.get())
|
|
|
|
{ // aFrame is a text frame, see if it's inside a text control
|
|
|
|
// although this is a bit slow, the frame tree shouldn't be too deep, it's only called
|
|
|
|
// for the text frame's initial reflow (once in the text frame's lifetime)
|
|
|
|
// and we don't make any expensive calls.
|
|
|
|
// Doing it this way shields us from knowing anything about the frame structure inside a text control.
|
|
|
|
nsIFrame *parentFrame;
|
|
|
|
aFrame->GetParent(&parentFrame);
|
|
|
|
PRBool inTextControl = PR_FALSE;
|
|
|
|
while (parentFrame)
|
|
|
|
{
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
nsCOMPtr<nsIAtom> parentFrameType;
|
|
|
|
parentFrame->GetFrameType(getter_AddRefs(parentFrameType));
|
|
|
|
if (parentFrameType)
|
2000-08-24 08:26:43 +04:00
|
|
|
{
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
if (nsLayoutAtoms::textInputFrame == parentFrameType.get())
|
2000-08-24 08:26:43 +04:00
|
|
|
{
|
|
|
|
inTextControl = PR_TRUE; // found it
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parentFrame->GetParent(&parentFrame); // advance the loop up the frame tree
|
|
|
|
}
|
|
|
|
if (inTextControl)
|
|
|
|
{
|
|
|
|
nsLineBox *currentLine=nsnull;
|
2000-09-14 09:50:56 +04:00
|
|
|
// use localResult because a failure here should not be propagated to my caller
|
|
|
|
nsresult localResult = nsBlockFrame::GetCurrentLine(mBlockRS, ¤tLine);
|
|
|
|
if (NS_SUCCEEDED(localResult) && currentLine) {
|
2000-08-24 08:26:43 +04:00
|
|
|
currentLine->SetForceInvalidate(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// end fix for bug 45152
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->mJustificationNumSpaces = mTextJustificationNumSpaces;
|
|
|
|
pfd->mJustificationNumLetters = mTextJustificationNumLetters;
|
|
|
|
|
1999-04-24 00:01:38 +04:00
|
|
|
// XXX See if the frame is a placeholderFrame and if it is process
|
|
|
|
// the floater.
|
1999-04-23 19:15:53 +04:00
|
|
|
if (frameType) {
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
if (nsLayoutAtoms::placeholderFrame == frameType.get()) {
|
1999-04-25 21:01:07 +04:00
|
|
|
nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)aFrame)->GetOutOfFlowFrame();
|
|
|
|
if (outOfFlowFrame) {
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleDisplay* display;
|
1999-04-25 21:01:07 +04:00
|
|
|
|
|
|
|
// Make sure it's floated and not absolutely positioned
|
2001-06-01 02:19:43 +04:00
|
|
|
outOfFlowFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
|
|
|
if (!display->IsAbsolutelyPositioned()) {
|
1999-04-25 21:01:07 +04:00
|
|
|
if (eReflowReason_Incremental == reason) {
|
|
|
|
InitFloater((nsPlaceholderFrame*)aFrame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
AddFloater((nsPlaceholderFrame*)aFrame);
|
|
|
|
}
|
1999-04-29 04:16:09 +04:00
|
|
|
nsIAtom* oofft;
|
|
|
|
outOfFlowFrame->GetFrameType(&oofft);
|
|
|
|
if (oofft) {
|
|
|
|
if (oofft == nsLayoutAtoms::letterFrame) {
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_FIRSTLETTERSTYLEOK, PR_FALSE);
|
1999-04-29 04:16:09 +04:00
|
|
|
}
|
|
|
|
NS_RELEASE(oofft);
|
|
|
|
}
|
1999-04-25 21:01:07 +04:00
|
|
|
}
|
1999-04-23 19:15:53 +04:00
|
|
|
}
|
|
|
|
}
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
else if (nsLayoutAtoms::textFrame == frameType.get()) {
|
1999-09-03 07:47:49 +04:00
|
|
|
// Note non-empty text-frames for inline frame compatability hackery
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISTEXTFRAME, PR_TRUE);
|
2000-02-15 07:26:44 +03:00
|
|
|
// XXX An empty text frame at the end of the line seems not
|
|
|
|
// to have zero width.
|
1999-09-03 07:47:49 +04:00
|
|
|
if (metrics.width) {
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, PR_TRUE);
|
2000-02-15 07:26:44 +03:00
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsresult result = pfd->mFrame->GetContent(getter_AddRefs(content));
|
|
|
|
if ((NS_SUCCEEDED(result)) && content) {
|
|
|
|
nsCOMPtr<nsITextContent> textContent
|
|
|
|
= do_QueryInterface(content, &result);
|
|
|
|
if ((NS_SUCCEEDED(result)) && textContent) {
|
|
|
|
PRBool isWhitespace;
|
|
|
|
result = textContent->IsOnlyWhitespace(&isWhitespace);
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISNONWHITESPACETEXTFRAME, !isWhitespace);
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
// fix for bug 40882
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
const nsTextFragment* frag;
|
|
|
|
textContent->GetText(&frag);
|
|
|
|
if (frag && frag->Is2b() ) {
|
|
|
|
//PRBool isVisual;
|
|
|
|
//mPresContext->IsVisualMode(isVisual);
|
|
|
|
PRUnichar ch = /*(isVisual) ?
|
|
|
|
*(frag->Get2b() + frag->GetLength() - 1) :*/ *frag->Get2b();
|
|
|
|
if (IS_BIDI_DIACRITIC(ch) ) {
|
|
|
|
aFrame->SetBidiProperty(mPresContext,
|
|
|
|
nsLayoutAtoms::endsInDiacritic, (void*)ch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
|
|
|
}
|
1999-09-03 07:47:49 +04:00
|
|
|
}
|
|
|
|
}
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
else if (nsLayoutAtoms::letterFrame==frameType.get()) {
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISLETTERFRAME, PR_TRUE);
|
1999-10-29 18:33:26 +04:00
|
|
|
}
|
1999-04-23 19:15:53 +04:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
mSpaceManager->Translate(-tx, -ty);
|
|
|
|
|
2000-10-30 07:11:59 +03:00
|
|
|
NS_ASSERTION(metrics.width>=0, "bad width");
|
|
|
|
NS_ASSERTION(metrics.height>=0,"bad height");
|
|
|
|
if (metrics.width<0) metrics.width=0;
|
|
|
|
if (metrics.height<0) metrics.height=0;
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Note: break-before means ignore the reflow metrics since the
|
|
|
|
// frame will be reflowed another time.
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {
|
|
|
|
if (CRAZY_WIDTH(metrics.width) || CRAZY_HEIGHT(metrics.height)) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLineLayout: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" metrics=%d,%d!\n", metrics.width, metrics.height);
|
1999-03-24 18:41:49 +03:00
|
|
|
}
|
|
|
|
if (mComputeMaxElementSize &&
|
|
|
|
((nscoord(0xdeadbeef) == metrics.maxElementSize->width) ||
|
|
|
|
(nscoord(0xdeadbeef) == metrics.maxElementSize->height))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLineLayout: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" didn't set max-element-size!\n");
|
1999-03-24 18:41:49 +03:00
|
|
|
metrics.maxElementSize->width = 0;
|
|
|
|
metrics.maxElementSize->height = 0;
|
|
|
|
}
|
|
|
|
#ifdef REALLY_NOISY_MAX_ELEMENT_SIZE
|
|
|
|
// Note: there are common reflow situations where this *correctly*
|
|
|
|
// occurs; so only enable this debug noise when you really need to
|
|
|
|
// analyze in detail.
|
|
|
|
if (mComputeMaxElementSize &&
|
|
|
|
((metrics.maxElementSize->width > metrics.width) ||
|
|
|
|
(metrics.maxElementSize->height > metrics.height))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLineLayout: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": WARNING: maxElementSize=%d,%d > metrics=%d,%d\n",
|
1999-03-24 18:41:49 +03:00
|
|
|
metrics.maxElementSize->width,
|
|
|
|
metrics.maxElementSize->height,
|
|
|
|
metrics.width, metrics.height);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if ((metrics.width == nscoord(0xdeadbeef)) ||
|
|
|
|
(metrics.height == nscoord(0xdeadbeef)) ||
|
|
|
|
(metrics.ascent == nscoord(0xdeadbeef)) ||
|
|
|
|
(metrics.descent == nscoord(0xdeadbeef))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLineLayout: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" didn't set whad %d,%d,%d,%d!\n", metrics.width, metrics.height,
|
1999-03-24 18:41:49 +03:00
|
|
|
metrics.ascent, metrics.descent);
|
|
|
|
}
|
1999-03-20 02:07:17 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
1999-03-20 22:38:50 +03:00
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
1999-03-24 18:41:49 +03:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {
|
|
|
|
if (mComputeMaxElementSize) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": maxElementSize=%d,%d wh=%d,%d,\n",
|
1999-03-24 18:41:49 +03:00
|
|
|
metrics.maxElementSize->width,
|
|
|
|
metrics.maxElementSize->height,
|
|
|
|
metrics.width, metrics.height);
|
|
|
|
}
|
1999-03-20 22:38:50 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
aFrame->GetFrameState(&state);
|
|
|
|
if (NS_FRAME_OUTSIDE_CHILDREN & state) {
|
1999-12-06 18:49:53 +03:00
|
|
|
pfd->mCombinedArea = metrics.mOverflowArea;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mCombinedArea.x = 0;
|
|
|
|
pfd->mCombinedArea.y = 0;
|
|
|
|
pfd->mCombinedArea.width = metrics.width;
|
|
|
|
pfd->mCombinedArea.height = metrics.height;
|
|
|
|
}
|
|
|
|
pfd->mBounds.width = metrics.width;
|
|
|
|
pfd->mBounds.height = metrics.height;
|
|
|
|
if (mComputeMaxElementSize) {
|
|
|
|
pfd->mMaxElementSize = *metrics.maxElementSize;
|
|
|
|
}
|
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Size the frame and size its view (if it has one)
|
1999-11-24 09:03:41 +03:00
|
|
|
aFrame->SizeTo(mPresContext, metrics.width, metrics.height);
|
1999-11-19 18:33:29 +03:00
|
|
|
nsIView* view;
|
1999-11-24 09:03:41 +03:00
|
|
|
aFrame->GetView(mPresContext, &view);
|
1999-11-19 18:33:29 +03:00
|
|
|
if (view) {
|
|
|
|
nsIViewManager *vm;
|
2001-11-24 08:37:25 +03:00
|
|
|
view->GetViewManager(vm);
|
2001-12-01 17:31:45 +03:00
|
|
|
|
|
|
|
#if 0 // XXX This is the correct code. We'll turn it on later to mitigate risk.
|
|
|
|
vm->ResizeView(view, pfd->mCombinedArea);
|
|
|
|
#else // imitate the old, wrong code
|
|
|
|
nsRect r(0, 0, metrics.width, metrics.height);
|
|
|
|
vm->ResizeView(view, r);
|
|
|
|
#endif
|
1999-11-19 18:33:29 +03:00
|
|
|
NS_RELEASE(vm);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
1999-11-19 18:33:29 +03:00
|
|
|
// Tell the frame that we're done reflowing it
|
2001-12-07 17:51:12 +03:00
|
|
|
aFrame->DidReflow(mPresContext, &reflowState, NS_FRAME_REFLOW_FINISHED);
|
1999-11-19 18:33:29 +03:00
|
|
|
|
1999-10-29 18:33:26 +04:00
|
|
|
if (aMetrics) {
|
|
|
|
*aMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {
|
|
|
|
// If frame is complete and has a next-in-flow, we need to delete
|
|
|
|
// them now. Do not do this when a break-before is signaled because
|
|
|
|
// the frame is going to get reflowed again (and may end up wanting
|
|
|
|
// a next-in-flow where it ends up).
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {
|
|
|
|
nsIFrame* kidNextInFlow;
|
|
|
|
aFrame->GetNextInFlow(&kidNextInFlow);
|
|
|
|
if (nsnull != kidNextInFlow) {
|
|
|
|
// Remove all of the childs next-in-flows. Make sure that we ask
|
|
|
|
// the right parent to do the removal (it's possible that the
|
|
|
|
// parent is not this because we are executing pullup code)
|
|
|
|
nsHTMLContainerFrame* parent;
|
|
|
|
aFrame->GetParent((nsIFrame**) &parent);
|
|
|
|
parent->DeleteChildsNextInFlow(mPresContext, aFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if we can place the frame. If we can't fit it, then we
|
|
|
|
// return now.
|
1999-11-02 18:44:57 +03:00
|
|
|
if (CanPlaceFrame(pfd, reflowState, notSafeToBreak, metrics, aReflowStatus)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
// Place the frame, updating aBounds with the final size and
|
|
|
|
// location. Then apply the bottom+right margins (as
|
|
|
|
// appropriate) to the frame.
|
|
|
|
PlaceFrame(pfd, metrics);
|
|
|
|
PerSpanData* span = pfd->mSpan;
|
|
|
|
if (span) {
|
|
|
|
// The frame we just finished reflowing is an inline
|
|
|
|
// container. It needs its child frames vertically aligned,
|
|
|
|
// so do most of it now.
|
|
|
|
VerticalAlignFrames(span);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
2000-01-03 07:32:13 +03:00
|
|
|
aPushedFrame = PR_TRUE;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_TEXTSTARTSWITHNBSP, PR_FALSE); // reset for next time
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("End ReflowFrame ");
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" status=%x\n", aReflowStatus);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
2001-04-12 03:32:21 +04:00
|
|
|
|
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (state & NS_FRAME_IS_BIDI) {
|
|
|
|
nsITextFrame* textFrame = nsnull;
|
|
|
|
aFrame->QueryInterface(NS_GET_IID(nsITextFrame), (void**) &textFrame);
|
|
|
|
if (textFrame) {
|
|
|
|
// Since aReflowStatus may change, check it at the end
|
|
|
|
if (NS_INLINE_IS_BREAK_BEFORE(aReflowStatus) ) {
|
|
|
|
textFrame->SetOffsets(start, end);
|
|
|
|
nsFrameState frameState;
|
|
|
|
aFrame->GetFrameState(&frameState);
|
|
|
|
frameState |= NS_FRAME_IS_BIDI;
|
|
|
|
aFrame->SetFrameState(frameState);
|
|
|
|
}
|
|
|
|
else if (!NS_FRAME_IS_COMPLETE(aReflowStatus) ) {
|
|
|
|
PRInt32 newEnd;
|
|
|
|
aFrame->GetOffsets(start, newEnd);
|
|
|
|
if (newEnd != end) {
|
|
|
|
nsIFrame* nextInFlow;
|
|
|
|
aFrame->GetNextInFlow(&nextInFlow);
|
|
|
|
if (nextInFlow) {
|
|
|
|
nsITextFrame* nextTextInFlow = nsnull;
|
|
|
|
nextInFlow->QueryInterface(NS_GET_IID(nsITextFrame),
|
|
|
|
(void**) &nextTextInFlow);
|
|
|
|
if (nextTextInFlow) {
|
|
|
|
nextInFlow->GetOffsets(start, end);
|
|
|
|
nextTextInFlow->SetOffsets(newEnd, end);
|
|
|
|
nsFrameState frameState;
|
|
|
|
nextInFlow->GetFrameState(&frameState);
|
|
|
|
frameState |= NS_FRAME_IS_BIDI;
|
|
|
|
nextInFlow->SetFrameState(frameState);
|
|
|
|
}
|
|
|
|
} // nextInFlow
|
|
|
|
} // newEnd != end
|
|
|
|
} // !NS_FRAME_IS_COMPLETE(aReflowStatus)
|
|
|
|
} // textFrame
|
|
|
|
} // isBidiFrame
|
|
|
|
#endif // IBMBIDI
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-01-31 02:28:56 +03:00
|
|
|
nsLineLayout::ApplyStartMargin(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowState& aReflowState)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
2002-01-31 02:28:56 +03:00
|
|
|
NS_ASSERTION(aReflowState.mStyleDisplay->mFloats == NS_STYLE_FLOAT_NONE,
|
|
|
|
"How'd we get a floated inline frame? "
|
|
|
|
"The frame ctor should've dealt with this.");
|
|
|
|
|
|
|
|
// XXXwaterson probably not the right way to get this; e.g., embeddings, etc.
|
|
|
|
PRBool ltr = (NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection);
|
|
|
|
|
2002-03-21 01:14:27 +03:00
|
|
|
PRBool reducedBothMargins = PR_FALSE;
|
|
|
|
// An HR needs to reduce the avail width by both margins, because it effectively fits
|
|
|
|
// on one line. If it gets continued then only the continuation has any width. XXX - Are
|
|
|
|
// there other elements with these characterstics and if so, is there a bit indicating that?
|
|
|
|
if (NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth) {
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
pfd->mFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::hrFrame == frameType.get()) {
|
|
|
|
aReflowState.availableWidth -= pfd->mMargin.left + pfd->mMargin.right;
|
|
|
|
reducedBothMargins = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-31 02:28:56 +03:00
|
|
|
// Only apply start-margin on the first-in flow for inline frames
|
|
|
|
nsIFrame *prevInFlow;
|
|
|
|
pfd->mFrame->GetPrevInFlow(&prevInFlow);
|
|
|
|
if (prevInFlow) {
|
|
|
|
// Zero this out so that when we compute the max-element-size of
|
|
|
|
// the frame we will properly avoid adding in the starting margin.
|
|
|
|
if (ltr)
|
|
|
|
pfd->mMargin.left = 0;
|
|
|
|
else
|
|
|
|
pfd->mMargin.right = 0;
|
2001-12-06 23:14:10 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2002-03-21 01:14:27 +03:00
|
|
|
if ((NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth) && !reducedBothMargins){
|
2002-01-31 02:28:56 +03:00
|
|
|
// Adjust available width to account for the left margin. The
|
|
|
|
// right margin will be accounted for when we finish flowing the
|
|
|
|
// frame.
|
|
|
|
aReflowState.availableWidth -= ltr ? pfd->mMargin.left : pfd->mMargin.right;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2002-01-31 02:28:56 +03:00
|
|
|
if (ltr)
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBounds.x += pfd->mMargin.left;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* See if the frame can be placed now that we know it's desired size.
|
|
|
|
* We can always place the frame if the line is empty. Note that we
|
|
|
|
* know that the reflow-status is not a break-before because if it was
|
|
|
|
* ReflowFrame above would have returned false, preventing this method
|
|
|
|
* from being called. The logic in this method assumes that.
|
|
|
|
*
|
|
|
|
* Note that there is no check against the Y coordinate because we
|
|
|
|
* assume that the caller will take care of that.
|
|
|
|
*/
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::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)
|
|
|
|
{
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
NS_PRECONDITION(pfd && pfd->mFrame, "bad args, null pointers for frame data");
|
1999-03-19 00:03:25 +03:00
|
|
|
// Compute right margin to use
|
|
|
|
if (0 != pfd->mBounds.width) {
|
2002-01-31 02:28:56 +03:00
|
|
|
NS_ASSERTION(aReflowState.mStyleDisplay->mFloats == NS_STYLE_FLOAT_NONE,
|
|
|
|
"How'd we get a floated inline frame? "
|
|
|
|
"The frame ctor should've dealt with this.");
|
1999-03-21 04:14:43 +03:00
|
|
|
|
2002-01-31 02:28:56 +03:00
|
|
|
// XXXwaterson this is probably not exactly right; e.g., embeddings, etc.
|
|
|
|
PRBool ltr = (NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection);
|
1999-03-21 04:14:43 +03:00
|
|
|
|
2002-01-31 02:28:56 +03:00
|
|
|
if (NS_FRAME_IS_NOT_COMPLETE(aStatus)) {
|
|
|
|
// Only apply end margin for the last-in-flow. Zero this out so
|
|
|
|
// that when we compute the max-element-size of the frame we
|
|
|
|
// will properly avoid adding in the end margin.
|
|
|
|
if (ltr)
|
|
|
|
pfd->mMargin.right = 0;
|
|
|
|
else
|
|
|
|
pfd->mMargin.left = 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
2002-01-31 02:28:56 +03:00
|
|
|
else {
|
|
|
|
// Don't apply margin to empty frames.
|
|
|
|
pfd->mMargin.left = pfd->mMargin.right = 0;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
if (psd->mNoWrap) {
|
1999-11-02 18:44:57 +03:00
|
|
|
// When wrapping is off, everything fits.
|
1999-03-21 04:14:43 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
if (nsnull != psd->mFrame) {
|
|
|
|
nsFrame::ListTag(stdout, psd->mFrame->mFrame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": aNotSafeToBreak=%s frame=", aNotSafeToBreak ? "true" : "false");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" frameWidth=%d\n", pfd->mBounds.XMost() + rightMargin - psd->mX);
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Set outside to PR_TRUE if the result of the reflow leads to the
|
|
|
|
// frame sticking outside of our available area.
|
2002-01-31 02:28:56 +03:00
|
|
|
PRBool outside = pfd->mBounds.XMost() + pfd->mMargin.right > psd->mRightEdge;
|
1999-03-21 04:14:43 +03:00
|
|
|
if (!outside) {
|
|
|
|
// If it fits, it fits
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> inside\n");
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-03-21 04:14:43 +03:00
|
|
|
// When it doesn't fit, check for a few special conditions where we
|
|
|
|
// allow it to fit anyway.
|
2002-01-31 02:28:56 +03:00
|
|
|
if (0 == pfd->mMargin.left + pfd->mBounds.width + pfd->mMargin.right) {
|
1999-03-19 00:03:25 +03:00
|
|
|
// Empty frames always fit right where they are
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> empty frame fits\n");
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
#ifdef FIX_BUG_50257
|
|
|
|
// another special case: always place a BR
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
pfd->mFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::brFrame == frameType.get()) {
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> BR frame fits\n");
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
#endif
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
if (aNotSafeToBreak) {
|
|
|
|
// There are no frames on the line or we are in the first word on
|
|
|
|
// the line. If the line isn't impacted by a floater then the
|
|
|
|
// current frame fits.
|
2000-04-17 18:40:46 +04:00
|
|
|
if (!GetFlag(LL_IMPACTEDBYFLOATERS)) {
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> not-safe and not-impacted fits: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
while (nsnull != psd) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("<psd=%p x=%d left=%d> ", psd, psd->mX, psd->mLeftEdge);
|
1999-03-24 18:41:49 +03:00
|
|
|
psd = psd->mParent;
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
1999-03-21 04:14:43 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else if (GetFlag(LL_LASTFLOATERWASLETTERFRAME)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
// Another special case: see if the floater is a letter
|
|
|
|
// frame. If it is, then allow the frame next to it to fit.
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
// This must be the first piece of non-empty text (because
|
|
|
|
// aNotSafeToBreak is true) or its a piece of text that is
|
|
|
|
// part of a larger word.
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISSTICKY, PR_TRUE);
|
1999-10-29 18:33:26 +04:00
|
|
|
}
|
|
|
|
else if (pfd->mSpan) {
|
|
|
|
PerFrameData* pf = pfd->mSpan->mFirstFrame;
|
|
|
|
while (pf) {
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pf->GetFlag(PFD_ISSTICKY)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
// If one of the spans children was sticky then the span
|
|
|
|
// itself is sticky.
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISSTICKY, PR_TRUE);
|
1999-10-29 18:33:26 +04:00
|
|
|
}
|
|
|
|
pf = pf->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_ISSTICKY)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> last floater was letter frame && frame is sticky\n");
|
1999-10-29 18:33:26 +04:00
|
|
|
#endif
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a piece of text inside a letter frame...
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME)) {
|
|
|
|
if (psd->mFrame && psd->mFrame->GetFlag(PFD_ISLETTERFRAME)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
psd->mFrame->mFrame->GetPrevInFlow(&prevInFlow);
|
|
|
|
if (prevInFlow) {
|
|
|
|
nsIFrame* prevPrevInFlow;
|
|
|
|
prevInFlow->GetPrevInFlow(&prevPrevInFlow);
|
|
|
|
if (!prevPrevInFlow) {
|
|
|
|
// And it's the first continuation of the letter frame...
|
|
|
|
// Then make sure that the text fits
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else if (pfd->GetFlag(PFD_ISLETTERFRAME)) {
|
1999-10-29 18:33:26 +04:00
|
|
|
// If this is the first continuation of the letter frame...
|
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
pfd->mFrame->GetPrevInFlow(&prevInFlow);
|
|
|
|
if (prevInFlow) {
|
|
|
|
nsIFrame* prevPrevInFlow;
|
|
|
|
prevInFlow->GetPrevInFlow(&prevPrevInFlow);
|
|
|
|
if (!prevPrevInFlow) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
1999-11-02 18:44:57 +03:00
|
|
|
// Special check for span frames
|
|
|
|
if (pfd->mSpan && pfd->mSpan->mContainsFloater) {
|
|
|
|
// If the span either directly or indirectly contains a floater then
|
|
|
|
// it fits. Why? It's kind of complicated, but here goes:
|
|
|
|
//
|
|
|
|
// 1. CanPlaceFrame is used for all frame placements on a line,
|
|
|
|
// and in a span. This includes recursively placement of frames
|
|
|
|
// inside of spans, and the span itself. Because the logic always
|
|
|
|
// checks for room before proceeding (the code above here), the
|
|
|
|
// only things on a line will be those things that "fit".
|
|
|
|
//
|
|
|
|
// 2. Before a floater is placed on a line, the line has to be empty
|
|
|
|
// (otherwise its a "below current line" flaoter and will be placed
|
|
|
|
// after the line).
|
|
|
|
//
|
|
|
|
// Therefore, if the span directly or indirectly has a floater
|
|
|
|
// then it means that at the time of the placement of the floater
|
|
|
|
// the line was empty. Because of #1, only the frames that fit can
|
|
|
|
// be added after that point, therefore we can assume that the
|
|
|
|
// current span being placed has fit.
|
|
|
|
//
|
|
|
|
// So how do we get here and have a span that should already fit
|
|
|
|
// and yet doesn't: Simple: span's that have the no-wrap attribute
|
|
|
|
// set on them and contain a floater and are placed where they
|
|
|
|
// don't naturally fit.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yet another special check. If the text happens to have started
|
|
|
|
// with a non-breaking space, then we make it sticky on its left
|
|
|
|
// edge...Which means that whatever piece of text we just formatted
|
|
|
|
// will be the piece that fits (the text frame logic knows to stop
|
|
|
|
// when it runs out of room).
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME) && GetFlag(LL_TEXTSTARTSWITHNBSP)) {
|
1999-11-02 18:44:57 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ==> didn't fit\n");
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
1999-03-21 04:14:43 +03:00
|
|
|
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
|
|
|
return PR_FALSE;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Place the frame. Update running counters.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsLineLayout::PlaceFrame(PerFrameData* pfd, nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
|
|
|
// If frame is zero width then do not apply its left and right margins.
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
PRBool emptyFrame = PR_FALSE;
|
|
|
|
if ((0 == pfd->mBounds.width) && (0 == pfd->mBounds.height)) {
|
|
|
|
pfd->mBounds.x = psd->mX;
|
|
|
|
pfd->mBounds.y = mTopEdge;
|
|
|
|
emptyFrame = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record ascent and update max-ascent and max-descent values
|
|
|
|
pfd->mAscent = aMetrics.ascent;
|
|
|
|
pfd->mDescent = aMetrics.descent;
|
|
|
|
|
|
|
|
// If the band was updated during the reflow of that frame then we
|
|
|
|
// need to adjust any prior frames that were reflowed.
|
2000-04-17 18:40:46 +04:00
|
|
|
if (GetFlag(LL_UPDATEDBAND) && InBlockContext()) {
|
1999-03-19 00:03:25 +03:00
|
|
|
UpdateFrames();
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_UPDATEDBAND, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Advance to next X coordinate
|
|
|
|
psd->mX = pfd->mBounds.XMost() + pfd->mMargin.right;
|
|
|
|
|
|
|
|
// If the frame is a not aware of white-space and it takes up some
|
1999-07-14 21:29:32 +04:00
|
|
|
// width, disable leading white-space compression for the next frame
|
1999-03-19 00:03:25 +03:00
|
|
|
// to be reflowed.
|
2000-04-17 18:40:46 +04:00
|
|
|
if ((!GetFlag(LL_UNDERSTANDSNWHITESPACE)) && pfd->mBounds.width) {
|
|
|
|
SetFlag(LL_ENDSINWHITESPACE, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
1999-03-24 18:41:49 +03:00
|
|
|
// Count the number of frames on the line...
|
|
|
|
mTotalPlacedFrames++;
|
2001-12-04 02:30:32 +03:00
|
|
|
if (psd->mX != psd->mLeftEdge || pfd->mBounds.x != psd->mLeftEdge) {
|
1999-03-24 18:41:49 +03:00
|
|
|
// As soon as a frame placed on the line advances an X coordinate
|
|
|
|
// of any span we can no longer place a floater on the line.
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_CANPLACEFLOATER, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsLineLayout::AddBulletFrame(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
|
|
|
|
|
|
|
PerFrameData* pfd;
|
|
|
|
nsresult rv = NewPerFrameData(&pfd);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRootSpan->AppendFrame(pfd);
|
|
|
|
pfd->mFrame = aFrame;
|
|
|
|
pfd->mMargin.SizeTo(0, 0, 0, 0);
|
|
|
|
pfd->mBorderPadding.SizeTo(0, 0, 0, 0);
|
|
|
|
pfd->mFrameType = NS_CSS_FRAME_TYPE_INLINE|NS_FRAME_REPLACED_ELEMENT;
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->mFlags = 0; // all flags default to false
|
|
|
|
pfd->SetFlag(PFD_ISBULLET, PR_TRUE);
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mAscent = aMetrics.ascent;
|
|
|
|
pfd->mDescent = aMetrics.descent;
|
1999-09-10 01:04:37 +04:00
|
|
|
|
1999-03-22 23:45:09 +03:00
|
|
|
// Note: y value will be updated during vertical alignment
|
|
|
|
aFrame->GetRect(pfd->mBounds);
|
1999-12-06 18:49:53 +03:00
|
|
|
pfd->mCombinedArea = aMetrics.mOverflowArea;
|
1999-03-19 00:03:25 +03:00
|
|
|
if (mComputeMaxElementSize) {
|
|
|
|
pfd->mMaxElementSize.SizeTo(aMetrics.width, aMetrics.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsLineLayout::DumpPerSpanData(PerSpanData* psd, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
nsFrame::IndentBy(stdout, aIndent);
|
2001-10-25 05:08:40 +04:00
|
|
|
printf("%p: left=%d x=%d right=%d\n", NS_STATIC_CAST(void*, psd),
|
|
|
|
psd->mLeftEdge, psd->mX, psd->mRightEdge);
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
nsFrame::IndentBy(stdout, aIndent+1);
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" %d,%d,%d,%d\n", pfd->mBounds.x, pfd->mBounds.y,
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBounds.width, pfd->mBounds.height);
|
|
|
|
if (pfd->mSpan) {
|
|
|
|
DumpPerSpanData(pfd->mSpan, aIndent + 1);
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VALIGN_OTHER 0
|
|
|
|
#define VALIGN_TOP 1
|
|
|
|
#define VALIGN_BOTTOM 2
|
|
|
|
|
2000-09-12 00:46:44 +04:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::IsPercentageUnitSides(const nsStyleSides* aSides)
|
|
|
|
{
|
|
|
|
return eStyleUnit_Percent == aSides->GetLeftUnit()
|
|
|
|
|| eStyleUnit_Percent == aSides->GetRightUnit()
|
|
|
|
|| eStyleUnit_Percent == aSides->GetTopUnit()
|
|
|
|
|| eStyleUnit_Percent == aSides->GetBottomUnit();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsLineLayout::IsPercentageAwareReplacedElement(nsIPresContext *aPresContext,
|
|
|
|
nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
nsFrameState frameState;
|
|
|
|
aFrame->GetFrameState(&frameState);
|
|
|
|
if (frameState & NS_FRAME_REPLACED_ELEMENT)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
aFrame->GetFrameType(getter_AddRefs(frameType));
|
2000-09-12 01:43:46 +04:00
|
|
|
if (nsLayoutAtoms::brFrame != frameType.get() &&
|
|
|
|
nsLayoutAtoms::textFrame != frameType.get())
|
2000-09-12 00:46:44 +04:00
|
|
|
{
|
2001-02-07 12:57:26 +03:00
|
|
|
nsresult rv;
|
|
|
|
const nsStyleMargin* margin;
|
|
|
|
rv = aFrame->GetStyleData(eStyleStruct_Margin,(const nsStyleStruct*&) margin);
|
2000-09-12 00:46:44 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_TRUE; // just to be on the safe side
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
if (IsPercentageUnitSides(&margin->mMargin)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-09-12 00:46:44 +04:00
|
|
|
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStylePadding* padding;
|
|
|
|
rv = aFrame->GetStyleData(eStyleStruct_Padding,(const nsStyleStruct*&) padding);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_TRUE; // just to be on the safe side
|
|
|
|
}
|
|
|
|
if (IsPercentageUnitSides(&padding->mPadding)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStyleBorder* border;
|
|
|
|
rv = aFrame->GetStyleData(eStyleStruct_Border,(const nsStyleStruct*&) border);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_TRUE; // just to be on the safe side
|
|
|
|
}
|
|
|
|
if (IsPercentageUnitSides(&border->mBorder)) {
|
2000-09-12 00:46:44 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStylePosition* pos;
|
|
|
|
rv = aFrame->GetStyleData(eStyleStruct_Position,(const nsStyleStruct*&) pos);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return PR_TRUE; // just to be on the safe side
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eStyleUnit_Percent == pos->mWidth.GetUnit()
|
|
|
|
|| eStyleUnit_Percent == pos->mMaxWidth.GetUnit()
|
|
|
|
|| eStyleUnit_Percent == pos->mMinWidth.GetUnit()
|
|
|
|
|| eStyleUnit_Percent == pos->mHeight.GetUnit()
|
|
|
|
|| eStyleUnit_Percent == pos->mMinHeight.GetUnit()
|
|
|
|
|| eStyleUnit_Percent == pos->mMaxHeight.GetUnit()
|
|
|
|
|| IsPercentageUnitSides(&pos->mOffset)) { // XXX need more here!!!
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsPercentageAwareFrame(nsIPresContext *aPresContext, nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsFrameState childFrameState;
|
|
|
|
aFrame->GetFrameState(&childFrameState);
|
|
|
|
if (childFrameState & NS_FRAME_REPLACED_ELEMENT) {
|
|
|
|
if (nsLineLayout::IsPercentageAwareReplacedElement(aPresContext, aFrame)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nsIFrame *child;
|
|
|
|
aFrame->FirstChild(aPresContext, nsnull, &child);
|
|
|
|
if (child)
|
|
|
|
{ // aFrame is an inline container frame, check my frame state
|
|
|
|
if (childFrameState & NS_INLINE_FRAME_CONTAINS_PERCENT_AWARE_CHILD) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else it's a frame we just don't care about
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-05 12:24:18 +04:00
|
|
|
void
|
2001-07-04 06:00:05 +04:00
|
|
|
nsLineLayout::VerticalAlignLine(nsLineBox* aLineBox,
|
|
|
|
nsSize& aMaxElementSizeResult,
|
|
|
|
nscoord& aLineBoxAscent)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
|
|
|
// Synthesize a PerFrameData for the block frame
|
|
|
|
PerFrameData rootPFD;
|
|
|
|
rootPFD.mFrame = mBlockReflowState->frame;
|
1999-07-20 07:41:03 +04:00
|
|
|
rootPFD.mFrameType = mBlockReflowState->mFrameType;
|
1999-03-19 00:03:25 +03:00
|
|
|
rootPFD.mAscent = 0;
|
|
|
|
rootPFD.mDescent = 0;
|
|
|
|
mRootSpan->mFrame = &rootPFD;
|
2000-02-15 07:26:44 +03:00
|
|
|
mLineBox = aLineBox;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Partially place the children of the block frame. The baseline for
|
|
|
|
// this operation is set to zero so that the y coordinates for all
|
|
|
|
// of the placed children will be relative to there.
|
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
VerticalAlignFrames(psd);
|
|
|
|
|
|
|
|
// Compute the line-height. The line-height will be the larger of:
|
|
|
|
//
|
|
|
|
// [1] maxY - minY (the distance between the highest childs top edge
|
|
|
|
// and the lowest childs bottom edge)
|
|
|
|
//
|
|
|
|
// [2] the maximum logical box height (since not every frame may have
|
|
|
|
// participated in #1; for example: top/bottom aligned frames)
|
|
|
|
//
|
|
|
|
// [3] the minimum line height (line-height property set on the
|
|
|
|
// block frame)
|
|
|
|
nscoord lineHeight = psd->mMaxY - psd->mMinY;
|
|
|
|
|
|
|
|
// Now that the line-height is computed, we need to know where the
|
|
|
|
// baseline is in the line. Position baseline so that mMinY is just
|
|
|
|
// inside the top of the line box.
|
|
|
|
nscoord baselineY;
|
|
|
|
if (psd->mMinY < 0) {
|
|
|
|
baselineY = mTopEdge - psd->mMinY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
baselineY = mTopEdge;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's also possible that the line-height isn't tall enough because
|
|
|
|
// of top/bottom aligned elements that were not accounted for in
|
|
|
|
// min/max Y.
|
|
|
|
//
|
|
|
|
// The CSS2 spec doesn't really say what happens when to the
|
|
|
|
// baseline in this situations. What we do is if the largest top
|
|
|
|
// aligned box height is greater than the line-height then we leave
|
|
|
|
// the baseline alone. If the largest bottom aligned box is greater
|
|
|
|
// than the line-height then we slide the baseline down by the extra
|
|
|
|
// amount.
|
|
|
|
//
|
|
|
|
// Navigator 4 gives precedence to the first top/bottom aligned
|
|
|
|
// object. We just let bottom aligned objects win.
|
|
|
|
if (lineHeight < mMaxBottomBoxHeight) {
|
|
|
|
// When the line is shorter than the maximum top aligned box
|
|
|
|
nscoord extra = mMaxBottomBoxHeight - lineHeight;
|
|
|
|
baselineY += extra;
|
|
|
|
lineHeight = mMaxBottomBoxHeight;
|
|
|
|
}
|
|
|
|
if (lineHeight < mMaxTopBoxHeight) {
|
|
|
|
lineHeight = mMaxTopBoxHeight;
|
|
|
|
}
|
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [line]==> lineHeight=%d baselineY=%d\n", lineHeight, baselineY);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now position all of the frames in the root span. We will also
|
|
|
|
// recurse over the child spans and place any top/bottom aligned
|
|
|
|
// frames we find.
|
|
|
|
// XXX PERFORMANCE: set a bit per-span to avoid the extra work
|
2001-07-04 06:00:05 +04:00
|
|
|
// (propagate it upward too)
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
nscoord maxElementWidth = 0;
|
|
|
|
nscoord maxElementHeight = 0;
|
2001-08-30 02:59:09 +04:00
|
|
|
PRBool prevFrameAccumulates = PR_FALSE;
|
|
|
|
nscoord accumulatedWidth = 0;
|
2001-09-08 23:26:34 +04:00
|
|
|
#ifdef HACK_MEW
|
|
|
|
PRBool strictMode = InStrictMode();
|
|
|
|
PRBool inUnconstrainedTable = InUnconstrainedTableCell(*mBlockReflowState);
|
|
|
|
#endif
|
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
int frameCount = 0;
|
|
|
|
#endif
|
2001-08-30 02:59:09 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
while (nsnull != pfd) {
|
2001-08-30 02:59:09 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Compute max-element-size if necessary
|
|
|
|
if (mComputeMaxElementSize) {
|
2001-08-30 02:59:09 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord mw = pfd->mMaxElementSize.width +
|
|
|
|
pfd->mMargin.left + pfd->mMargin.right;
|
2000-06-15 03:15:59 +04:00
|
|
|
if (psd->mNoWrap) {
|
|
|
|
maxElementWidth += mw;
|
|
|
|
}
|
|
|
|
else {
|
2001-08-30 02:59:09 +04:00
|
|
|
|
|
|
|
#ifdef HACK_MEW
|
2001-09-29 01:42:03 +04:00
|
|
|
|
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
frameCount++;
|
|
|
|
#endif
|
2001-09-08 23:26:34 +04:00
|
|
|
// if in Quirks mode and in a table cell with an unconstrained width, then emulate an IE
|
|
|
|
// quirk to keep consecutive images from breaking the line
|
2001-08-30 02:59:09 +04:00
|
|
|
// - see bugs 54565, 32191, and their many dups
|
|
|
|
// XXX - reconsider how textFrame text measurement happens and have it take into account
|
|
|
|
// image frames as well, thus eliminating the need for this code
|
2001-09-29 01:42:03 +04:00
|
|
|
if (!strictMode && inUnconstrainedTable ) {
|
2001-09-18 03:13:57 +04:00
|
|
|
|
2001-09-08 23:26:34 +04:00
|
|
|
PRBool inChild = PR_FALSE;
|
2001-09-29 01:42:03 +04:00
|
|
|
nscoord imgSizes = AccumulateImageSizes(*mPresContext, *pfd->mFrame);
|
|
|
|
PRBool curFrameAccumulates = (imgSizes > 0) ||
|
|
|
|
(pfd->mMaxElementSize.width == pfd->mCombinedArea.width &&
|
|
|
|
pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME));
|
|
|
|
// NOTE: we check for the maxElementWidth == the CombinedAreaWidth to detect when
|
|
|
|
// a textframe has whitespace in it and thus should not be used as the basis
|
|
|
|
// for accumulating the image width
|
|
|
|
// - this is to handle images in a text run
|
|
|
|
|
|
|
|
if(prevFrameAccumulates && curFrameAccumulates) {
|
2001-09-08 23:26:34 +04:00
|
|
|
accumulatedWidth += mw;
|
2001-09-29 01:42:03 +04:00
|
|
|
} else {
|
|
|
|
accumulatedWidth = mw;
|
2001-09-08 23:26:34 +04:00
|
|
|
}
|
|
|
|
// now update the prevFrame
|
|
|
|
prevFrameAccumulates = curFrameAccumulates;
|
|
|
|
|
|
|
|
#ifdef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
printf("(%d) last frame's MEW=%d | Accumulated MEW=%d\n", frameCount, mw, accumulatedWidth);
|
|
|
|
#endif // NOISY_MAX_ELEMENT_SIZE
|
|
|
|
|
|
|
|
mw = accumulatedWidth;
|
2001-08-30 02:59:09 +04:00
|
|
|
}
|
2001-09-08 23:26:34 +04:00
|
|
|
|
|
|
|
#endif // HACK_MEW
|
|
|
|
|
2001-08-30 02:59:09 +04:00
|
|
|
// and finally reset the max element width
|
2000-06-15 03:15:59 +04:00
|
|
|
if (maxElementWidth < mw) {
|
|
|
|
maxElementWidth = mw;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2001-08-30 02:59:09 +04:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord mh = pfd->mMaxElementSize.height +
|
|
|
|
pfd->mMargin.top + pfd->mMargin.bottom;
|
|
|
|
if (maxElementHeight < mh) {
|
|
|
|
maxElementHeight = mh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PerSpanData* span = pfd->mSpan;
|
1999-03-22 23:45:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(0xFF != pfd->mVerticalAlign, "umr");
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
switch (pfd->mVerticalAlign) {
|
|
|
|
case VALIGN_TOP:
|
|
|
|
if (span) {
|
|
|
|
pfd->mBounds.y = mTopEdge - pfd->mBorderPadding.top +
|
|
|
|
span->mTopLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = mTopEdge + pfd->mMargin.top;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VALIGN_BOTTOM:
|
|
|
|
if (span) {
|
|
|
|
// Compute bottom leading
|
|
|
|
pfd->mBounds.y = mTopEdge + lineHeight -
|
|
|
|
pfd->mBounds.height + pfd->mBorderPadding.bottom -
|
|
|
|
span->mBottomLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = mTopEdge + lineHeight - pfd->mMargin.bottom -
|
|
|
|
pfd->mBounds.height;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VALIGN_OTHER:
|
|
|
|
pfd->mBounds.y += baselineY;
|
|
|
|
break;
|
|
|
|
}
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [child of line]");
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": y=%d\n", pfd->mBounds.y);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
if (span) {
|
|
|
|
nscoord distanceFromTop = pfd->mBounds.y - mTopEdge;
|
|
|
|
PlaceTopBottomFrames(span, distanceFromTop, lineHeight);
|
|
|
|
}
|
2000-09-12 00:46:44 +04:00
|
|
|
// check to see if the frame is an inline replace element
|
|
|
|
// and if it is percent-aware. If so, mark the line.
|
|
|
|
if ((PR_FALSE==aLineBox->ResizeReflowOptimizationDisabled()) &&
|
|
|
|
pfd->mFrameType & NS_CSS_FRAME_TYPE_INLINE)
|
|
|
|
{
|
|
|
|
if (IsPercentageAwareFrame(mPresContext, pfd->mFrame))
|
|
|
|
aLineBox->DisableResizeReflowOptimization();
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill in returned line-box and max-element-size data
|
2000-02-15 07:26:44 +03:00
|
|
|
aLineBox->mBounds.x = psd->mLeftEdge;
|
|
|
|
aLineBox->mBounds.y = mTopEdge;
|
|
|
|
aLineBox->mBounds.width = psd->mX - psd->mLeftEdge;
|
|
|
|
aLineBox->mBounds.height = lineHeight;
|
1999-10-13 03:27:32 +04:00
|
|
|
mFinalLineHeight = lineHeight;
|
1999-03-19 00:03:25 +03:00
|
|
|
aMaxElementSizeResult.width = maxElementWidth;
|
|
|
|
aMaxElementSizeResult.height = maxElementHeight;
|
2000-06-05 12:24:18 +04:00
|
|
|
aLineBoxAscent = baselineY;
|
2001-07-04 06:00:05 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
|
|
|
printf(
|
|
|
|
" [line]==> bounds{x,y,w,h}={%d,%d,%d,%d} lh=%d a=%d mes{w,h}={%d,%d}\n",
|
|
|
|
aLineBox->mBounds.x, aLineBox->mBounds.y,
|
|
|
|
aLineBox->mBounds.width, aLineBox->mBounds.height,
|
|
|
|
mFinalLineHeight, aLineBoxAscent,
|
|
|
|
aMaxElementSizeResult.width, aMaxElementSizeResult.height);
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Undo root-span mFrame pointer to prevent brane damage later on...
|
|
|
|
mRootSpan->mFrame = nsnull;
|
2000-02-15 07:26:44 +03:00
|
|
|
mLineBox = nsnull;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::PlaceTopBottomFrames(PerSpanData* psd,
|
|
|
|
nscoord aDistanceFromTop,
|
|
|
|
nscoord aLineHeight)
|
|
|
|
{
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
PerSpanData* span = pfd->mSpan;
|
1999-03-22 23:45:09 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
NS_ASSERTION(0xFF != pfd->mVerticalAlign, "umr");
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
switch (pfd->mVerticalAlign) {
|
|
|
|
case VALIGN_TOP:
|
|
|
|
if (span) {
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop - pfd->mBorderPadding.top +
|
|
|
|
span->mTopLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop + pfd->mMargin.top;
|
|
|
|
}
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": y=%d dTop=%d [bp.top=%d topLeading=%d]\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBounds.y, aDistanceFromTop,
|
|
|
|
span ? pfd->mBorderPadding.top : 0,
|
|
|
|
span ? span->mTopLeading : 0);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case VALIGN_BOTTOM:
|
|
|
|
if (span) {
|
|
|
|
// Compute bottom leading
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop + aLineHeight -
|
|
|
|
pfd->mBounds.height + pfd->mBorderPadding.bottom -
|
|
|
|
span->mBottomLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop + aLineHeight -
|
|
|
|
pfd->mMargin.bottom - pfd->mBounds.height;
|
|
|
|
}
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" ");
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": y=%d\n", pfd->mBounds.y);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (span) {
|
1999-03-20 02:07:17 +03:00
|
|
|
nscoord distanceFromTop = aDistanceFromTop + pfd->mBounds.y;
|
1999-03-19 00:03:25 +03:00
|
|
|
PlaceTopBottomFrames(span, distanceFromTop, aLineHeight);
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-15 07:26:44 +03:00
|
|
|
#define VERTICAL_ALIGN_FRAMES_NO_MINIMUM 32767
|
|
|
|
#define VERTICAL_ALIGN_FRAMES_NO_MAXIMUM -32768
|
2000-02-02 10:38:23 +03:00
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Vertically place frames within a given span. Note: this doesn't
|
|
|
|
// place top/bottom aligned frames as those have to wait until the
|
|
|
|
// entire line box height is known. This is called after the span
|
|
|
|
// frame has finished being reflowed so that we know its height.
|
|
|
|
void
|
|
|
|
nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
|
|
|
|
{
|
|
|
|
// Get parent frame info
|
1999-11-02 01:38:17 +03:00
|
|
|
PerFrameData* spanFramePFD = psd->mFrame;
|
|
|
|
nsIFrame* spanFrame = spanFramePFD->mFrame;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Get the parent frame's font for all of the frames in this span
|
|
|
|
const nsStyleFont* parentFont;
|
1999-11-02 01:38:17 +03:00
|
|
|
spanFrame->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&)parentFont);
|
1999-03-19 00:03:25 +03:00
|
|
|
nsIRenderingContext* rc = mBlockReflowState->rendContext;
|
|
|
|
rc->SetFont(parentFont->mFont);
|
1999-09-10 01:04:37 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
rc->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
|
|
|
|
PRBool preMode = (mStyleText->mWhiteSpace == NS_STYLE_WHITESPACE_PRE) ||
|
|
|
|
(mStyleText->mWhiteSpace == NS_STYLE_WHITESPACE_MOZ_PRE_WRAP);
|
1999-11-02 01:38:17 +03:00
|
|
|
|
|
|
|
// See if the span is an empty continuation. It's an empty continuation iff:
|
|
|
|
// - it has a prev-in-flow
|
|
|
|
// - it has no next in flow
|
|
|
|
// - it's zero sized
|
|
|
|
nsIFrame* spanNextInFlow;
|
|
|
|
spanFrame->GetNextInFlow(&spanNextInFlow);
|
|
|
|
nsIFrame* spanPrevInFlow;
|
|
|
|
spanFrame->GetPrevInFlow(&spanPrevInFlow);
|
|
|
|
PRBool emptyContinuation = spanPrevInFlow && !spanNextInFlow &&
|
|
|
|
(0 == spanFramePFD->mBounds.width) && (0 == spanFramePFD->mBounds.height);
|
|
|
|
|
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("[%sSpan]", (psd == mRootSpan)?"Root":"");
|
1999-11-02 01:38:17 +03:00
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": preMode=%s strictMode=%s w/h=%d,%d emptyContinuation=%s",
|
1999-11-02 01:38:17 +03:00
|
|
|
preMode ? "yes" : "no",
|
|
|
|
InStrictMode() ? "yes" : "no",
|
|
|
|
spanFramePFD->mBounds.width, spanFramePFD->mBounds.height,
|
|
|
|
emptyContinuation ? "yes" : "no");
|
|
|
|
if (psd != mRootSpan) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" bp=%d,%d,%d,%d margin=%d,%d,%d,%d",
|
1999-11-02 01:38:17 +03:00
|
|
|
spanFramePFD->mBorderPadding.top,
|
|
|
|
spanFramePFD->mBorderPadding.right,
|
|
|
|
spanFramePFD->mBorderPadding.bottom,
|
|
|
|
spanFramePFD->mBorderPadding.left,
|
|
|
|
spanFramePFD->mMargin.top,
|
|
|
|
spanFramePFD->mMargin.right,
|
|
|
|
spanFramePFD->mMargin.bottom,
|
|
|
|
spanFramePFD->mMargin.left);
|
|
|
|
}
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-11-02 01:38:17 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Compute the span's mZeroEffectiveSpanBox flag. What we are trying
|
|
|
|
// to determine is how we should treat the span: should it act
|
|
|
|
// "normally" according to css2 or should it effectively
|
|
|
|
// "disappear".
|
|
|
|
//
|
|
|
|
// In general, if the document being processed is in strict mode
|
|
|
|
// then it should act normally (with one exception). The exception
|
|
|
|
// case is when a span is continued and yet the span is empty
|
|
|
|
// (e.g. compressed whitespace). For this kind of span we treat it
|
|
|
|
// as if it were not there so that it doesn't impact the
|
|
|
|
// line-height.
|
|
|
|
//
|
|
|
|
// In compatability mode, we should sometimes make it disappear. The
|
|
|
|
// cases that matter are those where the span contains no real text
|
|
|
|
// elements that would provide an ascent and descent and
|
|
|
|
// height. However, if css style elements have been applied to the
|
|
|
|
// span (border/padding/margin) so that it's clear the document
|
|
|
|
// author is intending css2 behavior then we act as if strict mode
|
|
|
|
// is set.
|
|
|
|
//
|
2000-03-16 04:14:57 +03:00
|
|
|
// This code works correctly for preMode, because a blank line
|
|
|
|
// in PRE mode is encoded as a text node with a LF in it, since
|
|
|
|
// text nodes with only whitespace are considered in preMode.
|
2001-10-25 05:08:40 +04:00
|
|
|
//
|
|
|
|
// Much of this logic is shared with the various implementations of
|
|
|
|
// nsIFrame::IsEmpty since they need to duplicate the way it makes
|
|
|
|
// some lines empty. However, nsIFrame::IsEmpty can't be reused here
|
|
|
|
// since this code sets zeroEffectiveSpanBox even when there are
|
|
|
|
// non-empty children.
|
|
|
|
PRBool zeroEffectiveSpanBox = PR_FALSE;
|
2000-03-16 04:14:57 +03:00
|
|
|
if ((emptyContinuation || !InStrictMode()) &&
|
1999-09-10 01:04:37 +04:00
|
|
|
((psd == mRootSpan) ||
|
1999-11-02 01:38:17 +03:00
|
|
|
((0 == spanFramePFD->mBorderPadding.top) &&
|
|
|
|
(0 == spanFramePFD->mBorderPadding.right) &&
|
|
|
|
(0 == spanFramePFD->mBorderPadding.bottom) &&
|
|
|
|
(0 == spanFramePFD->mBorderPadding.left) &&
|
|
|
|
(0 == spanFramePFD->mMargin.top) &&
|
|
|
|
(0 == spanFramePFD->mMargin.right) &&
|
|
|
|
(0 == spanFramePFD->mMargin.bottom) &&
|
|
|
|
(0 == spanFramePFD->mMargin.left)))) {
|
1999-09-10 01:04:37 +04:00
|
|
|
// This code handles an issue with compatability with non-css
|
|
|
|
// conformant browsers. In particular, there are some cases
|
|
|
|
// where the font-size and line-height for a span must be
|
|
|
|
// ignored and instead the span must *act* as if it were zero
|
|
|
|
// sized. In general, if the span contains any non-compressed
|
2000-02-15 07:26:44 +03:00
|
|
|
// text then we don't use this logic.
|
2001-12-24 02:23:41 +03:00
|
|
|
// However, this is not propagated outwards, since (in compatibility
|
2000-02-15 07:26:44 +03:00
|
|
|
// mode) we don't want big line heights for things like
|
|
|
|
// <p><font size="-1">Text</font></p>
|
2002-05-01 04:42:49 +04:00
|
|
|
|
|
|
|
// Don't count the first frame if it's only whitespace. (Somehow
|
|
|
|
// the last frame, if whitespace, is already ignored. So we're not
|
|
|
|
// quite compatible with Nav4.x, but it's probably good that we're
|
|
|
|
// ignoring the last frame. Still, I wonder where the code is
|
|
|
|
// that's doing it.) See bug 134580.
|
|
|
|
PRUint32 flag = preMode ? PFD_ISTEXTFRAME : PFD_ISNONWHITESPACETEXTFRAME;
|
1999-09-10 01:04:37 +04:00
|
|
|
zeroEffectiveSpanBox = PR_TRUE;
|
2002-05-01 04:42:49 +04:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
|
|
|
if (pfd->GetFlag(flag)) {
|
1999-09-10 01:04:37 +04:00
|
|
|
zeroEffectiveSpanBox = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-05-01 04:42:49 +04:00
|
|
|
flag = PFD_ISTEXTFRAME;
|
1999-09-10 01:04:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
psd->mZeroEffectiveSpanBox = zeroEffectiveSpanBox;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Setup baselineY, minY, and maxY
|
|
|
|
nscoord baselineY, minY, maxY;
|
|
|
|
if (psd == mRootSpan) {
|
|
|
|
// Use a zero baselineY since we don't yet know where the baseline
|
|
|
|
// will be (until we know how tall the line is; then we will
|
|
|
|
// know). In addition, use extreme values for the minY and maxY
|
|
|
|
// values so that only the child frames will impact their values
|
|
|
|
// (since these are children of the block, there is no span box to
|
|
|
|
// provide initial values).
|
2000-02-15 07:26:44 +03:00
|
|
|
baselineY = 0;
|
|
|
|
minY = VERTICAL_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
maxY = VERTICAL_ALIGN_FRAMES_NO_MAXIMUM;
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("[RootSpan]");
|
1999-11-02 01:38:17 +03:00
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": pass1 valign frames: topEdge=%d minLineHeight=%d zeroEffectiveSpanBox=%s\n",
|
1999-09-10 01:04:37 +04:00
|
|
|
mTopEdge, mMinLineHeight,
|
|
|
|
zeroEffectiveSpanBox ? "yes" : "no");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
}
|
1999-09-10 01:04:37 +04:00
|
|
|
else {
|
2000-02-15 07:26:44 +03:00
|
|
|
// Compute the logical height for this span. The logical height
|
|
|
|
// is based on the line-height value, not the font-size. Also
|
|
|
|
// compute the top leading.
|
|
|
|
nscoord logicalHeight =
|
|
|
|
nsHTMLReflowState::CalcLineHeight(mPresContext, rc, spanFrame);
|
|
|
|
nscoord contentHeight = spanFramePFD->mBounds.height -
|
|
|
|
spanFramePFD->mBorderPadding.top - spanFramePFD->mBorderPadding.bottom;
|
|
|
|
nscoord leading = logicalHeight - contentHeight;
|
|
|
|
psd->mTopLeading = leading / 2;
|
|
|
|
psd->mBottomLeading = leading - psd->mTopLeading;
|
|
|
|
psd->mLogicalHeight = logicalHeight;
|
|
|
|
|
1999-09-10 01:04:37 +04:00
|
|
|
if (zeroEffectiveSpanBox) {
|
2000-02-15 07:26:44 +03:00
|
|
|
// When the span-box is to be ignored, zero out the initial
|
1999-09-10 01:04:37 +04:00
|
|
|
// values so that the span doesn't impact the final line
|
|
|
|
// height. The contents of the span can impact the final line
|
|
|
|
// height.
|
2000-02-15 07:26:44 +03:00
|
|
|
|
|
|
|
// Note that things are readjusted for this span after its children
|
|
|
|
// are reflowed
|
|
|
|
minY = VERTICAL_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
maxY = VERTICAL_ALIGN_FRAMES_NO_MAXIMUM;
|
1999-09-10 01:04:37 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
// The initial values for the min and max Y values are in the spans
|
|
|
|
// coordinate space, and cover the logical height of the span. If
|
|
|
|
// there are child frames in this span that stick out of this area
|
|
|
|
// then the minY and maxY are updated by the amount of logical
|
|
|
|
// height that is outside this range.
|
1999-11-02 01:38:17 +03:00
|
|
|
minY = spanFramePFD->mBorderPadding.top - psd->mTopLeading;
|
1999-09-10 01:04:37 +04:00
|
|
|
maxY = minY + psd->mLogicalHeight;
|
1999-05-04 00:54:11 +04:00
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
|
|
|
|
// This is the distance from the top edge of the parents visual
|
|
|
|
// box to the baseline. The span already computed this for us,
|
|
|
|
// so just use it.
|
|
|
|
baselineY = spanFramePFD->mAscent;
|
|
|
|
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("[%sSpan]", (psd == mRootSpan)?"Root":"");
|
1999-11-02 01:38:17 +03:00
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": baseLine=%d logicalHeight=%d topLeading=%d h=%d bp=%d,%d zeroEffectiveSpanBox=%s\n",
|
1999-09-10 01:04:37 +04:00
|
|
|
baselineY, psd->mLogicalHeight, psd->mTopLeading,
|
1999-11-02 01:38:17 +03:00
|
|
|
spanFramePFD->mBounds.height,
|
|
|
|
spanFramePFD->mBorderPadding.top, spanFramePFD->mBorderPadding.bottom,
|
1999-09-10 01:04:37 +04:00
|
|
|
zeroEffectiveSpanBox ? "yes" : "no");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord maxTopBoxHeight = 0;
|
|
|
|
nscoord maxBottomBoxHeight = 0;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
nsIFrame* frame = pfd->mFrame;
|
|
|
|
|
2001-11-29 03:10:31 +03:00
|
|
|
// sanity check (see bug 105168, non-reproducable crashes from null frame)
|
|
|
|
NS_ASSERTION(frame, "null frame in PerFrameData - something is very very bad");
|
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Compute the logical height of the frame
|
|
|
|
nscoord logicalHeight;
|
|
|
|
nscoord topLeading;
|
|
|
|
PerSpanData* frameSpan = pfd->mSpan;
|
|
|
|
if (frameSpan) {
|
|
|
|
// For span frames the logical-height and top-leading was
|
|
|
|
// pre-computed when the span was reflowed.
|
|
|
|
logicalHeight = frameSpan->mLogicalHeight;
|
|
|
|
topLeading = frameSpan->mTopLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For other elements the logical height is the same as the
|
|
|
|
// frames height plus its margins.
|
|
|
|
logicalHeight = pfd->mBounds.height + pfd->mMargin.top +
|
|
|
|
pfd->mMargin.bottom;
|
|
|
|
topLeading = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get vertical-align property
|
2001-06-01 02:19:43 +04:00
|
|
|
const nsStyleTextReset* textStyle;
|
|
|
|
frame->GetStyleData(eStyleStruct_TextReset, (const nsStyleStruct*&)textStyle);
|
1999-03-19 00:03:25 +03:00
|
|
|
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
|
1999-11-02 01:12:45 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-19 00:03:25 +03:00
|
|
|
if (eStyleUnit_Inherit == verticalAlignUnit) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("XXX: vertical-align: inherit not implemented for ");
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1999-11-02 01:12:45 +03:00
|
|
|
#endif
|
1999-09-10 01:04:37 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [frame]");
|
1999-09-10 01:04:37 +04:00
|
|
|
nsFrame::ListTag(stdout, frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": verticalAlignUnit=%d (enum == %d)\n",
|
1999-09-10 01:04:37 +04:00
|
|
|
verticalAlignUnit,
|
|
|
|
((eStyleUnit_Enumerated == verticalAlignUnit)
|
|
|
|
? textStyle->mVerticalAlign.GetIntValue()
|
|
|
|
: -1));
|
|
|
|
#endif
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PRUint8 verticalAlignEnum;
|
|
|
|
nscoord parentAscent, parentDescent, parentXHeight;
|
|
|
|
nscoord parentSuperscript, parentSubscript;
|
|
|
|
nscoord coordOffset, percentOffset, elementLineHeight;
|
|
|
|
nscoord revisedBaselineY;
|
|
|
|
switch (verticalAlignUnit) {
|
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
default:
|
|
|
|
if (eStyleUnit_Enumerated == verticalAlignUnit) {
|
|
|
|
verticalAlignEnum = textStyle->mVerticalAlign.GetIntValue();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
verticalAlignEnum = NS_STYLE_VERTICAL_ALIGN_BASELINE;
|
|
|
|
}
|
|
|
|
switch (verticalAlignEnum) {
|
|
|
|
default:
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
|
|
|
// The elements baseline is aligned with the baseline of
|
|
|
|
// the parent.
|
|
|
|
if (frameSpan) {
|
|
|
|
// XXX explain
|
|
|
|
pfd->mBounds.y = baselineY - pfd->mAscent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// For non-span elements the borders, padding and
|
|
|
|
// margins are significant. Use the visual box height
|
|
|
|
// and the bottom margin as the distance off of the
|
|
|
|
// baseline.
|
|
|
|
pfd->mBounds.y = baselineY - pfd->mAscent - pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_SUB:
|
|
|
|
// Lower the baseline of the box to the subscript offset
|
|
|
|
// of the parent's box. This is identical to the baseline
|
|
|
|
// alignment except for the addition of the subscript
|
|
|
|
// offset to the baseline Y.
|
|
|
|
fm->GetSubscriptOffset(parentSubscript);
|
|
|
|
revisedBaselineY = baselineY + parentSubscript;
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent -
|
|
|
|
pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_SUPER:
|
|
|
|
// Raise the baseline of the box to the superscript offset
|
|
|
|
// of the parent's box. This is identical to the baseline
|
|
|
|
// alignment except for the subtraction of the superscript
|
|
|
|
// offset to the baseline Y.
|
|
|
|
fm->GetSuperscriptOffset(parentSuperscript);
|
|
|
|
revisedBaselineY = baselineY - parentSuperscript;
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent -
|
|
|
|
pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
|
|
|
pfd->mVerticalAlign = VALIGN_TOP;
|
|
|
|
if (logicalHeight > maxTopBoxHeight) {
|
|
|
|
maxTopBoxHeight = logicalHeight;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
|
|
|
pfd->mVerticalAlign = VALIGN_BOTTOM;
|
|
|
|
if (logicalHeight > maxBottomBoxHeight) {
|
|
|
|
maxBottomBoxHeight = logicalHeight;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
|
|
|
// Align the midpoint of the frame with 1/2 the parents
|
|
|
|
// x-height above the baseline.
|
|
|
|
fm->GetXHeight(parentXHeight);
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = baselineY -
|
|
|
|
(parentXHeight + pfd->mBounds.height)/2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = baselineY - (parentXHeight + logicalHeight)/2 +
|
|
|
|
pfd->mMargin.top;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
|
|
|
// The top of the logical box is aligned with the top of
|
|
|
|
// the parent elements text.
|
|
|
|
fm->GetMaxAscent(parentAscent);
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = baselineY - parentAscent -
|
|
|
|
pfd->mBorderPadding.top + frameSpan->mTopLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = baselineY - parentAscent + pfd->mMargin.top;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
|
|
|
// The bottom of the logical box is aligned with the
|
|
|
|
// bottom of the parent elements text.
|
|
|
|
fm->GetMaxDescent(parentDescent);
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = baselineY + parentDescent -
|
|
|
|
pfd->mBounds.height + pfd->mBorderPadding.bottom -
|
|
|
|
frameSpan->mBottomLeading;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = baselineY + parentDescent -
|
|
|
|
pfd->mBounds.height - pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
// According to the CSS2 spec (10.8.1), a positive value
|
|
|
|
// "raises" the box by the given distance while a negative value
|
|
|
|
// "lowers" the box by the given distance (with zero being the
|
|
|
|
// baseline). Since Y coordinates increase towards the bottom of
|
|
|
|
// the screen we reverse the sign.
|
|
|
|
coordOffset = textStyle->mVerticalAlign.GetCoordValue();
|
|
|
|
revisedBaselineY = baselineY - coordOffset;
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent -
|
|
|
|
pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
// Similar to a length value (eStyleUnit_Coord) except that the
|
|
|
|
// percentage is a function of the elements line-height value.
|
|
|
|
elementLineHeight =
|
1999-09-10 01:04:37 +04:00
|
|
|
nsHTMLReflowState::CalcLineHeight(mPresContext, rc, frame);
|
1999-03-19 00:03:25 +03:00
|
|
|
percentOffset = nscoord(
|
|
|
|
textStyle->mVerticalAlign.GetPercentValue() * elementLineHeight
|
|
|
|
);
|
|
|
|
revisedBaselineY = baselineY - percentOffset;
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent -
|
|
|
|
pfd->mMargin.bottom;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-10 01:04:37 +04:00
|
|
|
// Update minY/maxY for frames that we just placed. Do not factor
|
|
|
|
// text into the equation.
|
1999-03-19 00:03:25 +03:00
|
|
|
if (pfd->mVerticalAlign == VALIGN_OTHER) {
|
1999-09-10 01:04:37 +04:00
|
|
|
// Text frames do not contribute to the min/max Y values for the
|
|
|
|
// line (instead their parent frame's font-size contributes).
|
2001-09-27 22:34:30 +04:00
|
|
|
// XXXrbs -- relax this restriction because it causes text frames
|
|
|
|
// to jam together when 'font-size-adjust' is enabled
|
|
|
|
// and layout is using dynamic font heights (bug 20394)
|
|
|
|
// -- Note #1: With this code enabled and with the fact that we are not
|
|
|
|
// using Em[Ascent|Descent] as nsDimensions for text metrics in
|
|
|
|
// GFX mean that the discussion in bug 13072 cannot hold.
|
|
|
|
// -- Note #2: We still don't want empty-text frames to interfere.
|
|
|
|
// For example in quirks mode, avoiding empty text frames prevents
|
|
|
|
// "tall" lines around elements like <hr> since the rules of <hr>
|
|
|
|
// in quirks.css have pseudo text contents with LF in them.
|
|
|
|
#if 0
|
2000-04-17 18:40:46 +04:00
|
|
|
if (!pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
2001-09-27 22:34:30 +04:00
|
|
|
#else
|
|
|
|
// Only consider non empty text frames when line-height=normal
|
|
|
|
PRBool canUpdate = !pfd->GetFlag(PFD_ISTEXTFRAME);
|
|
|
|
if (!canUpdate && pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME)) {
|
|
|
|
const nsStyleText* textStyle;
|
|
|
|
frame->GetStyleData(eStyleStruct_Text, (const nsStyleStruct*&)textStyle);
|
|
|
|
canUpdate = textStyle->mLineHeight.GetUnit() == eStyleUnit_Normal ||
|
|
|
|
textStyle->mLineHeight.GetUnit() == eStyleUnit_Null;
|
|
|
|
}
|
|
|
|
if (canUpdate) {
|
|
|
|
#endif
|
1999-09-10 01:04:37 +04:00
|
|
|
nscoord yTop, yBottom;
|
|
|
|
if (frameSpan) {
|
|
|
|
// For spans that were are now placing, use their position
|
|
|
|
// plus their already computed min-Y and max-Y values for
|
|
|
|
// computing yTop and yBottom.
|
|
|
|
yTop = pfd->mBounds.y + frameSpan->mMinY;
|
|
|
|
yBottom = pfd->mBounds.y + frameSpan->mMaxY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
yTop = pfd->mBounds.y - pfd->mMargin.top;
|
|
|
|
yBottom = yTop + logicalHeight;
|
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
if (!preMode && !InStrictMode() && !logicalHeight ) {
|
|
|
|
// Check if it's a BR frame that is not alone on its line (it
|
|
|
|
// is given a height of zero to indicate this), and if so reset
|
|
|
|
// yTop and yBottom so that BR frames don't influence the line.
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
frame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::brFrame == frameType.get()) {
|
|
|
|
yTop = VERTICAL_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
yBottom = VERTICAL_ALIGN_FRAMES_NO_MAXIMUM;
|
|
|
|
}
|
|
|
|
}
|
1999-09-10 01:04:37 +04:00
|
|
|
if (yTop < minY) minY = yTop;
|
|
|
|
if (yBottom > maxY) maxY = yBottom;
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [frame]raw: a=%d d=%d h=%d bp=%d,%d logical: h=%d leading=%d y=%d minY=%d maxY=%d\n",
|
1999-09-10 01:04:37 +04:00
|
|
|
pfd->mAscent, pfd->mDescent, pfd->mBounds.height,
|
|
|
|
pfd->mBorderPadding.top, pfd->mBorderPadding.bottom,
|
|
|
|
logicalHeight,
|
|
|
|
pfd->mSpan ? topLeading : 0,
|
|
|
|
pfd->mBounds.y, minY, maxY);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
1999-09-10 01:04:37 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
if (psd != mRootSpan) {
|
1999-11-24 09:03:41 +03:00
|
|
|
frame->SetRect(mPresContext, pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
1999-09-10 01:04:37 +04:00
|
|
|
|
|
|
|
// Factor in the minimum line-height when handling the root-span for
|
|
|
|
// the block.
|
|
|
|
if (psd == mRootSpan) {
|
2000-02-15 07:26:44 +03:00
|
|
|
// We should factor in the block element's minimum line-height (as
|
|
|
|
// defined in section 10.8.1 of the css2 spec) assuming that
|
|
|
|
// mZeroEffectiveSpanBox is not set on the root span. This only happens
|
|
|
|
// in some cases in quirks mode:
|
|
|
|
// (1) if the root span contains non-whitespace text directly (this
|
|
|
|
// is handled by mZeroEffectiveSpanBox
|
|
|
|
// (2) if this is the first line of an LI element (whether or not
|
|
|
|
// there is a bullet (NN4/IE5 quirk)
|
|
|
|
// (3) if this is the last line of an LI, DT, or DD element
|
|
|
|
// (The last line before a block also counts, but not before a
|
|
|
|
// BR) (NN4/IE5 quirk)
|
|
|
|
PRBool applyMinLH = !(psd->mZeroEffectiveSpanBox); // (1) above
|
|
|
|
PRBool isFirstLine = !mLineNumber; // if the line number is 0
|
2000-04-17 18:40:46 +04:00
|
|
|
PRBool isLastLine = (!mLineBox->IsLineWrapped() && !GetFlag(LL_LINEENDSINBR));
|
2000-10-04 08:17:36 +04:00
|
|
|
PRBool foundLI = PR_FALSE; // hack to fix bug 50480.
|
|
|
|
//XXX: rather than remembering if we've found an LI, we really should be checking
|
|
|
|
// for the existence of a bullet frame. Likewise, the code below should not
|
|
|
|
// be checking for any particular content tag type, but rather should
|
|
|
|
// be checking for the existence of a bullet frame to determine if it's a list element or not.
|
2000-02-15 07:26:44 +03:00
|
|
|
if (!applyMinLH && (isFirstLine || isLastLine)) {
|
|
|
|
nsCOMPtr<nsIContent> blockContent;
|
|
|
|
nsresult result = mRootSpan->mFrame->mFrame->GetContent(getter_AddRefs(blockContent));
|
|
|
|
if ( NS_SUCCEEDED(result) && blockContent) {
|
|
|
|
nsCOMPtr<nsIAtom> blockTagAtom;
|
|
|
|
result = blockContent->GetTag(*(getter_AddRefs(blockTagAtom)));
|
|
|
|
if ( NS_SUCCEEDED(result) && blockTagAtom) {
|
|
|
|
// (2) above, if the first line of LI
|
2000-03-16 04:14:57 +03:00
|
|
|
if (isFirstLine && blockTagAtom.get() == nsHTMLAtoms::li) {
|
2002-03-15 11:03:18 +03:00
|
|
|
// if the line is empty, then don't force the min height (see bug 75963)
|
|
|
|
if (!IsZeroHeight()) {
|
2001-04-20 01:54:35 +04:00
|
|
|
applyMinLH = PR_TRUE;
|
|
|
|
foundLI = PR_TRUE;
|
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
|
|
|
// (3) above, if the last line of LI, DT, or DD
|
2000-10-04 08:17:36 +04:00
|
|
|
else if (!applyMinLH && isLastLine &&
|
2000-03-16 04:14:57 +03:00
|
|
|
((blockTagAtom.get() == nsHTMLAtoms::li) ||
|
|
|
|
(blockTagAtom.get() == nsHTMLAtoms::dt) ||
|
|
|
|
(blockTagAtom.get() == nsHTMLAtoms::dd))) {
|
2000-02-15 07:26:44 +03:00
|
|
|
applyMinLH = PR_TRUE;
|
2000-03-16 04:14:57 +03:00
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
|
|
|
}
|
1999-09-10 01:04:37 +04:00
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
if (applyMinLH) {
|
2000-10-04 08:17:36 +04:00
|
|
|
if ((psd->mX != psd->mLeftEdge) || preMode || foundLI) {
|
1999-09-10 01:04:37 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [span]==> adjusting min/maxY: currentValues: %d,%d", minY, maxY);
|
1999-09-10 01:04:37 +04:00
|
|
|
#endif
|
2000-02-15 07:26:44 +03:00
|
|
|
nscoord minimumLineHeight = mMinLineHeight;
|
1999-09-10 01:04:37 +04:00
|
|
|
nscoord fontAscent, fontHeight;
|
|
|
|
fm->GetMaxAscent(fontAscent);
|
1999-10-13 03:27:32 +04:00
|
|
|
if (nsHTMLReflowState::UseComputedHeight()) {
|
|
|
|
fontHeight = parentFont->mFont.size;
|
|
|
|
}
|
2000-02-02 10:38:23 +03:00
|
|
|
else
|
|
|
|
{
|
2000-02-15 07:26:44 +03:00
|
|
|
fm->GetHeight(fontHeight);
|
1999-10-13 03:27:32 +04:00
|
|
|
}
|
2000-02-02 10:38:23 +03:00
|
|
|
|
1999-09-10 01:04:37 +04:00
|
|
|
nscoord leading = minimumLineHeight - fontHeight;
|
|
|
|
nscoord yTop = -fontAscent - leading/2;
|
|
|
|
nscoord yBottom = yTop + minimumLineHeight;
|
|
|
|
if (yTop < minY) minY = yTop;
|
|
|
|
if (yBottom > maxY) maxY = yBottom;
|
2000-02-02 10:38:23 +03:00
|
|
|
|
1999-09-10 01:04:37 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" new values: %d,%d\n", minY, maxY);
|
1999-09-10 01:04:37 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// XXX issues:
|
|
|
|
// [1] BR's on empty lines stop working
|
|
|
|
// [2] May not honor css2's notion of handling empty elements
|
|
|
|
// [3] blank lines in a pre-section ("\n") (handled with preMode)
|
2000-02-19 06:42:30 +03:00
|
|
|
|
|
|
|
// XXX Are there other problems with this?
|
1999-09-10 01:04:37 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [span]==> zapping min/maxY: currentValues: %d,%d newValues: 0,0\n",
|
1999-09-10 01:04:37 +04:00
|
|
|
minY, maxY);
|
|
|
|
#endif
|
|
|
|
minY = maxY = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-15 07:26:44 +03:00
|
|
|
if ((minY == VERTICAL_ALIGN_FRAMES_NO_MINIMUM) ||
|
|
|
|
(maxY == VERTICAL_ALIGN_FRAMES_NO_MINIMUM)) {
|
2000-03-16 04:14:57 +03:00
|
|
|
minY = maxY = baselineY;
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((psd != mRootSpan) && (psd->mZeroEffectiveSpanBox)) {
|
2000-02-19 06:42:30 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [span]adjusting for zeroEffectiveSpanBox\n");
|
|
|
|
printf(" Original: minY=%d, maxY=%d, height=%d, ascent=%d, descent=%d, logicalHeight=%d, topLeading=%d, bottomLeading=%d\n",
|
2000-02-19 06:42:30 +03:00
|
|
|
minY, maxY, spanFramePFD->mBounds.height,
|
|
|
|
spanFramePFD->mAscent, spanFramePFD->mDescent,
|
|
|
|
psd->mLogicalHeight, psd->mTopLeading, psd->mBottomLeading);
|
|
|
|
#endif
|
2000-02-15 07:26:44 +03:00
|
|
|
nscoord goodMinY = spanFramePFD->mBorderPadding.top - psd->mTopLeading;
|
|
|
|
nscoord goodMaxY = goodMinY + psd->mLogicalHeight;
|
|
|
|
if (minY > goodMinY) {
|
|
|
|
nscoord adjust = minY - goodMinY; // positive
|
|
|
|
|
|
|
|
// shrink the logical extents
|
|
|
|
psd->mLogicalHeight -= adjust;
|
|
|
|
psd->mTopLeading -= adjust;
|
|
|
|
}
|
|
|
|
if (maxY < goodMaxY) {
|
|
|
|
nscoord adjust = goodMaxY - maxY;
|
|
|
|
psd->mLogicalHeight -= adjust;
|
|
|
|
psd->mBottomLeading -= adjust;
|
|
|
|
}
|
|
|
|
if (minY > 0) {
|
|
|
|
|
|
|
|
// shrink the content by moving its top down. This is tricky, since
|
|
|
|
// the top is the 0 for many coordinates, so what we do is
|
|
|
|
// move everything else up.
|
|
|
|
spanFramePFD->mAscent -= minY; // move the baseline up
|
|
|
|
spanFramePFD->mBounds.height -= minY; // move the bottom up
|
|
|
|
psd->mTopLeading += minY;
|
|
|
|
|
|
|
|
pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
pfd->mBounds.y -= minY; // move all the children back up
|
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
maxY -= minY; // since minY is in the frame's own coordinate system
|
|
|
|
minY = 0;
|
|
|
|
}
|
2000-02-19 06:42:30 +03:00
|
|
|
if (maxY < spanFramePFD->mBounds.height) {
|
|
|
|
nscoord adjust = spanFramePFD->mBounds.height - maxY;
|
2000-02-15 07:26:44 +03:00
|
|
|
spanFramePFD->mBounds.height -= adjust; // move the bottom up
|
|
|
|
spanFramePFD->mDescent -= adjust;
|
|
|
|
psd->mBottomLeading += adjust;
|
|
|
|
}
|
2000-02-19 06:42:30 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" New: minY=%d, maxY=%d, height=%d, ascent=%d, descent=%d, logicalHeight=%d, topLeading=%d, bottomLeading=%d\n",
|
2000-02-19 06:42:30 +03:00
|
|
|
minY, maxY, spanFramePFD->mBounds.height,
|
|
|
|
spanFramePFD->mAscent, spanFramePFD->mDescent,
|
|
|
|
psd->mLogicalHeight, psd->mTopLeading, psd->mBottomLeading);
|
|
|
|
#endif
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
psd->mMinY = minY;
|
|
|
|
psd->mMaxY = maxY;
|
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" [span]==> minY=%d maxY=%d delta=%d maxTopBoxHeight=%d maxBottomBoxHeight=%d\n",
|
1999-03-21 00:55:22 +03:00
|
|
|
minY, maxY, maxY - minY, maxTopBoxHeight, maxBottomBoxHeight);
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
if (maxTopBoxHeight > mMaxTopBoxHeight) {
|
|
|
|
mMaxTopBoxHeight = maxTopBoxHeight;
|
|
|
|
}
|
|
|
|
if (maxBottomBoxHeight > mMaxBottomBoxHeight) {
|
|
|
|
mMaxBottomBoxHeight = maxBottomBoxHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-21 04:14:22 +04:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::TrimTrailingWhiteSpaceIn(PerSpanData* psd,
|
|
|
|
nscoord* aDeltaWidth)
|
|
|
|
{
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifndef IBMBIDI
|
1999-09-21 04:14:22 +04:00
|
|
|
// XXX what about NS_STYLE_DIRECTION_RTL?
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
|
|
|
*aDeltaWidth = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif
|
1999-09-21 04:14:22 +04:00
|
|
|
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
if (!pfd) {
|
|
|
|
*aDeltaWidth = 0;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
pfd = pfd->Last();
|
|
|
|
while (nsnull != pfd) {
|
1999-09-24 21:23:33 +04:00
|
|
|
#ifdef REALLY_NOISY_TRIM
|
|
|
|
nsFrame::ListTag(stdout, (psd == mRootSpan
|
|
|
|
? mBlockReflowState->frame
|
|
|
|
: psd->mFrame->mFrame));
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": attempting trim of ");
|
1999-09-24 21:23:33 +04:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("\n");
|
1999-09-24 21:23:33 +04:00
|
|
|
#endif
|
|
|
|
PerSpanData* childSpan = pfd->mSpan;
|
|
|
|
if (childSpan) {
|
1999-09-21 04:14:22 +04:00
|
|
|
// Maybe the child span has the trailing white-space in it?
|
1999-09-24 21:23:33 +04:00
|
|
|
if (TrimTrailingWhiteSpaceIn(childSpan, aDeltaWidth)) {
|
|
|
|
nscoord deltaWidth = *aDeltaWidth;
|
|
|
|
if (deltaWidth) {
|
|
|
|
// Adjust the child spans frame size
|
|
|
|
pfd->mBounds.width -= deltaWidth;
|
1999-09-21 04:14:22 +04:00
|
|
|
if (psd != mRootSpan) {
|
1999-09-24 21:23:33 +04:00
|
|
|
// When the child span is not a direct child of the block
|
|
|
|
// we need to update the child spans frame rectangle
|
|
|
|
// because it most likely will not be done again. Spans
|
|
|
|
// that are direct children of the block will be updated
|
|
|
|
// later, however, because the VerticalAlignFrames method
|
|
|
|
// will be run after this method.
|
1999-09-21 04:14:22 +04:00
|
|
|
nsRect r;
|
1999-09-24 21:23:33 +04:00
|
|
|
nsIFrame* f = pfd->mFrame;
|
|
|
|
f->GetRect(r);
|
|
|
|
r.width -= deltaWidth;
|
1999-11-24 09:03:41 +03:00
|
|
|
f->SetRect(mPresContext, r);
|
1999-09-24 21:23:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the right edge of the span that contains the child span
|
|
|
|
psd->mX -= deltaWidth;
|
|
|
|
|
|
|
|
// Slide any frames that follow the child span over by the
|
|
|
|
// right amount. The only thing that can follow the child
|
|
|
|
// span is empty stuff, so we are just making things
|
|
|
|
// sensible (keeping the combined area honest).
|
|
|
|
while (pfd->mNext) {
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
pfd->mBounds.x -= deltaWidth;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else if (!pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
1999-09-21 04:14:22 +04:00
|
|
|
// If we hit a frame on the end that's not text, then there is
|
|
|
|
// no trailing whitespace to trim. Stop the search.
|
|
|
|
*aDeltaWidth = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
else if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME)) {
|
1999-09-21 04:14:22 +04:00
|
|
|
nscoord deltaWidth = 0;
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->TrimTrailingWhiteSpace(mPresContext,
|
1999-10-30 06:52:11 +04:00
|
|
|
*mBlockReflowState->rendContext,
|
|
|
|
deltaWidth);
|
1999-09-24 21:23:33 +04:00
|
|
|
#ifdef NOISY_TRIM
|
1999-10-30 06:52:11 +04:00
|
|
|
nsFrame::ListTag(stdout, (psd == mRootSpan
|
|
|
|
? mBlockReflowState->frame
|
|
|
|
: psd->mFrame->mFrame));
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": trim of ");
|
1999-10-30 06:52:11 +04:00
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(" returned %d\n", deltaWidth);
|
1999-09-24 21:23:33 +04:00
|
|
|
#endif
|
1999-10-30 06:52:11 +04:00
|
|
|
if (deltaWidth) {
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->mJustificationNumSpaces > 0) {
|
|
|
|
pfd->mJustificationNumSpaces--;
|
|
|
|
}
|
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
pfd->mBounds.width -= deltaWidth;
|
|
|
|
pfd->mCombinedArea.width -= deltaWidth;
|
|
|
|
if (0 == pfd->mBounds.width) {
|
|
|
|
pfd->mMaxElementSize.width = 0;
|
|
|
|
pfd->mMaxElementSize.height = 0;
|
|
|
|
}
|
1999-09-21 04:14:22 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// See if the text frame has already been placed in its parent
|
|
|
|
if (psd != mRootSpan) {
|
|
|
|
// The frame was already placed during psd's
|
|
|
|
// reflow. Update the frames rectangle now.
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-10-30 06:52:11 +04:00
|
|
|
}
|
1999-09-21 04:14:22 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Adjust containing span's right edge
|
|
|
|
psd->mX -= deltaWidth;
|
1999-09-21 04:14:22 +04:00
|
|
|
|
1999-10-30 06:52:11 +04:00
|
|
|
// Slide any frames that follow the text frame over by the
|
|
|
|
// right amount. The only thing that can follow the text
|
|
|
|
// frame is empty stuff, so we are just making things
|
|
|
|
// sensible (keeping the combined area honest).
|
|
|
|
while (pfd->mNext) {
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
pfd->mBounds.x -= deltaWidth;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass up to caller so they can shrink their span
|
|
|
|
*aDeltaWidth = deltaWidth;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
pfd = pfd->mPrev;
|
|
|
|
}
|
1999-10-30 06:52:11 +04:00
|
|
|
|
1999-09-21 04:14:22 +04:00
|
|
|
*aDeltaWidth = 0;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-10-13 03:27:32 +04:00
|
|
|
PRBool
|
1999-09-21 04:14:22 +04:00
|
|
|
nsLineLayout::TrimTrailingWhiteSpace()
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
1999-09-21 04:14:22 +04:00
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
nscoord deltaWidth;
|
|
|
|
TrimTrailingWhiteSpaceIn(psd, &deltaWidth);
|
1999-10-13 03:27:32 +04:00
|
|
|
return 0 != deltaWidth;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
void
|
|
|
|
nsLineLayout::ComputeJustificationWeights(PerSpanData* aPSD,
|
|
|
|
PRInt32* aNumSpaces,
|
|
|
|
PRInt32* aNumLetters)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPSD, "null arg");
|
|
|
|
NS_ASSERTION(aNumSpaces, "null arg");
|
|
|
|
NS_ASSERTION(aNumLetters, "null arg");
|
|
|
|
PRInt32 numSpaces = 0;
|
|
|
|
PRInt32 numLetters = 0;
|
|
|
|
|
|
|
|
for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nsnull; pfd = pfd->mNext) {
|
|
|
|
|
|
|
|
if (PR_TRUE == pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
|
|
|
numSpaces += pfd->mJustificationNumSpaces;
|
|
|
|
numLetters += pfd->mJustificationNumLetters;
|
|
|
|
}
|
|
|
|
else if (pfd->mSpan != nsnull) {
|
|
|
|
PRInt32 spanSpaces;
|
|
|
|
PRInt32 spanLetters;
|
|
|
|
|
|
|
|
ComputeJustificationWeights(pfd->mSpan, &spanSpaces, &spanLetters);
|
|
|
|
|
|
|
|
numSpaces += spanSpaces;
|
|
|
|
numLetters += spanLetters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNumSpaces = numSpaces;
|
|
|
|
*aNumLetters = numLetters;
|
|
|
|
}
|
|
|
|
|
|
|
|
nscoord
|
|
|
|
nsLineLayout::ApplyFrameJustification(PerSpanData* aPSD, FrameJustificationState* aState)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aPSD, "null arg");
|
|
|
|
NS_ASSERTION(aState, "null arg");
|
|
|
|
|
|
|
|
nscoord deltaX = 0;
|
|
|
|
for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nsnull; pfd = pfd->mNext) {
|
|
|
|
// Don't reposition bullets (and other frames that occur out of X-order?)
|
|
|
|
if (!pfd->GetFlag(PFD_ISBULLET)) {
|
|
|
|
nscoord dw = 0;
|
|
|
|
|
|
|
|
pfd->mBounds.x += deltaX;
|
|
|
|
|
|
|
|
if (PR_TRUE == pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
|
|
|
if (aState->mTotalWidthForSpaces > 0 &&
|
|
|
|
aState->mTotalNumSpaces > 0 && // we divide by this value, so must be non-zero
|
|
|
|
aState->mTotalNumLetters >0 // we divide by this value, so must be non-zero
|
|
|
|
) {
|
|
|
|
aState->mNumSpacesProcessed += pfd->mJustificationNumSpaces;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForSpaces =
|
|
|
|
(aState->mTotalWidthForSpaces*aState->mNumSpacesProcessed)
|
|
|
|
/aState->mTotalNumSpaces;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForSpaces - aState->mWidthForSpacesProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForSpacesProcessed = newAllocatedWidthForSpaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aState->mTotalWidthForLetters > 0) {
|
|
|
|
aState->mNumLettersProcessed += pfd->mJustificationNumLetters;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForLetters =
|
|
|
|
(aState->mTotalWidthForLetters*aState->mNumLettersProcessed)
|
|
|
|
/aState->mTotalNumLetters;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForLetters - aState->mWidthForLettersProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForLettersProcessed = newAllocatedWidthForLetters;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
dw += ApplyFrameJustification(pfd->mSpan, aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pfd->mBounds.width += dw;
|
|
|
|
deltaX += dw;
|
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deltaX;
|
|
|
|
}
|
|
|
|
|
2000-01-03 07:32:13 +03:00
|
|
|
PRBool
|
|
|
|
nsLineLayout::HorizontalAlignFrames(nsRect& aLineBounds,
|
|
|
|
PRBool aAllowJustify,
|
|
|
|
PRBool aShrinkWrapWidth)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
nscoord availWidth = psd->mRightEdge;
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == availWidth) {
|
|
|
|
// Don't bother horizontal aligning on pass1 table reflow
|
1999-09-24 21:23:33 +04:00
|
|
|
#ifdef NOISY_HORIZONTAL_ALIGN
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": skipping horizontal alignment in pass1 table reflow\n");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
2000-01-03 07:32:13 +03:00
|
|
|
return PR_TRUE;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
|
|
|
// This is to ensure proper indentation (e.g. of list items)
|
|
|
|
availWidth -= aLineBounds.x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif // IBMBIDI
|
1999-03-19 00:03:25 +03:00
|
|
|
availWidth -= psd->mLeftEdge;
|
|
|
|
nscoord remainingWidth = availWidth - aLineBounds.width;
|
1999-09-24 21:23:33 +04:00
|
|
|
#ifdef NOISY_HORIZONTAL_ALIGN
|
1999-03-19 00:03:25 +03:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2000-10-29 02:17:53 +04:00
|
|
|
printf(": availWidth=%d lineWidth=%d delta=%d\n",
|
1999-03-19 00:03:25 +03:00
|
|
|
availWidth, aLineBounds.width, remainingWidth);
|
|
|
|
#endif
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (remainingWidth + aLineBounds.x > 0) {
|
|
|
|
#else
|
2002-05-01 04:42:49 +04:00
|
|
|
// XXXldb What if it's less than 0??
|
1999-03-19 00:03:25 +03:00
|
|
|
if (remainingWidth > 0) {
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord dx = 0;
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
PRUint32 textAlign = mTextAlign;
|
|
|
|
// here is where we do special adjustments for HR's
|
|
|
|
// see bug 18754
|
|
|
|
if (!InStrictMode()) {
|
|
|
|
if (psd->mFirstFrame && psd->mFirstFrame->mFrame)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
psd->mFirstFrame->mFrame->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::hrFrame == frameType.get()) {
|
|
|
|
// get the alignment from the HR frame
|
|
|
|
{
|
2001-02-07 12:57:26 +03:00
|
|
|
const nsStyleMargin* margin;
|
|
|
|
psd->mFirstFrame->mFrame->GetStyleData(eStyleStruct_Margin,
|
|
|
|
(const nsStyleStruct*&)margin);
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
textAlign = NS_STYLE_TEXT_ALIGN_CENTER;
|
|
|
|
nsStyleCoord zero(nscoord(0));
|
|
|
|
nsStyleCoord temp;
|
2001-02-07 12:57:26 +03:00
|
|
|
if ((eStyleUnit_Coord==margin->mMargin.GetLeftUnit()) &&
|
|
|
|
(zero==margin->mMargin.GetLeft(temp)))
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
{
|
|
|
|
textAlign = NS_STYLE_TEXT_ALIGN_LEFT;
|
|
|
|
}
|
2001-02-07 12:57:26 +03:00
|
|
|
else if ((eStyleUnit_Coord==margin->mMargin.GetRightUnit()) &&
|
|
|
|
(zero==margin->mMargin.GetRight(temp))) {
|
bug 14280
nsTextTransformer.cpp.
I moved where we translate the nbsp to a (ascii 32 space character) until after the i18n routines are called, so they can properly account
for the space as non-breaking and therefore part of the first word in the block.
bug 39901 and 38396
nsHTMLImageLoader.*, nsImageFrame.cpp
I backed out the bad fix for 38396, and put in a new fix where I store a little state in the image loader flags for cases where the image
gets an unconstrained reflow and has %-based width. This does not handle %-based min-width or max-width, that would be a separate
bug that I'll file shortly. But this fixes the vast majority of real cases out there.
bug 18754
nsHRFrame.cpp, quirks.css, nsCSSFrameConstructor.cpp, last part of nsLineLayout.cpp
in quirks mode, I changed HR from a block element to a replaced inline element that acts like a block, using generated content to get
newlines before and after the HR. This isn't ideal, but it gets us backwards compatibility, and ian and dbaron have blessed the approach.
bug 50257
nsLineLayout.cpp
Did a couple of things in here:
* The actual fix is controlled by FIX_BUG_50257 #define symbol. This basically says that an break (BR) will always fit on a line.
A more general solution would probably be to round up to the nearest pixel, and if the thing is less than a pixel make it fit on a
line. This is a wimpier, safer solution.
* I noticed that the way we got the compatibility mode was way out of date, very wasteful. So I fixed that.
* I noticed that there were a bunch of redundant SetFlag calls. Since the flag variable is initialized to 0, setting a flag to 0 on a newly
created object is a waste.
nsBlockFrame.cpp -- just added a comment to some odd looking code, to make sure no one comes along later and breaks it
2000-09-12 01:15:02 +04:00
|
|
|
textAlign = NS_STYLE_TEXT_ALIGN_RIGHT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (textAlign) {
|
1999-03-19 00:03:25 +03:00
|
|
|
case NS_STYLE_TEXT_ALIGN_DEFAULT:
|
1999-03-22 23:45:09 +03:00
|
|
|
if (NS_STYLE_DIRECTION_LTR == psd->mDirection) {
|
1999-03-19 00:03:25 +03:00
|
|
|
// default alignment for left-to-right is left so do nothing
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Fall through to align right case for default alignment
|
|
|
|
// used when the direction is right-to-left.
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
1999-03-25 06:49:29 +03:00
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
|
2000-09-21 10:03:39 +04:00
|
|
|
{
|
|
|
|
// fix for bug 50758
|
|
|
|
// right-aligned text in a text control doesn't know how to paint itself
|
|
|
|
// so we force the invalidate here. Getting the current line is quick,
|
|
|
|
// and at worst we're invalidating more of the line (and just that line) than we need to.
|
|
|
|
nsLineBox *currentLine=nsnull;
|
|
|
|
// use localResult because a failure here should not be propagated to my caller
|
|
|
|
nsresult localResult = nsBlockFrame::GetCurrentLine(mBlockRS, ¤tLine);
|
|
|
|
if (NS_SUCCEEDED(localResult) && currentLine) {
|
|
|
|
currentLine->SetForceInvalidate(PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
dx = remainingWidth;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_JUSTIFY:
|
|
|
|
// If this is not the last line then go ahead and justify the
|
|
|
|
// frames in the line. If it is the last line then if the
|
|
|
|
// direction is right-to-left then we right-align the frames.
|
|
|
|
if (aAllowJustify) {
|
2000-04-17 18:40:46 +04:00
|
|
|
if (!aShrinkWrapWidth) {
|
|
|
|
PRInt32 numSpaces;
|
|
|
|
PRInt32 numLetters;
|
|
|
|
|
|
|
|
ComputeJustificationWeights(psd, &numSpaces, &numLetters);
|
|
|
|
|
|
|
|
if (numSpaces > 0) {
|
|
|
|
FrameJustificationState state = { numSpaces, numLetters, remainingWidth, 0, 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
ApplyFrameJustification(psd, &state);
|
|
|
|
}
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1999-03-22 23:45:09 +03:00
|
|
|
else if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
1999-03-19 00:03:25 +03:00
|
|
|
// right align the frames
|
1999-03-22 23:45:09 +03:00
|
|
|
dx = remainingWidth;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_CENTER:
|
1999-03-25 06:49:29 +03:00
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_CENTER:
|
1999-03-19 00:03:25 +03:00
|
|
|
dx = remainingWidth / 2;
|
|
|
|
break;
|
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
PerFrameData* lastPfd = psd->mLastFrame;
|
|
|
|
PerFrameData* bulletPfd = nsnull;
|
|
|
|
|
|
|
|
if (lastPfd->GetFlag(PFD_ISBULLET)
|
|
|
|
&& (NS_STYLE_DIRECTION_RTL == psd->mDirection) ) {
|
|
|
|
bulletPfd = lastPfd;
|
|
|
|
lastPfd = lastPfd->mPrev;
|
|
|
|
}
|
|
|
|
PRUint32 maxX = lastPfd->mBounds.XMost() + dx;
|
|
|
|
PRBool visualRTL = PR_FALSE;
|
|
|
|
|
|
|
|
if ( (NS_STYLE_DIRECTION_RTL == psd->mDirection)
|
|
|
|
&& (!psd->mChangedFrameDirection) ) {
|
|
|
|
psd->mChangedFrameDirection = PR_TRUE;
|
|
|
|
|
|
|
|
/* Assume that all frames have been right aligned.*/
|
|
|
|
if (aShrinkWrapWidth) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
mPresContext->IsVisualMode(visualRTL);
|
|
|
|
|
|
|
|
if (bulletPfd) {
|
|
|
|
bulletPfd->mBounds.x += maxX;
|
|
|
|
bulletPfd->mFrame->SetRect(mPresContext, bulletPfd->mBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( (0 != dx) || (visualRTL) ) {
|
|
|
|
#else
|
1999-03-19 00:03:25 +03:00
|
|
|
if (0 != dx) {
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif // IBMBIDI
|
2000-01-03 07:32:13 +03:00
|
|
|
// If we need to move the frames but we're shrink wrapping, then
|
|
|
|
// we need to wait until the final width is known
|
|
|
|
if (aShrinkWrapWidth) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
while ( (nsnull != pfd) && (bulletPfd != pfd) ) {
|
|
|
|
#else
|
1999-03-19 00:03:25 +03:00
|
|
|
while (nsnull != pfd) {
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif // IBMBIDI
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBounds.x += dx;
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
if (visualRTL) {
|
2002-01-31 02:28:56 +03:00
|
|
|
maxX = pfd->mBounds.x = maxX - (pfd->mMargin.left + pfd->mBounds.width + pfd->mMargin.right);
|
2001-04-12 03:32:21 +04:00
|
|
|
}
|
|
|
|
#endif // IBMBIDI
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
|
|
|
aLineBounds.x += dx;
|
|
|
|
#else
|
1999-10-15 03:10:59 +04:00
|
|
|
aLineBounds.width += dx;
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif
|
1999-05-08 04:48:39 +04:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifndef IBMBIDI
|
1999-09-21 04:14:22 +04:00
|
|
|
if ((NS_STYLE_DIRECTION_RTL == psd->mDirection) &&
|
|
|
|
!psd->mChangedFrameDirection) {
|
1999-05-08 04:48:39 +04:00
|
|
|
psd->mChangedFrameDirection = PR_TRUE;
|
|
|
|
|
|
|
|
/* Assume that all frames have been right aligned.*/
|
2000-01-03 07:32:13 +03:00
|
|
|
if (aShrinkWrapWidth) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-05-08 04:48:39 +04:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
PRUint32 maxX = psd->mRightEdge;
|
|
|
|
while (nsnull != pfd) {
|
2002-01-31 02:28:56 +03:00
|
|
|
pfd->mBounds.x = maxX - (pfd->mMargin.left + pfd->mBounds.width + pfd->mMargin.right);
|
1999-11-24 09:03:41 +03:00
|
|
|
pfd->mFrame->SetRect(mPresContext, pfd->mBounds);
|
1999-05-08 04:48:39 +04:00
|
|
|
maxX = pfd->mBounds.x;
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif // ndef IBMBIDI
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2000-01-03 07:32:13 +03:00
|
|
|
|
|
|
|
return PR_TRUE;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::RelativePositionFrames(nsRect& aCombinedArea)
|
|
|
|
{
|
|
|
|
RelativePositionFrames(mRootSpan, aCombinedArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::RelativePositionFrames(PerSpanData* psd, nsRect& aCombinedArea)
|
|
|
|
{
|
|
|
|
nsPoint origin;
|
|
|
|
nsRect spanCombinedArea;
|
|
|
|
PerFrameData* pfd;
|
|
|
|
|
1999-11-02 01:38:17 +03:00
|
|
|
nscoord minX, minY, maxX, maxY;
|
1999-03-19 00:03:25 +03:00
|
|
|
if (nsnull != psd->mFrame) {
|
|
|
|
// The minimum combined area for the frames in a span covers the
|
|
|
|
// entire span frame.
|
|
|
|
pfd = psd->mFrame;
|
1999-11-02 01:38:17 +03:00
|
|
|
minX = 0;
|
|
|
|
minY = 0;
|
|
|
|
maxX = pfd->mBounds.width;
|
|
|
|
maxY = pfd->mBounds.height;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The minimum combined area for the frames that are direct
|
|
|
|
// children of the block starts at the upper left corner of the
|
1999-10-13 03:27:32 +04:00
|
|
|
// line and is sized to match the size of the line's bounding box
|
|
|
|
// (the same size as the values returned from VerticalAlignFrames)
|
1999-11-02 01:38:17 +03:00
|
|
|
minX = psd->mLeftEdge;
|
|
|
|
maxX = psd->mX;
|
|
|
|
minY = mTopEdge;
|
|
|
|
maxY = mTopEdge + mFinalLineHeight;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pfd = psd->mFirstFrame;
|
1999-09-21 04:14:22 +04:00
|
|
|
PRBool updatedCombinedArea = PR_FALSE;
|
1999-03-19 00:03:25 +03:00
|
|
|
while (nsnull != pfd) {
|
|
|
|
nscoord x = pfd->mBounds.x;
|
|
|
|
nscoord y = pfd->mBounds.y;
|
|
|
|
|
|
|
|
// Adjust the origin of the frame
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_RELATIVEPOS)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
nsIFrame* frame = pfd->mFrame;
|
|
|
|
frame->GetOrigin(origin);
|
|
|
|
// XXX what about right and bottom?
|
|
|
|
nscoord dx = pfd->mOffsets.left;
|
|
|
|
nscoord dy = pfd->mOffsets.top;
|
1999-11-24 09:03:41 +03:00
|
|
|
frame->MoveTo(mPresContext, origin.x + dx, origin.y + dy);
|
1999-03-19 00:03:25 +03:00
|
|
|
x += dx;
|
|
|
|
y += dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note: the combined area of a child is in its coordinate
|
|
|
|
// system. We adjust the childs combined area into our coordinate
|
|
|
|
// system before computing the aggregated value by adding in
|
|
|
|
// <b>x</b> and <b>y</b> which were computed above.
|
|
|
|
nsRect* r = &pfd->mCombinedArea;
|
|
|
|
if (pfd->mSpan) {
|
|
|
|
// Compute a new combined area for the child span before
|
|
|
|
// aggregating it into our combined area.
|
|
|
|
r = &spanCombinedArea;
|
|
|
|
RelativePositionFrames(pfd->mSpan, spanCombinedArea);
|
|
|
|
}
|
|
|
|
|
2001-03-29 10:39:40 +04:00
|
|
|
// see bug 21415: we used to prevent empty inlines from impacting the
|
|
|
|
// size of the combined area, however that is wrong so now we allow
|
|
|
|
// empty inlines to contribute to the line's combined area.
|
|
|
|
// - the following comment is being preserved in case there are issues
|
|
|
|
// with floaters, as is alluded to.
|
|
|
|
#if 0
|
1999-09-21 04:14:22 +04:00
|
|
|
// Only if the frame has some area do we let it affect the
|
|
|
|
// combined area. Otherwise empty frames placed next to a floating
|
|
|
|
// element will cause the floaters margin to be relevant, which we
|
|
|
|
// don't want to happen.
|
|
|
|
if (r->width && r->height) {
|
2001-03-29 10:39:40 +04:00
|
|
|
#else
|
|
|
|
if(PR_TRUE) {
|
|
|
|
#endif
|
1999-09-21 04:14:22 +04:00
|
|
|
nscoord xl = x + r->x;
|
|
|
|
nscoord xr = x + r->XMost();
|
1999-11-02 01:38:17 +03:00
|
|
|
if (xl < minX) {
|
|
|
|
minX = xl;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
1999-11-02 01:38:17 +03:00
|
|
|
if (xr > maxX) {
|
|
|
|
maxX = xr;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
nscoord yt = y + r->y;
|
|
|
|
nscoord yb = y + r->YMost();
|
1999-11-02 01:38:17 +03:00
|
|
|
if (yt < minY) {
|
|
|
|
minY = yt;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
1999-11-02 01:38:17 +03:00
|
|
|
if (yb > maxY) {
|
|
|
|
maxY = yb;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
updatedCombinedArea = PR_TRUE;
|
1999-03-21 00:55:22 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute aggregated combined area
|
1999-09-21 04:14:22 +04:00
|
|
|
if (updatedCombinedArea) {
|
1999-11-02 01:38:17 +03:00
|
|
|
aCombinedArea.x = minX;
|
|
|
|
aCombinedArea.y = minY;
|
|
|
|
aCombinedArea.width = maxX - minX;
|
|
|
|
aCombinedArea.height = maxY - minY;
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aCombinedArea.x = 0;
|
1999-11-02 01:38:17 +03:00
|
|
|
aCombinedArea.y = minY;
|
1999-09-21 04:14:22 +04:00
|
|
|
aCombinedArea.width = 0;
|
|
|
|
aCombinedArea.height = 0;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// If we just computed a spans combined area, we need to update its
|
|
|
|
// NS_FRAME_OUTSIDE_CHILDREN bit..
|
|
|
|
if (nsnull != psd->mFrame) {
|
|
|
|
pfd = psd->mFrame;
|
|
|
|
nsIFrame* frame = pfd->mFrame;
|
|
|
|
nsFrameState oldState;
|
|
|
|
frame->GetFrameState(&oldState);
|
|
|
|
nsFrameState newState = oldState & ~NS_FRAME_OUTSIDE_CHILDREN;
|
1999-11-02 01:38:17 +03:00
|
|
|
if ((minX < 0) || (minY < 0) ||
|
|
|
|
(maxX > pfd->mBounds.width) || (maxY > pfd->mBounds.height)) {
|
1999-03-19 00:03:25 +03:00
|
|
|
newState |= NS_FRAME_OUTSIDE_CHILDREN;
|
|
|
|
}
|
|
|
|
if (newState != oldState) {
|
|
|
|
frame->SetFrameState(newState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::ForgetWordFrame(nsIFrame* aFrame)
|
|
|
|
{
|
2002-03-20 00:57:45 +03:00
|
|
|
if (0 != mWordFrames.GetSize()) {
|
|
|
|
NS_ASSERTION((void*)aFrame == mWordFrames.PeekFront(), "forget-word-frame");
|
|
|
|
mWordFrames.PopFront();
|
1998-10-20 04:23:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-10 08:35:01 +04:00
|
|
|
nsIFrame*
|
2000-07-27 09:16:08 +04:00
|
|
|
nsLineLayout::FindNextText(nsIPresContext* aPresContext, nsIFrame* aFrame)
|
1998-10-10 08:35:01 +04:00
|
|
|
{
|
2000-07-27 09:16:08 +04:00
|
|
|
// Grovel through the frame hierarchy to find a text frame that is
|
|
|
|
// "adjacent" to aFrame.
|
|
|
|
|
|
|
|
// So this is kind of funky. During reflow, overflow frames will
|
|
|
|
// have their parent pointers set up lazily. We assume that, on
|
|
|
|
// entry, aFrame has it's parent pointer set correctly (as do all of
|
|
|
|
// its ancestors). Starting from that, we need to make sure that as
|
|
|
|
// we traverse through frames trying to find the next text frame, we
|
|
|
|
// leave the frames with their parent pointers set correctly, so the
|
|
|
|
// *next* time we come through here, we're good to go.
|
|
|
|
|
|
|
|
// Build a path from the enclosing block frame down to aFrame. We'll
|
|
|
|
// use this to walk the frame tree. (XXXwaterson if I was clever, I
|
|
|
|
// wouldn't need to build this up before hand, and could incorporate
|
|
|
|
// this logic into the walking code directly.)
|
|
|
|
nsAutoVoidArray stack;
|
1998-10-10 08:35:01 +04:00
|
|
|
for (;;) {
|
2000-07-27 09:16:08 +04:00
|
|
|
stack.InsertElementAt(aFrame, 0);
|
|
|
|
|
|
|
|
aFrame->GetParent(&aFrame);
|
|
|
|
|
|
|
|
NS_ASSERTION(aFrame != nsnull, "wow, no block frame found");
|
|
|
|
if (! aFrame)
|
1998-10-10 08:35:01 +04:00
|
|
|
break;
|
|
|
|
|
2000-07-27 09:20:09 +04:00
|
|
|
const nsStyleDisplay* display;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Display, NS_REINTERPRET_CAST(const nsStyleStruct*&, display));
|
|
|
|
if (NS_STYLE_DISPLAY_INLINE != display->mDisplay)
|
2000-07-27 09:16:08 +04:00
|
|
|
break;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
1998-10-10 08:35:01 +04:00
|
|
|
|
2000-07-27 09:16:08 +04:00
|
|
|
// Using the path we've built up, walk the frame tree looking for
|
|
|
|
// the text frame that follows aFrame.
|
|
|
|
PRInt32 count;
|
|
|
|
while ((count = stack.Count()) != 0) {
|
|
|
|
PRInt32 lastIndex = count - 1;
|
|
|
|
nsIFrame* top = NS_STATIC_CAST(nsIFrame*, stack.ElementAt(lastIndex));
|
1998-10-10 08:35:01 +04:00
|
|
|
|
2000-10-10 02:03:03 +04:00
|
|
|
// If this is a frame that'll break a word, then bail.
|
|
|
|
PRBool canContinue;
|
|
|
|
top->CanContinueTextRun(canContinue);
|
|
|
|
if (! canContinue)
|
2000-10-13 04:44:53 +04:00
|
|
|
return nsnull;
|
2000-10-10 02:03:03 +04:00
|
|
|
|
|
|
|
// Advance to top's next sibling
|
2000-07-27 09:16:08 +04:00
|
|
|
nsIFrame* next;
|
|
|
|
top->GetNextSibling(&next);
|
|
|
|
|
|
|
|
if (! next) {
|
2000-10-10 02:03:03 +04:00
|
|
|
// No more siblings. Pop the top element to walk back up the
|
|
|
|
// frame tree.
|
2000-07-27 09:16:08 +04:00
|
|
|
stack.RemoveElementAt(lastIndex);
|
|
|
|
continue;
|
1999-09-02 22:01:59 +04:00
|
|
|
}
|
2000-07-27 09:16:08 +04:00
|
|
|
|
|
|
|
// We know top's parent is good, but next's might not be. So let's
|
|
|
|
// set it to be sure.
|
|
|
|
nsIFrame* parent;
|
|
|
|
top->GetParent(&parent);
|
|
|
|
next->SetParent(parent);
|
|
|
|
|
|
|
|
// Save next at the top of the stack...
|
|
|
|
stack.ReplaceElementAt(next, lastIndex);
|
|
|
|
|
2000-10-13 04:44:53 +04:00
|
|
|
// ...and prowl down to next's deepest child. We'll need to check
|
|
|
|
// for potential run-busters "on the way down", too.
|
2000-07-27 09:16:08 +04:00
|
|
|
for (;;) {
|
2000-10-13 04:44:53 +04:00
|
|
|
next->CanContinueTextRun(canContinue);
|
|
|
|
if (! canContinue)
|
|
|
|
return nsnull;
|
|
|
|
|
2000-07-27 09:16:08 +04:00
|
|
|
nsIFrame* child;
|
|
|
|
next->FirstChild(aPresContext, nsnull, &child);
|
|
|
|
|
|
|
|
if (! child)
|
|
|
|
break;
|
|
|
|
|
|
|
|
stack.AppendElement(child);
|
|
|
|
next = child;
|
1999-09-02 22:01:59 +04:00
|
|
|
}
|
2000-07-27 09:16:08 +04:00
|
|
|
|
|
|
|
// Ignore continuing frames
|
|
|
|
nsIFrame* prevInFlow;
|
|
|
|
next->GetPrevInFlow(&prevInFlow);
|
|
|
|
if (prevInFlow)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If this is a text frame, return it.
|
|
|
|
nsCOMPtr<nsIAtom> frameType;
|
|
|
|
next->GetFrameType(getter_AddRefs(frameType));
|
|
|
|
if (nsLayoutAtoms::textFrame == frameType.get())
|
|
|
|
return next;
|
1999-09-02 22:01:59 +04:00
|
|
|
}
|
|
|
|
|
2000-07-27 09:16:08 +04:00
|
|
|
// If we get here, then there are no more text frames in this block.
|
|
|
|
return nsnull;
|
1998-10-10 08:35:01 +04:00
|
|
|
}
|
|
|
|
|
2000-07-27 09:16:08 +04:00
|
|
|
|
1998-07-22 22:38:57 +04:00
|
|
|
PRBool
|
1999-03-19 00:03:25 +03:00
|
|
|
nsLineLayout::TreatFrameAsBlock(nsIFrame* aFrame)
|
1998-07-22 22:38:57 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
const nsStyleDisplay* display;
|
|
|
|
aFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&) display);
|
2001-06-01 02:19:43 +04:00
|
|
|
if (NS_STYLE_POSITION_ABSOLUTE == display->mPosition) {
|
1998-07-22 22:38:57 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
if (NS_STYLE_FLOAT_NONE != display->mFloats) {
|
1998-07-22 22:38:57 +04:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
switch (display->mDisplay) {
|
1998-07-22 22:38:57 +04:00
|
|
|
case NS_STYLE_DISPLAY_BLOCK:
|
|
|
|
case NS_STYLE_DISPLAY_LIST_ITEM:
|
1998-11-11 06:54:47 +03:00
|
|
|
case NS_STYLE_DISPLAY_RUN_IN:
|
|
|
|
case NS_STYLE_DISPLAY_COMPACT:
|
1998-07-22 22:38:57 +04:00
|
|
|
case NS_STYLE_DISPLAY_TABLE:
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|