2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* state and methods used while laying out a single line of a block frame */
|
|
|
|
|
2013-09-24 18:43:43 -07:00
|
|
|
// This has to be defined before nsLineLayout.h is included, because
|
|
|
|
// nsLineLayout.h has a #include for plarena.h, which needs this defined:
|
2007-03-22 10:30:00 -07:00
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK (sizeof(void*)-1)
|
2013-09-24 18:43:43 -07:00
|
|
|
#include "nsLineLayout.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-10 17:13:09 -08:00
|
|
|
#include "SVGTextFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBlockFrame.h"
|
|
|
|
#include "nsStyleConsts.h"
|
2011-12-27 12:18:48 -08:00
|
|
|
#include "nsContainerFrame.h"
|
2009-01-04 16:39:54 -08:00
|
|
|
#include "nsFloatManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
#include "nsPresContext.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
2007-09-23 19:19:14 -07:00
|
|
|
#include "nsTextFrame.h"
|
2013-10-01 14:01:49 -07:00
|
|
|
#include "nsStyleStructInlines.h"
|
2014-03-11 13:23:50 -07:00
|
|
|
#include "nsBidiPresUtils.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-03-11 13:23:50 -07:00
|
|
|
#undef NOISY_INLINEDIR_ALIGN
|
|
|
|
#undef NOISY_BLOCKDIR_ALIGN
|
|
|
|
#undef REALLY_NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
#undef NOISY_REFLOW
|
|
|
|
#undef REALLY_NOISY_REFLOW
|
|
|
|
#undef NOISY_PUSHING
|
|
|
|
#undef REALLY_NOISY_PUSHING
|
|
|
|
#undef DEBUG_ADD_TEXT
|
|
|
|
#undef NOISY_MAX_ELEMENT_SIZE
|
|
|
|
#undef REALLY_NOISY_MAX_ELEMENT_SIZE
|
|
|
|
#undef NOISY_CAN_PLACE_FRAME
|
|
|
|
#undef NOISY_TRIM
|
|
|
|
#undef REALLY_NOISY_TRIM
|
|
|
|
#endif
|
|
|
|
|
2011-04-28 15:48:52 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define FIX_BUG_50257
|
|
|
|
|
|
|
|
nsLineLayout::nsLineLayout(nsPresContext* aPresContext,
|
2009-01-04 16:39:54 -08:00
|
|
|
nsFloatManager* aFloatManager,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsHTMLReflowState* aOuterReflowState,
|
|
|
|
const nsLineList::iterator* aLine)
|
|
|
|
: mPresContext(aPresContext),
|
2009-01-04 16:39:54 -08:00
|
|
|
mFloatManager(aFloatManager),
|
2007-03-22 10:30:00 -07:00
|
|
|
mBlockReflowState(aOuterReflowState),
|
2012-07-30 07:20:58 -07:00
|
|
|
mLastOptionalBreakContent(nullptr),
|
|
|
|
mForceBreakContent(nullptr),
|
|
|
|
mBlockRS(nullptr),/* XXX temporary */
|
2014-01-23 10:26:39 -08:00
|
|
|
mLastOptionalBreakPriority(gfxBreakPriority::eNoBreak),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLastOptionalBreakContentOffset(-1),
|
|
|
|
mForceBreakContentOffset(-1),
|
2014-03-11 13:23:50 -07:00
|
|
|
mMinLineBSize(0),
|
2012-09-27 18:56:40 -07:00
|
|
|
mTextIndent(0),
|
|
|
|
mFirstLetterStyleOK(false),
|
|
|
|
mIsTopOfPage(false),
|
|
|
|
mImpactedByFloats(false),
|
|
|
|
mLastFloatWasLetterFrame(false),
|
|
|
|
mLineIsEmpty(false),
|
|
|
|
mLineEndsInBR(false),
|
|
|
|
mNeedBackup(false),
|
|
|
|
mInFirstLine(false),
|
|
|
|
mGotLineBox(false),
|
|
|
|
mInFirstLetter(false),
|
|
|
|
mHasBullet(false),
|
|
|
|
mDirtyNextLine(false),
|
|
|
|
mLineAtStart(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-22 18:45:26 -07:00
|
|
|
MOZ_ASSERT(aOuterReflowState, "aOuterReflowState must not be null");
|
2009-01-04 16:39:54 -08:00
|
|
|
NS_ASSERTION(aFloatManager || aOuterReflowState->frame->GetType() ==
|
2007-03-22 10:30:00 -07:00
|
|
|
nsGkAtoms::letterFrame,
|
2009-01-04 16:39:54 -08:00
|
|
|
"float manager should be present");
|
2007-03-22 10:30:00 -07:00
|
|
|
MOZ_COUNT_CTOR(nsLineLayout);
|
|
|
|
|
|
|
|
// Stash away some style data that we need
|
2013-12-13 09:42:43 -08:00
|
|
|
nsBlockFrame* blockFrame = do_QueryFrame(aOuterReflowState->frame);
|
|
|
|
if (blockFrame)
|
|
|
|
mStyleText = blockFrame->StyleTextForLineLayout();
|
|
|
|
else
|
|
|
|
mStyleText = aOuterReflowState->frame->StyleText();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mLineNumber = 0;
|
|
|
|
mTotalPlacedFrames = 0;
|
2014-03-11 13:23:50 -07:00
|
|
|
mBStartEdge = 0;
|
2007-10-20 00:30:26 -07:00
|
|
|
mTrimmableWidth = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
mInflationMinFontSize =
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::InflationMinFontSizeFor(aOuterReflowState->frame);
|
2011-11-23 18:48:23 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Instead of always pre-initializing the free-lists for frames and
|
|
|
|
// spans, we do it on demand so that situations that only use a few
|
|
|
|
// frames and spans won't waste a lot of time in unneeded
|
|
|
|
// initialization.
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "nsLineLayout", 1024);
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrameFreeList = nullptr;
|
|
|
|
mSpanFreeList = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentSpan = mRootSpan = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
mSpanDepth = 0;
|
|
|
|
|
|
|
|
if (aLine) {
|
2012-09-27 18:56:40 -07:00
|
|
|
mGotLineBox = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
mLineBox = *aLine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsLineLayout::~nsLineLayout()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsLineLayout);
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr == mRootSpan, "bad line-layout user");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find out if the frame has a non-null prev-in-flow, i.e., whether it
|
|
|
|
// is a continuation.
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool
|
2007-03-22 10:30:00 -07:00
|
|
|
HasPrevInFlow(nsIFrame *aFrame)
|
|
|
|
{
|
|
|
|
nsIFrame *prevInFlow = aFrame->GetPrevInFlow();
|
2012-07-30 07:20:58 -07:00
|
|
|
return prevInFlow != nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-11 13:23:50 -07:00
|
|
|
nsLineLayout::BeginLineReflow(nscoord aICoord, nscoord aBCoord,
|
|
|
|
nscoord aISize, nscoord aBSize,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aImpactedByFloats,
|
2011-10-18 05:51:58 -07:00
|
|
|
bool aIsTopOfPage,
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode aWritingMode,
|
|
|
|
nscoord aContainerWidth)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(nullptr == mRootSpan, "bad linelayout user");
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_WARN_IF_FALSE(aISize != NS_UNCONSTRAINEDSIZE,
|
2009-10-28 20:22:28 -07:00
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2014-03-11 13:23:50 -07:00
|
|
|
if ((aISize != NS_UNCONSTRAINEDSIZE) && CRAZY_SIZE(aISize)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
|
|
|
printf(": Init: bad caller: width WAS %d(0x%x)\n",
|
2014-03-11 13:23:50 -07:00
|
|
|
aISize, aISize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if ((aBSize != NS_UNCONSTRAINEDSIZE) && CRAZY_SIZE(aBSize)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
|
|
|
printf(": Init: bad caller: height WAS %d(0x%x)\n",
|
2014-03-11 13:23:50 -07:00
|
|
|
aBSize, aBSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
|
|
|
printf(": BeginLineReflow: %d,%d,%d,%d impacted=%s %s\n",
|
2014-03-11 13:23:50 -07:00
|
|
|
aICoord, aBCoord, aISize, aBSize,
|
2007-03-22 10:30:00 -07:00
|
|
|
aImpactedByFloats?"true":"false",
|
|
|
|
aIsTopOfPage ? "top-of-page" : "");
|
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0;
|
|
|
|
#endif
|
|
|
|
|
2012-09-27 18:56:40 -07:00
|
|
|
mFirstLetterStyleOK = false;
|
|
|
|
mIsTopOfPage = aIsTopOfPage;
|
|
|
|
mImpactedByFloats = aImpactedByFloats;
|
2007-03-22 10:30:00 -07:00
|
|
|
mTotalPlacedFrames = 0;
|
2012-09-27 18:56:40 -07:00
|
|
|
mLineIsEmpty = true;
|
|
|
|
mLineAtStart = true;
|
|
|
|
mLineEndsInBR = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mSpanDepth = 0;
|
2014-03-11 13:23:50 -07:00
|
|
|
mMaxStartBoxBSize = mMaxEndBoxBSize = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-27 18:56:40 -07:00
|
|
|
if (mGotLineBox) {
|
2009-08-10 19:48:42 -07:00
|
|
|
mLineBox->ClearHasBullet();
|
|
|
|
}
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
PerSpanData* psd = NewPerSpanData();
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentSpan = mRootSpan = psd;
|
|
|
|
psd->mReflowState = mBlockReflowState;
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mIStart = aICoord;
|
|
|
|
psd->mICoord = aICoord;
|
|
|
|
psd->mIEnd = aICoord + aISize;
|
|
|
|
mContainerWidth = aContainerWidth;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-12-04 20:14:56 -08:00
|
|
|
// If we're in a constrained height frame, then we don't allow a
|
|
|
|
// max line box width to take effect.
|
2013-04-22 18:45:26 -07:00
|
|
|
if (!(LineContainerFrame()->GetStateBits() &
|
|
|
|
NS_FRAME_IN_CONSTRAINED_HEIGHT)) {
|
2012-12-04 20:14:56 -08:00
|
|
|
|
|
|
|
// If the available size is greater than the maximum line box width (if
|
|
|
|
// specified), then we need to adjust the line box width to be at the max
|
|
|
|
// possible width.
|
|
|
|
nscoord maxLineBoxWidth =
|
2013-04-22 18:45:26 -07:00
|
|
|
LineContainerFrame()->PresContext()->PresShell()->MaxLineBoxWidth();
|
2012-12-04 20:14:56 -08:00
|
|
|
|
|
|
|
if (maxLineBoxWidth > 0 &&
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mIEnd - psd->mIStart > maxLineBoxWidth) {
|
|
|
|
psd->mIEnd = psd->mIStart + maxLineBoxWidth;
|
2012-12-04 20:14:56 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
mBStartEdge = aBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-13 09:42:43 -08:00
|
|
|
psd->mNoWrap =
|
|
|
|
!mStyleText->WhiteSpaceCanWrapStyle() || LineContainerFrame()->IsSVGText();
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mWritingMode = aWritingMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If this is the first line of a block then see if the text-indent
|
|
|
|
// property amounts to anything.
|
|
|
|
|
|
|
|
if (0 == mLineNumber && !HasPrevInFlow(mBlockReflowState->frame)) {
|
2010-08-31 09:05:12 -07:00
|
|
|
const nsStyleCoord &textIndent = mStyleText->mTextIndent;
|
|
|
|
nscoord pctBasis = 0;
|
|
|
|
if (textIndent.HasPercent()) {
|
|
|
|
pctBasis =
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState);
|
2010-08-31 09:05:12 -07:00
|
|
|
|
2012-09-27 18:56:40 -07:00
|
|
|
if (mGotLineBox) {
|
2007-05-30 08:08:50 -07:00
|
|
|
mLineBox->DisableResizeReflowOptimization();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-31 09:05:12 -07:00
|
|
|
nscoord indent = nsRuleNode::ComputeCoordPercentCalc(textIndent, pctBasis);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mTextIndent = indent;
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mICoord += indent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::EndLineReflow()
|
|
|
|
{
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": EndLineReflow: width=%d\n", mRootSpan->mICoord - mRootSpan->mIStart);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
FreeSpan(mRootSpan);
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentSpan = mRootSpan = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mSpansAllocated == mSpansFreed, "leak");
|
|
|
|
NS_ASSERTION(mFramesAllocated == mFramesFreed, "leak");
|
|
|
|
|
|
|
|
#if 0
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t maxSpansAllocated = NS_LINELAYOUT_NUM_SPANS;
|
|
|
|
static int32_t maxFramesAllocated = NS_LINELAYOUT_NUM_FRAMES;
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX swtich to a single mAvailLineWidth that we adjust as each frame
|
2014-03-11 13:23:50 -07:00
|
|
|
// on the line is placed. Each span can still have a per-span mICoord that
|
2007-03-22 10:30:00 -07:00
|
|
|
// tracks where a child frame is going in its span; they don't need a
|
2014-03-11 13:23:50 -07:00
|
|
|
// per-span mIStart?
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
2008-06-10 16:53:22 -07:00
|
|
|
nsLineLayout::UpdateBand(const nsRect& aNewAvailSpace,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* aFloatFrame)
|
|
|
|
{
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
|
|
|
LogicalRect availSpace(lineWM, aNewAvailSpace, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
2014-03-11 13:23:50 -07:00
|
|
|
printf("nsLL::UpdateBand %d, %d, %d, %d, (logical %d, %d, %d, %d); frame=%p\n will set mImpacted to true\n",
|
2008-06-10 16:53:22 -07:00
|
|
|
aNewAvailSpace.x, aNewAvailSpace.y,
|
|
|
|
aNewAvailSpace.width, aNewAvailSpace.height,
|
2014-03-11 13:23:50 -07:00
|
|
|
availSpace.IStart(lineWM), availSpace.BStart(lineWM),
|
|
|
|
availSpace.ISize(lineWM), availSpace.BSize(lineWM),
|
2009-05-14 02:31:35 -07:00
|
|
|
aFloatFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
#ifdef DEBUG
|
2014-03-11 13:23:50 -07:00
|
|
|
if ((availSpace.ISize(lineWM) != NS_UNCONSTRAINEDSIZE) &&
|
|
|
|
CRAZY_SIZE(availSpace.ISize(lineWM))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": UpdateBand: bad caller: ISize WAS %d(0x%x)\n",
|
|
|
|
availSpace.ISize(lineWM), availSpace.ISize(lineWM));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if ((availSpace.BSize(lineWM) != NS_UNCONSTRAINEDSIZE) &&
|
|
|
|
CRAZY_SIZE(availSpace.BSize(lineWM))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": UpdateBand: bad caller: BSize WAS %d(0x%x)\n",
|
|
|
|
availSpace.BSize(lineWM), availSpace.BSize(lineWM));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Compute the difference between last times width and the new width
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_WARN_IF_FALSE(mRootSpan->mIEnd != NS_UNCONSTRAINEDSIZE &&
|
2009-10-28 20:22:28 -07:00
|
|
|
aNewAvailSpace.width != NS_UNCONSTRAINEDSIZE,
|
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2014-03-11 13:23:50 -07:00
|
|
|
// The root span's mIStart moves to aICoord
|
|
|
|
nscoord deltaICoord = availSpace.IStart(lineWM) - mRootSpan->mIStart;
|
2008-06-10 16:53:22 -07:00
|
|
|
// The width of all spans changes by this much (the root span's
|
2014-03-11 13:23:50 -07:00
|
|
|
// mIEnd moves to aICoord + aISize, its new width is aISize)
|
|
|
|
nscoord deltaISize = availSpace.ISize(lineWM) -
|
|
|
|
(mRootSpan->mIEnd - mRootSpan->mIStart);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": UpdateBand: %d,%d,%d,%d deltaISize=%d deltaICoord=%d\n",
|
2008-06-10 16:53:22 -07:00
|
|
|
aNewAvailSpace.x, aNewAvailSpace.y,
|
2014-03-11 13:23:50 -07:00
|
|
|
aNewAvailSpace.width, aNewAvailSpace.height, deltaISize, deltaICoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2008-06-10 16:53:22 -07:00
|
|
|
// Update the root span position
|
2014-03-11 13:23:50 -07:00
|
|
|
mRootSpan->mIStart += deltaICoord;
|
|
|
|
mRootSpan->mIEnd += deltaICoord;
|
|
|
|
mRootSpan->mICoord += deltaICoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-10 16:53:22 -07: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) {
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mIEnd += deltaISize;
|
2011-10-17 07:59:28 -07:00
|
|
|
psd->mContainsFloat = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NOISY_REFLOW
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(" span %p: oldIEnd=%d newIEnd=%d\n",
|
|
|
|
psd, psd->mIEnd - deltaISize, psd->mIEnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
2008-06-10 16:53:22 -07:00
|
|
|
NS_ASSERTION(mRootSpan->mContainsFloat &&
|
2014-03-11 13:23:50 -07:00
|
|
|
mRootSpan->mIStart == availSpace.IStart(lineWM) &&
|
|
|
|
mRootSpan->mIEnd == availSpace.IEnd(lineWM),
|
2008-06-10 16:53:22 -07:00
|
|
|
"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.
|
2014-03-11 13:23:50 -07:00
|
|
|
if (deltaICoord != 0) {
|
2008-06-10 16:53:22 -07:00
|
|
|
for (PerFrameData* pfd = mRootSpan->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) += deltaICoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2008-06-10 16:53:22 -07:00
|
|
|
|
2014-06-17 05:19:38 -07:00
|
|
|
mBStartEdge = availSpace.BStart(lineWM);
|
2012-09-27 18:56:40 -07:00
|
|
|
mImpactedByFloats = true;
|
2008-06-10 16:53:22 -07:00
|
|
|
|
2012-09-27 18:56:40 -07:00
|
|
|
mLastFloatWasLetterFrame = nsGkAtoms::letterFrame == aFloatFrame->GetType();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
nsLineLayout::PerSpanData*
|
|
|
|
nsLineLayout::NewPerSpanData()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PerSpanData* psd = mSpanFreeList;
|
2013-02-23 02:38:15 -08:00
|
|
|
if (!psd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerSpanData));
|
2013-02-23 02:38:15 -08:00
|
|
|
if (!mem) {
|
|
|
|
NS_RUNTIMEABORT("OOM");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
psd = reinterpret_cast<PerSpanData*>(mem);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSpanFreeList = psd->mNextFreeSpan;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
psd->mParent = nullptr;
|
|
|
|
psd->mFrame = nullptr;
|
|
|
|
psd->mFirstFrame = nullptr;
|
|
|
|
psd->mLastFrame = nullptr;
|
2011-10-17 07:59:28 -07:00
|
|
|
psd->mContainsFloat = false;
|
|
|
|
psd->mZeroEffectiveSpanBox = false;
|
|
|
|
psd->mHasNonemptyContent = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansAllocated++;
|
|
|
|
#endif
|
2013-02-23 02:38:15 -08:00
|
|
|
return psd;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::BeginSpan(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowState* aSpanReflowState,
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord aIStart, nscoord aIEnd,
|
2011-08-03 11:30:58 -07:00
|
|
|
nscoord* aBaseline)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_ASSERTION(aIEnd != NS_UNCONSTRAINEDSIZE,
|
2007-12-12 13:51:00 -08:00
|
|
|
"should no longer be using unconstrained sizes");
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth+1);
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": BeginSpan leftEdge=%d rightEdge=%d\n", aIStart, aIEnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
PerSpanData* psd = NewPerSpanData();
|
|
|
|
// 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;
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mIStart = aIStart;
|
|
|
|
psd->mICoord = aIStart;
|
|
|
|
psd->mIEnd = aIEnd;
|
2013-02-23 02:38:15 -08:00
|
|
|
psd->mBaseline = aBaseline;
|
|
|
|
|
2013-03-24 20:50:59 -07:00
|
|
|
nsIFrame* frame = aSpanReflowState->frame;
|
|
|
|
psd->mNoWrap = !frame->StyleText()->WhiteSpaceCanWrap(frame);
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mWritingMode = aSpanReflowState->GetWritingMode();
|
2013-02-23 02:38:15 -08:00
|
|
|
|
|
|
|
// Switch to new span
|
|
|
|
mCurrentSpan = psd;
|
|
|
|
mSpanDepth++;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-12-12 13:51:18 -08:00
|
|
|
nscoord
|
|
|
|
nsLineLayout::EndSpan(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mSpanDepth > 0, "end-span without begin-span");
|
|
|
|
#ifdef NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": EndSpan width=%d\n", mCurrentSpan->mICoord - mCurrentSpan->mIStart);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord iSizeResult = psd->mLastFrame ? (psd->mICoord - psd->mIStart) : 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mSpanDepth--;
|
2012-07-30 07:20:58 -07:00
|
|
|
mCurrentSpan->mReflowState = nullptr; // no longer valid so null it out!
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentSpan = mCurrentSpan->mParent;
|
2014-03-11 13:23:50 -07:00
|
|
|
return iSizeResult;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::GetCurrentSpanCount() const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
PerFrameData* pfd = mRootSpan->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
count++;
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsLineLayout::SplitLineTo(int32_t aNewCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_PUSHING
|
|
|
|
printf("SplitLineTo %d (current count=%d); before:\n", aNewCount,
|
|
|
|
GetCurrentSpanCount());
|
|
|
|
DumpPerSpanData(mRootSpan, 1);
|
|
|
|
#endif
|
|
|
|
PerSpanData* psd = mRootSpan;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (--aNewCount == 0) {
|
|
|
|
// Truncate list at pfd (we keep pfd, but anything following is freed)
|
|
|
|
PerFrameData* next = pfd->mNext;
|
2012-07-30 07:20:58 -07:00
|
|
|
pfd->mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
psd->mLastFrame = pfd;
|
|
|
|
|
|
|
|
// Now release all of the frames following pfd
|
|
|
|
pfd = next;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != pfd->mSpan) {
|
2007-03-22 10:30:00 -07:00
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
pfd = next;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
#ifdef NOISY_PUSHING
|
|
|
|
printf("SplitLineTo %d (current count=%d); after:\n", aNewCount,
|
|
|
|
GetCurrentSpanCount());
|
|
|
|
DumpPerSpanData(mRootSpan, 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
printf("PushFrame %p, before:\n", psd);
|
|
|
|
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
|
2012-07-30 07:20:58 -07:00
|
|
|
psd->mFirstFrame = nullptr;
|
|
|
|
psd->mLastFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PerFrameData* prevFrame = pfd->mPrev;
|
2012-07-30 07:20:58 -07:00
|
|
|
prevFrame->mNext = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
psd->mLastFrame = prevFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now free it, and if it has a span, free that too
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != pfd->mSpan) {
|
2007-03-22 10:30:00 -07:00
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
#ifdef NOISY_PUSHING
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
|
|
|
printf("PushFrame: %p after:\n", psd);
|
|
|
|
DumpPerSpanData(psd, 1);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::FreeSpan(PerSpanData* psd)
|
|
|
|
{
|
|
|
|
// Free its frames
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
|
|
|
if (nullptr != pfd->mSpan) {
|
2007-03-22 10:30:00 -07:00
|
|
|
FreeSpan(pfd->mSpan);
|
|
|
|
}
|
|
|
|
PerFrameData* next = pfd->mNext;
|
|
|
|
pfd->mNext = mFrameFreeList;
|
|
|
|
mFrameFreeList = pfd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFramesFreed++;
|
|
|
|
#endif
|
|
|
|
pfd = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now put the span on the free list since it's free too
|
|
|
|
psd->mNextFreeSpan = mSpanFreeList;
|
|
|
|
mSpanFreeList = psd;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mSpansFreed++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-03-11 13:23:50 -07:00
|
|
|
nsLineLayout::IsZeroBSize()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2014-03-11 13:23:50 -07:00
|
|
|
if (0 != pfd->mBounds.BSize(psd->mWritingMode)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
nsLineLayout::PerFrameData*
|
2014-03-11 13:23:50 -07:00
|
|
|
nsLineLayout::NewPerFrameData(nsIFrame* aFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PerFrameData* pfd = mFrameFreeList;
|
2013-02-23 02:38:15 -08:00
|
|
|
if (!pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
void *mem;
|
|
|
|
PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerFrameData));
|
2013-02-23 02:38:15 -08:00
|
|
|
if (!mem) {
|
|
|
|
NS_RUNTIMEABORT("OOM");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
pfd = reinterpret_cast<PerFrameData*>(mem);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mFrameFreeList = pfd->mNext;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
pfd->mSpan = nullptr;
|
|
|
|
pfd->mNext = nullptr;
|
|
|
|
pfd->mPrev = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
pfd->mFlags = 0; // all flags default to false
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mFrame = aFrame;
|
|
|
|
|
|
|
|
WritingMode frameWM = aFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
|
|
|
pfd->mBounds = LogicalRect(lineWM);
|
|
|
|
pfd->mMargin = LogicalMargin(frameWM);
|
|
|
|
pfd->mBorderPadding = LogicalMargin(frameWM);
|
|
|
|
pfd->mOffsets = LogicalMargin(frameWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = 0xFF;
|
2007-03-22 10:30:00 -07:00
|
|
|
mFramesAllocated++;
|
|
|
|
#endif
|
2013-02-23 02:38:15 -08:00
|
|
|
return pfd;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::LineIsBreakable() const
|
|
|
|
{
|
2008-06-14 01:28:07 -07:00
|
|
|
// XXX mTotalPlacedFrames should go away and we should just use
|
2012-09-27 18:56:40 -07:00
|
|
|
// mLineIsEmpty here instead
|
|
|
|
if ((0 != mTotalPlacedFrames) || mImpactedByFloats) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07: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.
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
HasPercentageUnitSide(const nsStyleSides& aSides)
|
|
|
|
{
|
|
|
|
NS_FOR_CSS_SIDES(side) {
|
2010-08-31 09:05:12 -07:00
|
|
|
if (aSides.Get(side).HasPercent())
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2007-03-22 10:30:00 -07:00
|
|
|
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.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some of these things don't apply to non-replaced inline frames
|
2011-04-29 16:02:33 -07:00
|
|
|
// (that is, fType == nsGkAtoms::inlineFrame), but we won't bother making
|
2007-03-22 10:30:00 -07:00
|
|
|
// things unnecessarily complicated, since they'll probably be set
|
|
|
|
// quite rarely.
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleMargin* margin = aFrame->StyleMargin();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (HasPercentageUnitSide(margin->mMargin)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStylePadding* padding = aFrame->StylePadding();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (HasPercentageUnitSide(padding->mPadding)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note that borders can't be aware of percentages
|
|
|
|
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStylePosition* pos = aFrame->StylePosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-11 12:32:52 -07:00
|
|
|
if ((pos->WidthDependsOnContainer() &&
|
|
|
|
pos->mWidth.GetUnit() != eStyleUnit_Auto) ||
|
|
|
|
pos->MaxWidthDependsOnContainer() ||
|
|
|
|
pos->MinWidthDependsOnContainer() ||
|
2010-08-25 03:17:56 -07:00
|
|
|
pos->OffsetHasPercent(NS_SIDE_RIGHT) ||
|
|
|
|
pos->OffsetHasPercent(NS_SIDE_LEFT)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (eStyleUnit_Auto == pos->mWidth.GetUnit()) {
|
|
|
|
// We need to check for frames that shrink-wrap when they're auto
|
|
|
|
// width.
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleDisplay* disp = aFrame->StyleDisplay();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (disp->mDisplay == NS_STYLE_DISPLAY_INLINE_BLOCK ||
|
|
|
|
disp->mDisplay == NS_STYLE_DISPLAY_INLINE_TABLE ||
|
|
|
|
fType == nsGkAtoms::HTMLButtonControlFrame ||
|
|
|
|
fType == nsGkAtoms::gfxButtonControlFrame ||
|
|
|
|
fType == nsGkAtoms::fieldSetFrame ||
|
|
|
|
fType == nsGkAtoms::comboboxDisplayFrame) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-11-18 04:09:03 -08:00
|
|
|
|
2011-06-12 18:52:32 -07:00
|
|
|
// Per CSS 2.1, section 10.3.2:
|
|
|
|
// If 'height' and 'width' both have computed values of 'auto' and
|
|
|
|
// the element has an intrinsic ratio but no intrinsic height or
|
|
|
|
// width and the containing block's width does not itself depend
|
|
|
|
// on the replaced element's width, then the used value of 'width'
|
|
|
|
// is calculated from the constraint equation used for
|
|
|
|
// block-level, non-replaced elements in normal flow.
|
|
|
|
nsIFrame *f = const_cast<nsIFrame*>(aFrame);
|
|
|
|
if (f->GetIntrinsicRatio() != nsSize(0, 0) &&
|
|
|
|
// Some percents are treated like 'auto', so check != coord
|
|
|
|
pos->mHeight.GetUnit() != eStyleUnit_Coord) {
|
2013-09-30 14:26:04 -07:00
|
|
|
const IntrinsicSize &intrinsicSize = f->GetIntrinsicSize();
|
2011-06-12 18:52:32 -07:00
|
|
|
if (intrinsicSize.width.GetUnit() == eStyleUnit_None &&
|
|
|
|
intrinsicSize.height.GetUnit() == eStyleUnit_None) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-06-12 18:52:32 -07:00
|
|
|
}
|
2007-11-18 04:09:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:47:53 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::ReflowFrame(nsIFrame* aFrame,
|
|
|
|
nsReflowStatus& aReflowStatus,
|
|
|
|
nsHTMLReflowMetrics* aMetrics,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aPushedFrame)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Initialize OUT parameter
|
2011-10-17 07:59:28 -07:00
|
|
|
aPushedFrame = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
PerFrameData* pfd = NewPerFrameData(aFrame);
|
2007-03-22 10:30:00 -07:00
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
psd->AppendFrame(pfd);
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
|
|
|
printf("%p: Begin ReflowFrame pfd=%p ", psd, pfd);
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2014-06-18 09:55:00 -07:00
|
|
|
if (mCurrentSpan == mRootSpan) {
|
|
|
|
pfd->mFrame->Properties().Remove(nsIFrame::LineBaselineOffset());
|
|
|
|
} else {
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool hasLineOffset;
|
|
|
|
pfd->mFrame->Properties().Get(nsIFrame::LineBaselineOffset(), &hasLineOffset);
|
|
|
|
NS_ASSERTION(!hasLineOffset, "LineBaselineOffset was set but was not expected");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mTextJustificationNumSpaces = 0;
|
|
|
|
mTextJustificationNumLetters = 0;
|
|
|
|
|
|
|
|
// Stash copies of some of the computed state away for later
|
2014-03-11 13:23:50 -07:00
|
|
|
// (block-direction alignment, for example)
|
|
|
|
WritingMode frameWM = aFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-17 07:41:33 -07:00
|
|
|
// NOTE: While the inline direction coordinate remains relative to the
|
|
|
|
// parent span, the block direction coordinate is fixed at the top
|
|
|
|
// edge for the line. During VerticalAlignFrames we will repair this
|
|
|
|
// so that the block direction coordinate is properly set and relative
|
|
|
|
// to the appropriate span.
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) = psd->mICoord;
|
|
|
|
pfd->mBounds.BStart(lineWM) = mBStartEdge;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// We want to guarantee that we always make progress when
|
|
|
|
// formatting. Therefore, if the object being placed on the line is
|
|
|
|
// too big for the line, but it is the only thing on the line 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).)
|
|
|
|
//
|
|
|
|
// 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.
|
2012-09-27 18:56:40 -07:00
|
|
|
bool notSafeToBreak = LineIsEmpty() && !mImpactedByFloats;
|
2010-08-25 11:54:47 -07:00
|
|
|
|
|
|
|
// Figure out whether we're talking about a textframe here
|
|
|
|
nsIAtom* frameType = aFrame->GetType();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isText = frameType == nsGkAtoms::textFrame;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-25 11:54:47 -07:00
|
|
|
// Compute the available size for the frame. This available width
|
|
|
|
// includes room for the side margins.
|
|
|
|
// For now, set the available height to unconstrained always.
|
|
|
|
nsSize availSize(mBlockReflowState->ComputedWidth(), NS_UNCONSTRAINEDSIZE);
|
|
|
|
|
|
|
|
// 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.
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_WARN_IF_FALSE(psd->mIEnd != NS_UNCONSTRAINEDSIZE,
|
2010-08-25 11:54:47 -07:00
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord availableSpaceOnLine = psd->mIEnd - psd->mICoord;
|
2010-08-25 11:54:47 -07:00
|
|
|
|
|
|
|
// Setup reflow state for reflowing the frame
|
2011-04-28 15:48:52 -07:00
|
|
|
Maybe<nsHTMLReflowState> reflowStateHolder;
|
2010-08-25 11:54:47 -07:00
|
|
|
if (!isText) {
|
|
|
|
reflowStateHolder.construct(mPresContext, *psd->mReflowState,
|
|
|
|
aFrame, availSize);
|
|
|
|
nsHTMLReflowState& reflowState = reflowStateHolder.ref();
|
|
|
|
reflowState.mLineLayout = this;
|
2012-09-27 18:56:40 -07:00
|
|
|
reflowState.mFlags.mIsTopOfPage = mIsTopOfPage;
|
2010-08-25 11:54:47 -07:00
|
|
|
if (reflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE)
|
2013-12-27 09:59:21 -08:00
|
|
|
reflowState.AvailableWidth() = availableSpaceOnLine;
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode stateWM = reflowState.GetWritingMode();
|
|
|
|
pfd->mMargin =
|
|
|
|
reflowState.ComputedLogicalMargin().ConvertTo(frameWM, stateWM);
|
|
|
|
pfd->mBorderPadding =
|
|
|
|
reflowState.ComputedLogicalBorderPadding().ConvertTo(frameWM, stateWM);
|
2010-08-25 11:54:47 -07:00
|
|
|
pfd->SetFlag(PFD_RELATIVEPOS,
|
2013-08-07 11:46:44 -07:00
|
|
|
reflowState.mStyleDisplay->IsRelativelyPositionedStyle());
|
2010-08-25 11:54:47 -07:00
|
|
|
if (pfd->GetFlag(PFD_RELATIVEPOS)) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mOffsets =
|
|
|
|
reflowState.ComputedLogicalOffsets().ConvertTo(frameWM, stateWM);
|
2010-08-25 11:54:47 -07:00
|
|
|
}
|
|
|
|
|
2014-05-20 07:04:54 -07:00
|
|
|
// Calculate whether the the frame should have a start margin and
|
|
|
|
// subtract the margin from the available width if necessary.
|
|
|
|
// The margin will be applied to the starting inline coordinates of
|
|
|
|
// the frame in CanPlaceFrame() after reflowing the frame.
|
|
|
|
AllowForStartMargin(pfd, reflowState);
|
2010-08-25 11:54:47 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
// if isText(), no need to propagate NS_FRAME_IS_DIRTY from the parent,
|
|
|
|
// because reflow doesn't look at the dirty bits on the frame being reflowed.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-02-15 13:34:52 -08: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.) (Note also that we can only make
|
|
|
|
// this IsPercentageAware check *after* we've constructed our
|
|
|
|
// nsHTMLReflowState, because that construction may be what forces aFrame
|
|
|
|
// to lazily initialize its (possibly-percent-valued) intrinsic size.)
|
2012-09-27 18:56:40 -07:00
|
|
|
if (mGotLineBox && IsPercentageAware(aFrame)) {
|
2011-02-15 13:34:52 -08:00
|
|
|
mLineBox->DisableResizeReflowOptimization();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2014-03-11 13:23:50 -07:00
|
|
|
// moving it when we do the block-direction alignment
|
2007-03-22 10:30:00 -07:00
|
|
|
aFrame->WillReflow(mPresContext);
|
|
|
|
|
2010-08-11 12:32:53 -07:00
|
|
|
// Adjust spacemanager coordinate system for the frame.
|
2014-03-11 13:23:50 -07:00
|
|
|
nsHTMLReflowMetrics metrics(lineWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
2013-12-27 09:59:52 -08:00
|
|
|
metrics.Width() = nscoord(0xdeadbeef);
|
|
|
|
metrics.Height() = nscoord(0xdeadbeef);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
nsRect physicalBounds = pfd->mBounds.GetPhysicalRect(lineWM, mContainerWidth);
|
|
|
|
nscoord tx = physicalBounds.x;
|
|
|
|
nscoord ty = physicalBounds.y;
|
2009-01-04 16:39:54 -08:00
|
|
|
mFloatManager->Translate(tx, ty);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t savedOptionalBreakOffset;
|
2008-07-24 00:16:18 -07:00
|
|
|
gfxBreakPriority savedOptionalBreakPriority;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* savedOptionalBreakContent =
|
2008-07-24 00:16:18 -07:00
|
|
|
GetLastOptionalBreakPosition(&savedOptionalBreakOffset,
|
|
|
|
&savedOptionalBreakPriority);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-25 11:54:47 -07:00
|
|
|
if (!isText) {
|
2014-05-12 17:47:52 -07:00
|
|
|
aFrame->Reflow(mPresContext, metrics, reflowStateHolder.ref(),
|
|
|
|
aReflowStatus);
|
2010-08-25 11:54:47 -07:00
|
|
|
} else {
|
|
|
|
static_cast<nsTextFrame*>(aFrame)->
|
|
|
|
ReflowText(*this, availableSpaceOnLine, psd->mReflowState->rendContext,
|
2013-04-14 03:11:07 -07:00
|
|
|
metrics, aReflowStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pfd->mJustificationNumSpaces = mTextJustificationNumSpaces;
|
|
|
|
pfd->mJustificationNumLetters = mTextJustificationNumLetters;
|
|
|
|
|
2008-02-14 01:08:33 -08: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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool placedFloat = false;
|
|
|
|
bool isEmpty;
|
2008-03-11 17:46:18 -07:00
|
|
|
if (!frameType) {
|
|
|
|
isEmpty = pfd->mFrame->IsEmpty();
|
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsGkAtoms::placeholderFrame == frameType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isEmpty = true;
|
|
|
|
pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* outOfFlowFrame = nsLayoutUtils::GetFloatFromPlaceholder(aFrame);
|
|
|
|
if (outOfFlowFrame) {
|
2008-08-12 02:29:35 -07:00
|
|
|
// Add mTrimmableWidth to the available width since if the line ends
|
|
|
|
// here, the width of the inline content will be reduced by
|
|
|
|
// mTrimmableWidth.
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord availableWidth = psd->mIEnd - (psd->mICoord - mTrimmableWidth);
|
2008-08-12 02:29:35 -07:00
|
|
|
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;
|
|
|
|
}
|
2010-08-05 21:59:20 -07:00
|
|
|
placedFloat = AddFloat(outOfFlowFrame, availableWidth);
|
2007-12-05 00:15:15 -08:00
|
|
|
NS_ASSERTION(!(outOfFlowFrame->GetType() == nsGkAtoms::letterFrame &&
|
|
|
|
GetFirstLetterStyleOK()),
|
|
|
|
"FirstLetterStyle set on line with floating first letter");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-08-25 11:54:47 -07:00
|
|
|
else if (isText) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Note non-empty text-frames for inline frame compatibility hackery
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_ISTEXTFRAME, true);
|
2008-02-14 01:08:33 -08:00
|
|
|
nsTextFrame* textFrame = static_cast<nsTextFrame*>(pfd->mFrame);
|
2008-03-11 17:46:18 -07:00
|
|
|
isEmpty = !textFrame->HasNoncollapsedCharacters();
|
|
|
|
if (!isEmpty) {
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, true);
|
2008-02-14 01:08:33 -08:00
|
|
|
nsIContent* content = textFrame->GetContent();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const nsTextFragment* frag = content->GetText();
|
|
|
|
if (frag) {
|
|
|
|
pfd->SetFlag(PFD_ISNONWHITESPACETEXTFRAME,
|
|
|
|
!content->TextIsOnlyWhitespace());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nsGkAtoms::brFrame == frameType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, true);
|
|
|
|
isEmpty = false;
|
2008-02-14 01:08:33 -08:00
|
|
|
} else {
|
|
|
|
if (nsGkAtoms::letterFrame==frameType) {
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_ISLETTERFRAME, true);
|
2008-02-14 01:08:33 -08:00
|
|
|
}
|
2008-03-11 17:46:18 -07:00
|
|
|
if (pfd->mSpan) {
|
2010-03-09 16:14:14 -08:00
|
|
|
isEmpty = !pfd->mSpan->mHasNonemptyContent && pfd->mFrame->IsSelfEmpty();
|
2008-03-11 17:46:18 -07:00
|
|
|
} else {
|
|
|
|
isEmpty = pfd->mFrame->IsEmpty();
|
2008-02-14 01:08:33 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-04 16:39:54 -08:00
|
|
|
mFloatManager->Translate(-tx, -ty);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-12-27 09:59:52 -08: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;
|
2007-03-22 10:30:00 -07: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)) {
|
2014-03-11 13:23:50 -07:00
|
|
|
if (CRAZY_SIZE(metrics.Width()) || CRAZY_SIZE(metrics.Height())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("nsLineLayout: ");
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2013-12-27 09:59:52 -08:00
|
|
|
printf(" metrics=%d,%d!\n", metrics.Width(), metrics.Height());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-12-27 09:59:52 -08:00
|
|
|
if ((metrics.Width() == nscoord(0xdeadbeef)) ||
|
|
|
|
(metrics.Height() == nscoord(0xdeadbeef))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("nsLineLayout: ");
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
2013-12-27 09:59:52 -08:00
|
|
|
printf(" didn't set w/h %d,%d!\n", metrics.Width(), metrics.Height());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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.
|
2010-10-06 21:25:45 -07:00
|
|
|
pfd->mOverflowAreas = metrics.mOverflowAreas;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-05 02:39:36 -07:00
|
|
|
pfd->mBounds.ISize(lineWM) = metrics.ISize(lineWM);
|
|
|
|
pfd->mBounds.BSize(lineWM) = metrics.BSize(lineWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Size the frame, but |RelativePositionFrames| will size the view.
|
2013-12-27 09:59:52 -08:00
|
|
|
aFrame->SetSize(nsSize(metrics.Width(), metrics.Height()));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Tell the frame that we're done reflowing it
|
2010-08-25 11:54:47 -07:00
|
|
|
aFrame->DidReflow(mPresContext,
|
2012-07-30 07:20:58 -07:00
|
|
|
isText ? nullptr : reflowStateHolder.addr(),
|
2012-11-13 22:47:33 -08:00
|
|
|
nsDidReflowStatus::FINISHED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aMetrics) {
|
|
|
|
*aMetrics = metrics;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) {
|
|
|
|
// If frame is complete and has a next-in-flow, we need to delete
|
|
|
|
// them now. Do not do this when a break-before is signaled because
|
|
|
|
// the frame is going to get reflowed again (and may end up wanting
|
|
|
|
// a next-in-flow where it ends up).
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aReflowStatus)) {
|
|
|
|
nsIFrame* kidNextInFlow = aFrame->GetNextInFlow();
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != kidNextInFlow) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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)
|
2014-05-24 15:20:40 -07:00
|
|
|
kidNextInFlow->GetParent()->
|
|
|
|
DeleteNextInFlowChild(kidNextInFlow, true);
|
2007-03-22 10:30:00 -07: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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool continuingTextRun = aFrame->CanContinueTextRun();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-07 15:00:37 -08:00
|
|
|
// Clear any residual mTrimmableWidth if this isn't a text frame
|
|
|
|
if (!continuingTextRun && !pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) {
|
|
|
|
mTrimmableWidth = 0;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if we can place the frame. If we can't fit it, then we
|
|
|
|
// return now.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool optionalBreakAfterFits;
|
2010-08-25 11:54:47 -07:00
|
|
|
NS_ASSERTION(isText ||
|
2012-08-02 04:38:49 -07:00
|
|
|
!reflowStateHolder.ref().IsFloating(),
|
2010-08-25 11:54:47 -07:00
|
|
|
"How'd we get a floated inline frame? "
|
|
|
|
"The frame ctor should've dealt with this.");
|
2014-03-11 13:23:50 -07:00
|
|
|
if (CanPlaceFrame(pfd, notSafeToBreak, continuingTextRun,
|
2012-07-30 07:20:58 -07:00
|
|
|
savedOptionalBreakContent != nullptr, metrics,
|
2007-12-07 01:17:19 -08:00
|
|
|
aReflowStatus, &optionalBreakAfterFits)) {
|
2008-03-11 17:46:18 -07:00
|
|
|
if (!isEmpty) {
|
2011-10-17 07:59:28 -07:00
|
|
|
psd->mHasNonemptyContent = true;
|
2012-09-27 18:56:40 -07:00
|
|
|
mLineIsEmpty = false;
|
2010-03-09 16:14:14 -08:00
|
|
|
if (!pfd->mSpan) {
|
|
|
|
// nonempty leaf content has been placed
|
2012-09-27 18:56:40 -07:00
|
|
|
mLineAtStart = false;
|
2010-03-09 16:14:14 -08:00
|
|
|
}
|
2008-02-14 02:03:01 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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
|
2014-03-11 13:23:50 -07:00
|
|
|
// container. It needs its child frames aligned in the block direction,
|
2007-03-22 10:30:00 -07:00
|
|
|
// so do most of it now.
|
2014-06-17 07:41:33 -07:00
|
|
|
VerticalAlignFrames(span);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!continuingTextRun) {
|
2008-06-14 01:28:07 -07:00
|
|
|
if (!psd->mNoWrap && (!LineIsEmpty() || placedFloat)) {
|
2007-03-22 10:30:00 -07: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
|
2012-09-27 23:57:33 -07:00
|
|
|
// that offset INT32_MAX means "after the content".
|
2014-01-23 10:26:39 -08:00
|
|
|
if (NotifyOptionalBreakPosition(aFrame->GetContent(), INT32_MAX, optionalBreakAfterFits, gfxBreakPriority::eNormalBreak)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If this returns true then we are being told to actually break here.
|
|
|
|
aReflowStatus = NS_INLINE_LINE_BREAK_AFTER(aReflowStatus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
2011-10-17 07:59:28 -07:00
|
|
|
aPushedFrame = true;
|
2007-03-22 10:30:00 -07: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 00:16:18 -07:00
|
|
|
savedOptionalBreakOffset,
|
|
|
|
savedOptionalBreakPriority);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PushFrame(aFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef REALLY_NOISY_REFLOW
|
|
|
|
nsFrame::IndentBy(stdout, mSpanDepth);
|
|
|
|
printf("End ReflowFrame ");
|
|
|
|
nsFrame::ListTag(stdout, aFrame);
|
|
|
|
printf(" status=%x\n", aReflowStatus);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-20 07:04:54 -07:00
|
|
|
nsLineLayout::AllowForStartMargin(PerFrameData* pfd,
|
|
|
|
nsHTMLReflowState& aReflowState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-02 04:38:49 -07:00
|
|
|
NS_ASSERTION(!aReflowState.IsFloating(),
|
2007-03-22 10:30:00 -07:00
|
|
|
"How'd we get a floated inline frame? "
|
|
|
|
"The frame ctor should've dealt with this.");
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = pfd->mFrame->GetWritingMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-05-11 19:04:58 -07:00
|
|
|
// Only apply start-margin on the first-in flow for inline frames,
|
2009-09-18 11:00:21 -07:00
|
|
|
// and make sure to not apply it to any inline other than the first
|
2014-02-06 17:45:33 -08:00
|
|
|
// in an ib split. Note that the ib sibling (block-in-inline
|
|
|
|
// sibling) annotations only live on the first continuation, but we
|
|
|
|
// don't want to apply the start margin for later continuations
|
2014-05-05 10:55:54 -07:00
|
|
|
// anyway. For box-decoration-break:clone we apply the start-margin
|
|
|
|
// on all continuations.
|
|
|
|
if ((pfd->mFrame->GetPrevContinuation() ||
|
|
|
|
pfd->mFrame->FrameIsNonFirstInIBSplit()) &&
|
|
|
|
aReflowState.mStyleBorder->mBoxDecorationBreak ==
|
|
|
|
NS_STYLE_BOX_DECORATION_BREAK_SLICE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Zero this out so that when we compute the max-element-width of
|
|
|
|
// the frame we will properly avoid adding in the starting margin.
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mMargin.IStart(frameWM) = 0;
|
2014-05-20 07:04:54 -07:00
|
|
|
} else {
|
2013-12-27 09:59:21 -08:00
|
|
|
NS_WARN_IF_FALSE(NS_UNCONSTRAINEDSIZE != aReflowState.AvailableWidth(),
|
2009-10-28 20:22:28 -07:00
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2007-03-22 10:30:00 -07:00
|
|
|
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
|
2014-03-11 13:23:50 -07:00
|
|
|
// start margin. The end margin will be accounted for when we
|
2007-03-22 10:30:00 -07:00
|
|
|
// finish flowing the frame.
|
2014-05-20 07:04:54 -07:00
|
|
|
aReflowState.AvailableWidth() -= pfd->mMargin.IStart(frameWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-20 20:44:26 -07:00
|
|
|
nscoord
|
2014-03-11 13:23:50 -07:00
|
|
|
nsLineLayout::GetCurrentFrameInlineDistanceFromBlock()
|
2007-05-20 20:44:26 -07:00
|
|
|
{
|
|
|
|
PerSpanData* psd;
|
|
|
|
nscoord x = 0;
|
|
|
|
for (psd = mCurrentSpan; psd; psd = psd->mParent) {
|
2014-03-11 13:23:50 -07:00
|
|
|
x += psd->mICoord;
|
2007-05-20 20:44:26 -07:00
|
|
|
}
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::CanPlaceFrame(PerFrameData* pfd,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotSafeToBreak,
|
|
|
|
bool aFrameCanContinueTextRun,
|
|
|
|
bool aCanRollBackBeforeFrame,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
2007-12-07 01:17:19 -08:00
|
|
|
nsReflowStatus& aStatus,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aOptionalBreakAfterFits)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(pfd && pfd->mFrame, "bad args, null pointers for frame data");
|
2014-03-11 01:22:52 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
*aOptionalBreakAfterFits = true;
|
2014-02-17 20:07:45 -08:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = pfd->mFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2014-02-17 20:07:45 -08:00
|
|
|
/*
|
|
|
|
* We want to only apply the end margin if we're the last continuation and
|
|
|
|
* either not in an {ib} split or the last inline in it. In all other
|
|
|
|
* cases we want to zero it out. That means zeroing it out if any of these
|
|
|
|
* conditions hold:
|
|
|
|
* 1) The frame is not complete (in this case it will get a next-in-flow)
|
|
|
|
* 2) The frame is complete but has a non-fluid continuation on its
|
|
|
|
* continuation chain. Note that if it has a fluid continuation, that
|
|
|
|
* continuation will get destroyed later, so we don't want to drop the
|
|
|
|
* end-margin in that case.
|
|
|
|
* 3) The frame is in an {ib} split and is not the last part.
|
|
|
|
*
|
|
|
|
* However, none of that applies if this is a letter frame (XXXbz why?)
|
2014-05-05 10:55:54 -07:00
|
|
|
*
|
|
|
|
* For box-decoration-break:clone we apply the end margin on all
|
|
|
|
* continuations (that are not letter frames).
|
2014-02-17 20:07:45 -08:00
|
|
|
*/
|
|
|
|
if ((NS_FRAME_IS_NOT_COMPLETE(aStatus) ||
|
|
|
|
pfd->mFrame->LastInFlow()->GetNextContinuation() ||
|
2014-05-05 10:55:54 -07:00
|
|
|
pfd->mFrame->FrameIsNonLastInIBSplit()) &&
|
|
|
|
!pfd->GetFlag(PFD_ISLETTERFRAME) &&
|
|
|
|
pfd->mFrame->StyleBorder()->mBoxDecorationBreak ==
|
|
|
|
NS_STYLE_BOX_DECORATION_BREAK_SLICE) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mMargin.IEnd(frameWM) = 0;
|
|
|
|
}
|
2014-05-20 07:04:54 -07:00
|
|
|
|
|
|
|
// Convert the frame's margins to the line's writing mode and apply
|
|
|
|
// the start margin to the frame bounds.
|
2014-03-11 13:23:50 -07:00
|
|
|
LogicalMargin usedMargins = pfd->mMargin.ConvertTo(lineWM, frameWM);
|
|
|
|
nscoord startMargin = usedMargins.IStart(lineWM);
|
|
|
|
nscoord endMargin = usedMargins.IEnd(lineWM);
|
|
|
|
|
2014-05-20 07:04:54 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) += startMargin;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PerSpanData* psd = mCurrentSpan;
|
|
|
|
if (psd->mNoWrap) {
|
|
|
|
// When wrapping is off, everything fits.
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != psd->mFrame) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::ListTag(stdout, psd->mFrame->mFrame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
|
|
|
}
|
|
|
|
printf(": aNotSafeToBreak=%s frame=", aNotSafeToBreak ? "true" : "false");
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(" frameWidth=%d, margins=%d,%d\n",
|
|
|
|
pfd->mBounds.IEnd(lineWM) + endMargin - psd->mICoord,
|
|
|
|
startMargin, endMargin);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
// Set outside to true if the result of the reflow leads to the
|
2007-03-22 10:30:00 -07:00
|
|
|
// frame sticking outside of our available area.
|
2014-03-11 13:23:50 -07:00
|
|
|
bool outside = pfd->mBounds.IEnd(lineWM) - mTrimmableWidth + endMargin >
|
|
|
|
psd->mIEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!outside) {
|
|
|
|
// If it fits, it fits
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> inside\n");
|
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
*aOptionalBreakAfterFits = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// When it doesn't fit, check for a few special conditions where we
|
|
|
|
// allow it to fit anyway.
|
2014-03-11 13:23:50 -07:00
|
|
|
if (0 == startMargin + pfd->mBounds.ISize(lineWM) + endMargin) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Empty frames always fit right where they are
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> empty frame fits\n");
|
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FIX_BUG_50257
|
|
|
|
// another special case: always place a BR
|
|
|
|
if (nsGkAtoms::brFrame == pfd->mFrame->GetType()) {
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> BR frame fits\n");
|
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (aNotSafeToBreak) {
|
|
|
|
// 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
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> not-safe and not-impacted fits: ");
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != psd) {
|
2014-03-11 13:23:50 -07:00
|
|
|
printf("<psd=%p x=%d left=%d> ", psd, psd->mICoord, psd->mIStart);
|
2007-03-22 10:30:00 -07:00
|
|
|
psd = psd->mParent;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Special check for span frames
|
|
|
|
if (pfd->mSpan && pfd->mSpan->mContainsFloat) {
|
|
|
|
// If the span either directly or indirectly contains a float then
|
|
|
|
// it fits. Why? It's kind of complicated, but here goes:
|
|
|
|
//
|
|
|
|
// 1. CanPlaceFrame is used for all frame placements on a line,
|
|
|
|
// and in a span. This includes recursively placement of frames
|
|
|
|
// inside of spans, and the span itself. Because the logic always
|
|
|
|
// checks for room before proceeding (the code above here), the
|
|
|
|
// only things on a line will be those things that "fit".
|
|
|
|
//
|
|
|
|
// 2. Before a float is placed on a line, the line has to be empty
|
|
|
|
// (otherwise it's a "below current line" float and will be placed
|
|
|
|
// after the line).
|
|
|
|
//
|
|
|
|
// Therefore, if the span directly or indirectly has a float
|
|
|
|
// then it means that at the time of the placement of the float
|
|
|
|
// the line was empty. Because of #1, only the frames that fit can
|
|
|
|
// be added after that point, therefore we can assume that the
|
|
|
|
// current span being placed has fit.
|
|
|
|
//
|
|
|
|
// So how do we get here and have a span that should already fit
|
|
|
|
// and yet doesn't: Simple: span's that have the no-wrap attribute
|
|
|
|
// set on them and contain a float and are placed where they
|
|
|
|
// don't naturally fit.
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFrameCanContinueTextRun) {
|
2007-11-18 13:36:18 -08: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.
|
2007-03-22 10:30:00 -07: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-18 13:36:18 -08:00
|
|
|
|
|
|
|
// We will want to try backup.
|
2012-09-27 18:56:40 -07:00
|
|
|
mNeedBackup = true;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef NOISY_CAN_PLACE_FRAME
|
|
|
|
printf(" ==> didn't fit\n");
|
|
|
|
#endif
|
|
|
|
aStatus = NS_INLINE_LINE_BREAK_BEFORE();
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Place the frame. Update running counters.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsLineLayout::PlaceFrame(PerFrameData* pfd, nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
2014-06-11 02:45:31 -07:00
|
|
|
WritingMode frameWM = pfd->mFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Record ascent and update max-ascent and max-descent values
|
2014-06-11 02:45:31 -07:00
|
|
|
if (aMetrics.BlockStartAscent() == nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
|
2014-06-17 05:19:38 -07:00
|
|
|
pfd->mAscent = pfd->mFrame->GetLogicalBaseline(lineWM);
|
2014-06-11 02:45:31 -07:00
|
|
|
} else {
|
|
|
|
pfd->mAscent = aMetrics.BlockStartAscent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Advance to next inline coordinate
|
|
|
|
mCurrentSpan->mICoord = pfd->mBounds.IEnd(lineWM) +
|
|
|
|
pfd->mMargin.ConvertTo(lineWM, frameWM).IEnd(lineWM);
|
2014-02-17 20:07:45 -08:00
|
|
|
|
|
|
|
// Count the number of non-placeholder frames on the line...
|
|
|
|
if (pfd->mFrame->GetType() == nsGkAtoms::placeholderFrame) {
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_ASSERTION(pfd->mBounds.ISize(lineWM) == 0 &&
|
|
|
|
pfd->mBounds.BSize(lineWM) == 0,
|
2014-02-17 20:07:45 -08:00
|
|
|
"placeholders should have 0 width/height (checking "
|
|
|
|
"placeholders were never counted by the old code in "
|
|
|
|
"this function)");
|
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
mTotalPlacedFrames++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 02:38:15 -08:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::AddBulletFrame(nsIFrame* aFrame,
|
|
|
|
const nsHTMLReflowMetrics& aMetrics)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user");
|
2012-09-27 18:56:40 -07:00
|
|
|
NS_ASSERTION(mGotLineBox, "must have line box");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-11 03:46:36 -07:00
|
|
|
nsIFrame *blockFrame = mBlockReflowState->frame;
|
|
|
|
NS_ASSERTION(blockFrame->IsFrameOfType(nsIFrame::eBlockFrame),
|
|
|
|
"must be for block");
|
|
|
|
if (!static_cast<nsBlockFrame*>(blockFrame)->BulletIsEmpty()) {
|
2012-09-27 18:56:40 -07:00
|
|
|
mHasBullet = true;
|
2009-09-11 03:46:36 -07:00
|
|
|
mLineBox->SetHasBullet();
|
|
|
|
}
|
2009-08-10 19:48:42 -07:00
|
|
|
|
2014-06-11 02:45:31 -07:00
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2014-03-11 13:23:50 -07:00
|
|
|
PerFrameData* pfd = NewPerFrameData(aFrame);
|
2013-02-23 02:38:15 -08:00
|
|
|
mRootSpan->AppendFrame(pfd);
|
|
|
|
pfd->SetFlag(PFD_ISBULLET, true);
|
2014-06-11 02:45:31 -07:00
|
|
|
if (aMetrics.BlockStartAscent() == nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
|
2014-06-17 05:19:38 -07:00
|
|
|
pfd->mAscent = aFrame->GetLogicalBaseline(lineWM);
|
2014-06-11 02:45:31 -07:00
|
|
|
} else {
|
|
|
|
pfd->mAscent = aMetrics.BlockStartAscent();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Note: block-coord value will be updated during block-direction alignment
|
2014-06-11 02:45:31 -07:00
|
|
|
pfd->mBounds = LogicalRect(lineWM, aFrame->GetRect(), mContainerWidth);
|
2013-02-23 02:38:15 -08:00
|
|
|
pfd->mOverflowAreas = aMetrics.mOverflowAreas;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsLineLayout::DumpPerSpanData(PerSpanData* psd, int32_t aIndent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsFrame::IndentBy(stdout, aIndent);
|
2007-07-08 00:08:04 -07:00
|
|
|
printf("%p: left=%d x=%d right=%d\n", static_cast<void*>(psd),
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mIStart, psd->mICoord, psd->mIEnd);
|
2007-03-22 10:30:00 -07:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFrame::IndentBy(stdout, aIndent+1);
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
nsRect rect = pfd->mBounds.GetPhysicalRect(psd->mWritingMode,
|
|
|
|
mContainerWidth);
|
|
|
|
printf(" %d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (pfd->mSpan) {
|
|
|
|
DumpPerSpanData(pfd->mSpan, aIndent + 1);
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define VALIGN_OTHER 0
|
|
|
|
#define VALIGN_TOP 1
|
|
|
|
#define VALIGN_BOTTOM 2
|
|
|
|
|
|
|
|
void
|
2014-06-17 07:41:33 -07:00
|
|
|
nsLineLayout::VerticalAlignLine()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Synthesize a PerFrameData for the block frame
|
2014-03-11 13:23:50 -07:00
|
|
|
PerFrameData rootPFD(mBlockReflowState->frame->GetWritingMode());
|
2007-03-22 10:30:00 -07:00
|
|
|
rootPFD.mFrame = mBlockReflowState->frame;
|
|
|
|
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;
|
2014-06-17 07:41:33 -07:00
|
|
|
VerticalAlignFrames(psd);
|
|
|
|
|
|
|
|
// *** Note that comments here still use the anachronistic term
|
|
|
|
// "line-height" when we really mean "size of the line in the block
|
|
|
|
// direction", "vertical-align" when we really mean "alignment in
|
|
|
|
// the block direction", and "top" and "bottom" when we really mean
|
|
|
|
// "block start" and "block end". This is partly for brevity and
|
|
|
|
// partly to retain the association with the CSS line-height and
|
|
|
|
// vertical-align properties.
|
2014-03-11 13:23:50 -07:00
|
|
|
//
|
2007-03-22 10:30:00 -07:00
|
|
|
// Compute the line-height. The line-height will be the larger of:
|
|
|
|
//
|
2014-03-11 13:23:50 -07:00
|
|
|
// [1] maxBCoord - minBCoord (the distance between the first child's
|
|
|
|
// block-start edge and the last child's block-end edge)
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2014-03-11 13:23:50 -07:00
|
|
|
// [2] the maximum logical box block size (since not every frame may have
|
2014-06-17 07:41:33 -07:00
|
|
|
// participated in #1; for example: "top" and "botttom" aligned frames)
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2014-03-11 13:23:50 -07:00
|
|
|
// [3] the minimum line height ("line-height" property set on the
|
2007-03-22 10:30:00 -07:00
|
|
|
// block frame)
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord lineBSize = psd->mMaxBCoord - psd->mMinBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Now that the line-height is computed, we need to know where the
|
2014-03-11 13:23:50 -07:00
|
|
|
// baseline is in the line. Position baseline so that mMinBCoord is just
|
|
|
|
// inside the start of the line box.
|
|
|
|
nscoord baselineBCoord;
|
|
|
|
if (psd->mMinBCoord < 0) {
|
|
|
|
baselineBCoord = mBStartEdge - psd->mMinBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
baselineBCoord = mBStartEdge;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// It's also possible that the line block-size isn't tall enough because
|
2014-06-17 07:41:33 -07:00
|
|
|
// of "top" and "bottom" aligned elements that were not accounted for in
|
2014-03-11 13:23:50 -07:00
|
|
|
// min/max BCoord.
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// The CSS2 spec doesn't really say what happens when to the
|
2014-03-11 13:23:50 -07:00
|
|
|
// baseline in this situations. What we do is if the largest start
|
|
|
|
// aligned box block size is greater than the line block-size then we leave
|
|
|
|
// the baseline alone. If the largest end aligned box is greater
|
|
|
|
// than the line block-size then we slide the baseline forward by the extra
|
2007-03-22 10:30:00 -07:00
|
|
|
// amount.
|
|
|
|
//
|
|
|
|
// Navigator 4 gives precedence to the first top/bottom aligned
|
2014-03-11 13:23:50 -07:00
|
|
|
// object. We just let block end aligned objects win.
|
|
|
|
if (lineBSize < mMaxEndBoxBSize) {
|
|
|
|
// When the line is shorter than the maximum block start aligned box
|
|
|
|
nscoord extra = mMaxEndBoxBSize - lineBSize;
|
|
|
|
baselineBCoord += extra;
|
|
|
|
lineBSize = mMaxEndBoxBSize;
|
|
|
|
}
|
|
|
|
if (lineBSize < mMaxStartBoxBSize) {
|
|
|
|
lineBSize = mMaxStartBoxBSize;
|
|
|
|
}
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" [line]==> lineBSize=%d baselineBCoord=%d\n", lineBSize, baselineBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now position all of the frames in the root span. We will also
|
2014-06-17 07:41:33 -07:00
|
|
|
// recurse over the child spans and place any frames we find with
|
|
|
|
// vertical-align: top or bottom.
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX PERFORMANCE: set a bit per-span to avoid the extra work
|
|
|
|
// (propagate it upward too)
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode lineWM = psd->mWritingMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2014-03-11 13:23:50 -07:00
|
|
|
if (pfd->mBlockDirAlign == VALIGN_OTHER) {
|
|
|
|
pfd->mBounds.BStart(lineWM) += baselineBCoord;
|
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-17 07:41:33 -07:00
|
|
|
PlaceTopBottomFrames(psd, -mBStartEdge, lineBSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Fill in returned line-box and max-element-width data
|
2014-04-16 01:03:28 -07:00
|
|
|
mLineBox->SetBounds(lineWM,
|
|
|
|
psd->mIStart, mBStartEdge,
|
|
|
|
psd->mICoord - psd->mIStart, lineBSize,
|
|
|
|
mContainerWidth);
|
2014-03-11 13:23:50 -07:00
|
|
|
|
|
|
|
mFinalLineBSize = lineBSize;
|
2014-06-17 05:19:38 -07:00
|
|
|
mLineBox->SetLogicalAscent(baselineBCoord - mBStartEdge);
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(
|
|
|
|
" [line]==> bounds{x,y,w,h}={%d,%d,%d,%d} lh=%d a=%d\n",
|
2014-06-02 13:26:00 -07:00
|
|
|
mLineBox->GetBounds().IStart(lineWM), mLineBox->GetBounds().BStart(lineWM),
|
|
|
|
mLineBox->GetBounds().ISize(lineWM), mLineBox->GetBounds().BSize(lineWM),
|
2014-06-17 05:19:38 -07:00
|
|
|
mFinalLineBSize, mLineBox->GetLogicalAscent());
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Undo root-span mFrame pointer to prevent brane damage later on...
|
2012-07-30 07:20:58 -07:00
|
|
|
mRootSpan->mFrame = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-17 07:41:33 -07:00
|
|
|
// Place frames with CSS property vertical-align: top or bottom.
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2014-06-17 07:41:33 -07:00
|
|
|
nsLineLayout::PlaceTopBottomFrames(PerSpanData* psd,
|
|
|
|
nscoord aDistanceFromStart,
|
|
|
|
nscoord aLineBSize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-06-06 09:26:58 -07:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2007-03-22 10:30:00 -07:00
|
|
|
PerSpanData* span = pfd->mSpan;
|
|
|
|
#ifdef DEBUG
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_ASSERTION(0xFF != pfd->mBlockDirAlign, "umr");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = pfd->mFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
|
|
|
switch (pfd->mBlockDirAlign) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case VALIGN_TOP:
|
|
|
|
if (span) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = -aDistanceFromStart - span->mMinBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) =
|
|
|
|
-aDistanceFromStart + pfd->mMargin.BStart(frameWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" ");
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
|
|
|
printf(": y=%d dTop=%d [bp.top=%d topLeading=%d]\n",
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM), aDistanceFromStart,
|
|
|
|
span ? pfd->mBorderPadding.BStart(frameWM) : 0,
|
|
|
|
span ? span->mBStartLeading : 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case VALIGN_BOTTOM:
|
|
|
|
if (span) {
|
|
|
|
// Compute bottom leading
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) =
|
|
|
|
-aDistanceFromStart + aLineBSize - span->mMaxBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = -aDistanceFromStart + aLineBSize -
|
|
|
|
pfd->mMargin.BEnd(frameWM) - pfd->mBounds.BSize(lineWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" ");
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": y=%d\n", pfd->mBounds.BStart(lineWM));
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (span) {
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord fromStart = aDistanceFromStart + pfd->mBounds.BStart(lineWM);
|
2014-06-17 07:41:33 -07:00
|
|
|
PlaceTopBottomFrames(span, fromStart, aLineBSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:13:09 -08:00
|
|
|
static float
|
2014-03-11 13:23:50 -07:00
|
|
|
GetInflationForBlockDirAlignment(nsIFrame* aFrame,
|
2014-01-10 17:13:09 -08:00
|
|
|
nscoord aInflationMinFontSize)
|
|
|
|
{
|
|
|
|
if (aFrame->IsSVGText()) {
|
|
|
|
const nsIFrame* container =
|
|
|
|
nsLayoutUtils::GetClosestFrameOfType(aFrame, nsGkAtoms::svgTextFrame);
|
|
|
|
NS_ASSERTION(container, "expected to find an ancestor SVGTextFrame");
|
|
|
|
return
|
|
|
|
static_cast<const SVGTextFrame*>(container)->GetFontSizeScaleFactor();
|
|
|
|
}
|
|
|
|
return nsLayoutUtils::FontSizeInflationInner(aFrame, aInflationMinFontSize);
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
#define BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM nscoord_MAX
|
|
|
|
#define BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM nscoord_MIN
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-06-17 07:41:33 -07:00
|
|
|
// Place frames in the block direction within a given span (CSS property
|
|
|
|
// vertical-align) Note: this doesn't place frames with vertical-align:
|
|
|
|
// top or bottom as those have to wait until the entire line box block
|
|
|
|
// size is known. This is called after the span frame has finished being
|
|
|
|
// reflowed so that we know its block size.
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2014-06-17 07:41:33 -07:00
|
|
|
nsLineLayout::VerticalAlignFrames(PerSpanData* psd)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Get parent frame info
|
|
|
|
PerFrameData* spanFramePFD = psd->mFrame;
|
|
|
|
nsIFrame* spanFrame = spanFramePFD->mFrame;
|
|
|
|
|
|
|
|
// Get the parent frame's font for all of the frames in this span
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2011-11-23 18:48:23 -08:00
|
|
|
float inflation =
|
2014-03-11 13:23:50 -07:00
|
|
|
GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize);
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(spanFrame, getter_AddRefs(fm),
|
|
|
|
inflation);
|
2011-08-14 10:08:04 -07:00
|
|
|
mBlockReflowState->rendContext->SetFont(fm);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool preMode = mStyleText->WhiteSpaceIsSignificant();
|
2007-03-22 10:30:00 -07: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
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = spanFramePFD->mFrame->GetWritingMode();
|
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool emptyContinuation = psd != mRootSpan &&
|
2008-10-15 13:57:27 -07:00
|
|
|
spanFrame->GetPrevInFlow() && !spanFrame->GetNextInFlow() &&
|
2014-03-11 13:23:50 -07:00
|
|
|
spanFramePFD->mBounds.IsZeroSize();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("[%sSpan]", (psd == mRootSpan)?"Root":"");
|
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
|
|
|
printf(": preMode=%s strictMode=%s w/h=%d,%d emptyContinuation=%s",
|
|
|
|
preMode ? "yes" : "no",
|
2007-10-01 19:36:26 -07:00
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_NavQuirks ? "yes" : "no",
|
2014-03-11 13:23:50 -07:00
|
|
|
spanFramePFD->mBounds.ISize(lineWM),
|
|
|
|
spanFramePFD->mBounds.BSize(lineWM),
|
2007-03-22 10:30:00 -07:00
|
|
|
emptyContinuation ? "yes" : "no");
|
|
|
|
if (psd != mRootSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = spanFramePFD->mFrame->GetWritingMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" bp=%d,%d,%d,%d margin=%d,%d,%d,%d",
|
2014-03-11 13:23:50 -07:00
|
|
|
spanFramePFD->mBorderPadding.Top(frameWM),
|
|
|
|
spanFramePFD->mBorderPadding.Right(frameWM),
|
|
|
|
spanFramePFD->mBorderPadding.Bottom(frameWM),
|
|
|
|
spanFramePFD->mBorderPadding.Left(frameWM),
|
|
|
|
spanFramePFD->mMargin.Top(frameWM),
|
|
|
|
spanFramePFD->mMargin.Right(frameWM),
|
|
|
|
spanFramePFD->mMargin.Bottom(frameWM),
|
|
|
|
spanFramePFD->mMargin.Left(frameWM));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Compute the span's mZeroEffectiveSpanBox flag. What we are trying
|
|
|
|
// to determine is how we should treat the span: should it act
|
|
|
|
// "normally" according to css2 or should it effectively
|
|
|
|
// "disappear".
|
|
|
|
//
|
|
|
|
// In general, if the document being processed is in 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
|
2014-03-11 13:23:50 -07:00
|
|
|
// line block-size.
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool zeroEffectiveSpanBox = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXXldb If we really have empty continuations, then all these other
|
|
|
|
// checks don't make sense for them.
|
|
|
|
// 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-01 19:36:26 -07:00
|
|
|
if ((emptyContinuation ||
|
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_FullStandards) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
((psd == mRootSpan) ||
|
2014-03-11 13:23:50 -07:00
|
|
|
(spanFramePFD->mBorderPadding.IsEmpty() &&
|
|
|
|
spanFramePFD->mMargin.IsEmpty()))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// This code handles an issue with compatibility with non-css
|
|
|
|
// conformant browsers. In particular, there are some cases
|
|
|
|
// where the font-size and line-height for a span must be
|
|
|
|
// ignored and instead the span must *act* as if it were zero
|
|
|
|
// sized. In general, if the span contains any non-compressed
|
|
|
|
// text then we don't use this logic.
|
|
|
|
// However, this is not propagated outwards, since (in compatibility
|
|
|
|
// mode) we don't want big line heights for things like
|
|
|
|
// <p><font size="-1">Text</font></p>
|
|
|
|
|
|
|
|
// 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.
|
2011-10-17 07:59:28 -07:00
|
|
|
zeroEffectiveSpanBox = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
|
|
|
if (pfd->GetFlag(PFD_ISTEXTFRAME) &&
|
|
|
|
(pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME) || preMode ||
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.ISize(mRootSpan->mWritingMode) != 0)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
zeroEffectiveSpanBox = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
psd->mZeroEffectiveSpanBox = zeroEffectiveSpanBox;
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Setup baselineBCoord, minBCoord, and maxBCoord
|
|
|
|
nscoord baselineBCoord, minBCoord, maxBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (psd == mRootSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
// Use a zero baselineBCoord since we don't yet know where the baseline
|
2007-03-22 10:30:00 -07:00
|
|
|
// will be (until we know how tall the line is; then we will
|
2014-03-11 13:23:50 -07:00
|
|
|
// know). In addition, use extreme values for the minBCoord and maxBCoord
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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).
|
2014-03-11 13:23:50 -07:00
|
|
|
baselineBCoord = 0;
|
|
|
|
minBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
maxBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM;
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("[RootSpan]");
|
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": pass1 valign frames: topEdge=%d minLineBSize=%d zeroEffectiveSpanBox=%s\n",
|
|
|
|
mBStartEdge, mMinLineBSize,
|
2007-03-22 10:30:00 -07:00
|
|
|
zeroEffectiveSpanBox ? "yes" : "no");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
// Compute the logical block size for this span. The logical block size
|
|
|
|
// is based on the "line-height" value, not the font-size. Also
|
2007-03-22 10:30:00 -07:00
|
|
|
// compute the top leading.
|
2011-11-23 18:48:23 -08:00
|
|
|
float inflation =
|
2014-03-11 13:23:50 -07:00
|
|
|
GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize);
|
|
|
|
nscoord logicalBSize = nsHTMLReflowState::
|
2014-03-12 20:33:21 -07:00
|
|
|
CalcLineHeight(spanFrame->GetContent(), spanFrame->StyleContext(),
|
2011-11-23 18:48:23 -08:00
|
|
|
mBlockReflowState->ComputedHeight(),
|
|
|
|
inflation);
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord contentBSize = spanFramePFD->mBounds.BSize(lineWM) -
|
|
|
|
spanFramePFD->mBorderPadding.BStart(frameWM) -
|
|
|
|
spanFramePFD->mBorderPadding.BEnd(frameWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Special-case for a ::first-letter frame, set the line height to
|
2014-03-11 13:23:50 -07:00
|
|
|
// the frame block size if the user has left line-height == normal
|
2008-10-15 13:57:27 -07:00
|
|
|
if (spanFramePFD->GetFlag(PFD_ISLETTERFRAME) &&
|
|
|
|
!spanFrame->GetPrevInFlow() &&
|
2013-02-16 13:51:02 -08:00
|
|
|
spanFrame->StyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal) {
|
2014-03-11 13:23:50 -07:00
|
|
|
logicalBSize = spanFramePFD->mBounds.BSize(lineWM);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord leading = logicalBSize - contentBSize;
|
|
|
|
psd->mBStartLeading = leading / 2;
|
|
|
|
psd->mBEndLeading = leading - psd->mBStartLeading;
|
|
|
|
psd->mLogicalBSize = logicalBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (zeroEffectiveSpanBox) {
|
|
|
|
// When the span-box is to be ignored, zero out the initial
|
|
|
|
// values so that the span doesn't impact the final line
|
|
|
|
// height. The contents of the span can impact the final line
|
|
|
|
// height.
|
|
|
|
|
|
|
|
// Note that things are readjusted for this span after its children
|
|
|
|
// are reflowed
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
maxBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// The initial values for the min and max block coord values are in the
|
|
|
|
// span's coordinate space, and cover the logical block size of the span.
|
|
|
|
// If there are child frames in this span that stick out of this area
|
|
|
|
// then the minBCoord and maxBCoord are updated by the amount of logical
|
|
|
|
// blockSize that is outside this range.
|
|
|
|
minBCoord = spanFramePFD->mBorderPadding.BStart(frameWM) -
|
|
|
|
psd->mBStartLeading;
|
|
|
|
maxBCoord = minBCoord + psd->mLogicalBSize;
|
2007-03-22 10:30:00 -07: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.
|
2014-03-11 13:23:50 -07:00
|
|
|
*psd->mBaseline = baselineBCoord = spanFramePFD->mAscent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf("[%sSpan]", (psd == mRootSpan)?"Root":"");
|
|
|
|
nsFrame::ListTag(stdout, spanFrame);
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(": baseLine=%d logicalBSize=%d topLeading=%d h=%d bp=%d,%d zeroEffectiveSpanBox=%s\n",
|
|
|
|
baselineBCoord, psd->mLogicalBSize, psd->mBStartLeading,
|
|
|
|
spanFramePFD->mBounds.BSize(lineWM),
|
|
|
|
spanFramePFD->mBorderPadding.Top(frameWM),
|
|
|
|
spanFramePFD->mBorderPadding.Bottom(frameWM),
|
2007-03-22 10:30:00 -07:00
|
|
|
zeroEffectiveSpanBox ? "yes" : "no");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord maxStartBoxBSize = 0;
|
|
|
|
nscoord maxEndBoxBSize = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame* frame = pfd->mFrame;
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode frameWM = frame->GetWritingMode();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// sanity check (see bug 105168, non-reproducible crashes from null frame)
|
|
|
|
NS_ASSERTION(frame, "null frame in PerFrameData - something is very very bad");
|
|
|
|
if (!frame) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Compute the logical block size of the frame
|
|
|
|
nscoord logicalBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
PerSpanData* frameSpan = pfd->mSpan;
|
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
// For span frames the logical-block-size and start-leading were
|
2007-03-22 10:30:00 -07:00
|
|
|
// pre-computed when the span was reflowed.
|
2014-03-11 13:23:50 -07:00
|
|
|
logicalBSize = frameSpan->mLogicalBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
// For other elements the logical block size is the same as the
|
|
|
|
// frame's block size plus its margins.
|
|
|
|
logicalBSize = pfd->mBounds.BSize(lineWM) +
|
|
|
|
pfd->mMargin.BStartEnd(frameWM);
|
|
|
|
if (logicalBSize < 0 &&
|
2013-11-12 10:38:29 -08:00
|
|
|
mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mAscent -= logicalBSize;
|
|
|
|
logicalBSize = 0;
|
2013-11-12 10:38:29 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Get vertical-align property ("vertical-align" is the CSS name for
|
|
|
|
// block-direction align)
|
2010-08-31 09:05:12 -07:00
|
|
|
const nsStyleCoord& verticalAlign =
|
2013-02-16 13:51:02 -08:00
|
|
|
frame->StyleTextReset()->mVerticalAlign;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t verticalAlignEnum = frame->VerticalAlignEnum();
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" [frame]");
|
|
|
|
nsFrame::ListTag(stdout, frame);
|
2012-08-02 04:38:48 -07:00
|
|
|
printf(": verticalAlignUnit=%d (enum == %d",
|
2011-10-18 10:44:43 -07:00
|
|
|
verticalAlign.GetUnit(),
|
2010-08-31 09:05:12 -07:00
|
|
|
((eStyleUnit_Enumerated == verticalAlign.GetUnit())
|
|
|
|
? verticalAlign.GetIntValue()
|
2007-03-22 10:30:00 -07:00
|
|
|
: -1));
|
2012-08-02 04:38:48 -07:00
|
|
|
if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) {
|
|
|
|
printf(", after SVG dominant-baseline conversion == %d",
|
|
|
|
verticalAlignEnum);
|
|
|
|
}
|
|
|
|
printf(")\n");
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-08-02 04:38:48 -07:00
|
|
|
if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) {
|
|
|
|
switch (verticalAlignEnum) {
|
2010-08-31 09:05:12 -07:00
|
|
|
default:
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
|
|
|
{
|
|
|
|
// The element's baseline is aligned with the baseline of
|
|
|
|
// the parent.
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord - pfd->mAscent;
|
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-31 09:05:12 -07:00
|
|
|
|
|
|
|
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
|
2014-03-11 13:23:50 -07:00
|
|
|
// offset to the baseline BCoord.
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord parentSubscript = fm->SubscriptOffset();
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord revisedBaselineBCoord = baselineBCoord + parentSubscript;
|
|
|
|
pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent;
|
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
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
|
2014-03-11 13:23:50 -07:00
|
|
|
// offset to the baseline BCoord.
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord parentSuperscript = fm->SuperscriptOffset();
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord revisedBaselineBCoord = baselineBCoord - parentSuperscript;
|
|
|
|
pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent;
|
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-31 09:05:12 -07:00
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
|
|
|
{
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_TOP;
|
|
|
|
nscoord subtreeBSize = logicalBSize;
|
2010-08-31 09:05:12 -07:00
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
subtreeBSize = frameSpan->mMaxBCoord - frameSpan->mMinBCoord;
|
|
|
|
NS_ASSERTION(subtreeBSize >= logicalBSize,
|
|
|
|
"unexpected subtree block size");
|
2008-06-06 09:26:58 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (subtreeBSize > maxStartBoxBSize) {
|
|
|
|
maxStartBoxBSize = subtreeBSize;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-31 09:05:12 -07:00
|
|
|
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
|
|
|
{
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_BOTTOM;
|
|
|
|
nscoord subtreeBSize = logicalBSize;
|
2010-08-31 09:05:12 -07:00
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
subtreeBSize = frameSpan->mMaxBCoord - frameSpan->mMinBCoord;
|
|
|
|
NS_ASSERTION(subtreeBSize >= logicalBSize,
|
|
|
|
"unexpected subtree block size");
|
2008-06-06 09:26:58 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (subtreeBSize > maxEndBoxBSize) {
|
|
|
|
maxEndBoxBSize = subtreeBSize;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-31 09:05:12 -07:00
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
|
|
|
{
|
|
|
|
// Align the midpoint of the frame with 1/2 the parents
|
|
|
|
// x-height above the baseline.
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord parentXHeight = fm->XHeight();
|
2010-08-31 09:05:12 -07:00
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord -
|
|
|
|
(parentXHeight + pfd->mBounds.BSize(lineWM))/2;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord -
|
|
|
|
(parentXHeight + logicalBSize)/2 +
|
|
|
|
pfd->mMargin.BStart(frameWM);
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-31 09:05:12 -07:00
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
|
|
|
{
|
|
|
|
// The top of the logical box is aligned with the top of
|
|
|
|
// the parent element's text.
|
2014-06-17 05:19:38 -07:00
|
|
|
// XXX For vertical text we will need a new API to get the logical
|
|
|
|
// max-ascent here
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord parentAscent = fm->MaxAscent();
|
2010-08-31 09:05:12 -07:00
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord - parentAscent -
|
|
|
|
pfd->mBorderPadding.BStart(frameWM) + frameSpan->mBStartLeading;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord - parentAscent +
|
|
|
|
pfd->mMargin.BStart(frameWM);
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-31 09:05:12 -07:00
|
|
|
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
|
|
|
{
|
|
|
|
// The bottom of the logical box is aligned with the
|
|
|
|
// bottom of the parent elements text.
|
2011-04-07 21:18:43 -07:00
|
|
|
nscoord parentDescent = fm->MaxDescent();
|
2010-08-31 09:05:12 -07:00
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord + parentDescent -
|
2014-03-24 02:23:12 -07:00
|
|
|
pfd->mBounds.BSize(lineWM) +
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBorderPadding.BEnd(frameWM) -
|
|
|
|
frameSpan->mBEndLeading;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord + parentDescent -
|
|
|
|
pfd->mBounds.BSize(lineWM) -
|
|
|
|
pfd->mMargin.BEnd(frameWM);
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE:
|
|
|
|
{
|
|
|
|
// Align the midpoint of the frame with the baseline of the parent.
|
|
|
|
if (frameSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord -
|
|
|
|
pfd->mBounds.BSize(lineWM)/2;
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) = baselineBCoord - logicalBSize/2 +
|
|
|
|
pfd->mMargin.BStart(frameWM);
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2010-08-31 09:05:12 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We have either a coord, a percent, or a calc().
|
|
|
|
nscoord pctBasis = 0;
|
|
|
|
if (verticalAlign.HasPercent()) {
|
|
|
|
// Percentages are like lengths, except treated as a percentage
|
2014-03-11 13:23:50 -07:00
|
|
|
// of the elements line block size value.
|
2011-11-23 18:48:23 -08:00
|
|
|
float inflation =
|
2014-03-11 13:23:50 -07:00
|
|
|
GetInflationForBlockDirAlignment(frame, mInflationMinFontSize);
|
2014-03-12 20:33:21 -07:00
|
|
|
pctBasis = nsHTMLReflowState::CalcLineHeight(frame->GetContent(),
|
2014-03-11 13:23:50 -07:00
|
|
|
frame->StyleContext(), mBlockReflowState->ComputedBSize(),
|
2011-11-23 18:48:23 -08:00
|
|
|
inflation);
|
2010-08-31 09:05:12 -07:00
|
|
|
}
|
|
|
|
nscoord offset =
|
|
|
|
nsRuleNode::ComputeCoordPercentCalc(verticalAlign, pctBasis);
|
|
|
|
// 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.
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord revisedBaselineBCoord = baselineBCoord - offset;
|
|
|
|
pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent;
|
|
|
|
pfd->mBlockDirAlign = VALIGN_OTHER;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Update minBCoord/maxBCoord for frames that we just placed. Do not factor
|
2007-03-22 10:30:00 -07:00
|
|
|
// text into the equation.
|
2014-03-11 13:23:50 -07:00
|
|
|
if (pfd->mBlockDirAlign == VALIGN_OTHER) {
|
2014-04-01 11:53:29 -07:00
|
|
|
// Text frames do not contribute to the min/max Y values for the
|
|
|
|
// line (instead their parent frame's font-size contributes).
|
2007-03-22 10:30:00 -07: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.
|
2014-04-01 11:53:29 -07:00
|
|
|
#if 0
|
|
|
|
if (!pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
|
|
|
#else
|
|
|
|
// Only consider non empty text frames when line-height=normal
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canUpdate = !pfd->GetFlag(PFD_ISTEXTFRAME);
|
2014-04-01 11:53:29 -07:00
|
|
|
if (!canUpdate && pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME)) {
|
2007-05-10 23:02:31 -07:00
|
|
|
canUpdate =
|
2013-02-16 13:51:02 -08:00
|
|
|
frame->StyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (canUpdate) {
|
2014-04-01 11:53:29 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord blockStart, blockEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (frameSpan) {
|
|
|
|
// For spans that were are now placing, use their position
|
|
|
|
// plus their already computed min-Y and max-Y values for
|
2014-03-11 13:23:50 -07:00
|
|
|
// computing blockStart and blockEnd.
|
|
|
|
blockStart = pfd->mBounds.BStart(lineWM) + frameSpan->mMinBCoord;
|
|
|
|
blockEnd = pfd->mBounds.BStart(lineWM) + frameSpan->mMaxBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
blockStart = pfd->mBounds.BStart(lineWM) -
|
|
|
|
pfd->mMargin.BStart(frameWM);
|
|
|
|
blockEnd = blockStart + logicalBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (!preMode &&
|
2007-10-01 19:36:26 -07:00
|
|
|
mPresContext->CompatibilityMode() != eCompatibility_FullStandards &&
|
2014-03-11 13:23:50 -07:00
|
|
|
!logicalBSize) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Check if it's a BR frame that is not alone on its line (it
|
2014-03-11 13:23:50 -07:00
|
|
|
// is given a block size of zero to indicate this), and if so reset
|
|
|
|
// blockStart and blockEnd so that BR frames don't influence the line.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (nsGkAtoms::brFrame == frame->GetType()) {
|
2014-03-11 13:23:50 -07:00
|
|
|
blockStart = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM;
|
|
|
|
blockEnd = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (blockStart < minBCoord) minBCoord = blockStart;
|
|
|
|
if (blockEnd > maxBCoord) maxBCoord = blockEnd;
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" [frame]raw: a=%d h=%d bp=%d,%d logical: h=%d leading=%d y=%d minBCoord=%d maxBCoord=%d\n",
|
|
|
|
pfd->mAscent, pfd->mBounds.BSize(lineWM),
|
|
|
|
pfd->mBorderPadding.Top(frameWM),
|
|
|
|
pfd->mBorderPadding.Bottom(frameWM),
|
|
|
|
logicalBSize,
|
|
|
|
frameSpan ? frameSpan->mBStartLeading : 0,
|
|
|
|
pfd->mBounds.BStart(lineWM), minBCoord, maxBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (psd != mRootSpan) {
|
2014-03-11 13:23:50 -07:00
|
|
|
frame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Factor in the minimum line block-size when handling the root-span for
|
2007-03-22 10:30:00 -07:00
|
|
|
// the block.
|
|
|
|
if (psd == mRootSpan) {
|
|
|
|
// 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
|
2009-08-10 19:48:42 -07:00
|
|
|
// (2) if this line has a bullet
|
2007-03-22 10:30:00 -07:00
|
|
|
// (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)
|
2009-08-10 19:48:42 -07:00
|
|
|
|
|
|
|
// (1) and (2) above
|
2012-09-27 18:56:40 -07:00
|
|
|
bool applyMinLH = !psd->mZeroEffectiveSpanBox || mHasBullet;
|
|
|
|
bool isLastLine = (!mLineBox->IsLineWrapped() && !mLineEndsInBR);
|
2009-08-10 19:48:42 -07:00
|
|
|
if (!applyMinLH && isLastLine) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIContent* blockContent = mRootSpan->mFrame->mFrame->GetContent();
|
|
|
|
if (blockContent) {
|
|
|
|
nsIAtom *blockTagAtom = blockContent->Tag();
|
|
|
|
// (3) above, if the last line of LI, DT, or DD
|
2009-08-10 19:48:42 -07:00
|
|
|
if (blockTagAtom == nsGkAtoms::li ||
|
|
|
|
blockTagAtom == nsGkAtoms::dt ||
|
|
|
|
blockTagAtom == nsGkAtoms::dd) {
|
2011-10-17 07:59:28 -07:00
|
|
|
applyMinLH = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (applyMinLH) {
|
2012-09-27 18:56:40 -07:00
|
|
|
if (psd->mHasNonemptyContent || preMode || mHasBullet) {
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" [span]==> adjusting min/maxBCoord: currentValues: %d,%d", minBCoord, maxBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord minimumLineBSize = mMinLineBSize;
|
|
|
|
nscoord blockStart =
|
|
|
|
-nsLayoutUtils::GetCenteredFontBaseline(fm, minimumLineBSize);
|
|
|
|
nscoord blockEnd = blockStart + minimumLineBSize;
|
2009-05-18 15:13:12 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
if (blockStart < minBCoord) minBCoord = blockStart;
|
|
|
|
if (blockEnd > maxBCoord) maxBCoord = blockEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" new values: %d,%d\n", minBCoord, maxBCoord);
|
2009-04-21 16:53:52 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" Used mMinLineBSize: %d, blockStart: %d, blockEnd: %d\n", mMinLineBSize, blockStart, blockEnd);
|
2007-03-22 10:30:00 -07: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)
|
|
|
|
|
|
|
|
// XXX Are there other problems with this?
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" [span]==> zapping min/maxBCoord: currentValues: %d,%d newValues: 0,0\n",
|
|
|
|
minBCoord, maxBCoord);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord = maxBCoord = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
if ((minBCoord == BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM) ||
|
|
|
|
(maxBCoord == BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM)) {
|
|
|
|
minBCoord = maxBCoord = baselineBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((psd != mRootSpan) && (psd->mZeroEffectiveSpanBox)) {
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
2007-03-22 10:30:00 -07:00
|
|
|
printf(" [span]adjusting for zeroEffectiveSpanBox\n");
|
2014-03-11 13:23:50 -07:00
|
|
|
printf(" Original: minBCoord=%d, maxBCoord=%d, bSize=%d, ascent=%d, logicalBSize=%d, topLeading=%d, bottomLeading=%d\n",
|
|
|
|
minBCoord, maxBCoord, spanFramePFD->mBounds.BSize(frameWM),
|
2007-03-22 10:30:00 -07:00
|
|
|
spanFramePFD->mAscent,
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mLogicalBSize, psd->mBStartLeading, psd->mBEndLeading);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord goodMinBCoord = spanFramePFD->mBorderPadding.BStart(frameWM) -
|
|
|
|
psd->mBStartLeading;
|
|
|
|
nscoord goodMaxBCoord = goodMinBCoord + psd->mLogicalBSize;
|
2012-01-01 14:35:12 -08:00
|
|
|
|
|
|
|
// For cases like the one in bug 714519 (text-decoration placement
|
2014-03-11 13:23:50 -07:00
|
|
|
// or making nsLineLayout::IsZeroBSize() handle
|
2012-01-01 14:35:12 -08:00
|
|
|
// vertical-align:top/bottom on a descendant of the line that's not
|
|
|
|
// a child of it), we want to treat elements that are
|
|
|
|
// vertical-align: top or bottom somewhat like children for the
|
|
|
|
// purposes of this quirk. To some extent, this is guessing, since
|
|
|
|
// they might end up being aligned anywhere. However, we'll guess
|
|
|
|
// that they'll be placed aligned with the top or bottom of this
|
|
|
|
// frame (as though this frame is the only thing in the line).
|
|
|
|
// (Guessing isn't crazy, since all we're doing is reducing the
|
|
|
|
// scope of a quirk and making the behavior more standards-like.)
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxStartBoxBSize > maxBCoord - minBCoord) {
|
|
|
|
// Distribute maxStartBoxBSize to ascent (baselineBCoord - minBCoord), and
|
|
|
|
// then to descent (maxBCoord - baselineBCoord) by adjusting minBCoord or
|
|
|
|
// maxBCoord, but not to exceed goodMinBCoord and goodMaxBCoord.
|
|
|
|
nscoord distribute = maxStartBoxBSize - (maxBCoord - minBCoord);
|
|
|
|
nscoord ascentSpace = std::max(minBCoord - goodMinBCoord, 0);
|
2012-01-01 14:35:12 -08:00
|
|
|
if (distribute > ascentSpace) {
|
|
|
|
distribute -= ascentSpace;
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord -= ascentSpace;
|
|
|
|
nscoord descentSpace = std::max(goodMaxBCoord - maxBCoord, 0);
|
2012-01-01 14:35:12 -08:00
|
|
|
if (distribute > descentSpace) {
|
2014-03-11 13:23:50 -07:00
|
|
|
maxBCoord += descentSpace;
|
2012-01-01 14:35:12 -08:00
|
|
|
} else {
|
2014-03-11 13:23:50 -07:00
|
|
|
maxBCoord += distribute;
|
2012-01-01 14:35:12 -08:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord -= distribute;
|
2012-01-01 14:35:12 -08:00
|
|
|
}
|
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxEndBoxBSize > maxBCoord - minBCoord) {
|
2012-01-01 14:35:12 -08:00
|
|
|
// Likewise, but preferring descent to ascent.
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord distribute = maxEndBoxBSize - (maxBCoord - minBCoord);
|
|
|
|
nscoord descentSpace = std::max(goodMaxBCoord - maxBCoord, 0);
|
2012-01-01 14:35:12 -08:00
|
|
|
if (distribute > descentSpace) {
|
|
|
|
distribute -= descentSpace;
|
2014-03-11 13:23:50 -07:00
|
|
|
maxBCoord += descentSpace;
|
|
|
|
nscoord ascentSpace = std::max(minBCoord - goodMinBCoord, 0);
|
2012-01-01 14:35:12 -08:00
|
|
|
if (distribute > ascentSpace) {
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord -= ascentSpace;
|
2012-01-01 14:35:12 -08:00
|
|
|
} else {
|
2014-03-11 13:23:50 -07:00
|
|
|
minBCoord -= distribute;
|
2012-01-01 14:35:12 -08:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-11 13:23:50 -07:00
|
|
|
maxBCoord += distribute;
|
2012-01-01 14:35:12 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
if (minBCoord > goodMinBCoord) {
|
|
|
|
nscoord adjust = minBCoord - goodMinBCoord; // positive
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// shrink the logical extents
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mLogicalBSize -= adjust;
|
|
|
|
psd->mBStartLeading -= adjust;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxBCoord < goodMaxBCoord) {
|
|
|
|
nscoord adjust = goodMaxBCoord - maxBCoord;
|
|
|
|
psd->mLogicalBSize -= adjust;
|
|
|
|
psd->mBEndLeading -= adjust;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (minBCoord > 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// shrink the content by moving its block start down. This is tricky,
|
|
|
|
// since the block start is the 0 for many coordinates, so what we do is
|
2007-03-22 10:30:00 -07:00
|
|
|
// move everything else up.
|
2014-03-11 13:23:50 -07:00
|
|
|
spanFramePFD->mAscent -= minBCoord; // move the baseline up
|
|
|
|
spanFramePFD->mBounds.BSize(lineWM) -= minBCoord; // move the block end up
|
|
|
|
psd->mBStartLeading += minBCoord;
|
|
|
|
*psd->mBaseline -= minBCoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
pfd = psd->mFirstFrame;
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.BStart(lineWM) -= minBCoord; // move all the children
|
|
|
|
// back up
|
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
pfd = pfd->mNext;
|
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
maxBCoord -= minBCoord; // since minBCoord is in the frame's own
|
|
|
|
// coordinate system
|
|
|
|
minBCoord = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxBCoord < spanFramePFD->mBounds.BSize(lineWM)) {
|
|
|
|
nscoord adjust = spanFramePFD->mBounds.BSize(lineWM) - maxBCoord;
|
|
|
|
spanFramePFD->mBounds.BSize(lineWM) -= adjust; // move the bottom up
|
|
|
|
psd->mBEndLeading += adjust;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" New: minBCoord=%d, maxBCoord=%d, bSize=%d, ascent=%d, logicalBSize=%d, topLeading=%d, bottomLeading=%d\n",
|
|
|
|
minBCoord, maxBCoord, spanFramePFD->mBounds.BSize(lineWM),
|
2007-03-22 10:30:00 -07:00
|
|
|
spanFramePFD->mAscent,
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mLogicalBSize, psd->mBStartLeading, psd->mBEndLeading);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mMinBCoord = minBCoord;
|
|
|
|
psd->mMaxBCoord = maxBCoord;
|
|
|
|
#ifdef NOISY_BLOCKDIR_ALIGN
|
|
|
|
printf(" [span]==> minBCoord=%d maxBCoord=%d delta=%d maxStartBoxBSize=%d maxEndBoxBSize=%d\n",
|
|
|
|
minBCoord, maxBCoord, maxBCoord - minBCoord, maxStartBoxBSize, maxEndBoxBSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxStartBoxBSize > mMaxStartBoxBSize) {
|
|
|
|
mMaxStartBoxBSize = maxStartBoxBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
if (maxEndBoxBSize > mMaxEndBoxBSize) {
|
|
|
|
mMaxEndBoxBSize = maxEndBoxBSize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SlideSpanFrameRect(nsIFrame* aFrame, nscoord aDeltaWidth)
|
|
|
|
{
|
2013-09-17 04:44:16 -07:00
|
|
|
// This should not use nsIFrame::MovePositionBy because it happens
|
|
|
|
// prior to relative positioning. In particular, because
|
|
|
|
// nsBlockFrame::PlaceLine calls aLineLayout.TrimTrailingWhiteSpace()
|
|
|
|
// prior to calling aLineLayout.RelativePositionFrames().
|
|
|
|
nsPoint p = aFrame->GetPosition();
|
|
|
|
p.x -= aDeltaWidth;
|
|
|
|
aFrame->SetPosition(p);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::TrimTrailingWhiteSpaceIn(PerSpanData* psd,
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord* aDeltaISize)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
PerFrameData* pfd = psd->mFirstFrame;
|
|
|
|
if (!pfd) {
|
2014-03-11 13:23:50 -07:00
|
|
|
*aDeltaISize = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
pfd = pfd->Last();
|
2012-07-30 07:20:58 -07:00
|
|
|
while (nullptr != pfd) {
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef REALLY_NOISY_TRIM
|
|
|
|
nsFrame::ListTag(stdout, (psd == mRootSpan
|
|
|
|
? mBlockReflowState->frame
|
|
|
|
: psd->mFrame->mFrame));
|
|
|
|
printf(": attempting trim of ");
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
PerSpanData* childSpan = pfd->mSpan;
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (childSpan) {
|
|
|
|
// Maybe the child span has the trailing white-space in it?
|
2014-03-11 13:23:50 -07:00
|
|
|
if (TrimTrailingWhiteSpaceIn(childSpan, aDeltaISize)) {
|
|
|
|
nscoord deltaISize = *aDeltaISize;
|
|
|
|
if (deltaISize) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Adjust the child spans frame size
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.ISize(lineWM) -= deltaISize;
|
2007-03-22 10:30:00 -07: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
|
2014-06-17 07:41:33 -07:00
|
|
|
// later, however, because the VerticalAlignFrames method
|
2007-03-22 10:30:00 -07:00
|
|
|
// will be run after this method.
|
|
|
|
nsIFrame* f = pfd->mFrame;
|
2014-03-11 13:23:50 -07:00
|
|
|
LogicalRect r(lineWM, f->GetRect(), mContainerWidth);
|
|
|
|
r.ISize(lineWM) -= deltaISize;
|
|
|
|
f->SetRect(lineWM, r, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
// Adjust the inline end edge of the span that contains the child span
|
|
|
|
psd->mICoord -= deltaISize;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Slide any frames that follow the child span over by the
|
2014-03-11 13:23:50 -07:00
|
|
|
// correct amount. The only thing that can follow the child
|
2007-03-22 10:30:00 -07:00
|
|
|
// span is empty stuff, so we are just making things
|
|
|
|
// sensible (keeping the combined area honest).
|
|
|
|
while (pfd->mNext) {
|
|
|
|
pfd = pfd->mNext;
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) -= deltaISize;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (psd != mRootSpan) {
|
|
|
|
// When the child span is not a direct child of the block
|
2014-03-11 13:23:50 -07:00
|
|
|
// we need to update the child span's frame rectangle
|
2007-03-22 10:30:00 -07:00
|
|
|
// because it most likely will not be done again. Spans
|
|
|
|
// that are direct children of the block will be updated
|
2014-06-17 07:41:33 -07:00
|
|
|
// later, however, because the VerticalAlignFrames method
|
2007-03-22 10:30:00 -07:00
|
|
|
// will be run after this method.
|
2014-03-11 13:23:50 -07:00
|
|
|
SlideSpanFrameRect(pfd->mFrame, deltaISize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!pfd->GetFlag(PFD_ISTEXTFRAME) &&
|
|
|
|
!pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) {
|
|
|
|
// 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.
|
2014-03-11 13:23:50 -07:00
|
|
|
*aDeltaISize = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-12-01 01:24:24 -08: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef NOISY_TRIM
|
|
|
|
nsFrame::ListTag(stdout, (psd == mRootSpan
|
|
|
|
? mBlockReflowState->frame
|
|
|
|
: psd->mFrame->mFrame));
|
|
|
|
printf(": trim of ");
|
|
|
|
nsFrame::ListTag(stdout, pfd->mFrame);
|
2007-12-01 01:24:24 -08:00
|
|
|
printf(" returned %d\n", trimOutput.mDeltaWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2007-12-01 01:24:24 -08:00
|
|
|
if (trimOutput.mLastCharIsJustifiable && pfd->mJustificationNumSpaces > 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
pfd->mJustificationNumSpaces--;
|
|
|
|
}
|
2007-12-01 01:24:24 -08:00
|
|
|
|
|
|
|
if (trimOutput.mChanged) {
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, true);
|
2007-12-01 01:24:24 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-12-01 01:24:24 -08:00
|
|
|
if (trimOutput.mDeltaWidth) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.ISize(lineWM) -= trimOutput.mDeltaWidth;
|
2007-03-22 10:30:00 -07: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.
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust containing span's right edge
|
2014-03-11 13:23:50 -07:00
|
|
|
psd->mICoord -= trimOutput.mDeltaWidth;
|
2007-03-22 10:30:00 -07: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;
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) -= trimOutput.mDeltaWidth;
|
2007-03-22 10:30:00 -07: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
|
2014-06-17 07:41:33 -07:00
|
|
|
// later, however, because the VerticalAlignFrames method
|
2007-03-22 10:30:00 -07:00
|
|
|
// will be run after this method.
|
2007-12-01 01:24:24 -08:00
|
|
|
SlideSpanFrameRect(pfd->mFrame, trimOutput.mDeltaWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 01:24:24 -08:00
|
|
|
if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME) || trimOutput.mChanged) {
|
|
|
|
// Pass up to caller so they can shrink their span
|
2014-03-11 13:23:50 -07:00
|
|
|
*aDeltaISize = trimOutput.mDeltaWidth;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-12-01 01:24:24 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
pfd = pfd->mPrev;
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
*aDeltaISize = 0;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsLineLayout::TrimTrailingWhiteSpace()
|
|
|
|
{
|
|
|
|
PerSpanData* psd = mRootSpan;
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord deltaISize;
|
|
|
|
TrimTrailingWhiteSpaceIn(psd, &deltaISize);
|
|
|
|
return 0 != deltaISize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsLineLayout::ComputeJustificationWeights(PerSpanData* aPSD,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t* aNumSpaces,
|
|
|
|
int32_t* aNumLetters)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aPSD, "null arg");
|
|
|
|
NS_ASSERTION(aNumSpaces, "null arg");
|
|
|
|
NS_ASSERTION(aNumLetters, "null arg");
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numSpaces = 0;
|
|
|
|
int32_t numLetters = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nullptr; pfd = pfd->mNext) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
if (true == pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
numSpaces += pfd->mJustificationNumSpaces;
|
|
|
|
numLetters += pfd->mJustificationNumLetters;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
else if (pfd->mSpan != nullptr) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t spanSpaces;
|
|
|
|
int32_t spanLetters;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
nscoord deltaICoord = 0;
|
2012-07-30 07:20:58 -07:00
|
|
|
for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nullptr; pfd = pfd->mNext) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Don't reposition bullets (and other frames that occur out of X-order?)
|
|
|
|
if (!pfd->GetFlag(PFD_ISBULLET)) {
|
|
|
|
nscoord dw = 0;
|
2014-03-24 10:50:13 -07:00
|
|
|
WritingMode lineWM = mRootSpan->mWritingMode;
|
2014-03-11 13:23:50 -07:00
|
|
|
|
|
|
|
pfd->mBounds.IStart(lineWM) += deltaICoord;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
if (true == pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aState->mTotalWidthForSpaces > 0 &&
|
|
|
|
aState->mTotalNumSpaces > 0) {
|
|
|
|
aState->mNumSpacesProcessed += pfd->mJustificationNumSpaces;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForSpaces =
|
|
|
|
(aState->mTotalWidthForSpaces*aState->mNumSpacesProcessed)
|
|
|
|
/aState->mTotalNumSpaces;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForSpaces - aState->mWidthForSpacesProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForSpacesProcessed = newAllocatedWidthForSpaces;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aState->mTotalWidthForLetters > 0 &&
|
|
|
|
aState->mTotalNumLetters > 0) {
|
|
|
|
aState->mNumLettersProcessed += pfd->mJustificationNumLetters;
|
|
|
|
|
|
|
|
nscoord newAllocatedWidthForLetters =
|
|
|
|
(aState->mTotalWidthForLetters*aState->mNumLettersProcessed)
|
|
|
|
/aState->mTotalNumLetters;
|
|
|
|
|
|
|
|
dw += newAllocatedWidthForLetters - aState->mWidthForLettersProcessed;
|
|
|
|
|
|
|
|
aState->mWidthForLettersProcessed = newAllocatedWidthForLetters;
|
|
|
|
}
|
2007-09-23 19:19:14 -07:00
|
|
|
|
|
|
|
if (dw) {
|
2011-10-17 07:59:28 -07:00
|
|
|
pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, true);
|
2007-09-23 19:19:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != pfd->mSpan) {
|
2007-03-22 10:30:00 -07:00
|
|
|
dw += ApplyFrameJustification(pfd->mSpan, aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.ISize(lineWM) += dw;
|
|
|
|
|
|
|
|
deltaICoord += dw;
|
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
return deltaICoord;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-17 07:41:33 -07:00
|
|
|
// Align inline frames within the line according to the CSS text-align
|
|
|
|
// property.
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2014-06-17 07:41:33 -07:00
|
|
|
nsLineLayout::TextAlignLine(nsLineBox* aLine,
|
|
|
|
bool aIsLastLine)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-12 09:52:21 -08:00
|
|
|
/**
|
|
|
|
* NOTE: aIsLastLine ain't necessarily so: it is correctly set by caller
|
|
|
|
* only in cases where the last line needs special handling.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
PerSpanData* psd = mRootSpan;
|
2014-04-16 01:03:28 -07:00
|
|
|
WritingMode lineWM = psd->mWritingMode;
|
2014-03-11 13:23:50 -07:00
|
|
|
NS_WARN_IF_FALSE(psd->mIEnd != NS_UNCONSTRAINEDSIZE,
|
2009-10-28 20:22:28 -07:00
|
|
|
"have unconstrained width; this should only result from "
|
|
|
|
"very large sizes, not attempts at intrinsic width "
|
|
|
|
"calculation");
|
2014-04-16 01:03:28 -07:00
|
|
|
nscoord availISize = psd->mIEnd - psd->mIStart;
|
|
|
|
nscoord remainingISize = availISize - aLine->ISize();
|
2014-03-11 13:23:50 -07:00
|
|
|
#ifdef NOISY_INLINEDIR_ALIGN
|
2013-10-27 13:56:32 -07:00
|
|
|
nsFrame::ListTag(stdout, mBlockReflowState->frame);
|
2014-04-16 01:03:28 -07:00
|
|
|
printf(": availISize=%d lineBounds.IStart=%d lineISize=%d delta=%d\n",
|
|
|
|
availISize, aLine->IStart(), aLine->ISize(), remainingISize);
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
2012-01-12 09:52:21 -08:00
|
|
|
|
2013-10-27 13:56:32 -07:00
|
|
|
// 'text-align-last: auto' is equivalent to the value of the 'text-align'
|
|
|
|
// property except when 'text-align' is set to 'justify', in which case it
|
|
|
|
// is 'justify' when 'text-justify' is 'distribute' and 'start' otherwise.
|
|
|
|
//
|
|
|
|
// XXX: the code below will have to change when we implement text-justify
|
|
|
|
//
|
|
|
|
nscoord dx = 0;
|
|
|
|
uint8_t textAlign = mStyleText->mTextAlign;
|
|
|
|
bool textAlignTrue = mStyleText->mTextAlignTrue;
|
|
|
|
if (aIsLastLine) {
|
|
|
|
textAlignTrue = mStyleText->mTextAlignLastTrue;
|
|
|
|
if (mStyleText->mTextAlignLast == NS_STYLE_TEXT_ALIGN_AUTO) {
|
|
|
|
if (textAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY) {
|
|
|
|
textAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;
|
2012-01-12 09:52:21 -08:00
|
|
|
}
|
2013-10-27 13:56:32 -07:00
|
|
|
} else {
|
|
|
|
textAlign = mStyleText->mTextAlignLast;
|
2012-01-12 09:52:21 -08:00
|
|
|
}
|
2013-10-27 13:56:32 -07:00
|
|
|
}
|
|
|
|
|
2014-04-16 01:03:28 -07:00
|
|
|
if ((remainingISize > 0 || textAlignTrue) &&
|
2013-10-27 13:56:32 -07:00
|
|
|
!(mBlockReflowState->frame->IsSVGText())) {
|
2012-01-12 09:52:21 -08:00
|
|
|
|
|
|
|
switch (textAlign) {
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_TEXT_ALIGN_JUSTIFY:
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t numSpaces;
|
|
|
|
int32_t numLetters;
|
2014-04-16 01:03:28 -07:00
|
|
|
|
2012-01-12 09:52:21 -08:00
|
|
|
ComputeJustificationWeights(psd, &numSpaces, &numLetters);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-12 09:52:21 -08:00
|
|
|
if (numSpaces > 0) {
|
|
|
|
FrameJustificationState state =
|
2014-04-16 01:03:28 -07:00
|
|
|
{ numSpaces, numLetters, remainingISize, 0, 0, 0, 0, 0 };
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-12 09:52:21 -08:00
|
|
|
// Apply the justification, and make sure to update our linebox
|
|
|
|
// width to account for it.
|
2014-04-16 01:03:28 -07:00
|
|
|
aLine->ExpandBy(ApplyFrameJustification(psd, &state),
|
|
|
|
mContainerWidth);
|
2012-01-12 09:52:21 -08:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-01-12 09:52:21 -08:00
|
|
|
// Fall through to the default case if we could not justify to fill
|
|
|
|
// the space.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_DEFAULT:
|
2014-03-11 13:23:50 -07:00
|
|
|
// default alignment is to start edge so do nothing
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_LEFT:
|
|
|
|
if (!lineWM.IsBidiLTR()) {
|
2014-04-16 01:03:28 -07:00
|
|
|
dx = remainingISize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT:
|
2014-03-11 13:23:50 -07:00
|
|
|
if (lineWM.IsBidiLTR()) {
|
2014-04-16 01:03:28 -07:00
|
|
|
dx = remainingISize;
|
2014-03-11 01:22:52 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-11 13:23:50 -07:00
|
|
|
case NS_STYLE_TEXT_ALIGN_END:
|
2014-04-16 01:03:28 -07:00
|
|
|
dx = remainingISize;
|
2014-03-11 01:22:52 -07:00
|
|
|
break;
|
2014-03-10 22:19:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
case NS_STYLE_TEXT_ALIGN_CENTER:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_MOZ_CENTER:
|
2014-04-16 01:03:28 -07:00
|
|
|
dx = remainingISize / 2;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-12 01:18:27 -07:00
|
|
|
|
|
|
|
if (dx) {
|
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
2014-03-11 13:23:50 -07:00
|
|
|
pfd->mBounds.IStart(lineWM) += dx;
|
|
|
|
pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-04-16 01:03:28 -07:00
|
|
|
aLine->IndentBy(dx, mContainerWidth);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-03-11 13:23:50 -07:00
|
|
|
|
|
|
|
if (mPresContext->BidiEnabled() &&
|
|
|
|
(!mPresContext->IsVisualMode() || !lineWM.IsBidiLTR())) {
|
2014-04-16 01:03:28 -07:00
|
|
|
nsBidiPresUtils::ReorderFrames(psd->mFirstFrame->mFrame,
|
|
|
|
aLine->GetChildCount(),
|
2014-03-11 13:23:50 -07:00
|
|
|
lineWM, mContainerWidth);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-06 21:25:45 -07:00
|
|
|
nsLineLayout::RelativePositionFrames(nsOverflowAreas& aOverflowAreas)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-10-06 21:25:45 -07:00
|
|
|
RelativePositionFrames(mRootSpan, aOverflowAreas);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-06 21:25:45 -07:00
|
|
|
nsLineLayout::RelativePositionFrames(PerSpanData* psd, nsOverflowAreas& aOverflowAreas)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-10-06 21:25:45 -07:00
|
|
|
nsOverflowAreas overflowAreas;
|
2014-03-11 13:23:50 -07:00
|
|
|
WritingMode wm = psd->mWritingMode;
|
2012-07-30 07:20:58 -07:00
|
|
|
if (nullptr != psd->mFrame) {
|
2010-10-06 21:25:45 -07:00
|
|
|
// The span's overflow areas come in three parts:
|
2007-03-22 10:30:00 -07:00
|
|
|
// -- this frame's width and height
|
2010-10-06 21:25:45 -07:00
|
|
|
// -- pfd->mOverflowAreas, which is the area of a bullet or the union
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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-11 17:43:09 -08: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-12 15:02:32 -07:00
|
|
|
|
2010-10-06 21:25:45 -07:00
|
|
|
overflowAreas.ScrollableOverflow().UnionRect(
|
|
|
|
psd->mFrame->mOverflowAreas.ScrollableOverflow(), adjustedBounds);
|
|
|
|
overflowAreas.VisualOverflow().UnionRect(
|
|
|
|
psd->mFrame->mOverflowAreas.VisualOverflow(), adjustedBounds);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2014-03-11 13:23:50 -07:00
|
|
|
LogicalRect rect(wm, psd->mIStart, mBStartEdge,
|
|
|
|
psd->mICoord - psd->mIStart, mFinalLineBSize);
|
2007-03-22 10:30:00 -07:00
|
|
|
// The minimum combined area for the frames that are direct
|
|
|
|
// children of the block starts at the upper left corner of the
|
|
|
|
// line and is sized to match the size of the line's bounding box
|
2014-06-17 07:41:33 -07:00
|
|
|
// (the same size as the values returned from VerticalAlignFrames)
|
2014-03-11 13:23:50 -07:00
|
|
|
overflowAreas.VisualOverflow() = rect.GetPhysicalRect(wm, mContainerWidth);
|
2010-10-06 21:25:45 -07:00
|
|
|
overflowAreas.ScrollableOverflow() = overflowAreas.VisualOverflow();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) {
|
|
|
|
nsIFrame* frame = pfd->mFrame;
|
2007-12-11 17:43:09 -08:00
|
|
|
nsPoint origin = frame->GetPosition();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Adjust the origin of the frame
|
|
|
|
if (pfd->GetFlag(PFD_RELATIVEPOS)) {
|
2014-03-11 13:23:50 -07:00
|
|
|
//XXX temporary until ApplyRelativePositioning can handle logical offsets
|
|
|
|
nsMargin physicalOffsets =
|
|
|
|
pfd->mOffsets.GetPhysicalMargin(pfd->mFrame->GetWritingMode());
|
2007-03-22 10:30:00 -07:00
|
|
|
// right and bottom are handled by
|
|
|
|
// nsHTMLReflowState::ComputeRelativeOffsets
|
2013-08-08 17:20:17 -07:00
|
|
|
nsHTMLReflowState::ApplyRelativePositioning(pfd->mFrame,
|
2014-03-11 13:23:50 -07:00
|
|
|
physicalOffsets,
|
2013-07-15 17:28:09 -07:00
|
|
|
&origin);
|
2007-12-11 17:43:09 -08:00
|
|
|
frame->SetPosition(origin);
|
2007-03-22 10:30:00 -07: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,
|
2010-10-06 21:25:45 -07:00
|
|
|
frame->GetView(), pfd->mOverflowAreas.VisualOverflow(),
|
|
|
|
NS_FRAME_NO_SIZE_VIEW);
|
2007-03-22 10:30:00 -07: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.
|
2010-10-06 21:25:45 -07:00
|
|
|
nsOverflowAreas r;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (pfd->mSpan) {
|
|
|
|
// Compute a new combined area for the child span before
|
|
|
|
// aggregating it into our combined area.
|
|
|
|
RelativePositionFrames(pfd->mSpan, r);
|
|
|
|
} else {
|
2010-10-06 21:25:45 -07:00
|
|
|
r = pfd->mOverflowAreas;
|
2007-11-08 22:49:38 -08:00
|
|
|
if (pfd->GetFlag(PFD_ISTEXTFRAME)) {
|
2011-08-03 11:30:58 -07:00
|
|
|
// We need to recompute overflow areas in two cases:
|
|
|
|
// (1) When PFD_RECOMPUTEOVERFLOW is set due to trimming
|
|
|
|
// (2) When there are text decorations, since we can't recompute the
|
2014-06-17 07:41:33 -07:00
|
|
|
// overflow area until Reflow and VerticalAlignLine have finished
|
2011-08-03 11:30:58 -07:00
|
|
|
if (pfd->GetFlag(PFD_RECOMPUTEOVERFLOW) ||
|
2013-02-15 21:38:33 -08:00
|
|
|
frame->StyleContext()->HasTextDecorationLines()) {
|
2007-11-08 22:49:38 -08:00
|
|
|
nsTextFrame* f = static_cast<nsTextFrame*>(frame);
|
2011-11-23 18:48:23 -08:00
|
|
|
r = f->RecomputeOverflow(*mBlockReflowState);
|
2007-11-08 22:49:38 -08:00
|
|
|
}
|
2010-10-06 21:25:45 -07:00
|
|
|
frame->FinishAndStoreOverflow(r, frame->GetSize());
|
2007-09-23 19:19:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
nsContainerFrame::PositionChildViews(frame);
|
|
|
|
}
|
|
|
|
|
2009-04-05 17:31:50 -07:00
|
|
|
// Do this here (rather than along with setting the overflow rect
|
|
|
|
// below) so we get leaf frames as well. No need to worry
|
2007-03-22 10:30:00 -07:00
|
|
|
// about the root span, since it doesn't have a frame.
|
|
|
|
if (frame->HasView())
|
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, frame,
|
2010-10-06 21:25:45 -07:00
|
|
|
frame->GetView(),
|
|
|
|
r.VisualOverflow(),
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_NO_MOVE_VIEW);
|
|
|
|
|
2010-10-06 21:25:45 -07:00
|
|
|
overflowAreas.UnionWith(r + origin);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we just computed a spans combined area, we need to update its
|
2009-04-05 17:31:50 -07:00
|
|
|
// overflow rect...
|
2007-03-22 10:30:00 -07:00
|
|
|
if (psd->mFrame) {
|
|
|
|
PerFrameData* spanPFD = psd->mFrame;
|
|
|
|
nsIFrame* frame = spanPFD->mFrame;
|
2010-10-06 21:25:45 -07:00
|
|
|
frame->FinishAndStoreOverflow(overflowAreas, frame->GetSize());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-10-06 21:25:45 -07:00
|
|
|
aOverflowAreas = overflowAreas;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|