michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* state and methods used while laying out a single line of a block frame */ michael@0: michael@0: // This has to be defined before nsLineLayout.h is included, because michael@0: // nsLineLayout.h has a #include for plarena.h, which needs this defined: michael@0: #define PL_ARENA_CONST_ALIGN_MASK (sizeof(void*)-1) michael@0: #include "nsLineLayout.h" michael@0: michael@0: #include "SVGTextFrame.h" michael@0: #include "nsBlockFrame.h" michael@0: #include "nsStyleConsts.h" michael@0: #include "nsContainerFrame.h" michael@0: #include "nsFloatManager.h" michael@0: #include "nsStyleContext.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsRenderingContext.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsIContent.h" michael@0: #include "nsLayoutUtils.h" michael@0: #include "nsTextFrame.h" michael@0: #include "nsStyleStructInlines.h" michael@0: #include "nsBidiPresUtils.h" michael@0: #include michael@0: michael@0: #ifdef DEBUG michael@0: #undef NOISY_INLINEDIR_ALIGN michael@0: #undef NOISY_BLOCKDIR_ALIGN michael@0: #undef REALLY_NOISY_BLOCKDIR_ALIGN michael@0: #undef NOISY_REFLOW michael@0: #undef REALLY_NOISY_REFLOW michael@0: #undef NOISY_PUSHING michael@0: #undef REALLY_NOISY_PUSHING michael@0: #undef DEBUG_ADD_TEXT michael@0: #undef NOISY_MAX_ELEMENT_SIZE michael@0: #undef REALLY_NOISY_MAX_ELEMENT_SIZE michael@0: #undef NOISY_CAN_PLACE_FRAME michael@0: #undef NOISY_TRIM michael@0: #undef REALLY_NOISY_TRIM michael@0: #endif michael@0: michael@0: using namespace mozilla; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: michael@0: #define FIX_BUG_50257 michael@0: michael@0: nsLineLayout::nsLineLayout(nsPresContext* aPresContext, michael@0: nsFloatManager* aFloatManager, michael@0: const nsHTMLReflowState* aOuterReflowState, michael@0: const nsLineList::iterator* aLine) michael@0: : mPresContext(aPresContext), michael@0: mFloatManager(aFloatManager), michael@0: mBlockReflowState(aOuterReflowState), michael@0: mLastOptionalBreakContent(nullptr), michael@0: mForceBreakContent(nullptr), michael@0: mBlockRS(nullptr),/* XXX temporary */ michael@0: mLastOptionalBreakPriority(gfxBreakPriority::eNoBreak), michael@0: mLastOptionalBreakContentOffset(-1), michael@0: mForceBreakContentOffset(-1), michael@0: mMinLineBSize(0), michael@0: mTextIndent(0), michael@0: mFirstLetterStyleOK(false), michael@0: mIsTopOfPage(false), michael@0: mImpactedByFloats(false), michael@0: mLastFloatWasLetterFrame(false), michael@0: mLineIsEmpty(false), michael@0: mLineEndsInBR(false), michael@0: mNeedBackup(false), michael@0: mInFirstLine(false), michael@0: mGotLineBox(false), michael@0: mInFirstLetter(false), michael@0: mHasBullet(false), michael@0: mDirtyNextLine(false), michael@0: mLineAtStart(false) michael@0: { michael@0: MOZ_ASSERT(aOuterReflowState, "aOuterReflowState must not be null"); michael@0: NS_ASSERTION(aFloatManager || aOuterReflowState->frame->GetType() == michael@0: nsGkAtoms::letterFrame, michael@0: "float manager should be present"); michael@0: MOZ_COUNT_CTOR(nsLineLayout); michael@0: michael@0: // Stash away some style data that we need michael@0: nsBlockFrame* blockFrame = do_QueryFrame(aOuterReflowState->frame); michael@0: if (blockFrame) michael@0: mStyleText = blockFrame->StyleTextForLineLayout(); michael@0: else michael@0: mStyleText = aOuterReflowState->frame->StyleText(); michael@0: michael@0: mLineNumber = 0; michael@0: mTotalPlacedFrames = 0; michael@0: mBStartEdge = 0; michael@0: mTrimmableWidth = 0; michael@0: michael@0: mInflationMinFontSize = michael@0: nsLayoutUtils::InflationMinFontSizeFor(aOuterReflowState->frame); michael@0: michael@0: // Instead of always pre-initializing the free-lists for frames and michael@0: // spans, we do it on demand so that situations that only use a few michael@0: // frames and spans won't waste a lot of time in unneeded michael@0: // initialization. michael@0: PL_INIT_ARENA_POOL(&mArena, "nsLineLayout", 1024); michael@0: mFrameFreeList = nullptr; michael@0: mSpanFreeList = nullptr; michael@0: michael@0: mCurrentSpan = mRootSpan = nullptr; michael@0: mSpanDepth = 0; michael@0: michael@0: if (aLine) { michael@0: mGotLineBox = true; michael@0: mLineBox = *aLine; michael@0: } michael@0: } michael@0: michael@0: nsLineLayout::~nsLineLayout() michael@0: { michael@0: MOZ_COUNT_DTOR(nsLineLayout); michael@0: michael@0: NS_ASSERTION(nullptr == mRootSpan, "bad line-layout user"); michael@0: michael@0: PL_FinishArenaPool(&mArena); michael@0: } michael@0: michael@0: // Find out if the frame has a non-null prev-in-flow, i.e., whether it michael@0: // is a continuation. michael@0: inline bool michael@0: HasPrevInFlow(nsIFrame *aFrame) michael@0: { michael@0: nsIFrame *prevInFlow = aFrame->GetPrevInFlow(); michael@0: return prevInFlow != nullptr; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::BeginLineReflow(nscoord aICoord, nscoord aBCoord, michael@0: nscoord aISize, nscoord aBSize, michael@0: bool aImpactedByFloats, michael@0: bool aIsTopOfPage, michael@0: WritingMode aWritingMode, michael@0: nscoord aContainerWidth) michael@0: { michael@0: NS_ASSERTION(nullptr == mRootSpan, "bad linelayout user"); michael@0: NS_WARN_IF_FALSE(aISize != NS_UNCONSTRAINEDSIZE, michael@0: "have unconstrained width; this should only result from " michael@0: "very large sizes, not attempts at intrinsic width " michael@0: "calculation"); michael@0: #ifdef DEBUG michael@0: if ((aISize != NS_UNCONSTRAINEDSIZE) && CRAZY_SIZE(aISize)) { michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": Init: bad caller: width WAS %d(0x%x)\n", michael@0: aISize, aISize); michael@0: } michael@0: if ((aBSize != NS_UNCONSTRAINEDSIZE) && CRAZY_SIZE(aBSize)) { michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": Init: bad caller: height WAS %d(0x%x)\n", michael@0: aBSize, aBSize); michael@0: } michael@0: #endif michael@0: #ifdef NOISY_REFLOW michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": BeginLineReflow: %d,%d,%d,%d impacted=%s %s\n", michael@0: aICoord, aBCoord, aISize, aBSize, michael@0: aImpactedByFloats?"true":"false", michael@0: aIsTopOfPage ? "top-of-page" : ""); michael@0: #endif michael@0: #ifdef DEBUG michael@0: mSpansAllocated = mSpansFreed = mFramesAllocated = mFramesFreed = 0; michael@0: #endif michael@0: michael@0: mFirstLetterStyleOK = false; michael@0: mIsTopOfPage = aIsTopOfPage; michael@0: mImpactedByFloats = aImpactedByFloats; michael@0: mTotalPlacedFrames = 0; michael@0: mLineIsEmpty = true; michael@0: mLineAtStart = true; michael@0: mLineEndsInBR = false; michael@0: mSpanDepth = 0; michael@0: mMaxStartBoxBSize = mMaxEndBoxBSize = 0; michael@0: michael@0: if (mGotLineBox) { michael@0: mLineBox->ClearHasBullet(); michael@0: } michael@0: michael@0: PerSpanData* psd = NewPerSpanData(); michael@0: mCurrentSpan = mRootSpan = psd; michael@0: psd->mReflowState = mBlockReflowState; michael@0: psd->mIStart = aICoord; michael@0: psd->mICoord = aICoord; michael@0: psd->mIEnd = aICoord + aISize; michael@0: mContainerWidth = aContainerWidth; michael@0: michael@0: // If we're in a constrained height frame, then we don't allow a michael@0: // max line box width to take effect. michael@0: if (!(LineContainerFrame()->GetStateBits() & michael@0: NS_FRAME_IN_CONSTRAINED_HEIGHT)) { michael@0: michael@0: // If the available size is greater than the maximum line box width (if michael@0: // specified), then we need to adjust the line box width to be at the max michael@0: // possible width. michael@0: nscoord maxLineBoxWidth = michael@0: LineContainerFrame()->PresContext()->PresShell()->MaxLineBoxWidth(); michael@0: michael@0: if (maxLineBoxWidth > 0 && michael@0: psd->mIEnd - psd->mIStart > maxLineBoxWidth) { michael@0: psd->mIEnd = psd->mIStart + maxLineBoxWidth; michael@0: } michael@0: } michael@0: michael@0: mBStartEdge = aBCoord; michael@0: michael@0: psd->mNoWrap = michael@0: !mStyleText->WhiteSpaceCanWrapStyle() || LineContainerFrame()->IsSVGText(); michael@0: psd->mWritingMode = aWritingMode; michael@0: michael@0: // If this is the first line of a block then see if the text-indent michael@0: // property amounts to anything. michael@0: michael@0: if (0 == mLineNumber && !HasPrevInFlow(mBlockReflowState->frame)) { michael@0: const nsStyleCoord &textIndent = mStyleText->mTextIndent; michael@0: nscoord pctBasis = 0; michael@0: if (textIndent.HasPercent()) { michael@0: pctBasis = michael@0: nsHTMLReflowState::GetContainingBlockContentWidth(mBlockReflowState); michael@0: michael@0: if (mGotLineBox) { michael@0: mLineBox->DisableResizeReflowOptimization(); michael@0: } michael@0: } michael@0: nscoord indent = nsRuleNode::ComputeCoordPercentCalc(textIndent, pctBasis); michael@0: michael@0: mTextIndent = indent; michael@0: michael@0: psd->mICoord += indent; michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::EndLineReflow() michael@0: { michael@0: #ifdef NOISY_REFLOW michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": EndLineReflow: width=%d\n", mRootSpan->mICoord - mRootSpan->mIStart); michael@0: #endif michael@0: michael@0: FreeSpan(mRootSpan); michael@0: mCurrentSpan = mRootSpan = nullptr; michael@0: michael@0: NS_ASSERTION(mSpansAllocated == mSpansFreed, "leak"); michael@0: NS_ASSERTION(mFramesAllocated == mFramesFreed, "leak"); michael@0: michael@0: #if 0 michael@0: static int32_t maxSpansAllocated = NS_LINELAYOUT_NUM_SPANS; michael@0: static int32_t maxFramesAllocated = NS_LINELAYOUT_NUM_FRAMES; michael@0: if (mSpansAllocated > maxSpansAllocated) { michael@0: printf("XXX: saw a line with %d spans\n", mSpansAllocated); michael@0: maxSpansAllocated = mSpansAllocated; michael@0: } michael@0: if (mFramesAllocated > maxFramesAllocated) { michael@0: printf("XXX: saw a line with %d frames\n", mFramesAllocated); michael@0: maxFramesAllocated = mFramesAllocated; michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: // XXX swtich to a single mAvailLineWidth that we adjust as each frame michael@0: // on the line is placed. Each span can still have a per-span mICoord that michael@0: // tracks where a child frame is going in its span; they don't need a michael@0: // per-span mIStart? michael@0: michael@0: void michael@0: nsLineLayout::UpdateBand(const nsRect& aNewAvailSpace, michael@0: nsIFrame* aFloatFrame) michael@0: { michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: LogicalRect availSpace(lineWM, aNewAvailSpace, mContainerWidth); michael@0: #ifdef REALLY_NOISY_REFLOW michael@0: printf("nsLL::UpdateBand %d, %d, %d, %d, (logical %d, %d, %d, %d); frame=%p\n will set mImpacted to true\n", michael@0: aNewAvailSpace.x, aNewAvailSpace.y, michael@0: aNewAvailSpace.width, aNewAvailSpace.height, michael@0: availSpace.IStart(lineWM), availSpace.BStart(lineWM), michael@0: availSpace.ISize(lineWM), availSpace.BSize(lineWM), michael@0: aFloatFrame); michael@0: #endif michael@0: #ifdef DEBUG michael@0: if ((availSpace.ISize(lineWM) != NS_UNCONSTRAINEDSIZE) && michael@0: CRAZY_SIZE(availSpace.ISize(lineWM))) { michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": UpdateBand: bad caller: ISize WAS %d(0x%x)\n", michael@0: availSpace.ISize(lineWM), availSpace.ISize(lineWM)); michael@0: } michael@0: if ((availSpace.BSize(lineWM) != NS_UNCONSTRAINEDSIZE) && michael@0: CRAZY_SIZE(availSpace.BSize(lineWM))) { michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": UpdateBand: bad caller: BSize WAS %d(0x%x)\n", michael@0: availSpace.BSize(lineWM), availSpace.BSize(lineWM)); michael@0: } michael@0: #endif michael@0: michael@0: // Compute the difference between last times width and the new width michael@0: NS_WARN_IF_FALSE(mRootSpan->mIEnd != NS_UNCONSTRAINEDSIZE && michael@0: aNewAvailSpace.width != NS_UNCONSTRAINEDSIZE, michael@0: "have unconstrained width; this should only result from " michael@0: "very large sizes, not attempts at intrinsic width " michael@0: "calculation"); michael@0: // The root span's mIStart moves to aICoord michael@0: nscoord deltaICoord = availSpace.IStart(lineWM) - mRootSpan->mIStart; michael@0: // The width of all spans changes by this much (the root span's michael@0: // mIEnd moves to aICoord + aISize, its new width is aISize) michael@0: nscoord deltaISize = availSpace.ISize(lineWM) - michael@0: (mRootSpan->mIEnd - mRootSpan->mIStart); michael@0: #ifdef NOISY_REFLOW michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": UpdateBand: %d,%d,%d,%d deltaISize=%d deltaICoord=%d\n", michael@0: aNewAvailSpace.x, aNewAvailSpace.y, michael@0: aNewAvailSpace.width, aNewAvailSpace.height, deltaISize, deltaICoord); michael@0: #endif michael@0: michael@0: // Update the root span position michael@0: mRootSpan->mIStart += deltaICoord; michael@0: mRootSpan->mIEnd += deltaICoord; michael@0: mRootSpan->mICoord += deltaICoord; michael@0: michael@0: // Now update the right edges of the open spans to account for any michael@0: // change in available space width michael@0: for (PerSpanData* psd = mCurrentSpan; psd; psd = psd->mParent) { michael@0: psd->mIEnd += deltaISize; michael@0: psd->mContainsFloat = true; michael@0: #ifdef NOISY_REFLOW michael@0: printf(" span %p: oldIEnd=%d newIEnd=%d\n", michael@0: psd, psd->mIEnd - deltaISize, psd->mIEnd); michael@0: #endif michael@0: } michael@0: NS_ASSERTION(mRootSpan->mContainsFloat && michael@0: mRootSpan->mIStart == availSpace.IStart(lineWM) && michael@0: mRootSpan->mIEnd == availSpace.IEnd(lineWM), michael@0: "root span was updated incorrectly?"); michael@0: michael@0: // Update frame bounds michael@0: // Note: Only adjust the outermost frames (the ones that are direct michael@0: // children of the block), not the ones in the child spans. The reason michael@0: // is simple: the frames in the spans have coordinates local to their michael@0: // parent therefore they are moved when their parent span is moved. michael@0: if (deltaICoord != 0) { michael@0: for (PerFrameData* pfd = mRootSpan->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: pfd->mBounds.IStart(lineWM) += deltaICoord; michael@0: } michael@0: } michael@0: michael@0: mBStartEdge = aNewAvailSpace.y; michael@0: mImpactedByFloats = true; michael@0: michael@0: mLastFloatWasLetterFrame = nsGkAtoms::letterFrame == aFloatFrame->GetType(); michael@0: } michael@0: michael@0: nsLineLayout::PerSpanData* michael@0: nsLineLayout::NewPerSpanData() michael@0: { michael@0: PerSpanData* psd = mSpanFreeList; michael@0: if (!psd) { michael@0: void *mem; michael@0: PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerSpanData)); michael@0: if (!mem) { michael@0: NS_RUNTIMEABORT("OOM"); michael@0: } michael@0: psd = reinterpret_cast(mem); michael@0: } michael@0: else { michael@0: mSpanFreeList = psd->mNextFreeSpan; michael@0: } michael@0: psd->mParent = nullptr; michael@0: psd->mFrame = nullptr; michael@0: psd->mFirstFrame = nullptr; michael@0: psd->mLastFrame = nullptr; michael@0: psd->mContainsFloat = false; michael@0: psd->mZeroEffectiveSpanBox = false; michael@0: psd->mHasNonemptyContent = false; michael@0: michael@0: #ifdef DEBUG michael@0: mSpansAllocated++; michael@0: #endif michael@0: return psd; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::BeginSpan(nsIFrame* aFrame, michael@0: const nsHTMLReflowState* aSpanReflowState, michael@0: nscoord aIStart, nscoord aIEnd, michael@0: nscoord* aBaseline) michael@0: { michael@0: NS_ASSERTION(aIEnd != NS_UNCONSTRAINEDSIZE, michael@0: "should no longer be using unconstrained sizes"); michael@0: #ifdef NOISY_REFLOW michael@0: nsFrame::IndentBy(stdout, mSpanDepth+1); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf(": BeginSpan leftEdge=%d rightEdge=%d\n", aIStart, aIEnd); michael@0: #endif michael@0: michael@0: PerSpanData* psd = NewPerSpanData(); michael@0: // Link up span frame's pfd to point to its child span data michael@0: PerFrameData* pfd = mCurrentSpan->mLastFrame; michael@0: NS_ASSERTION(pfd->mFrame == aFrame, "huh?"); michael@0: pfd->mSpan = psd; michael@0: michael@0: // Init new span michael@0: psd->mFrame = pfd; michael@0: psd->mParent = mCurrentSpan; michael@0: psd->mReflowState = aSpanReflowState; michael@0: psd->mIStart = aIStart; michael@0: psd->mICoord = aIStart; michael@0: psd->mIEnd = aIEnd; michael@0: psd->mBaseline = aBaseline; michael@0: michael@0: nsIFrame* frame = aSpanReflowState->frame; michael@0: psd->mNoWrap = !frame->StyleText()->WhiteSpaceCanWrap(frame); michael@0: psd->mWritingMode = aSpanReflowState->GetWritingMode(); michael@0: michael@0: // Switch to new span michael@0: mCurrentSpan = psd; michael@0: mSpanDepth++; michael@0: } michael@0: michael@0: nscoord michael@0: nsLineLayout::EndSpan(nsIFrame* aFrame) michael@0: { michael@0: NS_ASSERTION(mSpanDepth > 0, "end-span without begin-span"); michael@0: #ifdef NOISY_REFLOW michael@0: nsFrame::IndentBy(stdout, mSpanDepth); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf(": EndSpan width=%d\n", mCurrentSpan->mICoord - mCurrentSpan->mIStart); michael@0: #endif michael@0: PerSpanData* psd = mCurrentSpan; michael@0: nscoord iSizeResult = psd->mLastFrame ? (psd->mICoord - psd->mIStart) : 0; michael@0: michael@0: mSpanDepth--; michael@0: mCurrentSpan->mReflowState = nullptr; // no longer valid so null it out! michael@0: mCurrentSpan = mCurrentSpan->mParent; michael@0: return iSizeResult; michael@0: } michael@0: michael@0: int32_t michael@0: nsLineLayout::GetCurrentSpanCount() const michael@0: { michael@0: NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user"); michael@0: int32_t count = 0; michael@0: PerFrameData* pfd = mRootSpan->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: count++; michael@0: pfd = pfd->mNext; michael@0: } michael@0: return count; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::SplitLineTo(int32_t aNewCount) michael@0: { michael@0: NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user"); michael@0: michael@0: #ifdef REALLY_NOISY_PUSHING michael@0: printf("SplitLineTo %d (current count=%d); before:\n", aNewCount, michael@0: GetCurrentSpanCount()); michael@0: DumpPerSpanData(mRootSpan, 1); michael@0: #endif michael@0: PerSpanData* psd = mRootSpan; michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: if (--aNewCount == 0) { michael@0: // Truncate list at pfd (we keep pfd, but anything following is freed) michael@0: PerFrameData* next = pfd->mNext; michael@0: pfd->mNext = nullptr; michael@0: psd->mLastFrame = pfd; michael@0: michael@0: // Now release all of the frames following pfd michael@0: pfd = next; michael@0: while (nullptr != pfd) { michael@0: next = pfd->mNext; michael@0: pfd->mNext = mFrameFreeList; michael@0: mFrameFreeList = pfd; michael@0: #ifdef DEBUG michael@0: mFramesFreed++; michael@0: #endif michael@0: if (nullptr != pfd->mSpan) { michael@0: FreeSpan(pfd->mSpan); michael@0: } michael@0: pfd = next; michael@0: } michael@0: break; michael@0: } michael@0: pfd = pfd->mNext; michael@0: } michael@0: #ifdef NOISY_PUSHING michael@0: printf("SplitLineTo %d (current count=%d); after:\n", aNewCount, michael@0: GetCurrentSpanCount()); michael@0: DumpPerSpanData(mRootSpan, 1); michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::PushFrame(nsIFrame* aFrame) michael@0: { michael@0: PerSpanData* psd = mCurrentSpan; michael@0: NS_ASSERTION(psd->mLastFrame->mFrame == aFrame, "pushing non-last frame"); michael@0: michael@0: #ifdef REALLY_NOISY_PUSHING michael@0: nsFrame::IndentBy(stdout, mSpanDepth); michael@0: printf("PushFrame %p, before:\n", psd); michael@0: DumpPerSpanData(psd, 1); michael@0: #endif michael@0: michael@0: // Take the last frame off of the span's frame list michael@0: PerFrameData* pfd = psd->mLastFrame; michael@0: if (pfd == psd->mFirstFrame) { michael@0: // We are pushing away the only frame...empty the list michael@0: psd->mFirstFrame = nullptr; michael@0: psd->mLastFrame = nullptr; michael@0: } michael@0: else { michael@0: PerFrameData* prevFrame = pfd->mPrev; michael@0: prevFrame->mNext = nullptr; michael@0: psd->mLastFrame = prevFrame; michael@0: } michael@0: michael@0: // Now free it, and if it has a span, free that too michael@0: pfd->mNext = mFrameFreeList; michael@0: mFrameFreeList = pfd; michael@0: #ifdef DEBUG michael@0: mFramesFreed++; michael@0: #endif michael@0: if (nullptr != pfd->mSpan) { michael@0: FreeSpan(pfd->mSpan); michael@0: } michael@0: #ifdef NOISY_PUSHING michael@0: nsFrame::IndentBy(stdout, mSpanDepth); michael@0: printf("PushFrame: %p after:\n", psd); michael@0: DumpPerSpanData(psd, 1); michael@0: #endif michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::FreeSpan(PerSpanData* psd) michael@0: { michael@0: // Free its frames michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: if (nullptr != pfd->mSpan) { michael@0: FreeSpan(pfd->mSpan); michael@0: } michael@0: PerFrameData* next = pfd->mNext; michael@0: pfd->mNext = mFrameFreeList; michael@0: mFrameFreeList = pfd; michael@0: #ifdef DEBUG michael@0: mFramesFreed++; michael@0: #endif michael@0: pfd = next; michael@0: } michael@0: michael@0: // Now put the span on the free list since it's free too michael@0: psd->mNextFreeSpan = mSpanFreeList; michael@0: mSpanFreeList = psd; michael@0: #ifdef DEBUG michael@0: mSpansFreed++; michael@0: #endif michael@0: } michael@0: michael@0: bool michael@0: nsLineLayout::IsZeroBSize() michael@0: { michael@0: PerSpanData* psd = mCurrentSpan; michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: if (0 != pfd->mBounds.BSize(psd->mWritingMode)) { michael@0: return false; michael@0: } michael@0: pfd = pfd->mNext; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: nsLineLayout::PerFrameData* michael@0: nsLineLayout::NewPerFrameData(nsIFrame* aFrame) michael@0: { michael@0: PerFrameData* pfd = mFrameFreeList; michael@0: if (!pfd) { michael@0: void *mem; michael@0: PL_ARENA_ALLOCATE(mem, &mArena, sizeof(PerFrameData)); michael@0: if (!mem) { michael@0: NS_RUNTIMEABORT("OOM"); michael@0: } michael@0: pfd = reinterpret_cast(mem); michael@0: } michael@0: else { michael@0: mFrameFreeList = pfd->mNext; michael@0: } michael@0: pfd->mSpan = nullptr; michael@0: pfd->mNext = nullptr; michael@0: pfd->mPrev = nullptr; michael@0: pfd->mFlags = 0; // all flags default to false michael@0: pfd->mFrame = aFrame; michael@0: michael@0: WritingMode frameWM = aFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: pfd->mBounds = LogicalRect(lineWM); michael@0: pfd->mMargin = LogicalMargin(frameWM); michael@0: pfd->mBorderPadding = LogicalMargin(frameWM); michael@0: pfd->mOffsets = LogicalMargin(frameWM); michael@0: michael@0: #ifdef DEBUG michael@0: pfd->mBlockDirAlign = 0xFF; michael@0: mFramesAllocated++; michael@0: #endif michael@0: return pfd; michael@0: } michael@0: michael@0: bool michael@0: nsLineLayout::LineIsBreakable() const michael@0: { michael@0: // XXX mTotalPlacedFrames should go away and we should just use michael@0: // mLineIsEmpty here instead michael@0: if ((0 != mTotalPlacedFrames) || mImpactedByFloats) { michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: // Checks all four sides for percentage units. This means it should michael@0: // only be used for things (margin, padding) where percentages on top michael@0: // and bottom depend on the *width* just like percentages on left and michael@0: // right. michael@0: static bool michael@0: HasPercentageUnitSide(const nsStyleSides& aSides) michael@0: { michael@0: NS_FOR_CSS_SIDES(side) { michael@0: if (aSides.Get(side).HasPercent()) michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: static bool michael@0: IsPercentageAware(const nsIFrame* aFrame) michael@0: { michael@0: NS_ASSERTION(aFrame, "null frame is not allowed"); michael@0: michael@0: nsIAtom *fType = aFrame->GetType(); michael@0: if (fType == nsGkAtoms::textFrame) { michael@0: // None of these things can ever be true for text frames. michael@0: return false; michael@0: } michael@0: michael@0: // Some of these things don't apply to non-replaced inline frames michael@0: // (that is, fType == nsGkAtoms::inlineFrame), but we won't bother making michael@0: // things unnecessarily complicated, since they'll probably be set michael@0: // quite rarely. michael@0: michael@0: const nsStyleMargin* margin = aFrame->StyleMargin(); michael@0: if (HasPercentageUnitSide(margin->mMargin)) { michael@0: return true; michael@0: } michael@0: michael@0: const nsStylePadding* padding = aFrame->StylePadding(); michael@0: if (HasPercentageUnitSide(padding->mPadding)) { michael@0: return true; michael@0: } michael@0: michael@0: // Note that borders can't be aware of percentages michael@0: michael@0: const nsStylePosition* pos = aFrame->StylePosition(); michael@0: michael@0: if ((pos->WidthDependsOnContainer() && michael@0: pos->mWidth.GetUnit() != eStyleUnit_Auto) || michael@0: pos->MaxWidthDependsOnContainer() || michael@0: pos->MinWidthDependsOnContainer() || michael@0: pos->OffsetHasPercent(NS_SIDE_RIGHT) || michael@0: pos->OffsetHasPercent(NS_SIDE_LEFT)) { michael@0: return true; michael@0: } michael@0: michael@0: if (eStyleUnit_Auto == pos->mWidth.GetUnit()) { michael@0: // We need to check for frames that shrink-wrap when they're auto michael@0: // width. michael@0: const nsStyleDisplay* disp = aFrame->StyleDisplay(); michael@0: if (disp->mDisplay == NS_STYLE_DISPLAY_INLINE_BLOCK || michael@0: disp->mDisplay == NS_STYLE_DISPLAY_INLINE_TABLE || michael@0: fType == nsGkAtoms::HTMLButtonControlFrame || michael@0: fType == nsGkAtoms::gfxButtonControlFrame || michael@0: fType == nsGkAtoms::fieldSetFrame || michael@0: fType == nsGkAtoms::comboboxDisplayFrame) { michael@0: return true; michael@0: } michael@0: michael@0: // Per CSS 2.1, section 10.3.2: michael@0: // If 'height' and 'width' both have computed values of 'auto' and michael@0: // the element has an intrinsic ratio but no intrinsic height or michael@0: // width and the containing block's width does not itself depend michael@0: // on the replaced element's width, then the used value of 'width' michael@0: // is calculated from the constraint equation used for michael@0: // block-level, non-replaced elements in normal flow. michael@0: nsIFrame *f = const_cast(aFrame); michael@0: if (f->GetIntrinsicRatio() != nsSize(0, 0) && michael@0: // Some percents are treated like 'auto', so check != coord michael@0: pos->mHeight.GetUnit() != eStyleUnit_Coord) { michael@0: const IntrinsicSize &intrinsicSize = f->GetIntrinsicSize(); michael@0: if (intrinsicSize.width.GetUnit() == eStyleUnit_None && michael@0: intrinsicSize.height.GetUnit() == eStyleUnit_None) { michael@0: return true; michael@0: } michael@0: } michael@0: } michael@0: michael@0: return false; michael@0: } michael@0: michael@0: nsresult michael@0: nsLineLayout::ReflowFrame(nsIFrame* aFrame, michael@0: nsReflowStatus& aReflowStatus, michael@0: nsHTMLReflowMetrics* aMetrics, michael@0: bool& aPushedFrame) michael@0: { michael@0: // Initialize OUT parameter michael@0: aPushedFrame = false; michael@0: michael@0: PerFrameData* pfd = NewPerFrameData(aFrame); michael@0: PerSpanData* psd = mCurrentSpan; michael@0: psd->AppendFrame(pfd); michael@0: michael@0: #ifdef REALLY_NOISY_REFLOW michael@0: nsFrame::IndentBy(stdout, mSpanDepth); michael@0: printf("%p: Begin ReflowFrame pfd=%p ", psd, pfd); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf("\n"); michael@0: #endif michael@0: michael@0: mTextJustificationNumSpaces = 0; michael@0: mTextJustificationNumLetters = 0; michael@0: michael@0: // Stash copies of some of the computed state away for later michael@0: // (block-direction alignment, for example) michael@0: WritingMode frameWM = aFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: michael@0: // NOTE: While the x coordinate remains relative to the parent span, michael@0: // the y coordinate is fixed at the top edge for the line. During michael@0: // BlockDirAlignFrames we will repair this so that the y coordinate michael@0: // is properly set and relative to the appropriate span. michael@0: pfd->mBounds.IStart(lineWM) = psd->mICoord; michael@0: pfd->mBounds.BStart(lineWM) = mBStartEdge; michael@0: michael@0: // We want to guarantee that we always make progress when michael@0: // formatting. Therefore, if the object being placed on the line is michael@0: // too big for the line, but it is the only thing on the line and is not michael@0: // impacted by a float, then we go ahead and place it anyway. (If the line michael@0: // is impacted by one or more floats, then it is safe to break because michael@0: // we can move the line down below float(s).) michael@0: // michael@0: // Capture this state *before* we reflow the frame in case it clears michael@0: // the state out. We need to know how to treat the current frame michael@0: // when breaking. michael@0: bool notSafeToBreak = LineIsEmpty() && !mImpactedByFloats; michael@0: michael@0: // Figure out whether we're talking about a textframe here michael@0: nsIAtom* frameType = aFrame->GetType(); michael@0: bool isText = frameType == nsGkAtoms::textFrame; michael@0: michael@0: // Compute the available size for the frame. This available width michael@0: // includes room for the side margins. michael@0: // For now, set the available height to unconstrained always. michael@0: nsSize availSize(mBlockReflowState->ComputedWidth(), NS_UNCONSTRAINEDSIZE); michael@0: michael@0: // Inline-ish and text-ish things don't compute their width; michael@0: // everything else does. We need to give them an available width that michael@0: // reflects the space left on the line. michael@0: NS_WARN_IF_FALSE(psd->mIEnd != NS_UNCONSTRAINEDSIZE, michael@0: "have unconstrained width; this should only result from " michael@0: "very large sizes, not attempts at intrinsic width " michael@0: "calculation"); michael@0: nscoord availableSpaceOnLine = psd->mIEnd - psd->mICoord; michael@0: michael@0: // Setup reflow state for reflowing the frame michael@0: Maybe reflowStateHolder; michael@0: if (!isText) { michael@0: reflowStateHolder.construct(mPresContext, *psd->mReflowState, michael@0: aFrame, availSize); michael@0: nsHTMLReflowState& reflowState = reflowStateHolder.ref(); michael@0: reflowState.mLineLayout = this; michael@0: reflowState.mFlags.mIsTopOfPage = mIsTopOfPage; michael@0: if (reflowState.ComputedWidth() == NS_UNCONSTRAINEDSIZE) michael@0: reflowState.AvailableWidth() = availableSpaceOnLine; michael@0: WritingMode stateWM = reflowState.GetWritingMode(); michael@0: pfd->mMargin = michael@0: reflowState.ComputedLogicalMargin().ConvertTo(frameWM, stateWM); michael@0: pfd->mBorderPadding = michael@0: reflowState.ComputedLogicalBorderPadding().ConvertTo(frameWM, stateWM); michael@0: pfd->SetFlag(PFD_RELATIVEPOS, michael@0: reflowState.mStyleDisplay->IsRelativelyPositionedStyle()); michael@0: if (pfd->GetFlag(PFD_RELATIVEPOS)) { michael@0: pfd->mOffsets = michael@0: reflowState.ComputedLogicalOffsets().ConvertTo(frameWM, stateWM); michael@0: } michael@0: michael@0: // Calculate whether the the frame should have a start margin and michael@0: // subtract the margin from the available width if necessary. michael@0: // The margin will be applied to the starting inline coordinates of michael@0: // the frame in CanPlaceFrame() after reflowing the frame. michael@0: AllowForStartMargin(pfd, reflowState); michael@0: } michael@0: // if isText(), no need to propagate NS_FRAME_IS_DIRTY from the parent, michael@0: // because reflow doesn't look at the dirty bits on the frame being reflowed. michael@0: michael@0: // See if this frame depends on the width of its containing block. If michael@0: // so, disable resize reflow optimizations for the line. (Note that, michael@0: // to be conservative, we do this if we *try* to fit a frame on a michael@0: // line, even if we don't succeed.) (Note also that we can only make michael@0: // this IsPercentageAware check *after* we've constructed our michael@0: // nsHTMLReflowState, because that construction may be what forces aFrame michael@0: // to lazily initialize its (possibly-percent-valued) intrinsic size.) michael@0: if (mGotLineBox && IsPercentageAware(aFrame)) { michael@0: mLineBox->DisableResizeReflowOptimization(); michael@0: } michael@0: michael@0: // Let frame know that are reflowing it. Note that we don't bother michael@0: // positioning the frame yet, because we're probably going to end up michael@0: // moving it when we do the block-direction alignment michael@0: aFrame->WillReflow(mPresContext); michael@0: michael@0: // Adjust spacemanager coordinate system for the frame. michael@0: nsHTMLReflowMetrics metrics(lineWM); michael@0: #ifdef DEBUG michael@0: metrics.Width() = nscoord(0xdeadbeef); michael@0: metrics.Height() = nscoord(0xdeadbeef); michael@0: #endif michael@0: nsRect physicalBounds = pfd->mBounds.GetPhysicalRect(lineWM, mContainerWidth); michael@0: nscoord tx = physicalBounds.x; michael@0: nscoord ty = physicalBounds.y; michael@0: mFloatManager->Translate(tx, ty); michael@0: michael@0: int32_t savedOptionalBreakOffset; michael@0: gfxBreakPriority savedOptionalBreakPriority; michael@0: nsIContent* savedOptionalBreakContent = michael@0: GetLastOptionalBreakPosition(&savedOptionalBreakOffset, michael@0: &savedOptionalBreakPriority); michael@0: michael@0: if (!isText) { michael@0: nsresult rv = aFrame->Reflow(mPresContext, metrics, reflowStateHolder.ref(), michael@0: aReflowStatus); michael@0: if (NS_FAILED(rv)) { michael@0: NS_WARNING( "Reflow of frame failed in nsLineLayout" ); michael@0: return rv; michael@0: } michael@0: } else { michael@0: static_cast(aFrame)-> michael@0: ReflowText(*this, availableSpaceOnLine, psd->mReflowState->rendContext, michael@0: metrics, aReflowStatus); michael@0: } michael@0: michael@0: pfd->mJustificationNumSpaces = mTextJustificationNumSpaces; michael@0: pfd->mJustificationNumLetters = mTextJustificationNumLetters; michael@0: michael@0: // See if the frame is a placeholderFrame and if it is process michael@0: // the float. At the same time, check if the frame has any non-collapsed-away michael@0: // content. michael@0: bool placedFloat = false; michael@0: bool isEmpty; michael@0: if (!frameType) { michael@0: isEmpty = pfd->mFrame->IsEmpty(); michael@0: } else { michael@0: if (nsGkAtoms::placeholderFrame == frameType) { michael@0: isEmpty = true; michael@0: pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, true); michael@0: nsIFrame* outOfFlowFrame = nsLayoutUtils::GetFloatFromPlaceholder(aFrame); michael@0: if (outOfFlowFrame) { michael@0: // Add mTrimmableWidth to the available width since if the line ends michael@0: // here, the width of the inline content will be reduced by michael@0: // mTrimmableWidth. michael@0: nscoord availableWidth = psd->mIEnd - (psd->mICoord - mTrimmableWidth); michael@0: if (psd->mNoWrap) { michael@0: // If we place floats after inline content where there's michael@0: // no break opportunity, we don't know how much additional michael@0: // width is required for the non-breaking content after the float, michael@0: // so we can't know whether the float plus that content will fit michael@0: // on the line. So for now, don't place floats after inline michael@0: // content where there's no break opportunity. This is incorrect michael@0: // but hopefully rare. Fixing it will require significant michael@0: // restructuring of line layout. michael@0: // We might as well allow zero-width floats to be placed, though. michael@0: availableWidth = 0; michael@0: } michael@0: placedFloat = AddFloat(outOfFlowFrame, availableWidth); michael@0: NS_ASSERTION(!(outOfFlowFrame->GetType() == nsGkAtoms::letterFrame && michael@0: GetFirstLetterStyleOK()), michael@0: "FirstLetterStyle set on line with floating first letter"); michael@0: } michael@0: } michael@0: else if (isText) { michael@0: // Note non-empty text-frames for inline frame compatibility hackery michael@0: pfd->SetFlag(PFD_ISTEXTFRAME, true); michael@0: nsTextFrame* textFrame = static_cast(pfd->mFrame); michael@0: isEmpty = !textFrame->HasNoncollapsedCharacters(); michael@0: if (!isEmpty) { michael@0: pfd->SetFlag(PFD_ISNONEMPTYTEXTFRAME, true); michael@0: nsIContent* content = textFrame->GetContent(); michael@0: michael@0: const nsTextFragment* frag = content->GetText(); michael@0: if (frag) { michael@0: pfd->SetFlag(PFD_ISNONWHITESPACETEXTFRAME, michael@0: !content->TextIsOnlyWhitespace()); michael@0: } michael@0: } michael@0: } michael@0: else if (nsGkAtoms::brFrame == frameType) { michael@0: pfd->SetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE, true); michael@0: isEmpty = false; michael@0: } else { michael@0: if (nsGkAtoms::letterFrame==frameType) { michael@0: pfd->SetFlag(PFD_ISLETTERFRAME, true); michael@0: } michael@0: if (pfd->mSpan) { michael@0: isEmpty = !pfd->mSpan->mHasNonemptyContent && pfd->mFrame->IsSelfEmpty(); michael@0: } else { michael@0: isEmpty = pfd->mFrame->IsEmpty(); michael@0: } michael@0: } michael@0: } michael@0: michael@0: mFloatManager->Translate(-tx, -ty); michael@0: michael@0: NS_ASSERTION(metrics.Width() >= 0, "bad width"); michael@0: NS_ASSERTION(metrics.Height() >= 0,"bad height"); michael@0: if (metrics.Width() < 0) metrics.Width() = 0; michael@0: if (metrics.Height() < 0) metrics.Height() = 0; michael@0: michael@0: #ifdef DEBUG michael@0: // Note: break-before means ignore the reflow metrics since the michael@0: // frame will be reflowed another time. michael@0: if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) { michael@0: if (CRAZY_SIZE(metrics.Width()) || CRAZY_SIZE(metrics.Height())) { michael@0: printf("nsLineLayout: "); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf(" metrics=%d,%d!\n", metrics.Width(), metrics.Height()); michael@0: } michael@0: if ((metrics.Width() == nscoord(0xdeadbeef)) || michael@0: (metrics.Height() == nscoord(0xdeadbeef))) { michael@0: printf("nsLineLayout: "); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf(" didn't set w/h %d,%d!\n", metrics.Width(), metrics.Height()); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: // Unlike with non-inline reflow, the overflow area here does *not* michael@0: // include the accumulation of the frame's bounds and its inline michael@0: // descendants' bounds. Nor does it include the outline area; it's michael@0: // just the union of the bounds of any absolute children. That is michael@0: // added in later by nsLineLayout::ReflowInlineFrames. michael@0: pfd->mOverflowAreas = metrics.mOverflowAreas; michael@0: michael@0: pfd->mBounds.ISize(lineWM) = metrics.ISize(); michael@0: pfd->mBounds.BSize(lineWM) = metrics.BSize(); michael@0: michael@0: // Size the frame, but |RelativePositionFrames| will size the view. michael@0: aFrame->SetSize(nsSize(metrics.Width(), metrics.Height())); michael@0: michael@0: // Tell the frame that we're done reflowing it michael@0: aFrame->DidReflow(mPresContext, michael@0: isText ? nullptr : reflowStateHolder.addr(), michael@0: nsDidReflowStatus::FINISHED); michael@0: michael@0: if (aMetrics) { michael@0: *aMetrics = metrics; michael@0: } michael@0: michael@0: if (!NS_INLINE_IS_BREAK_BEFORE(aReflowStatus)) { michael@0: // If frame is complete and has a next-in-flow, we need to delete michael@0: // them now. Do not do this when a break-before is signaled because michael@0: // the frame is going to get reflowed again (and may end up wanting michael@0: // a next-in-flow where it ends up). michael@0: if (NS_FRAME_IS_COMPLETE(aReflowStatus)) { michael@0: nsIFrame* kidNextInFlow = aFrame->GetNextInFlow(); michael@0: if (nullptr != kidNextInFlow) { michael@0: // Remove all of the childs next-in-flows. Make sure that we ask michael@0: // the right parent to do the removal (it's possible that the michael@0: // parent is not this because we are executing pullup code) michael@0: nsContainerFrame* parent = static_cast michael@0: (kidNextInFlow->GetParent()); michael@0: parent->DeleteNextInFlowChild(kidNextInFlow, true); michael@0: } michael@0: } michael@0: michael@0: // Check whether this frame breaks up text runs. All frames break up text michael@0: // runs (hence return false here) except for text frames and inline containers. michael@0: bool continuingTextRun = aFrame->CanContinueTextRun(); michael@0: michael@0: // Clear any residual mTrimmableWidth if this isn't a text frame michael@0: if (!continuingTextRun && !pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) { michael@0: mTrimmableWidth = 0; michael@0: } michael@0: michael@0: // See if we can place the frame. If we can't fit it, then we michael@0: // return now. michael@0: bool optionalBreakAfterFits; michael@0: NS_ASSERTION(isText || michael@0: !reflowStateHolder.ref().IsFloating(), michael@0: "How'd we get a floated inline frame? " michael@0: "The frame ctor should've dealt with this."); michael@0: if (CanPlaceFrame(pfd, notSafeToBreak, continuingTextRun, michael@0: savedOptionalBreakContent != nullptr, metrics, michael@0: aReflowStatus, &optionalBreakAfterFits)) { michael@0: if (!isEmpty) { michael@0: psd->mHasNonemptyContent = true; michael@0: mLineIsEmpty = false; michael@0: if (!pfd->mSpan) { michael@0: // nonempty leaf content has been placed michael@0: mLineAtStart = false; michael@0: } michael@0: } michael@0: michael@0: // Place the frame, updating aBounds with the final size and michael@0: // location. Then apply the bottom+right margins (as michael@0: // appropriate) to the frame. michael@0: PlaceFrame(pfd, metrics); michael@0: PerSpanData* span = pfd->mSpan; michael@0: if (span) { michael@0: // The frame we just finished reflowing is an inline michael@0: // container. It needs its child frames aligned in the block direction, michael@0: // so do most of it now. michael@0: BlockDirAlignFrames(span); michael@0: } michael@0: michael@0: if (!continuingTextRun) { michael@0: if (!psd->mNoWrap && (!LineIsEmpty() || placedFloat)) { michael@0: // record soft break opportunity after this content that can't be michael@0: // part of a text run. This is not a text frame so we know michael@0: // that offset INT32_MAX means "after the content". michael@0: if (NotifyOptionalBreakPosition(aFrame->GetContent(), INT32_MAX, optionalBreakAfterFits, gfxBreakPriority::eNormalBreak)) { michael@0: // If this returns true then we are being told to actually break here. michael@0: aReflowStatus = NS_INLINE_LINE_BREAK_AFTER(aReflowStatus); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: else { michael@0: PushFrame(aFrame); michael@0: aPushedFrame = true; michael@0: // Undo any saved break positions that the frame might have told us about, michael@0: // since we didn't end up placing it michael@0: RestoreSavedBreakPosition(savedOptionalBreakContent, michael@0: savedOptionalBreakOffset, michael@0: savedOptionalBreakPriority); michael@0: } michael@0: } michael@0: else { michael@0: PushFrame(aFrame); michael@0: } michael@0: michael@0: #ifdef REALLY_NOISY_REFLOW michael@0: nsFrame::IndentBy(stdout, mSpanDepth); michael@0: printf("End ReflowFrame "); michael@0: nsFrame::ListTag(stdout, aFrame); michael@0: printf(" status=%x\n", aReflowStatus); michael@0: #endif michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::AllowForStartMargin(PerFrameData* pfd, michael@0: nsHTMLReflowState& aReflowState) michael@0: { michael@0: NS_ASSERTION(!aReflowState.IsFloating(), michael@0: "How'd we get a floated inline frame? " michael@0: "The frame ctor should've dealt with this."); michael@0: michael@0: WritingMode frameWM = pfd->mFrame->GetWritingMode(); michael@0: michael@0: // Only apply start-margin on the first-in flow for inline frames, michael@0: // and make sure to not apply it to any inline other than the first michael@0: // in an ib split. Note that the ib sibling (block-in-inline michael@0: // sibling) annotations only live on the first continuation, but we michael@0: // don't want to apply the start margin for later continuations michael@0: // anyway. michael@0: if (pfd->mFrame->GetPrevContinuation() || michael@0: pfd->mFrame->FrameIsNonFirstInIBSplit()) { michael@0: // Zero this out so that when we compute the max-element-width of michael@0: // the frame we will properly avoid adding in the starting margin. michael@0: pfd->mMargin.IStart(frameWM) = 0; michael@0: } else { michael@0: NS_WARN_IF_FALSE(NS_UNCONSTRAINEDSIZE != aReflowState.AvailableWidth(), michael@0: "have unconstrained width; this should only result from " michael@0: "very large sizes, not attempts at intrinsic width " michael@0: "calculation"); michael@0: if (NS_UNCONSTRAINEDSIZE == aReflowState.ComputedWidth()) { michael@0: // For inline-ish and text-ish things (which don't compute widths michael@0: // in the reflow state), adjust available width to account for the michael@0: // start margin. The end margin will be accounted for when we michael@0: // finish flowing the frame. michael@0: aReflowState.AvailableWidth() -= pfd->mMargin.IStart(frameWM); michael@0: } michael@0: } michael@0: } michael@0: michael@0: nscoord michael@0: nsLineLayout::GetCurrentFrameInlineDistanceFromBlock() michael@0: { michael@0: PerSpanData* psd; michael@0: nscoord x = 0; michael@0: for (psd = mCurrentSpan; psd; psd = psd->mParent) { michael@0: x += psd->mICoord; michael@0: } michael@0: return x; michael@0: } michael@0: michael@0: /** michael@0: * See if the frame can be placed now that we know it's desired size. michael@0: * We can always place the frame if the line is empty. Note that we michael@0: * know that the reflow-status is not a break-before because if it was michael@0: * ReflowFrame above would have returned false, preventing this method michael@0: * from being called. The logic in this method assumes that. michael@0: * michael@0: * Note that there is no check against the Y coordinate because we michael@0: * assume that the caller will take care of that. michael@0: */ michael@0: bool michael@0: nsLineLayout::CanPlaceFrame(PerFrameData* pfd, michael@0: bool aNotSafeToBreak, michael@0: bool aFrameCanContinueTextRun, michael@0: bool aCanRollBackBeforeFrame, michael@0: nsHTMLReflowMetrics& aMetrics, michael@0: nsReflowStatus& aStatus, michael@0: bool* aOptionalBreakAfterFits) michael@0: { michael@0: NS_PRECONDITION(pfd && pfd->mFrame, "bad args, null pointers for frame data"); michael@0: michael@0: *aOptionalBreakAfterFits = true; michael@0: michael@0: WritingMode frameWM = pfd->mFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: /* michael@0: * We want to only apply the end margin if we're the last continuation and michael@0: * either not in an {ib} split or the last inline in it. In all other michael@0: * cases we want to zero it out. That means zeroing it out if any of these michael@0: * conditions hold: michael@0: * 1) The frame is not complete (in this case it will get a next-in-flow) michael@0: * 2) The frame is complete but has a non-fluid continuation on its michael@0: * continuation chain. Note that if it has a fluid continuation, that michael@0: * continuation will get destroyed later, so we don't want to drop the michael@0: * end-margin in that case. michael@0: * 3) The frame is in an {ib} split and is not the last part. michael@0: * michael@0: * However, none of that applies if this is a letter frame (XXXbz why?) michael@0: */ michael@0: if ((NS_FRAME_IS_NOT_COMPLETE(aStatus) || michael@0: pfd->mFrame->LastInFlow()->GetNextContinuation() || michael@0: pfd->mFrame->FrameIsNonLastInIBSplit()) michael@0: && !pfd->GetFlag(PFD_ISLETTERFRAME)) { michael@0: pfd->mMargin.IEnd(frameWM) = 0; michael@0: } michael@0: michael@0: // Convert the frame's margins to the line's writing mode and apply michael@0: // the start margin to the frame bounds. michael@0: LogicalMargin usedMargins = pfd->mMargin.ConvertTo(lineWM, frameWM); michael@0: nscoord startMargin = usedMargins.IStart(lineWM); michael@0: nscoord endMargin = usedMargins.IEnd(lineWM); michael@0: michael@0: pfd->mBounds.IStart(lineWM) += startMargin; michael@0: michael@0: PerSpanData* psd = mCurrentSpan; michael@0: if (psd->mNoWrap) { michael@0: // When wrapping is off, everything fits. michael@0: return true; michael@0: } michael@0: michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: if (nullptr != psd->mFrame) { michael@0: nsFrame::ListTag(stdout, psd->mFrame->mFrame); michael@0: } michael@0: else { michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: } michael@0: printf(": aNotSafeToBreak=%s frame=", aNotSafeToBreak ? "true" : "false"); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: printf(" frameWidth=%d, margins=%d,%d\n", michael@0: pfd->mBounds.IEnd(lineWM) + endMargin - psd->mICoord, michael@0: startMargin, endMargin); michael@0: #endif michael@0: michael@0: // Set outside to true if the result of the reflow leads to the michael@0: // frame sticking outside of our available area. michael@0: bool outside = pfd->mBounds.IEnd(lineWM) - mTrimmableWidth + endMargin > michael@0: psd->mIEnd; michael@0: if (!outside) { michael@0: // If it fits, it fits michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> inside\n"); michael@0: #endif michael@0: return true; michael@0: } michael@0: *aOptionalBreakAfterFits = false; michael@0: michael@0: // When it doesn't fit, check for a few special conditions where we michael@0: // allow it to fit anyway. michael@0: if (0 == startMargin + pfd->mBounds.ISize(lineWM) + endMargin) { michael@0: // Empty frames always fit right where they are michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> empty frame fits\n"); michael@0: #endif michael@0: return true; michael@0: } michael@0: michael@0: #ifdef FIX_BUG_50257 michael@0: // another special case: always place a BR michael@0: if (nsGkAtoms::brFrame == pfd->mFrame->GetType()) { michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> BR frame fits\n"); michael@0: #endif michael@0: return true; michael@0: } michael@0: #endif michael@0: michael@0: if (aNotSafeToBreak) { michael@0: // There are no frames on the line that take up width and the line is michael@0: // not impacted by floats, so we must allow the current frame to be michael@0: // placed on the line michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> not-safe and not-impacted fits: "); michael@0: while (nullptr != psd) { michael@0: printf(" ", psd, psd->mICoord, psd->mIStart); michael@0: psd = psd->mParent; michael@0: } michael@0: printf("\n"); michael@0: #endif michael@0: return true; michael@0: } michael@0: michael@0: // Special check for span frames michael@0: if (pfd->mSpan && pfd->mSpan->mContainsFloat) { michael@0: // If the span either directly or indirectly contains a float then michael@0: // it fits. Why? It's kind of complicated, but here goes: michael@0: // michael@0: // 1. CanPlaceFrame is used for all frame placements on a line, michael@0: // and in a span. This includes recursively placement of frames michael@0: // inside of spans, and the span itself. Because the logic always michael@0: // checks for room before proceeding (the code above here), the michael@0: // only things on a line will be those things that "fit". michael@0: // michael@0: // 2. Before a float is placed on a line, the line has to be empty michael@0: // (otherwise it's a "below current line" float and will be placed michael@0: // after the line). michael@0: // michael@0: // Therefore, if the span directly or indirectly has a float michael@0: // then it means that at the time of the placement of the float michael@0: // the line was empty. Because of #1, only the frames that fit can michael@0: // be added after that point, therefore we can assume that the michael@0: // current span being placed has fit. michael@0: // michael@0: // So how do we get here and have a span that should already fit michael@0: // and yet doesn't: Simple: span's that have the no-wrap attribute michael@0: // set on them and contain a float and are placed where they michael@0: // don't naturally fit. michael@0: return true; michael@0: } michael@0: michael@0: if (aFrameCanContinueTextRun) { michael@0: // Let it fit, but we reserve the right to roll back. michael@0: // Note that we usually won't get here because a text frame will break michael@0: // itself to avoid exceeding the available width. michael@0: // We'll only get here for text frames that couldn't break early enough. michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> placing overflowing textrun, requesting backup\n"); michael@0: #endif michael@0: michael@0: // We will want to try backup. michael@0: mNeedBackup = true; michael@0: return true; michael@0: } michael@0: michael@0: #ifdef NOISY_CAN_PLACE_FRAME michael@0: printf(" ==> didn't fit\n"); michael@0: #endif michael@0: aStatus = NS_INLINE_LINE_BREAK_BEFORE(); michael@0: return false; michael@0: } michael@0: michael@0: /** michael@0: * Place the frame. Update running counters. michael@0: */ michael@0: void michael@0: nsLineLayout::PlaceFrame(PerFrameData* pfd, nsHTMLReflowMetrics& aMetrics) michael@0: { michael@0: // Record ascent and update max-ascent and max-descent values michael@0: if (aMetrics.TopAscent() == nsHTMLReflowMetrics::ASK_FOR_BASELINE) michael@0: pfd->mAscent = pfd->mFrame->GetBaseline(); michael@0: else michael@0: pfd->mAscent = aMetrics.TopAscent(); michael@0: michael@0: // Advance to next inline coordinate michael@0: WritingMode frameWM = pfd->mFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: mCurrentSpan->mICoord = pfd->mBounds.IEnd(lineWM) + michael@0: pfd->mMargin.ConvertTo(lineWM, frameWM).IEnd(lineWM); michael@0: michael@0: // Count the number of non-placeholder frames on the line... michael@0: if (pfd->mFrame->GetType() == nsGkAtoms::placeholderFrame) { michael@0: NS_ASSERTION(pfd->mBounds.ISize(lineWM) == 0 && michael@0: pfd->mBounds.BSize(lineWM) == 0, michael@0: "placeholders should have 0 width/height (checking " michael@0: "placeholders were never counted by the old code in " michael@0: "this function)"); michael@0: } else { michael@0: mTotalPlacedFrames++; michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::AddBulletFrame(nsIFrame* aFrame, michael@0: const nsHTMLReflowMetrics& aMetrics) michael@0: { michael@0: NS_ASSERTION(mCurrentSpan == mRootSpan, "bad linelayout user"); michael@0: NS_ASSERTION(mGotLineBox, "must have line box"); michael@0: michael@0: nsIFrame *blockFrame = mBlockReflowState->frame; michael@0: NS_ASSERTION(blockFrame->IsFrameOfType(nsIFrame::eBlockFrame), michael@0: "must be for block"); michael@0: if (!static_cast(blockFrame)->BulletIsEmpty()) { michael@0: mHasBullet = true; michael@0: mLineBox->SetHasBullet(); michael@0: } michael@0: michael@0: PerFrameData* pfd = NewPerFrameData(aFrame); michael@0: mRootSpan->AppendFrame(pfd); michael@0: pfd->SetFlag(PFD_ISBULLET, true); michael@0: if (aMetrics.TopAscent() == nsHTMLReflowMetrics::ASK_FOR_BASELINE) michael@0: pfd->mAscent = aFrame->GetBaseline(); michael@0: else michael@0: pfd->mAscent = aMetrics.TopAscent(); michael@0: michael@0: // Note: block-coord value will be updated during block-direction alignment michael@0: pfd->mBounds = LogicalRect(mRootSpan->mWritingMode, michael@0: aFrame->GetRect(), mContainerWidth); michael@0: pfd->mOverflowAreas = aMetrics.mOverflowAreas; michael@0: } michael@0: michael@0: #ifdef DEBUG michael@0: void michael@0: nsLineLayout::DumpPerSpanData(PerSpanData* psd, int32_t aIndent) michael@0: { michael@0: nsFrame::IndentBy(stdout, aIndent); michael@0: printf("%p: left=%d x=%d right=%d\n", static_cast(psd), michael@0: psd->mIStart, psd->mICoord, psd->mIEnd); michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: nsFrame::IndentBy(stdout, aIndent+1); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: nsRect rect = pfd->mBounds.GetPhysicalRect(psd->mWritingMode, michael@0: mContainerWidth); michael@0: printf(" %d,%d,%d,%d\n", rect.x, rect.y, rect.width, rect.height); michael@0: if (pfd->mSpan) { michael@0: DumpPerSpanData(pfd->mSpan, aIndent + 1); michael@0: } michael@0: pfd = pfd->mNext; michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: #define VALIGN_OTHER 0 michael@0: #define VALIGN_TOP 1 michael@0: #define VALIGN_BOTTOM 2 michael@0: michael@0: void michael@0: nsLineLayout::BlockDirAlignLine() michael@0: { michael@0: // Synthesize a PerFrameData for the block frame michael@0: PerFrameData rootPFD(mBlockReflowState->frame->GetWritingMode()); michael@0: rootPFD.mFrame = mBlockReflowState->frame; michael@0: rootPFD.mAscent = 0; michael@0: mRootSpan->mFrame = &rootPFD; michael@0: michael@0: // Partially place the children of the block frame. The baseline for michael@0: // this operation is set to zero so that the y coordinates for all michael@0: // of the placed children will be relative to there. michael@0: PerSpanData* psd = mRootSpan; michael@0: BlockDirAlignFrames(psd); michael@0: michael@0: // *** Note that comments here still use the anachronistic term "line-height" michael@0: // when we really mean "size of the line in the block direction". This is michael@0: // partly for brevity and partly to retain the association with the CSS michael@0: // line-height property michael@0: // michael@0: // Compute the line-height. The line-height will be the larger of: michael@0: // michael@0: // [1] maxBCoord - minBCoord (the distance between the first child's michael@0: // block-start edge and the last child's block-end edge) michael@0: // michael@0: // [2] the maximum logical box block size (since not every frame may have michael@0: // participated in #1; for example: block-start/end aligned frames) michael@0: // michael@0: // [3] the minimum line height ("line-height" property set on the michael@0: // block frame) michael@0: nscoord lineBSize = psd->mMaxBCoord - psd->mMinBCoord; michael@0: michael@0: // Now that the line-height is computed, we need to know where the michael@0: // baseline is in the line. Position baseline so that mMinBCoord is just michael@0: // inside the start of the line box. michael@0: nscoord baselineBCoord; michael@0: if (psd->mMinBCoord < 0) { michael@0: baselineBCoord = mBStartEdge - psd->mMinBCoord; michael@0: } michael@0: else { michael@0: baselineBCoord = mBStartEdge; michael@0: } michael@0: michael@0: // It's also possible that the line block-size isn't tall enough because michael@0: // of block start/end aligned elements that were not accounted for in michael@0: // min/max BCoord. michael@0: // michael@0: // The CSS2 spec doesn't really say what happens when to the michael@0: // baseline in this situations. What we do is if the largest start michael@0: // aligned box block size is greater than the line block-size then we leave michael@0: // the baseline alone. If the largest end aligned box is greater michael@0: // than the line block-size then we slide the baseline forward by the extra michael@0: // amount. michael@0: // michael@0: // Navigator 4 gives precedence to the first top/bottom aligned michael@0: // object. We just let block end aligned objects win. michael@0: if (lineBSize < mMaxEndBoxBSize) { michael@0: // When the line is shorter than the maximum block start aligned box michael@0: nscoord extra = mMaxEndBoxBSize - lineBSize; michael@0: baselineBCoord += extra; michael@0: lineBSize = mMaxEndBoxBSize; michael@0: } michael@0: if (lineBSize < mMaxStartBoxBSize) { michael@0: lineBSize = mMaxStartBoxBSize; michael@0: } michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [line]==> lineBSize=%d baselineBCoord=%d\n", lineBSize, baselineBCoord); michael@0: #endif michael@0: michael@0: // Now position all of the frames in the root span. We will also michael@0: // recurse over the child spans and place any block start/end aligned michael@0: // frames we find. michael@0: // XXX PERFORMANCE: set a bit per-span to avoid the extra work michael@0: // (propagate it upward too) michael@0: WritingMode lineWM = psd->mWritingMode; michael@0: for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: if (pfd->mBlockDirAlign == VALIGN_OTHER) { michael@0: pfd->mBounds.BStart(lineWM) += baselineBCoord; michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: } michael@0: } michael@0: PlaceStartEndFrames(psd, -mBStartEdge, lineBSize); michael@0: michael@0: // If the frame being reflowed has text decorations, we simulate the michael@0: // propagation of those decorations to a line-level element by storing the michael@0: // offset in a frame property on any child frames that are aligned in the michael@0: // block direction somewhere other than the baseline. This property is then michael@0: // used by nsTextFrame::GetTextDecorations when the same conditions are met. michael@0: if (rootPFD.mFrame->StyleContext()->HasTextDecorationLines()) { michael@0: for (const PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: const nsIFrame *const f = pfd->mFrame; michael@0: if (f->VerticalAlignEnum() != NS_STYLE_VERTICAL_ALIGN_BASELINE) { michael@0: const nscoord offset = baselineBCoord - pfd->mBounds.BStart(lineWM); michael@0: f->Properties().Set(nsIFrame::LineBaselineOffset(), michael@0: NS_INT32_TO_PTR(offset)); michael@0: } michael@0: } michael@0: } michael@0: michael@0: // Fill in returned line-box and max-element-width data michael@0: mLineBox->SetBounds(lineWM, michael@0: psd->mIStart, mBStartEdge, michael@0: psd->mICoord - psd->mIStart, lineBSize, michael@0: mContainerWidth); michael@0: michael@0: mFinalLineBSize = lineBSize; michael@0: mLineBox->SetAscent(baselineBCoord - mBStartEdge); michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf( michael@0: " [line]==> bounds{x,y,w,h}={%d,%d,%d,%d} lh=%d a=%d\n", michael@0: mLineBox->mBounds.IStart(lineWM), mLineBox->mBounds.BStart(lineWM), michael@0: mLineBox->mBounds.ISize(lineWM), mLineBox->mBounds.BSize(lineWM), michael@0: mFinalLineBSize, mLineBox->GetAscent()); michael@0: #endif michael@0: michael@0: // Undo root-span mFrame pointer to prevent brane damage later on... michael@0: mRootSpan->mFrame = nullptr; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::PlaceStartEndFrames(PerSpanData* psd, michael@0: nscoord aDistanceFromStart, michael@0: nscoord aLineBSize) michael@0: { michael@0: for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: PerSpanData* span = pfd->mSpan; michael@0: #ifdef DEBUG michael@0: NS_ASSERTION(0xFF != pfd->mBlockDirAlign, "umr"); michael@0: #endif michael@0: WritingMode frameWM = pfd->mFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: switch (pfd->mBlockDirAlign) { michael@0: case VALIGN_TOP: michael@0: if (span) { michael@0: pfd->mBounds.BStart(lineWM) = -aDistanceFromStart - span->mMinBCoord; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = michael@0: -aDistanceFromStart + pfd->mMargin.BStart(frameWM); michael@0: } michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" "); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: printf(": y=%d dTop=%d [bp.top=%d topLeading=%d]\n", michael@0: pfd->mBounds.BStart(lineWM), aDistanceFromStart, michael@0: span ? pfd->mBorderPadding.BStart(frameWM) : 0, michael@0: span ? span->mBStartLeading : 0); michael@0: #endif michael@0: break; michael@0: case VALIGN_BOTTOM: michael@0: if (span) { michael@0: // Compute bottom leading michael@0: pfd->mBounds.BStart(lineWM) = michael@0: -aDistanceFromStart + aLineBSize - span->mMaxBCoord; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = -aDistanceFromStart + aLineBSize - michael@0: pfd->mMargin.BEnd(frameWM) - pfd->mBounds.BSize(lineWM); michael@0: } michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" "); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: printf(": y=%d\n", pfd->mBounds.BStart(lineWM)); michael@0: #endif michael@0: break; michael@0: } michael@0: if (span) { michael@0: nscoord fromStart = aDistanceFromStart + pfd->mBounds.BStart(lineWM); michael@0: PlaceStartEndFrames(span, fromStart, aLineBSize); michael@0: } michael@0: } michael@0: } michael@0: michael@0: static float michael@0: GetInflationForBlockDirAlignment(nsIFrame* aFrame, michael@0: nscoord aInflationMinFontSize) michael@0: { michael@0: if (aFrame->IsSVGText()) { michael@0: const nsIFrame* container = michael@0: nsLayoutUtils::GetClosestFrameOfType(aFrame, nsGkAtoms::svgTextFrame); michael@0: NS_ASSERTION(container, "expected to find an ancestor SVGTextFrame"); michael@0: return michael@0: static_cast(container)->GetFontSizeScaleFactor(); michael@0: } michael@0: return nsLayoutUtils::FontSizeInflationInner(aFrame, aInflationMinFontSize); michael@0: } michael@0: michael@0: #define BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM nscoord_MAX michael@0: #define BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM nscoord_MIN michael@0: michael@0: // Place frames in the block direction within a given span. Note: this doesn't michael@0: // place block start/end aligned frames as those have to wait until the michael@0: // entire line box block size is known. This is called after the span michael@0: // frame has finished being reflowed so that we know its block size. michael@0: void michael@0: nsLineLayout::BlockDirAlignFrames(PerSpanData* psd) michael@0: { michael@0: // Get parent frame info michael@0: PerFrameData* spanFramePFD = psd->mFrame; michael@0: nsIFrame* spanFrame = spanFramePFD->mFrame; michael@0: michael@0: // Get the parent frame's font for all of the frames in this span michael@0: nsRefPtr fm; michael@0: float inflation = michael@0: GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize); michael@0: nsLayoutUtils::GetFontMetricsForFrame(spanFrame, getter_AddRefs(fm), michael@0: inflation); michael@0: mBlockReflowState->rendContext->SetFont(fm); michael@0: michael@0: bool preMode = mStyleText->WhiteSpaceIsSignificant(); michael@0: michael@0: // See if the span is an empty continuation. It's an empty continuation iff: michael@0: // - it has a prev-in-flow michael@0: // - it has no next in flow michael@0: // - it's zero sized michael@0: WritingMode frameWM = spanFramePFD->mFrame->GetWritingMode(); michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: bool emptyContinuation = psd != mRootSpan && michael@0: spanFrame->GetPrevInFlow() && !spanFrame->GetNextInFlow() && michael@0: spanFramePFD->mBounds.IsZeroSize(); michael@0: michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf("[%sSpan]", (psd == mRootSpan)?"Root":""); michael@0: nsFrame::ListTag(stdout, spanFrame); michael@0: printf(": preMode=%s strictMode=%s w/h=%d,%d emptyContinuation=%s", michael@0: preMode ? "yes" : "no", michael@0: mPresContext->CompatibilityMode() != eCompatibility_NavQuirks ? "yes" : "no", michael@0: spanFramePFD->mBounds.ISize(lineWM), michael@0: spanFramePFD->mBounds.BSize(lineWM), michael@0: emptyContinuation ? "yes" : "no"); michael@0: if (psd != mRootSpan) { michael@0: WritingMode frameWM = spanFramePFD->mFrame->GetWritingMode(); michael@0: printf(" bp=%d,%d,%d,%d margin=%d,%d,%d,%d", michael@0: spanFramePFD->mBorderPadding.Top(frameWM), michael@0: spanFramePFD->mBorderPadding.Right(frameWM), michael@0: spanFramePFD->mBorderPadding.Bottom(frameWM), michael@0: spanFramePFD->mBorderPadding.Left(frameWM), michael@0: spanFramePFD->mMargin.Top(frameWM), michael@0: spanFramePFD->mMargin.Right(frameWM), michael@0: spanFramePFD->mMargin.Bottom(frameWM), michael@0: spanFramePFD->mMargin.Left(frameWM)); michael@0: } michael@0: printf("\n"); michael@0: #endif michael@0: michael@0: // Compute the span's mZeroEffectiveSpanBox flag. What we are trying michael@0: // to determine is how we should treat the span: should it act michael@0: // "normally" according to css2 or should it effectively michael@0: // "disappear". michael@0: // michael@0: // In general, if the document being processed is in full standards michael@0: // mode then it should act normally (with one exception). The michael@0: // exception case is when a span is continued and yet the span is michael@0: // empty (e.g. compressed whitespace). For this kind of span we treat michael@0: // it as if it were not there so that it doesn't impact the michael@0: // line block-size. michael@0: // michael@0: // In almost standards mode or quirks mode, we should sometimes make michael@0: // it disappear. The cases that matter are those where the span michael@0: // contains no real text elements that would provide an ascent and michael@0: // descent and height. However, if css style elements have been michael@0: // applied to the span (border/padding/margin) so that it's clear the michael@0: // document author is intending css2 behavior then we act as if strict michael@0: // mode is set. michael@0: // michael@0: // This code works correctly for preMode, because a blank line michael@0: // in PRE mode is encoded as a text node with a LF in it, since michael@0: // text nodes with only whitespace are considered in preMode. michael@0: // michael@0: // Much of this logic is shared with the various implementations of michael@0: // nsIFrame::IsEmpty since they need to duplicate the way it makes michael@0: // some lines empty. However, nsIFrame::IsEmpty can't be reused here michael@0: // since this code sets zeroEffectiveSpanBox even when there are michael@0: // non-empty children. michael@0: bool zeroEffectiveSpanBox = false; michael@0: // XXXldb If we really have empty continuations, then all these other michael@0: // checks don't make sense for them. michael@0: // XXXldb This should probably just use nsIFrame::IsSelfEmpty, assuming that michael@0: // it agrees with this code. (If it doesn't agree, it probably should.) michael@0: if ((emptyContinuation || michael@0: mPresContext->CompatibilityMode() != eCompatibility_FullStandards) && michael@0: ((psd == mRootSpan) || michael@0: (spanFramePFD->mBorderPadding.IsEmpty() && michael@0: spanFramePFD->mMargin.IsEmpty()))) { michael@0: // This code handles an issue with compatibility with non-css michael@0: // conformant browsers. In particular, there are some cases michael@0: // where the font-size and line-height for a span must be michael@0: // ignored and instead the span must *act* as if it were zero michael@0: // sized. In general, if the span contains any non-compressed michael@0: // text then we don't use this logic. michael@0: // However, this is not propagated outwards, since (in compatibility michael@0: // mode) we don't want big line heights for things like michael@0: //

Text

michael@0: michael@0: // We shouldn't include any whitespace that collapses, unless we're michael@0: // preformatted (in which case it shouldn't, but the width=0 test is michael@0: // perhaps incorrect). This includes whitespace at the beginning of michael@0: // a line and whitespace preceded (?) by other whitespace. michael@0: // See bug 134580 and bug 155333. michael@0: zeroEffectiveSpanBox = true; michael@0: for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: if (pfd->GetFlag(PFD_ISTEXTFRAME) && michael@0: (pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME) || preMode || michael@0: pfd->mBounds.ISize(mRootSpan->mWritingMode) != 0)) { michael@0: zeroEffectiveSpanBox = false; michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: psd->mZeroEffectiveSpanBox = zeroEffectiveSpanBox; michael@0: michael@0: // Setup baselineBCoord, minBCoord, and maxBCoord michael@0: nscoord baselineBCoord, minBCoord, maxBCoord; michael@0: if (psd == mRootSpan) { michael@0: // Use a zero baselineBCoord since we don't yet know where the baseline michael@0: // will be (until we know how tall the line is; then we will michael@0: // know). In addition, use extreme values for the minBCoord and maxBCoord michael@0: // values so that only the child frames will impact their values michael@0: // (since these are children of the block, there is no span box to michael@0: // provide initial values). michael@0: baselineBCoord = 0; michael@0: minBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM; michael@0: maxBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM; michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf("[RootSpan]"); michael@0: nsFrame::ListTag(stdout, spanFrame); michael@0: printf(": pass1 valign frames: topEdge=%d minLineBSize=%d zeroEffectiveSpanBox=%s\n", michael@0: mBStartEdge, mMinLineBSize, michael@0: zeroEffectiveSpanBox ? "yes" : "no"); michael@0: #endif michael@0: } michael@0: else { michael@0: // Compute the logical block size for this span. The logical block size michael@0: // is based on the "line-height" value, not the font-size. Also michael@0: // compute the top leading. michael@0: float inflation = michael@0: GetInflationForBlockDirAlignment(spanFrame, mInflationMinFontSize); michael@0: nscoord logicalBSize = nsHTMLReflowState:: michael@0: CalcLineHeight(spanFrame->GetContent(), spanFrame->StyleContext(), michael@0: mBlockReflowState->ComputedHeight(), michael@0: inflation); michael@0: nscoord contentBSize = spanFramePFD->mBounds.BSize(lineWM) - michael@0: spanFramePFD->mBorderPadding.BStart(frameWM) - michael@0: spanFramePFD->mBorderPadding.BEnd(frameWM); michael@0: michael@0: // Special-case for a ::first-letter frame, set the line height to michael@0: // the frame block size if the user has left line-height == normal michael@0: if (spanFramePFD->GetFlag(PFD_ISLETTERFRAME) && michael@0: !spanFrame->GetPrevInFlow() && michael@0: spanFrame->StyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal) { michael@0: logicalBSize = spanFramePFD->mBounds.BSize(lineWM); michael@0: } michael@0: michael@0: nscoord leading = logicalBSize - contentBSize; michael@0: psd->mBStartLeading = leading / 2; michael@0: psd->mBEndLeading = leading - psd->mBStartLeading; michael@0: psd->mLogicalBSize = logicalBSize; michael@0: michael@0: if (zeroEffectiveSpanBox) { michael@0: // When the span-box is to be ignored, zero out the initial michael@0: // values so that the span doesn't impact the final line michael@0: // height. The contents of the span can impact the final line michael@0: // height. michael@0: michael@0: // Note that things are readjusted for this span after its children michael@0: // are reflowed michael@0: minBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM; michael@0: maxBCoord = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM; michael@0: } michael@0: else { michael@0: michael@0: // The initial values for the min and max block coord values are in the michael@0: // span's coordinate space, and cover the logical block size of the span. michael@0: // If there are child frames in this span that stick out of this area michael@0: // then the minBCoord and maxBCoord are updated by the amount of logical michael@0: // blockSize that is outside this range. michael@0: minBCoord = spanFramePFD->mBorderPadding.BStart(frameWM) - michael@0: psd->mBStartLeading; michael@0: maxBCoord = minBCoord + psd->mLogicalBSize; michael@0: } michael@0: michael@0: // This is the distance from the top edge of the parents visual michael@0: // box to the baseline. The span already computed this for us, michael@0: // so just use it. michael@0: *psd->mBaseline = baselineBCoord = spanFramePFD->mAscent; michael@0: michael@0: michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf("[%sSpan]", (psd == mRootSpan)?"Root":""); michael@0: nsFrame::ListTag(stdout, spanFrame); michael@0: printf(": baseLine=%d logicalBSize=%d topLeading=%d h=%d bp=%d,%d zeroEffectiveSpanBox=%s\n", michael@0: baselineBCoord, psd->mLogicalBSize, psd->mBStartLeading, michael@0: spanFramePFD->mBounds.BSize(lineWM), michael@0: spanFramePFD->mBorderPadding.Top(frameWM), michael@0: spanFramePFD->mBorderPadding.Bottom(frameWM), michael@0: zeroEffectiveSpanBox ? "yes" : "no"); michael@0: #endif michael@0: } michael@0: michael@0: nscoord maxStartBoxBSize = 0; michael@0: nscoord maxEndBoxBSize = 0; michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: nsIFrame* frame = pfd->mFrame; michael@0: WritingMode frameWM = frame->GetWritingMode(); michael@0: michael@0: // sanity check (see bug 105168, non-reproducible crashes from null frame) michael@0: NS_ASSERTION(frame, "null frame in PerFrameData - something is very very bad"); michael@0: if (!frame) { michael@0: return; michael@0: } michael@0: michael@0: // Compute the logical block size of the frame michael@0: nscoord logicalBSize; michael@0: PerSpanData* frameSpan = pfd->mSpan; michael@0: if (frameSpan) { michael@0: // For span frames the logical-block-size and start-leading were michael@0: // pre-computed when the span was reflowed. michael@0: logicalBSize = frameSpan->mLogicalBSize; michael@0: } michael@0: else { michael@0: // For other elements the logical block size is the same as the michael@0: // frame's block size plus its margins. michael@0: logicalBSize = pfd->mBounds.BSize(lineWM) + michael@0: pfd->mMargin.BStartEnd(frameWM); michael@0: if (logicalBSize < 0 && michael@0: mPresContext->CompatibilityMode() == eCompatibility_NavQuirks) { michael@0: pfd->mAscent -= logicalBSize; michael@0: logicalBSize = 0; michael@0: } michael@0: } michael@0: michael@0: // Get vertical-align property ("vertical-align" is the CSS name for michael@0: // block-direction align) michael@0: const nsStyleCoord& verticalAlign = michael@0: frame->StyleTextReset()->mVerticalAlign; michael@0: uint8_t verticalAlignEnum = frame->VerticalAlignEnum(); michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [frame]"); michael@0: nsFrame::ListTag(stdout, frame); michael@0: printf(": verticalAlignUnit=%d (enum == %d", michael@0: verticalAlign.GetUnit(), michael@0: ((eStyleUnit_Enumerated == verticalAlign.GetUnit()) michael@0: ? verticalAlign.GetIntValue() michael@0: : -1)); michael@0: if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) { michael@0: printf(", after SVG dominant-baseline conversion == %d", michael@0: verticalAlignEnum); michael@0: } michael@0: printf(")\n"); michael@0: #endif michael@0: michael@0: if (verticalAlignEnum != nsIFrame::eInvalidVerticalAlign) { michael@0: switch (verticalAlignEnum) { michael@0: default: michael@0: case NS_STYLE_VERTICAL_ALIGN_BASELINE: michael@0: { michael@0: // The element's baseline is aligned with the baseline of michael@0: // the parent. michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - pfd->mAscent; michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_SUB: michael@0: { michael@0: // Lower the baseline of the box to the subscript offset michael@0: // of the parent's box. This is identical to the baseline michael@0: // alignment except for the addition of the subscript michael@0: // offset to the baseline BCoord. michael@0: nscoord parentSubscript = fm->SubscriptOffset(); michael@0: nscoord revisedBaselineBCoord = baselineBCoord + parentSubscript; michael@0: pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent; michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_SUPER: michael@0: { michael@0: // Raise the baseline of the box to the superscript offset michael@0: // of the parent's box. This is identical to the baseline michael@0: // alignment except for the subtraction of the superscript michael@0: // offset to the baseline BCoord. michael@0: nscoord parentSuperscript = fm->SuperscriptOffset(); michael@0: nscoord revisedBaselineBCoord = baselineBCoord - parentSuperscript; michael@0: pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent; michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_TOP: michael@0: { michael@0: pfd->mBlockDirAlign = VALIGN_TOP; michael@0: nscoord subtreeBSize = logicalBSize; michael@0: if (frameSpan) { michael@0: subtreeBSize = frameSpan->mMaxBCoord - frameSpan->mMinBCoord; michael@0: NS_ASSERTION(subtreeBSize >= logicalBSize, michael@0: "unexpected subtree block size"); michael@0: } michael@0: if (subtreeBSize > maxStartBoxBSize) { michael@0: maxStartBoxBSize = subtreeBSize; michael@0: } michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_BOTTOM: michael@0: { michael@0: pfd->mBlockDirAlign = VALIGN_BOTTOM; michael@0: nscoord subtreeBSize = logicalBSize; michael@0: if (frameSpan) { michael@0: subtreeBSize = frameSpan->mMaxBCoord - frameSpan->mMinBCoord; michael@0: NS_ASSERTION(subtreeBSize >= logicalBSize, michael@0: "unexpected subtree block size"); michael@0: } michael@0: if (subtreeBSize > maxEndBoxBSize) { michael@0: maxEndBoxBSize = subtreeBSize; michael@0: } michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_MIDDLE: michael@0: { michael@0: // Align the midpoint of the frame with 1/2 the parents michael@0: // x-height above the baseline. michael@0: nscoord parentXHeight = fm->XHeight(); michael@0: if (frameSpan) { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - michael@0: (parentXHeight + pfd->mBounds.BSize(lineWM))/2; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - michael@0: (parentXHeight + logicalBSize)/2 + michael@0: pfd->mMargin.BStart(frameWM); michael@0: } michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP: michael@0: { michael@0: // The top of the logical box is aligned with the top of michael@0: // the parent element's text. michael@0: nscoord parentAscent = fm->MaxAscent(); michael@0: if (frameSpan) { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - parentAscent - michael@0: pfd->mBorderPadding.BStart(frameWM) + frameSpan->mBStartLeading; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - parentAscent + michael@0: pfd->mMargin.BStart(frameWM); michael@0: } michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM: michael@0: { michael@0: // The bottom of the logical box is aligned with the michael@0: // bottom of the parent elements text. michael@0: nscoord parentDescent = fm->MaxDescent(); michael@0: if (frameSpan) { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord + parentDescent - michael@0: pfd->mBounds.BSize(lineWM) + michael@0: pfd->mBorderPadding.BEnd(frameWM) - michael@0: frameSpan->mBEndLeading; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord + parentDescent - michael@0: pfd->mBounds.BSize(lineWM) - michael@0: pfd->mMargin.BEnd(frameWM); michael@0: } michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: michael@0: case NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE: michael@0: { michael@0: // Align the midpoint of the frame with the baseline of the parent. michael@0: if (frameSpan) { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - michael@0: pfd->mBounds.BSize(lineWM)/2; michael@0: } michael@0: else { michael@0: pfd->mBounds.BStart(lineWM) = baselineBCoord - logicalBSize/2 + michael@0: pfd->mMargin.BStart(frameWM); michael@0: } michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: break; michael@0: } michael@0: } michael@0: } else { michael@0: // We have either a coord, a percent, or a calc(). michael@0: nscoord pctBasis = 0; michael@0: if (verticalAlign.HasPercent()) { michael@0: // Percentages are like lengths, except treated as a percentage michael@0: // of the elements line block size value. michael@0: float inflation = michael@0: GetInflationForBlockDirAlignment(frame, mInflationMinFontSize); michael@0: pctBasis = nsHTMLReflowState::CalcLineHeight(frame->GetContent(), michael@0: frame->StyleContext(), mBlockReflowState->ComputedBSize(), michael@0: inflation); michael@0: } michael@0: nscoord offset = michael@0: nsRuleNode::ComputeCoordPercentCalc(verticalAlign, pctBasis); michael@0: // According to the CSS2 spec (10.8.1), a positive value michael@0: // "raises" the box by the given distance while a negative value michael@0: // "lowers" the box by the given distance (with zero being the michael@0: // baseline). Since Y coordinates increase towards the bottom of michael@0: // the screen we reverse the sign. michael@0: nscoord revisedBaselineBCoord = baselineBCoord - offset; michael@0: pfd->mBounds.BStart(lineWM) = revisedBaselineBCoord - pfd->mAscent; michael@0: pfd->mBlockDirAlign = VALIGN_OTHER; michael@0: } michael@0: michael@0: // Update minBCoord/maxBCoord for frames that we just placed. Do not factor michael@0: // text into the equation. michael@0: if (pfd->mBlockDirAlign == VALIGN_OTHER) { michael@0: // Text frames do not contribute to the min/max Y values for the michael@0: // line (instead their parent frame's font-size contributes). michael@0: // XXXrbs -- relax this restriction because it causes text frames michael@0: // to jam together when 'font-size-adjust' is enabled michael@0: // and layout is using dynamic font heights (bug 20394) michael@0: // -- Note #1: With this code enabled and with the fact that we are not michael@0: // using Em[Ascent|Descent] as nsDimensions for text metrics in michael@0: // GFX mean that the discussion in bug 13072 cannot hold. michael@0: // -- Note #2: We still don't want empty-text frames to interfere. michael@0: // For example in quirks mode, avoiding empty text frames prevents michael@0: // "tall" lines around elements like
since the rules of
michael@0: // in quirks.css have pseudo text contents with LF in them. michael@0: #if 0 michael@0: if (!pfd->GetFlag(PFD_ISTEXTFRAME)) { michael@0: #else michael@0: // Only consider non empty text frames when line-height=normal michael@0: bool canUpdate = !pfd->GetFlag(PFD_ISTEXTFRAME); michael@0: if (!canUpdate && pfd->GetFlag(PFD_ISNONWHITESPACETEXTFRAME)) { michael@0: canUpdate = michael@0: frame->StyleText()->mLineHeight.GetUnit() == eStyleUnit_Normal; michael@0: } michael@0: if (canUpdate) { michael@0: #endif michael@0: nscoord blockStart, blockEnd; michael@0: if (frameSpan) { michael@0: // For spans that were are now placing, use their position michael@0: // plus their already computed min-Y and max-Y values for michael@0: // computing blockStart and blockEnd. michael@0: blockStart = pfd->mBounds.BStart(lineWM) + frameSpan->mMinBCoord; michael@0: blockEnd = pfd->mBounds.BStart(lineWM) + frameSpan->mMaxBCoord; michael@0: } michael@0: else { michael@0: blockStart = pfd->mBounds.BStart(lineWM) - michael@0: pfd->mMargin.BStart(frameWM); michael@0: blockEnd = blockStart + logicalBSize; michael@0: } michael@0: if (!preMode && michael@0: mPresContext->CompatibilityMode() != eCompatibility_FullStandards && michael@0: !logicalBSize) { michael@0: // Check if it's a BR frame that is not alone on its line (it michael@0: // is given a block size of zero to indicate this), and if so reset michael@0: // blockStart and blockEnd so that BR frames don't influence the line. michael@0: if (nsGkAtoms::brFrame == frame->GetType()) { michael@0: blockStart = BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM; michael@0: blockEnd = BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM; michael@0: } michael@0: } michael@0: if (blockStart < minBCoord) minBCoord = blockStart; michael@0: if (blockEnd > maxBCoord) maxBCoord = blockEnd; michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [frame]raw: a=%d h=%d bp=%d,%d logical: h=%d leading=%d y=%d minBCoord=%d maxBCoord=%d\n", michael@0: pfd->mAscent, pfd->mBounds.BSize(lineWM), michael@0: pfd->mBorderPadding.Top(frameWM), michael@0: pfd->mBorderPadding.Bottom(frameWM), michael@0: logicalBSize, michael@0: frameSpan ? frameSpan->mBStartLeading : 0, michael@0: pfd->mBounds.BStart(lineWM), minBCoord, maxBCoord); michael@0: #endif michael@0: } michael@0: if (psd != mRootSpan) { michael@0: frame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: } michael@0: } michael@0: pfd = pfd->mNext; michael@0: } michael@0: michael@0: // Factor in the minimum line block-size when handling the root-span for michael@0: // the block. michael@0: if (psd == mRootSpan) { michael@0: // We should factor in the block element's minimum line-height (as michael@0: // defined in section 10.8.1 of the css2 spec) assuming that michael@0: // mZeroEffectiveSpanBox is not set on the root span. This only happens michael@0: // in some cases in quirks mode: michael@0: // (1) if the root span contains non-whitespace text directly (this michael@0: // is handled by mZeroEffectiveSpanBox michael@0: // (2) if this line has a bullet michael@0: // (3) if this is the last line of an LI, DT, or DD element michael@0: // (The last line before a block also counts, but not before a michael@0: // BR) (NN4/IE5 quirk) michael@0: michael@0: // (1) and (2) above michael@0: bool applyMinLH = !psd->mZeroEffectiveSpanBox || mHasBullet; michael@0: bool isLastLine = (!mLineBox->IsLineWrapped() && !mLineEndsInBR); michael@0: if (!applyMinLH && isLastLine) { michael@0: nsIContent* blockContent = mRootSpan->mFrame->mFrame->GetContent(); michael@0: if (blockContent) { michael@0: nsIAtom *blockTagAtom = blockContent->Tag(); michael@0: // (3) above, if the last line of LI, DT, or DD michael@0: if (blockTagAtom == nsGkAtoms::li || michael@0: blockTagAtom == nsGkAtoms::dt || michael@0: blockTagAtom == nsGkAtoms::dd) { michael@0: applyMinLH = true; michael@0: } michael@0: } michael@0: } michael@0: if (applyMinLH) { michael@0: if (psd->mHasNonemptyContent || preMode || mHasBullet) { michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [span]==> adjusting min/maxBCoord: currentValues: %d,%d", minBCoord, maxBCoord); michael@0: #endif michael@0: nscoord minimumLineBSize = mMinLineBSize; michael@0: nscoord blockStart = michael@0: -nsLayoutUtils::GetCenteredFontBaseline(fm, minimumLineBSize); michael@0: nscoord blockEnd = blockStart + minimumLineBSize; michael@0: michael@0: if (blockStart < minBCoord) minBCoord = blockStart; michael@0: if (blockEnd > maxBCoord) maxBCoord = blockEnd; michael@0: michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" new values: %d,%d\n", minBCoord, maxBCoord); michael@0: #endif michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" Used mMinLineBSize: %d, blockStart: %d, blockEnd: %d\n", mMinLineBSize, blockStart, blockEnd); michael@0: #endif michael@0: } michael@0: else { michael@0: // XXX issues: michael@0: // [1] BR's on empty lines stop working michael@0: // [2] May not honor css2's notion of handling empty elements michael@0: // [3] blank lines in a pre-section ("\n") (handled with preMode) michael@0: michael@0: // XXX Are there other problems with this? michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [span]==> zapping min/maxBCoord: currentValues: %d,%d newValues: 0,0\n", michael@0: minBCoord, maxBCoord); michael@0: #endif michael@0: minBCoord = maxBCoord = 0; michael@0: } michael@0: } michael@0: } michael@0: michael@0: if ((minBCoord == BLOCKDIR_ALIGN_FRAMES_NO_MINIMUM) || michael@0: (maxBCoord == BLOCKDIR_ALIGN_FRAMES_NO_MAXIMUM)) { michael@0: minBCoord = maxBCoord = baselineBCoord; michael@0: } michael@0: michael@0: if ((psd != mRootSpan) && (psd->mZeroEffectiveSpanBox)) { michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [span]adjusting for zeroEffectiveSpanBox\n"); michael@0: printf(" Original: minBCoord=%d, maxBCoord=%d, bSize=%d, ascent=%d, logicalBSize=%d, topLeading=%d, bottomLeading=%d\n", michael@0: minBCoord, maxBCoord, spanFramePFD->mBounds.BSize(frameWM), michael@0: spanFramePFD->mAscent, michael@0: psd->mLogicalBSize, psd->mBStartLeading, psd->mBEndLeading); michael@0: #endif michael@0: nscoord goodMinBCoord = spanFramePFD->mBorderPadding.BStart(frameWM) - michael@0: psd->mBStartLeading; michael@0: nscoord goodMaxBCoord = goodMinBCoord + psd->mLogicalBSize; michael@0: michael@0: // For cases like the one in bug 714519 (text-decoration placement michael@0: // or making nsLineLayout::IsZeroBSize() handle michael@0: // vertical-align:top/bottom on a descendant of the line that's not michael@0: // a child of it), we want to treat elements that are michael@0: // vertical-align: top or bottom somewhat like children for the michael@0: // purposes of this quirk. To some extent, this is guessing, since michael@0: // they might end up being aligned anywhere. However, we'll guess michael@0: // that they'll be placed aligned with the top or bottom of this michael@0: // frame (as though this frame is the only thing in the line). michael@0: // (Guessing isn't crazy, since all we're doing is reducing the michael@0: // scope of a quirk and making the behavior more standards-like.) michael@0: if (maxStartBoxBSize > maxBCoord - minBCoord) { michael@0: // Distribute maxStartBoxBSize to ascent (baselineBCoord - minBCoord), and michael@0: // then to descent (maxBCoord - baselineBCoord) by adjusting minBCoord or michael@0: // maxBCoord, but not to exceed goodMinBCoord and goodMaxBCoord. michael@0: nscoord distribute = maxStartBoxBSize - (maxBCoord - minBCoord); michael@0: nscoord ascentSpace = std::max(minBCoord - goodMinBCoord, 0); michael@0: if (distribute > ascentSpace) { michael@0: distribute -= ascentSpace; michael@0: minBCoord -= ascentSpace; michael@0: nscoord descentSpace = std::max(goodMaxBCoord - maxBCoord, 0); michael@0: if (distribute > descentSpace) { michael@0: maxBCoord += descentSpace; michael@0: } else { michael@0: maxBCoord += distribute; michael@0: } michael@0: } else { michael@0: minBCoord -= distribute; michael@0: } michael@0: } michael@0: if (maxEndBoxBSize > maxBCoord - minBCoord) { michael@0: // Likewise, but preferring descent to ascent. michael@0: nscoord distribute = maxEndBoxBSize - (maxBCoord - minBCoord); michael@0: nscoord descentSpace = std::max(goodMaxBCoord - maxBCoord, 0); michael@0: if (distribute > descentSpace) { michael@0: distribute -= descentSpace; michael@0: maxBCoord += descentSpace; michael@0: nscoord ascentSpace = std::max(minBCoord - goodMinBCoord, 0); michael@0: if (distribute > ascentSpace) { michael@0: minBCoord -= ascentSpace; michael@0: } else { michael@0: minBCoord -= distribute; michael@0: } michael@0: } else { michael@0: maxBCoord += distribute; michael@0: } michael@0: } michael@0: michael@0: if (minBCoord > goodMinBCoord) { michael@0: nscoord adjust = minBCoord - goodMinBCoord; // positive michael@0: michael@0: // shrink the logical extents michael@0: psd->mLogicalBSize -= adjust; michael@0: psd->mBStartLeading -= adjust; michael@0: } michael@0: if (maxBCoord < goodMaxBCoord) { michael@0: nscoord adjust = goodMaxBCoord - maxBCoord; michael@0: psd->mLogicalBSize -= adjust; michael@0: psd->mBEndLeading -= adjust; michael@0: } michael@0: if (minBCoord > 0) { michael@0: michael@0: // shrink the content by moving its block start down. This is tricky, michael@0: // since the block start is the 0 for many coordinates, so what we do is michael@0: // move everything else up. michael@0: spanFramePFD->mAscent -= minBCoord; // move the baseline up michael@0: spanFramePFD->mBounds.BSize(lineWM) -= minBCoord; // move the block end up michael@0: psd->mBStartLeading += minBCoord; michael@0: *psd->mBaseline -= minBCoord; michael@0: michael@0: pfd = psd->mFirstFrame; michael@0: while (nullptr != pfd) { michael@0: pfd->mBounds.BStart(lineWM) -= minBCoord; // move all the children michael@0: // back up michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: pfd = pfd->mNext; michael@0: } michael@0: maxBCoord -= minBCoord; // since minBCoord is in the frame's own michael@0: // coordinate system michael@0: minBCoord = 0; michael@0: } michael@0: if (maxBCoord < spanFramePFD->mBounds.BSize(lineWM)) { michael@0: nscoord adjust = spanFramePFD->mBounds.BSize(lineWM) - maxBCoord; michael@0: spanFramePFD->mBounds.BSize(lineWM) -= adjust; // move the bottom up michael@0: psd->mBEndLeading += adjust; michael@0: } michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" New: minBCoord=%d, maxBCoord=%d, bSize=%d, ascent=%d, logicalBSize=%d, topLeading=%d, bottomLeading=%d\n", michael@0: minBCoord, maxBCoord, spanFramePFD->mBounds.BSize(lineWM), michael@0: spanFramePFD->mAscent, michael@0: psd->mLogicalBSize, psd->mBStartLeading, psd->mBEndLeading); michael@0: #endif michael@0: } michael@0: michael@0: psd->mMinBCoord = minBCoord; michael@0: psd->mMaxBCoord = maxBCoord; michael@0: #ifdef NOISY_BLOCKDIR_ALIGN michael@0: printf(" [span]==> minBCoord=%d maxBCoord=%d delta=%d maxStartBoxBSize=%d maxEndBoxBSize=%d\n", michael@0: minBCoord, maxBCoord, maxBCoord - minBCoord, maxStartBoxBSize, maxEndBoxBSize); michael@0: #endif michael@0: if (maxStartBoxBSize > mMaxStartBoxBSize) { michael@0: mMaxStartBoxBSize = maxStartBoxBSize; michael@0: } michael@0: if (maxEndBoxBSize > mMaxEndBoxBSize) { michael@0: mMaxEndBoxBSize = maxEndBoxBSize; michael@0: } michael@0: } michael@0: michael@0: static void SlideSpanFrameRect(nsIFrame* aFrame, nscoord aDeltaWidth) michael@0: { michael@0: // This should not use nsIFrame::MovePositionBy because it happens michael@0: // prior to relative positioning. In particular, because michael@0: // nsBlockFrame::PlaceLine calls aLineLayout.TrimTrailingWhiteSpace() michael@0: // prior to calling aLineLayout.RelativePositionFrames(). michael@0: nsPoint p = aFrame->GetPosition(); michael@0: p.x -= aDeltaWidth; michael@0: aFrame->SetPosition(p); michael@0: } michael@0: michael@0: bool michael@0: nsLineLayout::TrimTrailingWhiteSpaceIn(PerSpanData* psd, michael@0: nscoord* aDeltaISize) michael@0: { michael@0: PerFrameData* pfd = psd->mFirstFrame; michael@0: if (!pfd) { michael@0: *aDeltaISize = 0; michael@0: return false; michael@0: } michael@0: pfd = pfd->Last(); michael@0: while (nullptr != pfd) { michael@0: #ifdef REALLY_NOISY_TRIM michael@0: nsFrame::ListTag(stdout, (psd == mRootSpan michael@0: ? mBlockReflowState->frame michael@0: : psd->mFrame->mFrame)); michael@0: printf(": attempting trim of "); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: printf("\n"); michael@0: #endif michael@0: PerSpanData* childSpan = pfd->mSpan; michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: if (childSpan) { michael@0: // Maybe the child span has the trailing white-space in it? michael@0: if (TrimTrailingWhiteSpaceIn(childSpan, aDeltaISize)) { michael@0: nscoord deltaISize = *aDeltaISize; michael@0: if (deltaISize) { michael@0: // Adjust the child spans frame size michael@0: pfd->mBounds.ISize(lineWM) -= deltaISize; michael@0: if (psd != mRootSpan) { michael@0: // When the child span is not a direct child of the block michael@0: // we need to update the child spans frame rectangle michael@0: // because it most likely will not be done again. Spans michael@0: // that are direct children of the block will be updated michael@0: // later, however, because the BlockDirAlignFrames method michael@0: // will be run after this method. michael@0: nsIFrame* f = pfd->mFrame; michael@0: LogicalRect r(lineWM, f->GetRect(), mContainerWidth); michael@0: r.ISize(lineWM) -= deltaISize; michael@0: f->SetRect(lineWM, r, mContainerWidth); michael@0: } michael@0: michael@0: // Adjust the inline end edge of the span that contains the child span michael@0: psd->mICoord -= deltaISize; michael@0: michael@0: // Slide any frames that follow the child span over by the michael@0: // correct amount. The only thing that can follow the child michael@0: // span is empty stuff, so we are just making things michael@0: // sensible (keeping the combined area honest). michael@0: while (pfd->mNext) { michael@0: pfd = pfd->mNext; michael@0: pfd->mBounds.IStart(lineWM) -= deltaISize; michael@0: if (psd != mRootSpan) { michael@0: // When the child span is not a direct child of the block michael@0: // we need to update the child span's frame rectangle michael@0: // because it most likely will not be done again. Spans michael@0: // that are direct children of the block will be updated michael@0: // later, however, because the BlockDirAlignFrames method michael@0: // will be run after this method. michael@0: SlideSpanFrameRect(pfd->mFrame, deltaISize); michael@0: } michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: } michael@0: else if (!pfd->GetFlag(PFD_ISTEXTFRAME) && michael@0: !pfd->GetFlag(PFD_SKIPWHENTRIMMINGWHITESPACE)) { michael@0: // If we hit a frame on the end that's not text and not a placeholder, michael@0: // then there is no trailing whitespace to trim. Stop the search. michael@0: *aDeltaISize = 0; michael@0: return true; michael@0: } michael@0: else if (pfd->GetFlag(PFD_ISTEXTFRAME)) { michael@0: // Call TrimTrailingWhiteSpace even on empty textframes because they michael@0: // might have a soft hyphen which should now appear, changing the frame's michael@0: // width michael@0: nsTextFrame::TrimOutput trimOutput = static_cast(pfd->mFrame)-> michael@0: TrimTrailingWhiteSpace(mBlockReflowState->rendContext); michael@0: #ifdef NOISY_TRIM michael@0: nsFrame::ListTag(stdout, (psd == mRootSpan michael@0: ? mBlockReflowState->frame michael@0: : psd->mFrame->mFrame)); michael@0: printf(": trim of "); michael@0: nsFrame::ListTag(stdout, pfd->mFrame); michael@0: printf(" returned %d\n", trimOutput.mDeltaWidth); michael@0: #endif michael@0: if (trimOutput.mLastCharIsJustifiable && pfd->mJustificationNumSpaces > 0) { michael@0: pfd->mJustificationNumSpaces--; michael@0: } michael@0: michael@0: if (trimOutput.mChanged) { michael@0: pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, true); michael@0: } michael@0: michael@0: if (trimOutput.mDeltaWidth) { michael@0: pfd->mBounds.ISize(lineWM) -= trimOutput.mDeltaWidth; michael@0: michael@0: // See if the text frame has already been placed in its parent michael@0: if (psd != mRootSpan) { michael@0: // The frame was already placed during psd's michael@0: // reflow. Update the frames rectangle now. michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: } michael@0: michael@0: // Adjust containing span's right edge michael@0: psd->mICoord -= trimOutput.mDeltaWidth; michael@0: michael@0: // Slide any frames that follow the text frame over by the michael@0: // right amount. The only thing that can follow the text michael@0: // frame is empty stuff, so we are just making things michael@0: // sensible (keeping the combined area honest). michael@0: while (pfd->mNext) { michael@0: pfd = pfd->mNext; michael@0: pfd->mBounds.IStart(lineWM) -= trimOutput.mDeltaWidth; michael@0: if (psd != mRootSpan) { michael@0: // When the child span is not a direct child of the block michael@0: // we need to update the child spans frame rectangle michael@0: // because it most likely will not be done again. Spans michael@0: // that are direct children of the block will be updated michael@0: // later, however, because the BlockDirAlignFrames method michael@0: // will be run after this method. michael@0: SlideSpanFrameRect(pfd->mFrame, trimOutput.mDeltaWidth); michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (pfd->GetFlag(PFD_ISNONEMPTYTEXTFRAME) || trimOutput.mChanged) { michael@0: // Pass up to caller so they can shrink their span michael@0: *aDeltaISize = trimOutput.mDeltaWidth; michael@0: return true; michael@0: } michael@0: } michael@0: pfd = pfd->mPrev; michael@0: } michael@0: michael@0: *aDeltaISize = 0; michael@0: return false; michael@0: } michael@0: michael@0: bool michael@0: nsLineLayout::TrimTrailingWhiteSpace() michael@0: { michael@0: PerSpanData* psd = mRootSpan; michael@0: nscoord deltaISize; michael@0: TrimTrailingWhiteSpaceIn(psd, &deltaISize); michael@0: return 0 != deltaISize; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::ComputeJustificationWeights(PerSpanData* aPSD, michael@0: int32_t* aNumSpaces, michael@0: int32_t* aNumLetters) michael@0: { michael@0: NS_ASSERTION(aPSD, "null arg"); michael@0: NS_ASSERTION(aNumSpaces, "null arg"); michael@0: NS_ASSERTION(aNumLetters, "null arg"); michael@0: int32_t numSpaces = 0; michael@0: int32_t numLetters = 0; michael@0: michael@0: for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nullptr; pfd = pfd->mNext) { michael@0: michael@0: if (true == pfd->GetFlag(PFD_ISTEXTFRAME)) { michael@0: numSpaces += pfd->mJustificationNumSpaces; michael@0: numLetters += pfd->mJustificationNumLetters; michael@0: } michael@0: else if (pfd->mSpan != nullptr) { michael@0: int32_t spanSpaces; michael@0: int32_t spanLetters; michael@0: michael@0: ComputeJustificationWeights(pfd->mSpan, &spanSpaces, &spanLetters); michael@0: michael@0: numSpaces += spanSpaces; michael@0: numLetters += spanLetters; michael@0: } michael@0: } michael@0: michael@0: *aNumSpaces = numSpaces; michael@0: *aNumLetters = numLetters; michael@0: } michael@0: michael@0: nscoord michael@0: nsLineLayout::ApplyFrameJustification(PerSpanData* aPSD, FrameJustificationState* aState) michael@0: { michael@0: NS_ASSERTION(aPSD, "null arg"); michael@0: NS_ASSERTION(aState, "null arg"); michael@0: michael@0: nscoord deltaICoord = 0; michael@0: for (PerFrameData* pfd = aPSD->mFirstFrame; pfd != nullptr; pfd = pfd->mNext) { michael@0: // Don't reposition bullets (and other frames that occur out of X-order?) michael@0: if (!pfd->GetFlag(PFD_ISBULLET)) { michael@0: nscoord dw = 0; michael@0: WritingMode lineWM = mRootSpan->mWritingMode; michael@0: michael@0: pfd->mBounds.IStart(lineWM) += deltaICoord; michael@0: michael@0: if (true == pfd->GetFlag(PFD_ISTEXTFRAME)) { michael@0: if (aState->mTotalWidthForSpaces > 0 && michael@0: aState->mTotalNumSpaces > 0) { michael@0: aState->mNumSpacesProcessed += pfd->mJustificationNumSpaces; michael@0: michael@0: nscoord newAllocatedWidthForSpaces = michael@0: (aState->mTotalWidthForSpaces*aState->mNumSpacesProcessed) michael@0: /aState->mTotalNumSpaces; michael@0: michael@0: dw += newAllocatedWidthForSpaces - aState->mWidthForSpacesProcessed; michael@0: michael@0: aState->mWidthForSpacesProcessed = newAllocatedWidthForSpaces; michael@0: } michael@0: michael@0: if (aState->mTotalWidthForLetters > 0 && michael@0: aState->mTotalNumLetters > 0) { michael@0: aState->mNumLettersProcessed += pfd->mJustificationNumLetters; michael@0: michael@0: nscoord newAllocatedWidthForLetters = michael@0: (aState->mTotalWidthForLetters*aState->mNumLettersProcessed) michael@0: /aState->mTotalNumLetters; michael@0: michael@0: dw += newAllocatedWidthForLetters - aState->mWidthForLettersProcessed; michael@0: michael@0: aState->mWidthForLettersProcessed = newAllocatedWidthForLetters; michael@0: } michael@0: michael@0: if (dw) { michael@0: pfd->SetFlag(PFD_RECOMPUTEOVERFLOW, true); michael@0: } michael@0: } michael@0: else { michael@0: if (nullptr != pfd->mSpan) { michael@0: dw += ApplyFrameJustification(pfd->mSpan, aState); michael@0: } michael@0: } michael@0: michael@0: pfd->mBounds.ISize(lineWM) += dw; michael@0: michael@0: deltaICoord += dw; michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: } michael@0: } michael@0: return deltaICoord; michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::InlineDirAlignFrames(nsLineBox* aLine, michael@0: bool aIsLastLine) michael@0: { michael@0: /** michael@0: * NOTE: aIsLastLine ain't necessarily so: it is correctly set by caller michael@0: * only in cases where the last line needs special handling. michael@0: */ michael@0: PerSpanData* psd = mRootSpan; michael@0: WritingMode lineWM = psd->mWritingMode; michael@0: NS_WARN_IF_FALSE(psd->mIEnd != NS_UNCONSTRAINEDSIZE, michael@0: "have unconstrained width; this should only result from " michael@0: "very large sizes, not attempts at intrinsic width " michael@0: "calculation"); michael@0: nscoord availISize = psd->mIEnd - psd->mIStart; michael@0: nscoord remainingISize = availISize - aLine->ISize(); michael@0: #ifdef NOISY_INLINEDIR_ALIGN michael@0: nsFrame::ListTag(stdout, mBlockReflowState->frame); michael@0: printf(": availISize=%d lineBounds.IStart=%d lineISize=%d delta=%d\n", michael@0: availISize, aLine->IStart(), aLine->ISize(), remainingISize); michael@0: #endif michael@0: michael@0: // 'text-align-last: auto' is equivalent to the value of the 'text-align' michael@0: // property except when 'text-align' is set to 'justify', in which case it michael@0: // is 'justify' when 'text-justify' is 'distribute' and 'start' otherwise. michael@0: // michael@0: // XXX: the code below will have to change when we implement text-justify michael@0: // michael@0: nscoord dx = 0; michael@0: uint8_t textAlign = mStyleText->mTextAlign; michael@0: bool textAlignTrue = mStyleText->mTextAlignTrue; michael@0: if (aIsLastLine) { michael@0: textAlignTrue = mStyleText->mTextAlignLastTrue; michael@0: if (mStyleText->mTextAlignLast == NS_STYLE_TEXT_ALIGN_AUTO) { michael@0: if (textAlign == NS_STYLE_TEXT_ALIGN_JUSTIFY) { michael@0: textAlign = NS_STYLE_TEXT_ALIGN_DEFAULT; michael@0: } michael@0: } else { michael@0: textAlign = mStyleText->mTextAlignLast; michael@0: } michael@0: } michael@0: michael@0: if ((remainingISize > 0 || textAlignTrue) && michael@0: !(mBlockReflowState->frame->IsSVGText())) { michael@0: michael@0: switch (textAlign) { michael@0: case NS_STYLE_TEXT_ALIGN_JUSTIFY: michael@0: int32_t numSpaces; michael@0: int32_t numLetters; michael@0: michael@0: ComputeJustificationWeights(psd, &numSpaces, &numLetters); michael@0: michael@0: if (numSpaces > 0) { michael@0: FrameJustificationState state = michael@0: { numSpaces, numLetters, remainingISize, 0, 0, 0, 0, 0 }; michael@0: michael@0: // Apply the justification, and make sure to update our linebox michael@0: // width to account for it. michael@0: aLine->ExpandBy(ApplyFrameJustification(psd, &state), michael@0: mContainerWidth); michael@0: remainingISize = availISize - aLine->ISize(); michael@0: break; michael@0: } michael@0: // Fall through to the default case if we could not justify to fill michael@0: // the space. michael@0: michael@0: case NS_STYLE_TEXT_ALIGN_DEFAULT: michael@0: // default alignment is to start edge so do nothing michael@0: break; michael@0: michael@0: case NS_STYLE_TEXT_ALIGN_LEFT: michael@0: case NS_STYLE_TEXT_ALIGN_MOZ_LEFT: michael@0: if (!lineWM.IsBidiLTR()) { michael@0: dx = remainingISize; michael@0: } michael@0: break; michael@0: michael@0: case NS_STYLE_TEXT_ALIGN_RIGHT: michael@0: case NS_STYLE_TEXT_ALIGN_MOZ_RIGHT: michael@0: if (lineWM.IsBidiLTR()) { michael@0: dx = remainingISize; michael@0: } michael@0: break; michael@0: michael@0: case NS_STYLE_TEXT_ALIGN_END: michael@0: dx = remainingISize; michael@0: break; michael@0: michael@0: michael@0: case NS_STYLE_TEXT_ALIGN_CENTER: michael@0: case NS_STYLE_TEXT_ALIGN_MOZ_CENTER: michael@0: dx = remainingISize / 2; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: if (dx) { michael@0: for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: pfd->mBounds.IStart(lineWM) += dx; michael@0: pfd->mFrame->SetRect(lineWM, pfd->mBounds, mContainerWidth); michael@0: } michael@0: aLine->IndentBy(dx, mContainerWidth); michael@0: } michael@0: michael@0: if (mPresContext->BidiEnabled() && michael@0: (!mPresContext->IsVisualMode() || !lineWM.IsBidiLTR())) { michael@0: nsBidiPresUtils::ReorderFrames(psd->mFirstFrame->mFrame, michael@0: aLine->GetChildCount(), michael@0: lineWM, mContainerWidth); michael@0: } michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::RelativePositionFrames(nsOverflowAreas& aOverflowAreas) michael@0: { michael@0: RelativePositionFrames(mRootSpan, aOverflowAreas); michael@0: } michael@0: michael@0: void michael@0: nsLineLayout::RelativePositionFrames(PerSpanData* psd, nsOverflowAreas& aOverflowAreas) michael@0: { michael@0: nsOverflowAreas overflowAreas; michael@0: WritingMode wm = psd->mWritingMode; michael@0: if (nullptr != psd->mFrame) { michael@0: // The span's overflow areas come in three parts: michael@0: // -- this frame's width and height michael@0: // -- pfd->mOverflowAreas, which is the area of a bullet or the union michael@0: // of a relatively positioned frame's absolute children michael@0: // -- the bounds of all inline descendants michael@0: // The former two parts are computed right here, we gather the descendants michael@0: // below. michael@0: // At this point psd->mFrame->mBounds might be out of date since michael@0: // bidi reordering can move and resize the frames. So use the frame's michael@0: // rect instead of mBounds. michael@0: nsRect adjustedBounds(nsPoint(0, 0), psd->mFrame->mFrame->GetSize()); michael@0: michael@0: overflowAreas.ScrollableOverflow().UnionRect( michael@0: psd->mFrame->mOverflowAreas.ScrollableOverflow(), adjustedBounds); michael@0: overflowAreas.VisualOverflow().UnionRect( michael@0: psd->mFrame->mOverflowAreas.VisualOverflow(), adjustedBounds); michael@0: } michael@0: else { michael@0: LogicalRect rect(wm, psd->mIStart, mBStartEdge, michael@0: psd->mICoord - psd->mIStart, mFinalLineBSize); michael@0: // The minimum combined area for the frames that are direct michael@0: // children of the block starts at the upper left corner of the michael@0: // line and is sized to match the size of the line's bounding box michael@0: // (the same size as the values returned from BlockDirAlignFrames) michael@0: overflowAreas.VisualOverflow() = rect.GetPhysicalRect(wm, mContainerWidth); michael@0: overflowAreas.ScrollableOverflow() = overflowAreas.VisualOverflow(); michael@0: } michael@0: michael@0: for (PerFrameData* pfd = psd->mFirstFrame; pfd; pfd = pfd->mNext) { michael@0: nsIFrame* frame = pfd->mFrame; michael@0: nsPoint origin = frame->GetPosition(); michael@0: michael@0: // Adjust the origin of the frame michael@0: if (pfd->GetFlag(PFD_RELATIVEPOS)) { michael@0: //XXX temporary until ApplyRelativePositioning can handle logical offsets michael@0: nsMargin physicalOffsets = michael@0: pfd->mOffsets.GetPhysicalMargin(pfd->mFrame->GetWritingMode()); michael@0: // right and bottom are handled by michael@0: // nsHTMLReflowState::ComputeRelativeOffsets michael@0: nsHTMLReflowState::ApplyRelativePositioning(pfd->mFrame, michael@0: physicalOffsets, michael@0: &origin); michael@0: frame->SetPosition(origin); michael@0: } michael@0: michael@0: // We must position the view correctly before positioning its michael@0: // descendants so that widgets are positioned properly (since only michael@0: // some views have widgets). michael@0: if (frame->HasView()) michael@0: nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, frame, michael@0: frame->GetView(), pfd->mOverflowAreas.VisualOverflow(), michael@0: NS_FRAME_NO_SIZE_VIEW); michael@0: michael@0: // Note: the combined area of a child is in its coordinate michael@0: // system. We adjust the childs combined area into our coordinate michael@0: // system before computing the aggregated value by adding in michael@0: // x and y which were computed above. michael@0: nsOverflowAreas r; michael@0: if (pfd->mSpan) { michael@0: // Compute a new combined area for the child span before michael@0: // aggregating it into our combined area. michael@0: RelativePositionFrames(pfd->mSpan, r); michael@0: } else { michael@0: r = pfd->mOverflowAreas; michael@0: if (pfd->GetFlag(PFD_ISTEXTFRAME)) { michael@0: // We need to recompute overflow areas in two cases: michael@0: // (1) When PFD_RECOMPUTEOVERFLOW is set due to trimming michael@0: // (2) When there are text decorations, since we can't recompute the michael@0: // overflow area until Reflow and BlockDirAlignLine have finished michael@0: if (pfd->GetFlag(PFD_RECOMPUTEOVERFLOW) || michael@0: frame->StyleContext()->HasTextDecorationLines()) { michael@0: nsTextFrame* f = static_cast(frame); michael@0: r = f->RecomputeOverflow(*mBlockReflowState); michael@0: } michael@0: frame->FinishAndStoreOverflow(r, frame->GetSize()); michael@0: } michael@0: michael@0: // If we have something that's not an inline but with a complex frame michael@0: // hierarchy inside that contains views, they need to be michael@0: // positioned. michael@0: // All descendant views must be repositioned even if this frame michael@0: // does have a view in case this frame's view does not have a michael@0: // widget and some of the descendant views do have widgets -- michael@0: // otherwise the widgets won't be repositioned. michael@0: nsContainerFrame::PositionChildViews(frame); michael@0: } michael@0: michael@0: // Do this here (rather than along with setting the overflow rect michael@0: // below) so we get leaf frames as well. No need to worry michael@0: // about the root span, since it doesn't have a frame. michael@0: if (frame->HasView()) michael@0: nsContainerFrame::SyncFrameViewAfterReflow(mPresContext, frame, michael@0: frame->GetView(), michael@0: r.VisualOverflow(), michael@0: NS_FRAME_NO_MOVE_VIEW); michael@0: michael@0: overflowAreas.UnionWith(r + origin); michael@0: } michael@0: michael@0: // If we just computed a spans combined area, we need to update its michael@0: // overflow rect... michael@0: if (psd->mFrame) { michael@0: PerFrameData* spanPFD = psd->mFrame; michael@0: nsIFrame* frame = spanPFD->mFrame; michael@0: frame->FinishAndStoreOverflow(overflowAreas, frame->GetSize()); michael@0: } michael@0: aOverflowAreas = overflowAreas; michael@0: }