2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-18 20:25:41 +04:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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>
|
2003-01-02 02:53:20 +03:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2000-04-17 18:40:46 +04:00
|
|
|
* Robert O'Callahan <roc+moz@cs.cmu.edu>
|
2004-06-20 13:51:10 +04:00
|
|
|
* IBM Corporation
|
2005-08-31 02:46:45 +04:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* state and methods used while laying out a single line of a block frame */
|
|
|
|
|
2004-07-15 21:50:34 +04:00
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK (sizeof(void*)-1)
|
|
|
|
#include "plarena.h"
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
2004-05-05 05:46:15 +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"
|
2001-10-26 09:06:07 +04:00
|
|
|
#include "nsSpaceManager.h"
|
2003-02-22 03:32:13 +03:00
|
|
|
#include "nsStyleContext.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-09-23 06:31:16 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
2008-03-13 05:36:58 +03:00
|
|
|
#include "nsIThebesFontMetrics.h"
|
1999-03-19 00:03:25 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1999-04-25 21:01:07 +04:00
|
|
|
#include "nsPlaceholderFrame.h"
|
1999-09-03 07:47:49 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIHTMLDocument.h"
|
|
|
|
#include "nsIContent.h"
|
2000-04-17 18:40:46 +04:00
|
|
|
#include "nsTextFragment.h"
|
2002-02-19 23:41:32 +03:00
|
|
|
#include "nsBidiUtils.h"
|
2004-09-13 17:35:46 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-09-24 06:19:14 +04:00
|
|
|
#include "nsTextFrame.h"
|
2008-02-16 18:31:27 +03:00
|
|
|
#include "nsCSSRendering.h"
|
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
|
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
|
2001-10-26 09:06:07 +04:00
|
|
|
nsSpaceManager* aSpaceManager,
|
2007-01-18 04:20:09 +03:00
|
|
|
const nsHTMLReflowState* aOuterReflowState,
|
|
|
|
const nsLineList::iterator* aLine)
|
1999-03-19 00:03:25 +03:00
|
|
|
: mPresContext(aPresContext),
|
|
|
|
mSpaceManager(aSpaceManager),
|
|
|
|
mBlockReflowState(aOuterReflowState),
|
2006-10-19 05:47:47 +04:00
|
|
|
mLastOptionalBreakContent(nsnull),
|
|
|
|
mForceBreakContent(nsnull),
|
|
|
|
mLastOptionalBreakContentOffset(-1),
|
|
|
|
mForceBreakContentOffset(-1),
|
2008-07-24 11:16:18 +04:00
|
|
|
mLastOptionalBreakPriority(eNoBreak),
|
1999-04-28 02:13:06 +04:00
|
|
|
mBlockRS(nsnull),/* XXX temporary */
|
1999-08-28 01:50:06 +04:00
|
|
|
mMinLineHeight(0),
|
2006-10-19 05:47:47 +04:00
|
|
|
mTextIndent(0)
|
1998-06-18 20:25:41 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
NS_ASSERTION(aSpaceManager || aOuterReflowState->frame->GetType() ==
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::letterFrame,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
"space manager should be present");
|
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
|
2003-05-15 07:42:21 +04:00
|
|
|
mStyleText = aOuterReflowState->frame->GetStyleText();
|
1999-03-19 00:03:25 +03:00
|
|
|
mTextAlign = mStyleText->mTextAlign;
|
1998-06-18 20:25:41 +04:00
|
|
|
mLineNumber = 0;
|
2000-04-17 18:40:46 +04:00
|
|
|
mFlags = 0; // default all flags to false except those that follow here...
|
2003-10-14 01:51:02 +04:00
|
|
|
mPlacedFloats = 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
mTotalPlacedFrames = 0;
|
2005-06-17 06:46:36 +04:00
|
|
|
mTopEdge = 0;
|
2007-10-20 11:30:26 +04:00
|
|
|
mTrimmableWidth = 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2002-08-14 17:00:16 +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
|
2005-11-21 01:05:24 +03:00
|
|
|
// frames and spans won't waste a lot of time in unneeded
|
2002-08-14 17:00:16 +04:00
|
|
|
// initialization.
|
2004-07-15 21:50:34 +04:00
|
|
|
PL_INIT_ARENA_POOL(&mArena, "nsLineLayout", 1024);
|
2002-08-14 17:00:16 +04:00
|
|
|
mFrameFreeList = nsnull;
|
|
|
|
mSpanFreeList = nsnull;
|
|
|
|
|
1999-03-30 03:46:34 +04:00
|
|
|
mCurrentSpan = mRootSpan = nsnull;
|
1999-03-19 00:03:25 +03:00
|
|
|
mSpanDepth = 0;
|
|
|
|
|
2007-01-18 04:20:09 +03:00
|
|
|
if (aLine) {
|
|
|
|
SetFlag(LL_GOTLINEBOX, PR_TRUE);
|
|
|
|
mLineBox = *aLine;
|
|
|
|
}
|
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");
|
|
|
|
|
2004-07-15 21:50:34 +04:00
|
|
|
// PL_FreeArenaPool takes our memory and puts in on a global free list so
|
|
|
|
// that the next time an arena makes an allocation it will not have to go
|
|
|
|
// all the way down to malloc. This is desirable as this class is created
|
|
|
|
// and destroyed in a tight loop.
|
|
|
|
//
|
|
|
|
// I looked at the code. It is not technically necessary to call
|
|
|
|
// PL_FinishArenaPool() after PL_FreeArenaPool(), but from an API
|
|
|
|
// standpoint, I think we are susposed to. It will be very fast anyway,
|
|
|
|
// since PL_FreeArenaPool() has done all the work.
|
|
|
|
PL_FreeArenaPool(&mArena);
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
}
|
|
|
|
|
2002-05-14 16:55:55 +04:00
|
|
|
// Find out if the frame has a non-null prev-in-flow, i.e., whether it
|
|
|
|
// is a continuation.
|
|
|
|
inline PRBool
|
|
|
|
HasPrevInFlow(nsIFrame *aFrame)
|
|
|
|
{
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame *prevInFlow = aFrame->GetPrevInFlow();
|
2002-05-14 16:55:55 +04:00
|
|
|
return prevInFlow != nsnull;
|
|
|
|
}
|
|
|
|
|
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,
|
2003-10-14 01:51:02 +04:00
|
|
|
PRBool aImpactedByFloats,
|
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");
|
2007-12-13 00:51:00 +03:00
|
|
|
NS_ASSERTION(aWidth != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"should no longer be using unconstrained widths");
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aWidth != NS_UNCONSTRAINEDSIZE) && CRAZY_WIDTH(aWidth)) {
|
2002-12-11 05:38:33 +03:00
|
|
|
NS_NOTREACHED("bad width");
|
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);
|
|
|
|
}
|
1999-03-21 00:55:22 +03:00
|
|
|
if ((aHeight != NS_UNCONSTRAINEDSIZE) && CRAZY_HEIGHT(aHeight)) {
|
2002-12-11 05:38:33 +03:00
|
|
|
NS_NOTREACHED("bad height");
|
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);
|
|
|
|
}
|
|
|
|
#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,
|
2003-10-14 01:51:02 +04:00
|
|
|
aImpactedByFloats?"true":"false",
|
1999-03-19 00:03:25 +03:00
|
|
|
aIsTopOfPage ? "top-of-page" : "");
|
|
|
|
#endif
|
2002-08-14 17:00:16 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0;
|
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_FIRSTLETTERSTYLEOK, PR_FALSE);
|
|
|
|
SetFlag(LL_ISTOPOFPAGE, aIsTopOfPage);
|
2003-10-14 01:51:02 +04:00
|
|
|
mPlacedFloats = 0;
|
|
|
|
SetFlag(LL_IMPACTEDBYFLOATS, aImpactedByFloats);
|
1999-03-19 00:03:25 +03:00
|
|
|
mTotalPlacedFrames = 0;
|
2008-06-14 12:28:07 +04:00
|
|
|
SetFlag(LL_LINEISEMPTY, PR_TRUE);
|
2000-04-17 18:40:46 +04:00
|
|
|
SetFlag(LL_LINEENDSINBR, PR_FALSE);
|
1999-03-19 00:03:25 +03:00
|
|
|
mSpanDepth = 0;
|
|
|
|
mMaxTopBoxHeight = mMaxBottomBoxHeight = 0;
|
|
|
|
|
|
|
|
PerSpanData* psd;
|
|
|
|
NewPerSpanData(&psd);
|
|
|
|
mCurrentSpan = mRootSpan = psd;
|
|
|
|
psd->mReflowState = mBlockReflowState;
|
|
|
|
psd->mLeftEdge = aX;
|
|
|
|
psd->mX = aX;
|
2007-12-13 00:51:00 +03:00
|
|
|
psd->mRightEdge = aX + aWidth;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
mTopEdge = aY;
|
1999-03-22 23:45:09 +03:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
psd->mNoWrap = !mStyleText->WhiteSpaceCanWrap();
|
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.
|
2006-10-19 05:47:47 +04:00
|
|
|
|
2002-05-14 16:55:55 +04:00
|
|
|
if (0 == mLineNumber && !HasPrevInFlow(mBlockReflowState->frame)) {
|
2001-12-11 05:45:44 +03:00
|
|
|
nscoord indent = 0;
|
|
|
|
nsStyleUnit unit = mStyleText->mTextIndent.GetUnit();
|
|
|
|
if (eStyleUnit_Coord == unit) {
|
|
|
|
indent = mStyleText->mTextIndent.GetCoordValue();
|
|
|
|
}
|
|
|
|
else if (eStyleUnit_Percent == unit) {
|
|
|
|
nscoord width =
|
2004-04-24 21:56:23 +04:00
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState);
|
2002-06-03 22:35:04 +04:00
|
|
|
if ((0 != width) && (NS_UNCONSTRAINEDSIZE != width)) {
|
2001-12-11 05:45:44 +03:00
|
|
|
indent = nscoord(mStyleText->mTextIndent.GetPercentValue() * width);
|
|
|
|
}
|
2007-05-30 19:08:50 +04:00
|
|
|
if (GetFlag(LL_GOTLINEBOX)) {
|
|
|
|
mLineBox->DisableResizeReflowOptimization();
|
|
|
|
}
|
2001-12-11 05:45:44 +03:00
|
|
|
}
|
|
|
|
|
2002-05-14 16:55:55 +04:00
|
|
|
mTextIndent = indent;
|
|
|
|
|
2001-12-11 05:45:44 +03:00
|
|
|
if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
2007-12-13 00:51:00 +03:00
|
|
|
psd->mRightEdge -= indent;
|
2001-12-11 05:45:44 +03:00
|
|
|
}
|
|
|
|
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
|
|
|
|
|
2002-08-14 17:00:16 +04:00
|
|
|
FreeSpan(mRootSpan);
|
1999-03-30 03:46:34 +04:00
|
|
|
mCurrentSpan = mRootSpan = nsnull;
|
2002-08-14 17:00:16 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(mSpansAllocated == mSpansFreed, "leak");
|
|
|
|
NS_ASSERTION(mFramesAllocated == mFramesFreed, "leak");
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
static PRInt32 maxSpansAllocated = NS_LINELAYOUT_NUM_SPANS;
|
|
|
|
static PRInt32 maxFramesAllocated = NS_LINELAYOUT_NUM_FRAMES;
|
|
|
|
if (mSpansAllocated > maxSpansAllocated) {
|
|
|
|
printf("XXX: saw a line with %d spans\n", mSpansAllocated);
|
|
|
|
maxSpansAllocated = mSpansAllocated;
|
|
|
|
}
|
|
|
|
if (mFramesAllocated > maxFramesAllocated) {
|
|
|
|
printf("XXX: saw a line with %d frames\n", mFramesAllocated);
|
|
|
|
maxFramesAllocated = mFramesAllocated;
|
|
|
|
}
|
|
|
|
#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
|
2008-06-11 03:53:22 +04:00
|
|
|
nsLineLayout::UpdateBand(const nsRect& aNewAvailSpace,
|
2003-10-14 01:51:02 +04:00
|
|
|
PRBool aPlacedLeftFloat,
|
|
|
|
nsIFrame* aFloatFrame)
|
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",
|
2008-06-11 03:53:22 +04:00
|
|
|
aNewAvailSpace.x, aNewAvailSpace.y,
|
|
|
|
aNewAvailSpace.width, aNewAvailSpace.height,
|
|
|
|
aFloatFrame, aPlacedLeftFloat?"true":"false");
|
2000-03-23 02:19:10 +03:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef DEBUG
|
2008-06-11 03:53:22 +04:00
|
|
|
if ((aNewAvailSpace.width != NS_UNCONSTRAINEDSIZE) && CRAZY_WIDTH(aNewAvailSpace.width)) {
|
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",
|
2008-06-11 03:53:22 +04:00
|
|
|
aNewAvailSpace.width, aNewAvailSpace.width);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2008-06-11 03:53:22 +04:00
|
|
|
if ((aNewAvailSpace.height != NS_UNCONSTRAINEDSIZE) && CRAZY_HEIGHT(aNewAvailSpace.height)) {
|
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",
|
2008-06-11 03:53:22 +04:00
|
|
|
aNewAvailSpace.height, aNewAvailSpace.height);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
1999-03-24 18:41:49 +03:00
|
|
|
|
|
|
|
// Compute the difference between last times width and the new width
|
2008-06-11 03:53:22 +04:00
|
|
|
NS_ASSERTION(mRootSpan->mRightEdge != NS_UNCONSTRAINEDSIZE &&
|
|
|
|
aNewAvailSpace.width != NS_UNCONSTRAINEDSIZE,
|
2007-12-13 00:51:00 +03:00
|
|
|
"shouldn't use unconstrained widths anymore");
|
2008-06-11 03:53:22 +04:00
|
|
|
// The root span's mLeftEdge moves to aX
|
|
|
|
nscoord deltaX = aNewAvailSpace.x - mRootSpan->mLeftEdge;
|
|
|
|
// The width of all spans changes by this much (the root span's
|
|
|
|
// mRightEdge moves to aX + aWidth, its new width is aWidth)
|
|
|
|
nscoord deltaWidth = aNewAvailSpace.width - (mRootSpan->mRightEdge - mRootSpan->mLeftEdge);
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2008-06-11 03:53:22 +04:00
|
|
|
printf(": UpdateBand: %d,%d,%d,%d deltaWidth=%d deltaX=%d %s float\n",
|
|
|
|
aNewAvailSpace.x, aNewAvailSpace.y,
|
|
|
|
aNewAvailSpace.width, aNewAvailSpace.height, deltaWidth, deltaX,
|
2003-10-14 01:51:02 +04:00
|
|
|
aPlacedLeftFloat ? "left" : "right");
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
2008-06-11 03:53:22 +04:00
|
|
|
// Update the root span position
|
|
|
|
mRootSpan->mLeftEdge += deltaX;
|
|
|
|
mRootSpan->mRightEdge += deltaX;
|
|
|
|
mRootSpan->mX += deltaX;
|
1999-03-24 18:41:49 +03:00
|
|
|
|
2008-06-11 03:53:22 +04:00
|
|
|
// Now update the right edges of the open spans to account for any
|
|
|
|
// change in available space width
|
|
|
|
for (PerSpanData* psd = mCurrentSpan; psd; psd = psd->mParent) {
|
2007-12-13 00:51:00 +03:00
|
|
|
psd->mRightEdge += deltaWidth;
|
2003-10-14 01:51:02 +04:00
|
|
|
psd->mContainsFloat = PR_TRUE;
|
2008-08-12 13:29:35 +04:00
|
|
|
NS_ASSERTION(psd->mX - mTrimmableWidth <= psd->mRightEdge,
|
2008-06-11 03:53:22 +04:00
|
|
|
"We placed a float where there was no room!");
|
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",
|
2008-06-11 03:53:22 +04:00
|
|
|
psd, psd->mRightEdge - deltaRightEdge, psd->mRightEdge);
|
1999-03-24 18:41:49 +03:00
|
|
|
#endif
|
|
|
|
}
|
2008-06-11 03:53:22 +04:00
|
|
|
NS_ASSERTION(mRootSpan->mContainsFloat &&
|
|
|
|
mRootSpan->mLeftEdge == aNewAvailSpace.x &&
|
|
|
|
mRootSpan->mRightEdge == aNewAvailSpace.XMost(),
|
|
|
|
"root span was updated incorrectly?");
|
|
|
|
|
|
|
|
// Update frame bounds
|
|
|
|
// 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.
|
|
|
|
if (deltaX != 0) {
|
|
|
|
for (PerFrameData* pfd = mRootSpan->mFirstFrame; pfd; pfd = pfd->mNext) {
|
|
|
|
pfd->mBounds.x += deltaX;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
2008-06-11 03:53:22 +04:00
|
|
|
|
|
|
|
mTopEdge = aNewAvailSpace.y;
|
|
|
|
mPlacedFloats |= (aPlacedLeftFloat ? PLACED_LEFT : PLACED_RIGHT);
|
|
|
|
SetFlag(LL_IMPACTEDBYFLOATS, PR_TRUE);
|
|
|
|
|
|
|
|
SetFlag(LL_LASTFLOATWASLETTERFRAME,
|
|
|
|
nsGkAtoms::letterFrame == aFloatFrame->GetType());
|
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
|
|
|
{
|
2002-08-14 17:00:16 +04:00
|
|
|
PerSpanData* psd = mSpanFreeList;
|
|
|
|
if (nsnull == psd) {
|
2004-07-15 21:50:34 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerSpanData));
|
|
|
|
if (nsnull == mem) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-08-14 17:00:16 +04:00
|
|
|
}
|
2007-07-08 11:08:04 +04:00
|
|
|
psd = reinterpret_cast<PerSpanData*>(mem);
|
2002-08-14 17:00:16 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSpanFreeList = psd->mNextFreeSpan;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
psd->mParent = nsnull;
|
|
|
|
psd->mFrame = nsnull;
|
|
|
|
psd->mFirstFrame = nsnull;
|
|
|
|
psd->mLastFrame = nsnull;
|
2003-10-14 01:51:02 +04:00
|
|
|
psd->mContainsFloat = PR_FALSE;
|
1999-11-02 18:44:57 +03:00
|
|
|
psd->mZeroEffectiveSpanBox = PR_FALSE;
|
2008-02-14 12:08:33 +03:00
|
|
|
psd->mHasNonemptyContent = PR_FALSE;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2002-08-14 17:00:16 +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
|
|
|
{
|
2007-12-13 00:51:00 +03:00
|
|
|
NS_ASSERTION(aRightEdge != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"should no longer be using unconstrained sizes");
|
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;
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
psd->mNoWrap =
|
|
|
|
!aSpanReflowState->frame->GetStyleText()->WhiteSpaceCanWrap();
|
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;
|
|
|
|
}
|
|
|
|
|
2007-12-13 00:51:18 +03:00
|
|
|
nscoord
|
|
|
|
nsLineLayout::EndSpan(nsIFrame* aFrame)
|
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;
|
2007-12-13 00:51:18 +03:00
|
|
|
nscoord widthResult = psd->mLastFrame ? (psd->mX - psd->mLeftEdge) : 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
mSpanDepth--;
|
|
|
|
mCurrentSpan->mReflowState = nsnull; // no longer valid so null it out!
|
|
|
|
mCurrentSpan = mCurrentSpan->mParent;
|
2007-12-13 00:51:18 +03:00
|
|
|
return widthResult;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2002-08-14 17:00:16 +04:00
|
|
|
// Truncate list at pfd (we keep pfd, but anything following is freed)
|
|
|
|
PerFrameData* next = pfd->mNext;
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mNext = nsnull;
|
|
|
|
psd->mLastFrame = pfd;
|
|
|
|
|
2002-08-14 17:00:16 +04:00
|
|
|
// Now release all of the frames following pfd
|
|
|
|
pfd = next;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-08-14 17:00:16 +04:00
|
|
|
// Now free it, and if it has a span, free that too
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
#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
|
|
|
|
}
|
|
|
|
|
2002-08-14 17:00:16 +04:00
|
|
|
void
|
|
|
|
nsLineLayout::FreeSpan(PerSpanData* psd)
|
|
|
|
{
|
|
|
|
// Free its frames
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
while (nsnull != pfd) {
|
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
PerFrameData* next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
|
|
|
pfd = next;
|
|
|
|
}
|
|
|
|
|
2005-11-21 01:05:24 +03:00
|
|
|
// Now put the span on the free list since it's free too
|
2002-08-14 17:00:16 +04:00
|
|
|
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)
|
|
|
|
{
|
2002-08-14 17:00:16 +04:00
|
|
|
PerFrameData* pfd = mFrameFreeList;
|
|
|
|
if (nsnull == pfd) {
|
2004-07-15 21:50:34 +04:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerFrameData));
|
|
|
|
if (nsnull == mem) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-08-14 17:00:16 +04:00
|
|
|
}
|
2007-07-08 11:08:04 +04:00
|
|
|
pfd = reinterpret_cast<PerFrameData*>(mem);
|
2002-08-14 17:00:16 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFrameFreeList = pfd->mNext;
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
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;
|
2002-08-14 17:00:16 +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::LineIsBreakable() const
|
|
|
|
{
|
2008-06-14 12:28:07 +04:00
|
|
|
// XXX mTotalPlacedFrames should go away and we should just use
|
|
|
|
// LL_LINEISEMPTY here instead
|
2003-10-14 01:51:02 +04:00
|
|
|
if ((0 != mTotalPlacedFrames) || GetFlag(LL_IMPACTEDBYFLOATS)) {
|
1999-03-24 18:41:49 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-01-27 21:40:26 +03:00
|
|
|
// Checks all four sides for percentage units. This means it should
|
|
|
|
// only be used for things (margin, padding) where percentages on top
|
|
|
|
// and bottom depend on the *width* just like percentages on left and
|
|
|
|
// right.
|
|
|
|
static PRBool
|
|
|
|
HasPercentageUnitSide(const nsStyleSides& aSides)
|
|
|
|
{
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
|
|
|
if (eStyleUnit_Percent == aSides.GetUnit(side))
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
inline PRBool
|
|
|
|
WidthDependsOnContainer(const nsStyleCoord& aCoord)
|
|
|
|
{
|
|
|
|
return aCoord.GetUnit() == eStyleUnit_Percent ||
|
|
|
|
(aCoord.GetUnit() == eStyleUnit_Enumerated &&
|
2007-11-15 21:10:31 +03:00
|
|
|
(aCoord.GetIntValue() == NS_STYLE_WIDTH_AVAILABLE ||
|
|
|
|
aCoord.GetIntValue() == NS_STYLE_WIDTH_FIT_CONTENT));
|
2007-05-04 03:11:00 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-01-27 21:40:26 +03:00
|
|
|
static PRBool
|
|
|
|
IsPercentageAware(const nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFrame, "null frame is not allowed");
|
|
|
|
|
|
|
|
nsIAtom *fType = aFrame->GetType();
|
|
|
|
if (fType == nsGkAtoms::textFrame) {
|
|
|
|
// None of these things can ever be true for text frames.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some of these things don't apply to non-replaced inline frames
|
|
|
|
// (that is, fType == nsGkAtoms::inlineFrame || fType ==
|
|
|
|
// nsGkAtoms::positionedInlineFrame), but we won't bother making
|
|
|
|
// things unnecessarily complicated, since they'll probably be set
|
|
|
|
// quite rarely.
|
|
|
|
|
|
|
|
const nsStyleMargin* margin = aFrame->GetStyleMargin();
|
|
|
|
if (HasPercentageUnitSide(margin->mMargin)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsStylePadding* padding = aFrame->GetStylePadding();
|
|
|
|
if (HasPercentageUnitSide(padding->mPadding)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that borders can't be aware of percentages
|
|
|
|
|
|
|
|
const nsStylePosition* pos = aFrame->GetStylePosition();
|
|
|
|
|
2007-05-04 03:11:00 +04:00
|
|
|
if (WidthDependsOnContainer(pos->mWidth) ||
|
|
|
|
WidthDependsOnContainer(pos->mMaxWidth) ||
|
|
|
|
WidthDependsOnContainer(pos->mMinWidth) ||
|
2007-01-27 21:40:26 +03:00
|
|
|
eStyleUnit_Percent == pos->mOffset.GetRightUnit() ||
|
|
|
|
eStyleUnit_Percent == pos->mOffset.GetLeftUnit()) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eStyleUnit_Auto == pos->mWidth.GetUnit()) {
|
|
|
|
// We need to check for frames that shrink-wrap when they're auto
|
|
|
|
// width.
|
|
|
|
const nsStyleDisplay* disp = aFrame->GetStyleDisplay();
|
|
|
|
if (disp->mDisplay == NS_STYLE_DISPLAY_INLINE_BLOCK ||
|
|
|
|
disp->mDisplay == NS_STYLE_DISPLAY_INLINE_TABLE ||
|
|
|
|
fType == nsGkAtoms::HTMLButtonControlFrame ||
|
|
|
|
fType == nsGkAtoms::gfxButtonControlFrame ||
|
2007-02-28 06:04:38 +03:00
|
|
|
fType == nsGkAtoms::fieldSetFrame ||
|
|
|
|
fType == nsGkAtoms::comboboxDisplayFrame) {
|
2007-01-27 21:40:26 +03:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-11-18 15:09:03 +03:00
|
|
|
|
|
|
|
// Handle SVG, which doesn't map width/height into style
|
2007-11-22 00:09:12 +03:00
|
|
|
if ((
|
|
|
|
#ifdef MOZ_SVG
|
|
|
|
fType == nsGkAtoms::svgOuterSVGFrame ||
|
|
|
|
#endif
|
2007-11-18 15:09:03 +03:00
|
|
|
fType == nsGkAtoms::subDocumentFrame) &&
|
|
|
|
const_cast<nsIFrame*>(aFrame)->GetIntrinsicSize().width.GetUnit() ==
|
|
|
|
eStyleUnit_Percent) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-01-27 21:40:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
nsresult
|
|
|
|
nsLineLayout::ReflowFrame(nsIFrame* aFrame,
|
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
|
|
|
|
|
2007-01-27 21:40:26 +03:00
|
|
|
// See if this frame depends on the width of its containing block. If
|
|
|
|
// so, disable resize reflow optimizations for the line. (Note that,
|
|
|
|
// to be conservative, we do this if we *try* to fit a frame on a
|
|
|
|
// line, even if we don't succeed.)
|
2007-02-08 16:53:51 +03:00
|
|
|
if (GetFlag(LL_GOTLINEBOX) && IsPercentageAware(aFrame)) {
|
2007-01-27 21:40:26 +03:00
|
|
|
mLineBox->DisableResizeReflowOptimization();
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// Compute the available size for the frame. This available width
|
2001-12-11 05:45:44 +03:00
|
|
|
// includes room for the side margins.
|
2005-06-17 06:46:36 +04:00
|
|
|
// For now, set the available height to unconstrained always.
|
2007-01-27 21:36:57 +03:00
|
|
|
nsSize availSize(mBlockReflowState->ComputedWidth(), 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,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aFrame, availSize);
|
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
|
|
|
mTextJustificationNumSpaces = 0;
|
|
|
|
mTextJustificationNumLetters = 0;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2007-01-27 21:36:57 +03:00
|
|
|
// Inline-ish and text-ish things don't compute their width;
|
|
|
|
// everything else does. We need to give them an available width that
|
|
|
|
// reflects the space left on the line.
|
|
|
|
NS_ASSERTION(psd->mRightEdge != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"shouldn't have unconstrained widths anymore");
|
|
|
|
if (reflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE)
|
|
|
|
reflowState.availableWidth = psd->mRightEdge - psd->mX;
|
|
|
|
|
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
|
2006-10-19 05:47:47 +04:00
|
|
|
// too big for the line, but it is the only thing on the line and is not
|
|
|
|
// impacted by a float, then we go ahead and place it anyway. (If the line
|
|
|
|
// is impacted by one or more floats, then it is safe to break because
|
|
|
|
// we can move the line down below float(s).)
|
1999-03-22 23:45:09 +03:00
|
|
|
//
|
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.
|
2008-06-14 12:28:07 +04:00
|
|
|
PRBool notSafeToBreak = LineIsEmpty() && !GetFlag(LL_IMPACTEDBYFLOATS);
|
2006-10-19 05:47:47 +04: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.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
nsHTMLReflowMetrics metrics;
|
1999-03-19 00:03:25 +03:00
|
|
|
#ifdef DEBUG
|
1999-03-20 02:07:17 +03:00
|
|
|
metrics.width = nscoord(0xdeadbeef);
|
|
|
|
metrics.height = nscoord(0xdeadbeef);
|
1999-03-19 00:03:25 +03:00
|
|
|
#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
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
2006-10-19 05:47:47 +04:00
|
|
|
PRInt32 savedOptionalBreakOffset;
|
2008-07-24 11:16:18 +04:00
|
|
|
gfxBreakPriority savedOptionalBreakPriority;
|
2006-10-19 05:47:47 +04:00
|
|
|
nsIContent* savedOptionalBreakContent =
|
2008-07-24 11:16:18 +04:00
|
|
|
GetLastOptionalBreakPosition(&savedOptionalBreakOffset,
|
|
|
|
&savedOptionalBreakPriority);
|
2002-05-29 02:50:43 +04:00
|
|
|
|
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;
|
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->mJustificationNumSpaces = mTextJustificationNumSpaces;
|
|
|
|
pfd->mJustificationNumLetters = mTextJustificationNumLetters;
|
|
|
|
|
2008-02-14 12:08:33 +03:00
|
|
|
// See if the frame is a placeholderFrame and if it is process
|
|
|
|
// the float. At the same time, check if the frame has any non-collapsed-away
|
|
|
|
// content.
|
2006-10-19 05:47:47 +04:00
|
|
|
PRBool placedFloat = PR_FALSE;
|
2008-03-12 03:46:18 +03:00
|
|
|
PRBool isEmpty;
|
|
|
|
if (!frameType) {
|
|
|
|
isEmpty = pfd->mFrame->IsEmpty();
|
|
|
|
} else {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::placeholderFrame == frameType) {
|
2008-03-12 03:46:18 +03:00
|
|
|
isEmpty = PR_TRUE;
|
2006-04-21 05:31:35 +04:00
|
|
|
pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, PR_TRUE);
|
2004-09-13 17:35:46 +04:00
|
|
|
nsIFrame* outOfFlowFrame = nsLayoutUtils::GetFloatFromPlaceholder(aFrame);
|
1999-04-25 21:01:07 +04:00
|
|
|
if (outOfFlowFrame) {
|
2007-07-08 11:08:04 +04:00
|
|
|
nsPlaceholderFrame* placeholder = static_cast<nsPlaceholderFrame*>(aFrame);
|
2008-08-12 13:29:35 +04:00
|
|
|
// Add mTrimmableWidth to the available width since if the line ends
|
|
|
|
// here, the width of the inline content will be reduced by
|
|
|
|
// mTrimmableWidth.
|
|
|
|
nscoord availableWidth = psd->mRightEdge - (psd->mX - mTrimmableWidth);
|
|
|
|
if (psd->mNoWrap) {
|
|
|
|
// If we place floats after inline content where there's
|
|
|
|
// no break opportunity, we don't know how much additional
|
|
|
|
// width is required for the non-breaking content after the float,
|
|
|
|
// so we can't know whether the float plus that content will fit
|
|
|
|
// on the line. So for now, don't place floats after inline
|
|
|
|
// content where there's no break opportunity. This is incorrect
|
|
|
|
// but hopefully rare. Fixing it will require significant
|
|
|
|
// restructuring of line layout.
|
|
|
|
// We might as well allow zero-width floats to be placed, though.
|
|
|
|
availableWidth = 0;
|
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// XXXldb What is this test supposed to be?
|
2007-05-06 23:16:51 +04:00
|
|
|
if (!NS_SUBTREE_DIRTY(aFrame)) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// incremental reflow of child
|
2008-06-11 03:53:22 +04:00
|
|
|
placedFloat = InitFloat(placeholder, availableWidth, aReflowStatus);
|
2004-09-13 17:35:46 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-06-11 03:53:22 +04:00
|
|
|
placedFloat = AddFloat(placeholder, availableWidth, aReflowStatus);
|
2005-03-23 06:35:08 +03:00
|
|
|
}
|
2007-12-05 11:15:15 +03:00
|
|
|
NS_ASSERTION(!(outOfFlowFrame->GetType() == nsGkAtoms::letterFrame &&
|
|
|
|
GetFirstLetterStyleOK()),
|
|
|
|
"FirstLetterStyle set on line with floating first letter");
|
1999-04-23 19:15:53 +04:00
|
|
|
}
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (nsGkAtoms::textFrame == frameType) {
|
2005-11-21 01:05:24 +03:00
|
|
|
// Note non-empty text-frames for inline frame compatibility hackery
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISTEXTFRAME, PR_TRUE);
|
2008-02-14 12:08:33 +03:00
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(pfd->mFrame);
|
2008-03-12 03:46:18 +03:00
|
|
|
isEmpty = !textFrame->HasNoncollapsedCharacters();
|
|
|
|
if (!isEmpty) {
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, PR_TRUE);
|
2008-02-14 12:08:33 +03:00
|
|
|
nsIContent* content = textFrame->GetContent();
|
2004-05-08 00:55:17 +04:00
|
|
|
|
2006-07-19 08:36:36 +04:00
|
|
|
const nsTextFragment* frag = content->GetText();
|
|
|
|
if (frag) {
|
2004-05-08 00:55:17 +04:00
|
|
|
pfd->SetFlag(PFD_ISNONWHITESPACETEXTFRAME,
|
2006-07-19 08:36:36 +04:00
|
|
|
!content->TextIsOnlyWhitespace());
|
2001-04-12 03:32:21 +04:00
|
|
|
// fix for bug 40882
|
|
|
|
#ifdef IBMBIDI
|
2004-06-01 10:20:16 +04:00
|
|
|
if (mPresContext->BidiEnabled()) {
|
|
|
|
if (frag->Is2b()) {
|
|
|
|
//PRBool isVisual;
|
|
|
|
//mPresContext->IsVisualMode(isVisual);
|
|
|
|
PRUnichar ch = /*(isVisual) ?
|
|
|
|
*(frag->Get2b() + frag->GetLength() - 1) :*/ *frag->Get2b();
|
|
|
|
if (IS_BIDI_DIACRITIC(ch)) {
|
2004-08-24 22:50:29 +04:00
|
|
|
mPresContext->PropertyTable()->SetProperty(aFrame,
|
2006-12-26 20:47:52 +03:00
|
|
|
nsGkAtoms::endsInDiacritic, NS_INT32_TO_PTR(ch),
|
2004-08-24 22:50:29 +04:00
|
|
|
nsnull, nsnull);
|
2004-06-01 10:20:16 +04:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
2004-05-08 00:55:17 +04:00
|
|
|
#endif // IBMBIDI
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
1999-09-03 07:47:49 +04:00
|
|
|
}
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (nsGkAtoms::brFrame == frameType) {
|
2006-04-21 05:31:35 +04:00
|
|
|
pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, PR_TRUE);
|
2008-03-12 03:46:18 +03:00
|
|
|
isEmpty = PR_FALSE;
|
2008-02-14 12:08:33 +03:00
|
|
|
} else {
|
|
|
|
if (nsGkAtoms::letterFrame==frameType) {
|
|
|
|
pfd->SetFlag(PFD_ISLETTERFRAME, PR_TRUE);
|
|
|
|
}
|
2008-03-12 03:46:18 +03:00
|
|
|
if (pfd->mSpan) {
|
|
|
|
isEmpty = !pfd->mSpan->mHasNonemptyContent && pfd->mFrame->IsSelfEmpty();
|
|
|
|
} else {
|
|
|
|
isEmpty = pfd->mFrame->IsEmpty();
|
2008-02-14 12:08:33 +03:00
|
|
|
}
|
2006-04-21 05:31:35 +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 ((metrics.width == nscoord(0xdeadbeef)) ||
|
2007-01-23 07:06:56 +03:00
|
|
|
(metrics.height == nscoord(0xdeadbeef))) {
|
2000-10-29 02:17:53 +04:00
|
|
|
printf("nsLineLayout: ");
|
1999-03-24 18:41:49 +03:00
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2007-01-23 07:06:56 +03:00
|
|
|
printf(" didn't set w/h %d,%d!\n", metrics.width, metrics.height);
|
1999-03-24 18:41:49 +03:00
|
|
|
}
|
1999-03-20 02:07:17 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
#endif
|
|
|
|
|
2004-08-25 17:03:28 +04:00
|
|
|
// Unlike with non-inline reflow, the overflow area here does *not*
|
|
|
|
// include the accumulation of the frame's bounds and its inline
|
|
|
|
// descendants' bounds. Nor does it include the outline area; it's
|
|
|
|
// just the union of the bounds of any absolute children. That is
|
|
|
|
// added in later by nsLineLayout::ReflowInlineFrames.
|
|
|
|
pfd->mCombinedArea = metrics.mOverflowArea;
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mBounds.width = metrics.width;
|
|
|
|
pfd->mBounds.height = metrics.height;
|
|
|
|
|
2003-07-23 04:14:16 +04:00
|
|
|
// Size the frame, but |RelativePositionFrames| will size the view.
|
2003-06-30 14:46:59 +04:00
|
|
|
aFrame->SetSize(nsSize(metrics.width, metrics.height));
|
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)) {
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* kidNextInFlow = aFrame->GetNextInFlow();
|
1999-03-19 00:03:25 +03:00
|
|
|
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)
|
2007-07-08 11:08:04 +04:00
|
|
|
nsHTMLContainerFrame* parent = static_cast<nsHTMLContainerFrame*>
|
|
|
|
(kidNextInFlow->GetParent());
|
2002-10-09 00:35:26 +04:00
|
|
|
parent->DeleteNextInFlowChild(mPresContext, kidNextInFlow);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
// Check whether this frame breaks up text runs. All frames break up text
|
|
|
|
// runs (hence return false here) except for text frames and inline containers.
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
PRBool continuingTextRun = aFrame->CanContinueTextRun();
|
2006-10-19 05:47:47 +04:00
|
|
|
|
2008-02-08 02:00:37 +03:00
|
|
|
// Clear any residual mTrimmableWidth if this isn't a text frame
|
|
|
|
if (!continuingTextRun && !pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) {
|
|
|
|
mTrimmableWidth = 0;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// See if we can place the frame. If we can't fit it, then we
|
|
|
|
// return now.
|
2007-12-07 12:17:19 +03:00
|
|
|
PRBool optionalBreakAfterFits;
|
2006-10-19 05:47:47 +04:00
|
|
|
if (CanPlaceFrame(pfd, reflowState, notSafeToBreak, continuingTextRun,
|
2007-05-21 07:44:26 +04:00
|
|
|
savedOptionalBreakContent != nsnull, metrics,
|
2007-12-07 12:17:19 +03:00
|
|
|
aReflowStatus, &optionalBreakAfterFits)) {
|
2008-03-12 03:46:18 +03:00
|
|
|
if (!isEmpty) {
|
2008-02-14 13:03:01 +03:00
|
|
|
psd->mHasNonemptyContent = PR_TRUE;
|
2008-06-14 12:28:07 +04:00
|
|
|
SetFlag(LL_LINEISEMPTY, PR_FALSE);
|
2008-02-14 13:03:01 +03:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
|
|
|
if (!continuingTextRun) {
|
2008-06-14 12:28:07 +04:00
|
|
|
if (!psd->mNoWrap && (!LineIsEmpty() || placedFloat)) {
|
2006-10-19 05:47:47 +04:00
|
|
|
// record soft break opportunity after this content that can't be
|
|
|
|
// part of a text run. This is not a text frame so we know
|
|
|
|
// that offset PR_INT32_MAX means "after the content".
|
2008-07-24 11:16:18 +04:00
|
|
|
if (NotifyOptionalBreakPosition(aFrame->GetContent(), PR_INT32_MAX, optionalBreakAfterFits, eNormalBreak)) {
|
2006-10-19 05:47:47 +04:00
|
|
|
// If this returns true then we are being told to actually break here.
|
|
|
|
aReflowStatus = NS_INLINE_LINE_BREAK_AFTER(aReflowStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
2000-01-03 07:32:13 +03:00
|
|
|
aPushedFrame = PR_TRUE;
|
2006-10-19 05:47:47 +04:00
|
|
|
// Undo any saved break positions that the frame might have told us about,
|
|
|
|
// since we didn't end up placing it
|
|
|
|
RestoreSavedBreakPosition(savedOptionalBreakContent,
|
2008-07-24 11:16:18 +04:00
|
|
|
savedOptionalBreakOffset,
|
|
|
|
savedOptionalBreakPriority);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Only apply start-margin on the first-in flow for inline frames
|
2006-02-22 00:33:47 +03:00
|
|
|
if (pfd->mFrame->GetPrevContinuation()) {
|
2003-01-09 17:26:32 +03:00
|
|
|
// Zero this out so that when we compute the max-element-width of
|
2002-01-31 02:28:56 +03:00
|
|
|
// 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
|
|
|
}
|
2006-06-15 12:16:23 +04:00
|
|
|
else {
|
|
|
|
pfd->mBounds.x += ltr ? pfd->mMargin.left : pfd->mMargin.right;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2007-01-27 21:36:57 +03:00
|
|
|
NS_ASSERTION(NS_UNCONSTRAINEDSIZE != aReflowState.availableWidth,
|
|
|
|
"shouldn't have unconstrained widths anymore");
|
|
|
|
if (NS_UNCONSTRAINEDSIZE == aReflowState.ComputedWidth()) {
|
|
|
|
// For inline-ish and text-ish things (which don't compute widths
|
|
|
|
// in the reflow state), adjust available width to account for the
|
|
|
|
// left margin. The right margin will be accounted for when we
|
|
|
|
// finish flowing the frame.
|
2006-06-15 12:16:23 +04:00
|
|
|
aReflowState.availableWidth -= ltr ? pfd->mMargin.left : pfd->mMargin.right;
|
|
|
|
}
|
2002-01-31 02:28:56 +03:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2007-05-21 07:44:26 +04:00
|
|
|
nscoord
|
|
|
|
nsLineLayout::GetCurrentFrameXDistanceFromBlock()
|
|
|
|
{
|
|
|
|
PerSpanData* psd;
|
|
|
|
nscoord x = 0;
|
|
|
|
for (psd = mCurrentSpan; psd; psd = psd->mParent) {
|
|
|
|
x += psd->mX;
|
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
/**
|
|
|
|
* 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,
|
2006-10-19 05:47:47 +04:00
|
|
|
PRBool aFrameCanContinueTextRun,
|
2007-05-21 07:44:26 +04:00
|
|
|
PRBool aCanRollBackBeforeFrame,
|
1999-03-19 00:03:25 +03:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
2007-12-07 12:17:19 +03:00
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
PRBool* aOptionalBreakAfterFits)
|
1999-03-19 00:03:25 +03: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
|
|
|
NS_PRECONDITION(pfd && pfd->mFrame, "bad args, null pointers for frame data");
|
2007-12-07 12:17:19 +03:00
|
|
|
|
|
|
|
*aOptionalBreakAfterFits = PR_TRUE;
|
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
|
|
|
|
2006-02-22 00:33:47 +03:00
|
|
|
if ((NS_FRAME_IS_NOT_COMPLETE(aStatus) || (pfd->mFrame->GetNextContinuation() && !pfd->mFrame->GetNextInFlow()))
|
|
|
|
&& !pfd->GetFlag(PFD_ISLETTERFRAME)) {
|
2002-01-31 02:28:56 +03:00
|
|
|
// Only apply end margin for the last-in-flow. Zero this out so
|
2003-01-09 17:26:32 +03:00
|
|
|
// that when we compute the max-element-width of the frame we
|
2002-01-31 02:28:56 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
PRBool ltr = NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection;
|
|
|
|
nscoord endMargin = ltr ? pfd->mMargin.right : pfd->mMargin.left;
|
|
|
|
|
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);
|
2006-10-19 05:47:47 +04:00
|
|
|
printf(" frameWidth=%d\n", pfd->mBounds.XMost() + endMargin - 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.
|
2007-10-20 11:30:26 +04:00
|
|
|
PRBool outside = pfd->mBounds.XMost() - mTrimmableWidth + endMargin > 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;
|
|
|
|
}
|
2007-12-07 12:17:19 +03:00
|
|
|
*aOptionalBreakAfterFits = PR_FALSE;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
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
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::brFrame == pfd->mFrame->GetType()) {
|
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 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) {
|
2006-10-19 05:47:47 +04:00
|
|
|
// There are no frames on the line that take up width and the line is
|
|
|
|
// not impacted by floats, so we must allow the current frame to be
|
|
|
|
// placed on the line
|
1999-03-24 18:41:49 +03:00
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2006-10-19 05:47:47 +04:00
|
|
|
printf(" ==> not-safe and not-impacted fits: ");
|
|
|
|
while (nsnull != psd) {
|
|
|
|
printf("<psd=%p x=%d left=%d> ", psd, psd->mX, psd->mLeftEdge);
|
|
|
|
psd = psd->mParent;
|
1999-03-21 04:14:43 +03:00
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
printf("\n");
|
1999-10-29 18:33:26 +04:00
|
|
|
#endif
|
2006-10-19 05:47:47 +04:00
|
|
|
return PR_TRUE;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2006-10-19 05:47:47 +04:00
|
|
|
|
1999-11-02 18:44:57 +03:00
|
|
|
// Special check for span frames
|
2003-10-14 01:51:02 +04:00
|
|
|
if (pfd->mSpan && pfd->mSpan->mContainsFloat) {
|
|
|
|
// If the span either directly or indirectly contains a float then
|
1999-11-02 18:44:57 +03:00
|
|
|
// 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".
|
|
|
|
//
|
2003-10-14 01:51:02 +04:00
|
|
|
// 2. Before a float is placed on a line, the line has to be empty
|
2005-11-21 01:05:24 +03:00
|
|
|
// (otherwise it's a "below current line" float and will be placed
|
1999-11-02 18:44:57 +03:00
|
|
|
// after the line).
|
|
|
|
//
|
2003-10-14 01:51:02 +04:00
|
|
|
// Therefore, if the span directly or indirectly has a float
|
|
|
|
// then it means that at the time of the placement of the float
|
1999-11-02 18:44:57 +03:00
|
|
|
// 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
|
2003-10-14 01:51:02 +04:00
|
|
|
// set on them and contain a float and are placed where they
|
1999-11-02 18:44:57 +03:00
|
|
|
// don't naturally fit.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-10-19 05:47:47 +04:00
|
|
|
if (aFrameCanContinueTextRun) {
|
2007-11-19 00:36:18 +03:00
|
|
|
// Let it fit, but we reserve the right to roll back.
|
|
|
|
// Note that we usually won't get here because a text frame will break
|
|
|
|
// itself to avoid exceeding the available width.
|
2006-10-19 05:47:47 +04:00
|
|
|
// We'll only get here for text frames that couldn't break early enough.
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> placing overflowing textrun, requesting backup\n");
|
|
|
|
#endif
|
2007-11-19 00:36:18 +03:00
|
|
|
|
|
|
|
// We will want to try backup.
|
|
|
|
SetFlag(LL_NEEDBACKUP, PR_TRUE);
|
2008-08-12 13:18:23 +04:00
|
|
|
return PR_TRUE;
|
2006-10-19 05:47:47 +04:00
|
|
|
}
|
|
|
|
|
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
|
2007-01-23 07:06:56 +03:00
|
|
|
if (aMetrics.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE)
|
|
|
|
pfd->mAscent = pfd->mFrame->GetBaseline();
|
|
|
|
else
|
|
|
|
pfd->mAscent = aMetrics.ascent;
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2006-06-15 12:16:23 +04:00
|
|
|
PRBool ltr = (NS_STYLE_DIRECTION_LTR == pfd->mFrame->GetStyleVisibility()->mDirection);
|
1999-03-19 00:03:25 +03:00
|
|
|
// Advance to next X coordinate
|
2006-06-15 12:16:23 +04:00
|
|
|
psd->mX = pfd->mBounds.XMost() + (ltr ? pfd->mMargin.right : pfd->mMargin.left);
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2004-10-19 11:12:55 +04:00
|
|
|
// Count the number of non-empty frames on the line...
|
|
|
|
if (!emptyFrame) {
|
|
|
|
mTotalPlacedFrames++;
|
|
|
|
}
|
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);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
pfd->mFrameType = NS_FRAME_REPLACED(NS_CSS_FRAME_TYPE_INLINE);
|
2000-04-17 18:40:46 +04:00
|
|
|
pfd->mFlags = 0; // all flags default to false
|
|
|
|
pfd->SetFlag(PFD_ISBULLET, PR_TRUE);
|
2007-01-23 07:06:56 +03:00
|
|
|
if (aMetrics.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE)
|
|
|
|
pfd->mAscent = aFrame->GetBaseline();
|
|
|
|
else
|
|
|
|
pfd->mAscent = aMetrics.ascent;
|
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
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mBounds = aFrame->GetRect();
|
1999-12-06 18:49:53 +03:00
|
|
|
pfd->mCombinedArea = aMetrics.mOverflowArea;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsLineLayout::DumpPerSpanData(PerSpanData* psd, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
nsFrame::IndentBy(stdout, aIndent);
|
2007-07-08 11:08:04 +04:00
|
|
|
printf("%p: left=%d x=%d right=%d\n", static_cast<void*>(psd),
|
2001-10-25 05:08:40 +04:00
|
|
|
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-06-05 12:24:18 +04:00
|
|
|
void
|
2007-01-18 04:20:09 +03:00
|
|
|
nsLineLayout::VerticalAlignLine()
|
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;
|
|
|
|
mRootSpan->mFrame = &rootPFD;
|
|
|
|
|
|
|
|
// 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)
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2008-06-06 20:26:58 +04:00
|
|
|
if (pfd->mVerticalAlign == VALIGN_OTHER) {
|
|
|
|
pfd->mBounds.y += baselineY;
|
|
|
|
pfd->mFrame->SetRect(pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
}
|
2008-06-06 20:26:58 +04:00
|
|
|
PlaceTopBottomFrames(psd, -mTopEdge, lineHeight);
|
1999-03-19 00:03:25 +03:00
|
|
|
|
2003-01-09 17:26:32 +03:00
|
|
|
// Fill in returned line-box and max-element-width data
|
2007-01-18 04:20:09 +03:00
|
|
|
mLineBox->mBounds.x = psd->mLeftEdge;
|
|
|
|
mLineBox->mBounds.y = mTopEdge;
|
|
|
|
mLineBox->mBounds.width = psd->mX - psd->mLeftEdge;
|
|
|
|
mLineBox->mBounds.height = lineHeight;
|
1999-10-13 03:27:32 +04:00
|
|
|
mFinalLineHeight = lineHeight;
|
2007-01-18 04:20:09 +03:00
|
|
|
mLineBox->SetAscent(baselineY - mTopEdge);
|
2001-07-04 06:00:05 +04:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
|
|
|
printf(
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
" [line]==> bounds{x,y,w,h}={%d,%d,%d,%d} lh=%d a=%d\n",
|
2007-01-18 04:20:09 +03:00
|
|
|
mLineBox->mBounds.x, mLineBox->mBounds.y,
|
|
|
|
mLineBox->mBounds.width, mLineBox->mBounds.height,
|
|
|
|
mFinalLineHeight, mLineBox->GetAscent());
|
2001-07-04 06:00:05 +04:00
|
|
|
#endif
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Undo root-span mFrame pointer to prevent brane damage later on...
|
|
|
|
mRootSpan->mFrame = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::PlaceTopBottomFrames(PerSpanData* psd,
|
|
|
|
nscoord aDistanceFromTop,
|
|
|
|
nscoord aLineHeight)
|
|
|
|
{
|
2008-06-06 20:26:58 +04:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
1999-03-19 00:03:25 +03:00
|
|
|
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) {
|
2008-06-06 20:26:58 +04:00
|
|
|
pfd->mBounds.y = -aDistanceFromTop - span->mMinY;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop + pfd->mMargin.top;
|
|
|
|
}
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(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
|
2008-06-06 20:26:58 +04:00
|
|
|
pfd->mBounds.y = -aDistanceFromTop + aLineHeight - span->mMaxY;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = -aDistanceFromTop + aLineHeight -
|
|
|
|
pfd->mMargin.bottom - pfd->mBounds.height;
|
|
|
|
}
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2003-02-22 03:32:13 +03:00
|
|
|
nsStyleContext* styleContext = spanFrame->GetStyleContext();
|
1999-03-19 00:03:25 +03:00
|
|
|
nsIRenderingContext* rc = mBlockReflowState->rendContext;
|
2007-05-05 10:09:50 +04:00
|
|
|
nsLayoutUtils::SetFontFromStyle(mBlockReflowState->rendContext, styleContext);
|
1999-09-10 01:04:37 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
rc->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
|
2008-02-20 05:07:48 +03:00
|
|
|
PRBool preMode = mStyleText->WhiteSpaceIsSignificant();
|
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
|
2004-09-14 06:28:03 +04:00
|
|
|
nsIFrame* spanNextInFlow = spanFrame->GetNextInFlow();
|
|
|
|
nsIFrame* spanPrevInFlow = spanFrame->GetPrevInFlow();
|
1999-11-02 01:38:17 +03:00
|
|
|
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",
|
2007-10-02 06:36:26 +04:00
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_NavQuirks ? "yes" : "no",
|
1999-11-02 01:38:17 +03:00
|
|
|
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".
|
|
|
|
//
|
2002-06-26 01:16:17 +04:00
|
|
|
// In general, if the document being processed is in full standards
|
|
|
|
// 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.
|
1999-11-02 01:38:17 +03:00
|
|
|
//
|
2002-06-26 01:16:17 +04:00
|
|
|
// In almost standards mode or quirks 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.
|
1999-11-02 01:38:17 +03:00
|
|
|
//
|
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;
|
2002-05-16 23:44:20 +04:00
|
|
|
// XXXldb If we really have empty continuations, then all these other
|
|
|
|
// checks don't make sense for them.
|
2004-12-16 04:20:57 +03:00
|
|
|
// XXXldb This should probably just use nsIFrame::IsSelfEmpty, assuming that
|
|
|
|
// it agrees with this code. (If it doesn't agree, it probably should.)
|
2007-10-02 06:36:26 +04:00
|
|
|
if ((emptyContinuation ||
|
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_FullStandards) &&
|
2004-03-10 20:13:39 +03:00
|
|
|
((psd == mRootSpan) ||
|
|
|
|
((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)))) {
|
2005-11-21 01:05:24 +03:00
|
|
|
// This code handles an issue with compatibility with non-css
|
1999-09-10 01:04:37 +04:00
|
|
|
// 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
|
|
|
|
2002-12-19 03:21:07 +03:00
|
|
|
// We shouldn't include any whitespace that collapses, unless we're
|
|
|
|
// preformatted (in which case it shouldn't, but the width=0 test is
|
|
|
|
// perhaps incorrect). This includes whitespace at the beginning of
|
|
|
|
// a line and whitespace preceded (?) by other whitespace.
|
|
|
|
// See bug 134580 and bug 155333.
|
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) {
|
2002-12-19 03:21:07 +03:00
|
|
|
if (pfd->GetFlag(PFD_ISTEXTFRAME) &&
|
|
|
|
(pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME) || preMode ||
|
|
|
|
pfd->mBounds.width != 0)) {
|
1999-09-10 01:04:37 +04:00
|
|
|
zeroEffectiveSpanBox = PR_FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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.
|
2008-07-18 03:37:12 +04:00
|
|
|
nscoord logicalHeight = nsHTMLReflowState::CalcLineHeight(spanFrame);
|
2000-02-15 07:26:44 +03:00
|
|
|
nscoord contentHeight = spanFramePFD->mBounds.height -
|
|
|
|
spanFramePFD->mBorderPadding.top - spanFramePFD->mBorderPadding.bottom;
|
2004-11-17 07:12:02 +03:00
|
|
|
|
|
|
|
// Special-case for a ::first-letter frame, set the line height to
|
|
|
|
// the frame height if the user has left line-height == normal
|
|
|
|
if (spanFramePFD->GetFlag(PFD_ISLETTERFRAME) && !spanPrevInFlow &&
|
|
|
|
spanFrame->GetStyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal) {
|
|
|
|
logicalHeight = spanFramePFD->mBounds.height;
|
|
|
|
}
|
|
|
|
|
2000-02-15 07:26:44 +03:00
|
|
|
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;
|
|
|
|
|
2006-11-02 02:02:18 +03:00
|
|
|
// sanity check (see bug 105168, non-reproducible crashes from null frame)
|
2001-11-29 03:10:31 +03:00
|
|
|
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
|
2003-05-15 07:42:21 +04:00
|
|
|
const nsStyleTextReset* textStyle = frame->GetStyleTextReset();
|
1999-03-19 00:03:25 +03:00
|
|
|
nsStyleUnit verticalAlignUnit = textStyle->mVerticalAlign.GetUnit();
|
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.
|
2007-01-23 07:06:56 +03:00
|
|
|
pfd->mBounds.y = baselineY - pfd->mAscent;
|
1999-03-19 00:03:25 +03:00
|
|
|
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;
|
2007-01-23 07:06:56 +03:00
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
1999-03-19 00:03:25 +03:00
|
|
|
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;
|
2007-01-23 07:06:56 +03:00
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
2008-06-06 20:26:58 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mVerticalAlign = VALIGN_TOP;
|
2008-06-06 20:26:58 +04:00
|
|
|
nscoord subtreeHeight = logicalHeight;
|
|
|
|
if (frameSpan) {
|
|
|
|
subtreeHeight = frameSpan->mMaxY - frameSpan->mMinY;
|
|
|
|
NS_ASSERTION(subtreeHeight >= logicalHeight,
|
|
|
|
"unexpected subtree height");
|
|
|
|
}
|
|
|
|
if (subtreeHeight > maxTopBoxHeight) {
|
|
|
|
maxTopBoxHeight = subtreeHeight;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
break;
|
2008-06-06 20:26:58 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
2008-06-06 20:26:58 +04:00
|
|
|
{
|
1999-03-19 00:03:25 +03:00
|
|
|
pfd->mVerticalAlign = VALIGN_BOTTOM;
|
2008-06-06 20:26:58 +04:00
|
|
|
nscoord subtreeHeight = logicalHeight;
|
|
|
|
if (frameSpan) {
|
|
|
|
subtreeHeight = frameSpan->mMaxY - frameSpan->mMinY;
|
|
|
|
NS_ASSERTION(subtreeHeight >= logicalHeight,
|
|
|
|
"unexpected subtree height");
|
|
|
|
}
|
|
|
|
if (subtreeHeight > maxBottomBoxHeight) {
|
|
|
|
maxBottomBoxHeight = subtreeHeight;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
break;
|
2008-06-06 20:26:58 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
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;
|
2005-08-31 02:46:45 +04:00
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE:
|
|
|
|
// Align the midpoint of the frame with the baseline of the parent.
|
|
|
|
if (frameSpan) {
|
|
|
|
pfd->mBounds.y = baselineY - pfd->mBounds.height/2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pfd->mBounds.y = baselineY - logicalHeight/2 + pfd->mMargin.top;
|
|
|
|
}
|
|
|
|
pfd->mVerticalAlign = VALIGN_OTHER;
|
|
|
|
break;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
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;
|
2007-01-23 07:06:56 +03:00
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
1999-03-19 00:03:25 +03:00
|
|
|
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.
|
2008-07-18 03:37:12 +04:00
|
|
|
elementLineHeight = nsHTMLReflowState::CalcLineHeight(frame);
|
1999-03-19 00:03:25 +03:00
|
|
|
percentOffset = nscoord(
|
|
|
|
textStyle->mVerticalAlign.GetPercentValue() * elementLineHeight
|
|
|
|
);
|
|
|
|
revisedBaselineY = baselineY - percentOffset;
|
2007-01-23 07:06:56 +03:00
|
|
|
pfd->mBounds.y = revisedBaselineY - pfd->mAscent;
|
1999-03-19 00:03:25 +03:00
|
|
|
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)) {
|
2007-05-11 10:02:31 +04:00
|
|
|
canUpdate =
|
|
|
|
frame->GetStyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal;
|
2001-09-27 22:34:30 +04:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2002-08-11 22:00:07 +04:00
|
|
|
if (!preMode &&
|
2007-10-02 06:36:26 +04:00
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_FullStandards &&
|
2002-08-11 22:00:07 +04:00
|
|
|
!logicalHeight) {
|
2000-02-15 07:26:44 +03:00
|
|
|
// 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.
|
2006-12-26 20:47:52 +03:00
|
|
|
if (nsGkAtoms::brFrame == frame->GetType()) {
|
2000-02-15 07:26:44 +03:00
|
|
|
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
|
2007-01-23 07:06:56 +03:00
|
|
|
printf(" [frame]raw: a=%d h=%d bp=%d,%d logical: h=%d leading=%d y=%d minY=%d maxY=%d\n",
|
|
|
|
pfd->mAscent, pfd->mBounds.height,
|
1999-09-10 01:04:37 +04:00
|
|
|
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) {
|
2003-06-30 14:46:59 +04:00
|
|
|
frame->SetRect(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)) {
|
2003-06-30 14:46:59 +04:00
|
|
|
nsIContent* blockContent = mRootSpan->mFrame->mFrame->GetContent();
|
|
|
|
if (blockContent) {
|
2003-11-19 04:20:56 +03:00
|
|
|
nsIAtom *blockTagAtom = blockContent->Tag();
|
|
|
|
// (2) above, if the first line of LI
|
2006-12-26 20:47:52 +03:00
|
|
|
if (isFirstLine && blockTagAtom == nsGkAtoms::li) {
|
2003-11-19 04:20:56 +03:00
|
|
|
// if the line is empty, then don't force the min height
|
|
|
|
// (see bug 75963)
|
|
|
|
if (!IsZeroHeight()) {
|
2000-02-15 07:26:44 +03:00
|
|
|
applyMinLH = PR_TRUE;
|
2003-11-19 04:20:56 +03:00
|
|
|
foundLI = PR_TRUE;
|
2000-03-16 04:14:57 +03:00
|
|
|
}
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
2003-11-19 04:20:56 +03:00
|
|
|
// (3) above, if the last line of LI, DT, or DD
|
|
|
|
else if (!applyMinLH && isLastLine &&
|
2006-12-26 20:47:52 +03:00
|
|
|
((blockTagAtom == nsGkAtoms::li) ||
|
|
|
|
(blockTagAtom == nsGkAtoms::dt) ||
|
|
|
|
(blockTagAtom == nsGkAtoms::dd))) {
|
2003-11-19 04:20:56 +03:00
|
|
|
applyMinLH = PR_TRUE;
|
|
|
|
}
|
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) {
|
2008-02-14 12:08:33 +03:00
|
|
|
if (psd->mHasNonemptyContent || 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);
|
2005-08-03 00:15:27 +04:00
|
|
|
fm->GetHeight(fontHeight);
|
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) ||
|
2007-01-11 21:10:47 +03:00
|
|
|
(maxY == VERTICAL_ALIGN_FRAMES_NO_MAXIMUM)) {
|
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");
|
2007-01-23 07:06:56 +03:00
|
|
|
printf(" Original: minY=%d, maxY=%d, height=%d, ascent=%d, logicalHeight=%d, topLeading=%d, bottomLeading=%d\n",
|
2000-02-19 06:42:30 +03:00
|
|
|
minY, maxY, spanFramePFD->mBounds.height,
|
2007-01-23 07:06:56 +03:00
|
|
|
spanFramePFD->mAscent,
|
2000-02-19 06:42:30 +03:00
|
|
|
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
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(pfd->mBounds);
|
2000-02-15 07:26:44 +03:00
|
|
|
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
|
|
|
|
psd->mBottomLeading += adjust;
|
|
|
|
}
|
2000-02-19 06:42:30 +03:00
|
|
|
#ifdef NOISY_VERTICAL_ALIGN
|
2007-01-23 07:06:56 +03:00
|
|
|
printf(" New: minY=%d, maxY=%d, height=%d, ascent=%d, logicalHeight=%d, topLeading=%d, bottomLeading=%d\n",
|
2000-02-19 06:42:30 +03:00
|
|
|
minY, maxY, spanFramePFD->mBounds.height,
|
2007-01-23 07:06:56 +03:00
|
|
|
spanFramePFD->mAscent,
|
2000-02-19 06:42:30 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-03 14:28:58 +04:00
|
|
|
static void SlideSpanFrameRect(nsIFrame* aFrame, nscoord aDeltaWidth)
|
|
|
|
{
|
|
|
|
nsRect r = aFrame->GetRect();
|
|
|
|
r.x -= aDeltaWidth;
|
|
|
|
aFrame->SetRect(r);
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
nsIFrame* f = pfd->mFrame;
|
2003-06-30 14:46:59 +04:00
|
|
|
nsRect r = f->GetRect();
|
1999-09-24 21:23:33 +04:00
|
|
|
r.width -= deltaWidth;
|
2003-06-30 14:46:59 +04:00
|
|
|
f->SetRect(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;
|
2006-05-03 14:28:58 +04:00
|
|
|
if (psd != mRootSpan) {
|
|
|
|
// 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.
|
|
|
|
SlideSpanFrameRect(pfd->mFrame, deltaWidth);
|
|
|
|
}
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2004-02-09 04:01:06 +03:00
|
|
|
else if (!pfd->GetFlag(PFD_ISTEXTFRAME) &&
|
2006-04-21 05:31:35 +04:00
|
|
|
!pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) {
|
2004-03-02 04:23:13 +03:00
|
|
|
// If we hit a frame on the end that's not text and not a placeholder,
|
|
|
|
// then there is no trailing whitespace to trim. Stop the search.
|
1999-09-21 04:14:22 +04:00
|
|
|
*aDeltaWidth = 0;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2007-12-01 12:24:24 +03:00
|
|
|
else if (pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
|
|
|
// Call TrimTrailingWhiteSpace even on empty textframes because they
|
|
|
|
// might have a soft hyphen which should now appear, changing the frame's
|
|
|
|
// width
|
|
|
|
nsTextFrame::TrimOutput trimOutput = static_cast<nsTextFrame*>(pfd->mFrame)->
|
|
|
|
TrimTrailingWhiteSpace(mBlockReflowState->rendContext);
|
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);
|
2007-12-01 12:24:24 +03:00
|
|
|
printf(" returned %d\n", trimOutput.mDeltaWidth);
|
1999-09-24 21:23:33 +04:00
|
|
|
#endif
|
2007-12-01 12:24:24 +03:00
|
|
|
if (trimOutput.mLastCharIsJustifiable && pfd->mJustificationNumSpaces > 0) {
|
2005-01-13 22:21:18 +03:00
|
|
|
pfd->mJustificationNumSpaces--;
|
|
|
|
}
|
2007-12-01 12:24:24 +03:00
|
|
|
|
|
|
|
if (trimOutput.mChanged) {
|
|
|
|
pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, PR_TRUE);
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
|
2007-12-01 12:24:24 +03:00
|
|
|
if (trimOutput.mDeltaWidth) {
|
|
|
|
pfd->mBounds.width -= trimOutput.mDeltaWidth;
|
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.
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(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
|
2007-12-01 12:24:24 +03:00
|
|
|
psd->mX -= trimOutput.mDeltaWidth;
|
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;
|
2007-12-01 12:24:24 +03:00
|
|
|
pfd->mBounds.x -= trimOutput.mDeltaWidth;
|
2006-05-03 14:28:58 +04:00
|
|
|
if (psd != mRootSpan) {
|
|
|
|
// 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.
|
2007-12-01 12:24:24 +03:00
|
|
|
SlideSpanFrameRect(pfd->mFrame, trimOutput.mDeltaWidth);
|
2006-05-03 14:28:58 +04:00
|
|
|
}
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 12:24:24 +03:00
|
|
|
if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME) || trimOutput.mChanged) {
|
|
|
|
// Pass up to caller so they can shrink their span
|
|
|
|
*aDeltaWidth = trimOutput.mDeltaWidth;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-09-21 04:14:22 +04:00
|
|
|
}
|
|
|
|
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 &&
|
2004-12-12 19:14:43 +03:00
|
|
|
aState->mTotalNumSpaces > 0) {
|
2000-04-17 18:40:46 +04:00
|
|
|
aState->mNumSpacesProcessed += pfd->mJustificationNumSpaces;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForSpaces =
|
|
|
|
(aState->mTotalWidthForSpaces*aState->mNumSpacesProcessed)
|
|
|
|
/aState->mTotalNumSpaces;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForSpaces - aState->mWidthForSpacesProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForSpacesProcessed = newAllocatedWidthForSpaces;
|
|
|
|
}
|
|
|
|
|
2004-12-12 19:14:43 +03:00
|
|
|
if (aState->mTotalWidthForLetters > 0 &&
|
|
|
|
aState->mTotalNumLetters > 0) {
|
2000-04-17 18:40:46 +04:00
|
|
|
aState->mNumLettersProcessed += pfd->mJustificationNumLetters;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForLetters =
|
|
|
|
(aState->mTotalWidthForLetters*aState->mNumLettersProcessed)
|
|
|
|
/aState->mTotalNumLetters;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForLetters - aState->mWidthForLettersProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForLettersProcessed = newAllocatedWidthForLetters;
|
|
|
|
}
|
2007-09-24 06:19:14 +04:00
|
|
|
|
|
|
|
if (dw) {
|
|
|
|
pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, PR_TRUE);
|
|
|
|
}
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nsnull != pfd->mSpan) {
|
|
|
|
dw += ApplyFrameJustification(pfd->mSpan, aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pfd->mBounds.width += dw;
|
2004-03-16 09:58:01 +03:00
|
|
|
|
2000-04-17 18:40:46 +04:00
|
|
|
deltaX += dw;
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(pfd->mBounds);
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return deltaX;
|
|
|
|
}
|
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
void
|
2000-01-03 07:32:13 +03:00
|
|
|
nsLineLayout::HorizontalAlignFrames(nsRect& aLineBounds,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
PRBool aAllowJustify)
|
1999-03-19 00:03:25 +03:00
|
|
|
{
|
|
|
|
PerSpanData* psd = mRootSpan;
|
2007-12-13 00:51:00 +03:00
|
|
|
NS_ASSERTION(psd->mRightEdge != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"shouldn't have unconstrained widths anymore");
|
|
|
|
nscoord availWidth = psd->mRightEdge - psd->mLeftEdge;
|
1999-03-19 00:03:25 +03:00
|
|
|
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
|
2004-06-20 13:51:10 +04:00
|
|
|
nscoord dx = 0;
|
|
|
|
#endif
|
|
|
|
|
2002-06-12 07:27:48 +04:00
|
|
|
if (remainingWidth > 0)
|
|
|
|
{
|
2004-06-20 13:51:10 +04:00
|
|
|
#ifndef IBMBIDI
|
1999-03-19 00:03:25 +03:00
|
|
|
nscoord dx = 0;
|
2004-06-20 13:51:10 +04:00
|
|
|
#endif
|
2003-07-30 12:13:07 +04:00
|
|
|
switch (mTextAlign) {
|
1999-03-19 00:03:25 +03:00
|
|
|
case NS_STYLE_TEXT_ALIGN_JUSTIFY:
|
|
|
|
// If this is not the last line then go ahead and justify the
|
2006-12-12 21:28:37 +03:00
|
|
|
// frames in the line.
|
1999-03-19 00:03:25 +03:00
|
|
|
if (aAllowJustify) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
PRInt32 numSpaces;
|
|
|
|
PRInt32 numLetters;
|
2000-04-17 18:40:46 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
ComputeJustificationWeights(psd, &numSpaces, &numLetters);
|
2000-04-17 18:40:46 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
if (numSpaces > 0) {
|
2006-12-12 21:28:37 +03:00
|
|
|
FrameJustificationState state =
|
|
|
|
{ numSpaces, numLetters, remainingWidth, 0, 0, 0, 0, 0 };
|
2000-04-17 18:40:46 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
// Apply the justification, and make sure to update our linebox
|
|
|
|
// width to account for it.
|
|
|
|
aLineBounds.width += ApplyFrameJustification(psd, &state);
|
2008-01-04 13:22:38 +03:00
|
|
|
remainingWidth = availWidth - aLineBounds.width;
|
2006-12-12 21:28:37 +03:00
|
|
|
break;
|
2000-04-17 18:40:46 +04:00
|
|
|
}
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2006-12-12 21:28:37 +03:00
|
|
|
// Fall through to the default case if we were told not to
|
|
|
|
// justify anything or could not justify to fill the space.
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_DEFAULT:
|
|
|
|
if (NS_STYLE_DIRECTION_LTR == psd->mDirection) {
|
|
|
|
// default alignment for left-to-right is left so do nothing
|
|
|
|
break;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2006-12-12 21:28:37 +03:00
|
|
|
// Fall through to align right case for default alignment
|
|
|
|
// used when the direction is right-to-left.
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
|
|
|
|
dx = remainingWidth;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_LEFT:
|
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
|
2004-06-20 13:51:10 +04:00
|
|
|
}
|
2006-03-15 20:10:35 +03:00
|
|
|
else if (remainingWidth < 0) {
|
|
|
|
if (NS_STYLE_DIRECTION_RTL == psd->mDirection) {
|
|
|
|
dx = remainingWidth;
|
|
|
|
psd->mX += dx;
|
|
|
|
psd->mLeftEdge += dx;
|
|
|
|
}
|
|
|
|
}
|
2004-06-20 13:51:10 +04:00
|
|
|
PRBool isRTL = ( (NS_STYLE_DIRECTION_RTL == psd->mDirection)
|
|
|
|
&& (!psd->mChangedFrameDirection) );
|
|
|
|
if (dx || isRTL) {
|
|
|
|
nscoord maxX = aLineBounds.XMost() + dx;
|
|
|
|
PRBool isVisualRTL = PR_FALSE;
|
2001-04-12 03:32:21 +04:00
|
|
|
|
2004-06-20 13:51:10 +04:00
|
|
|
if (isRTL) {
|
2007-11-09 10:49:56 +03:00
|
|
|
if (psd->mLastFrame->GetFlag(PFD_ISBULLET) ) {
|
|
|
|
PerFrameData* bulletPfd = psd->mLastFrame;
|
|
|
|
bulletPfd->mBounds.x -= remainingWidth;
|
|
|
|
bulletPfd->mFrame->SetRect(bulletPfd->mBounds);
|
|
|
|
}
|
2004-06-20 13:51:10 +04:00
|
|
|
|
2001-04-12 03:32:21 +04:00
|
|
|
psd->mChangedFrameDirection = PR_TRUE;
|
|
|
|
|
2004-06-20 13:51:10 +04:00
|
|
|
isVisualRTL = mPresContext->IsVisualMode();
|
2001-04-12 03:32:21 +04:00
|
|
|
}
|
2004-10-24 03:23:43 +04:00
|
|
|
if (dx || isVisualRTL)
|
2001-04-12 03:32:21 +04:00
|
|
|
#else
|
2004-10-24 03:23:43 +04:00
|
|
|
if (0 != dx)
|
|
|
|
#endif
|
|
|
|
{
|
2007-11-09 10:49:56 +03:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2001-04-12 03:32:21 +04:00
|
|
|
#ifdef IBMBIDI
|
2004-06-20 13:51:10 +04:00
|
|
|
if (isVisualRTL) {
|
2002-12-11 05:38:33 +03:00
|
|
|
// XXXldb Ugh. Could we handle this earlier so we don't get here?
|
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
|
|
|
}
|
2004-06-20 13:51:10 +04:00
|
|
|
else
|
2001-04-12 03:32:21 +04:00
|
|
|
#endif // IBMBIDI
|
2004-06-20 13:51:10 +04:00
|
|
|
pfd->mBounds.x += dx;
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(pfd->mBounds);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2001-04-12 03:32:21 +04:00
|
|
|
aLineBounds.x += dx;
|
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;
|
|
|
|
|
|
|
|
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);
|
2003-06-30 14:46:59 +04:00
|
|
|
pfd->mFrame->SetRect(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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::RelativePositionFrames(nsRect& aCombinedArea)
|
|
|
|
{
|
|
|
|
RelativePositionFrames(mRootSpan, aCombinedArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::RelativePositionFrames(PerSpanData* psd, nsRect& aCombinedArea)
|
|
|
|
{
|
2004-02-28 05:55:58 +03:00
|
|
|
nsRect combinedAreaResult;
|
1999-03-19 00:03:25 +03:00
|
|
|
if (nsnull != psd->mFrame) {
|
2004-08-25 17:03:28 +04:00
|
|
|
// The span's overflow area comes in three parts:
|
|
|
|
// -- this frame's width and height
|
|
|
|
// -- the pfd->mCombinedArea, which is the area of a bullet or the union
|
|
|
|
// of a relatively positioned frame's absolute children
|
|
|
|
// -- the bounds of all inline descendants
|
|
|
|
// The former two parts are computed right here, we gather the descendants
|
|
|
|
// below.
|
2007-12-12 04:43:09 +03:00
|
|
|
// At this point psd->mFrame->mBounds might be out of date since
|
|
|
|
// bidi reordering can move and resize the frames. So use the frame's
|
|
|
|
// rect instead of mBounds.
|
|
|
|
nsRect adjustedBounds(nsPoint(0, 0), psd->mFrame->mFrame->GetSize());
|
2008-06-13 02:02:32 +04:00
|
|
|
|
|
|
|
// Text-shadow overflow
|
|
|
|
if (mPresContext->CompatibilityMode() != eCompatibility_NavQuirks) {
|
|
|
|
nsRect shadowRect = nsLayoutUtils::GetTextShadowRectsUnion(adjustedBounds,
|
|
|
|
psd->mFrame->mFrame);
|
|
|
|
adjustedBounds.UnionRect(adjustedBounds, shadowRect);
|
|
|
|
}
|
|
|
|
|
2004-08-25 17:03:28 +04:00
|
|
|
combinedAreaResult.UnionRect(psd->mFrame->mCombinedArea, adjustedBounds);
|
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)
|
2004-02-28 05:55:58 +03:00
|
|
|
combinedAreaResult.x = psd->mLeftEdge;
|
|
|
|
// If this turns out to be negative, the rect will be treated as empty.
|
|
|
|
// Which is just fine.
|
|
|
|
combinedAreaResult.width = psd->mX - combinedAreaResult.x;
|
|
|
|
combinedAreaResult.y = mTopEdge;
|
|
|
|
combinedAreaResult.height = mFinalLineHeight;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2004-02-28 05:55:58 +03:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2003-08-01 02:03:26 +04:00
|
|
|
nsIFrame* frame = pfd->mFrame;
|
2007-12-12 04:43:09 +03:00
|
|
|
nsPoint origin = frame->GetPosition();
|
1999-03-19 00:03:25 +03:00
|
|
|
|
|
|
|
// Adjust the origin of the frame
|
2000-04-17 18:40:46 +04:00
|
|
|
if (pfd->GetFlag(PFD_RELATIVEPOS)) {
|
2003-08-01 02:03:26 +04:00
|
|
|
// right and bottom are handled by
|
|
|
|
// nsHTMLReflowState::ComputeRelativeOffsets
|
|
|
|
nsPoint change(pfd->mOffsets.left, pfd->mOffsets.top);
|
2004-02-28 05:55:58 +03:00
|
|
|
origin += change;
|
2007-12-12 04:43:09 +03:00
|
|
|
frame->SetPosition(origin);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2003-08-07 03:59:10 +04:00
|
|
|
// We must position the view correctly before positioning its
|
|
|
|
// descendants so that widgets are positioned properly (since only
|
|
|
|
// some views have widgets).
|
|
|
|
if (frame->HasView())
|
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, frame,
|
|
|
|
frame->GetView(),
|
|
|
|
&pfd->mCombinedArea, //ignored
|
|
|
|
NS_FRAME_NO_SIZE_VIEW);
|
|
|
|
|
1999-03-19 00:03:25 +03:00
|
|
|
// 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.
|
2004-08-25 17:03:28 +04:00
|
|
|
nsRect r;
|
1999-03-19 00:03:25 +03:00
|
|
|
if (pfd->mSpan) {
|
|
|
|
// Compute a new combined area for the child span before
|
|
|
|
// aggregating it into our combined area.
|
2004-08-25 17:03:28 +04:00
|
|
|
RelativePositionFrames(pfd->mSpan, r);
|
2003-08-07 03:59:10 +04:00
|
|
|
} else {
|
2007-09-24 06:19:14 +04:00
|
|
|
r = pfd->mCombinedArea;
|
2007-11-09 09:49:38 +03:00
|
|
|
if (pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
|
|
|
if (pfd->GetFlag(PFD_RECOMPUTEOVERFLOW)) {
|
|
|
|
nsTextFrame* f = static_cast<nsTextFrame*>(frame);
|
|
|
|
r = f->RecomputeOverflowRect();
|
|
|
|
}
|
|
|
|
frame->FinishAndStoreOverflow(&r, frame->GetSize());
|
2007-09-24 06:19:14 +04:00
|
|
|
}
|
2004-08-25 17:03:28 +04:00
|
|
|
|
2003-08-07 03:59:10 +04:00
|
|
|
// If we have something that's not an inline but with a complex frame
|
|
|
|
// hierarchy inside that contains views, they need to be
|
|
|
|
// positioned.
|
|
|
|
// All descendant views must be repositioned even if this frame
|
|
|
|
// does have a view in case this frame's view does not have a
|
|
|
|
// widget and some of the descendant views do have widgets --
|
|
|
|
// otherwise the widgets won't be repositioned.
|
2004-12-27 18:05:18 +03:00
|
|
|
nsContainerFrame::PositionChildViews(frame);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
2003-08-01 02:03:26 +04:00
|
|
|
// Do this here (rather than along with NS_FRAME_OUTSIDE_CHILDREN
|
|
|
|
// handling below) so we get leaf frames as well. No need to worry
|
|
|
|
// about the root span, since it doesn't have a frame.
|
|
|
|
if (frame->HasView())
|
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, frame,
|
2004-08-25 17:03:28 +04:00
|
|
|
frame->GetView(), &r,
|
2003-08-07 03:59:10 +04:00
|
|
|
NS_FRAME_NO_MOVE_VIEW);
|
2003-08-01 02:03:26 +04:00
|
|
|
|
2004-08-25 17:03:28 +04:00
|
|
|
combinedAreaResult.UnionRect(combinedAreaResult, r + origin);
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we just computed a spans combined area, we need to update its
|
2002-12-22 08:40:51 +03:00
|
|
|
// NS_FRAME_OUTSIDE_CHILDREN bit..
|
2003-06-30 14:46:59 +04:00
|
|
|
if (psd->mFrame) {
|
2004-02-28 05:55:58 +03:00
|
|
|
PerFrameData* spanPFD = psd->mFrame;
|
|
|
|
nsIFrame* frame = spanPFD->mFrame;
|
2004-07-16 20:56:21 +04:00
|
|
|
frame->FinishAndStoreOverflow(&combinedAreaResult, frame->GetSize());
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2004-07-16 20:56:21 +04:00
|
|
|
aCombinedArea = combinedAreaResult;
|
1999-03-19 00:03:25 +03:00
|
|
|
}
|
2008-02-16 18:31:27 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::CombineTextDecorations(nsPresContext* aPresContext,
|
|
|
|
PRUint8 aDecorations,
|
|
|
|
nsIFrame* aFrame,
|
|
|
|
nsRect& aCombinedArea,
|
|
|
|
nscoord aAscentOverride,
|
|
|
|
float aUnderlineSizeRatio)
|
|
|
|
{
|
|
|
|
if (!(aDecorations & (NS_STYLE_TEXT_DECORATION_UNDERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_OVERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_THROUGH)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(aFrame, getter_AddRefs(fm));
|
2008-03-13 05:36:58 +03:00
|
|
|
nsIThebesFontMetrics* tfm = static_cast<nsIThebesFontMetrics*>(fm.get());
|
|
|
|
gfxFontGroup* fontGroup = tfm->GetThebesFontGroup();
|
|
|
|
gfxFont* firstFont = fontGroup->GetFontAt(0);
|
|
|
|
if (!firstFont)
|
2008-03-30 00:25:15 +03:00
|
|
|
return; // OOM
|
2008-03-13 05:36:58 +03:00
|
|
|
const gfxFont::Metrics& metrics = firstFont->GetMetrics();
|
|
|
|
|
|
|
|
gfxFloat ascent = aAscentOverride == 0 ? metrics.maxAscent :
|
|
|
|
aPresContext->AppUnitsToGfxUnits(aAscentOverride);
|
2008-02-16 18:31:27 +03:00
|
|
|
nsRect decorationArea;
|
|
|
|
if (aDecorations & (NS_STYLE_TEXT_DECORATION_UNDERLINE |
|
|
|
|
NS_STYLE_TEXT_DECORATION_OVERLINE)) {
|
|
|
|
gfxSize size(aPresContext->AppUnitsToGfxUnits(aCombinedArea.width),
|
2008-03-13 05:36:58 +03:00
|
|
|
metrics.underlineSize);
|
2008-02-16 18:31:27 +03:00
|
|
|
if (aDecorations & NS_STYLE_TEXT_DECORATION_OVERLINE) {
|
|
|
|
decorationArea =
|
|
|
|
nsCSSRendering::GetTextDecorationRect(aPresContext, size, ascent,
|
2008-04-11 12:44:58 +04:00
|
|
|
metrics.maxAscent, NS_STYLE_TEXT_DECORATION_OVERLINE,
|
2008-02-16 18:31:27 +03:00
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aCombinedArea.UnionRect(aCombinedArea, decorationArea);
|
|
|
|
}
|
|
|
|
if (aDecorations & NS_STYLE_TEXT_DECORATION_UNDERLINE) {
|
2008-03-13 05:36:58 +03:00
|
|
|
aUnderlineSizeRatio = PR_MAX(aUnderlineSizeRatio, 1.0f);
|
2008-02-16 18:31:27 +03:00
|
|
|
size.height *= aUnderlineSizeRatio;
|
2008-03-13 05:36:58 +03:00
|
|
|
gfxFloat underlineOffset = fontGroup->GetUnderlineOffset();
|
2008-02-16 18:31:27 +03:00
|
|
|
decorationArea =
|
|
|
|
nsCSSRendering::GetTextDecorationRect(aPresContext, size, ascent,
|
2008-03-13 05:36:58 +03:00
|
|
|
underlineOffset,
|
|
|
|
NS_STYLE_TEXT_DECORATION_UNDERLINE,
|
2008-02-16 18:31:27 +03:00
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aCombinedArea.UnionRect(aCombinedArea, decorationArea);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aDecorations & NS_STYLE_TEXT_DECORATION_LINE_THROUGH) {
|
|
|
|
gfxSize size(aPresContext->AppUnitsToGfxUnits(aCombinedArea.width),
|
2008-03-13 05:36:58 +03:00
|
|
|
metrics.strikeoutSize);
|
2008-02-16 18:31:27 +03:00
|
|
|
decorationArea =
|
|
|
|
nsCSSRendering::GetTextDecorationRect(aPresContext, size, ascent,
|
2008-03-13 05:36:58 +03:00
|
|
|
metrics.strikeoutOffset,
|
|
|
|
NS_STYLE_TEXT_DECORATION_LINE_THROUGH,
|
2008-02-16 18:31:27 +03:00
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aCombinedArea.UnionRect(aCombinedArea, decorationArea);
|
|
|
|
}
|
|
|
|
}
|