Use logical text layout API in nsLineLayout. Bug 789096, r=jfkthame

This commit is contained in:
Simon Montagu 2014-03-11 13:23:50 -07:00
parent 2498a9e3b8
commit 677c6954d4
13 changed files with 846 additions and 764 deletions

View File

@ -1228,8 +1228,10 @@ nsBidiPresUtils::ResolveParagraphWithinBlock(nsBlockFrame* aBlockFrame,
}
void
nsBidiPresUtils::ReorderFrames(nsIFrame* aFirstFrameOnLine,
int32_t aNumFramesOnLine)
nsBidiPresUtils::ReorderFrames(nsIFrame* aFirstFrameOnLine,
int32_t aNumFramesOnLine,
WritingMode aLineWM,
nscoord& aLineWidth)
{
// If this line consists of a line frame, reorder the line frame's children.
if (aFirstFrameOnLine->GetType() == nsGkAtoms::lineFrame) {
@ -1242,7 +1244,7 @@ nsBidiPresUtils::ReorderFrames(nsIFrame* aFirstFrameOnLine,
}
BidiLineData bld(aFirstFrameOnLine, aNumFramesOnLine);
RepositionInlineFrames(&bld, aFirstFrameOnLine);
RepositionInlineFrames(&bld, aFirstFrameOnLine, aLineWM, aLineWidth);
}
nsIFrame*
@ -1282,22 +1284,20 @@ nsBidiPresUtils::GetFrameBaseLevel(nsIFrame* aFrame)
}
void
nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
nsContinuationStates* aContinuationStates,
bool& aIsLeftMost /* out */,
bool& aIsRightMost /* out */)
nsBidiPresUtils::IsFirstOrLast(nsIFrame* aFrame,
nsContinuationStates* aContinuationStates,
bool& aIsFirst /* out */,
bool& aIsLast /* out */)
{
const nsStyleVisibility* vis = aFrame->StyleVisibility();
bool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
/*
* Since we lay out frames from left to right (in both LTR and RTL), visiting a
* frame with 'mFirstVisualFrame == nullptr', means it's the first appearance of
* one of its continuation chain frames on the line.
* To determine if it's the last visual frame of its continuation chain on the line
* or not, we count the number of frames of the chain on the line, and then reduce
* it when we lay out a frame of the chain. If this value becomes 1 it means
* that it's the last visual frame of its continuation chain on this line.
* Since we lay out frames in the line's direction, visiting a frame with
* 'mFirstVisualFrame == nullptr', means it's the first appearance of one
* of its continuation chain frames on the line.
* To determine if it's the last visual frame of its continuation chain on
* the line or not, we count the number of frames of the chain on the line,
* and then reduce it when we lay out a frame of the chain. If this value
* becomes 1 it means that it's the last visual frame of its continuation
* chain on this line.
*/
nsFrameContinuationState* frameState = aContinuationStates->GetEntry(aFrame);
@ -1334,20 +1334,18 @@ nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
}
frameState->mHasContOnNextLines = (frame != nullptr);
aIsLeftMost = isLTR ? !frameState->mHasContOnPrevLines
: !frameState->mHasContOnNextLines;
aIsFirst = !frameState->mHasContOnPrevLines;
firstFrameState = frameState;
} else {
// aFrame is not the first visual frame of its continuation chain
aIsLeftMost = false;
aIsFirst = false;
firstFrameState = aContinuationStates->GetEntry(frameState->mFirstVisualFrame);
}
aIsRightMost = (firstFrameState->mFrameCount == 1) &&
(isLTR ? !firstFrameState->mHasContOnNextLines
: !firstFrameState->mHasContOnPrevLines);
aIsLast = (firstFrameState->mFrameCount == 1 &&
!firstFrameState->mHasContOnNextLines);
if ((aIsLeftMost || aIsRightMost) &&
if ((aIsFirst || aIsLast) &&
(aFrame->GetStateBits() & NS_FRAME_PART_OF_IBSPLIT)) {
// For ib splits, don't treat anything except the last part as
// endmost or anything except the first part as startmost.
@ -1355,19 +1353,11 @@ nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
nsIFrame* firstContinuation = aFrame->FirstContinuation();
if (firstContinuation->FrameIsNonLastInIBSplit()) {
// We are not endmost
if (isLTR) {
aIsRightMost = false;
} else {
aIsLeftMost = false;
}
aIsLast = false;
}
if (firstContinuation->FrameIsNonFirstInIBSplit()) {
// We are not startmost
if (isLTR) {
aIsLeftMost = false;
} else {
aIsRightMost = false;
}
aIsFirst = false;
}
}
@ -1376,29 +1366,39 @@ nsBidiPresUtils::IsLeftOrRightMost(nsIFrame* aFrame,
}
void
nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
bool aIsOddLevel,
nscoord& aLeft,
nsContinuationStates* aContinuationStates)
nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
bool aIsEvenLevel,
nscoord& aStart,
nsContinuationStates* aContinuationStates,
WritingMode aLineWM,
nscoord& aLineWidth)
{
if (!aFrame)
return;
bool isLeftMost, isRightMost;
IsLeftOrRightMost(aFrame,
aContinuationStates,
isLeftMost /* out */,
isRightMost /* out */);
bool isFirst, isLast;
IsFirstOrLast(aFrame,
aContinuationStates,
isFirst /* out */,
isLast /* out */);
WritingMode frameWM = aFrame->GetWritingMode();
nsInlineFrame* testFrame = do_QueryFrame(aFrame);
//XXX temporary until GetSkipSides is logicalized
bool isLeftMost = false, isRightMost = false;
if (testFrame) {
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_STATE_IS_SET);
isLeftMost = ((isFirst && frameWM.IsBidiLTR()) ||
(isLast && !frameWM.IsBidiLTR()));
if (isLeftMost)
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
else
aFrame->RemoveStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_LEFT_MOST);
isRightMost = ((isLast && frameWM.IsBidiLTR()) ||
(isFirst && !frameWM.IsBidiLTR()));
if (isRightMost)
aFrame->AddStateBits(NS_INLINE_FRAME_BIDI_VISUAL_IS_RIGHT_MOST);
else
@ -1407,26 +1407,30 @@ nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
// This method is called from nsBlockFrame::PlaceLine via the call to
// bidiUtils->ReorderFrames, so this is guaranteed to be after the inlines
// have been reflowed, which is required for GetUsedMargin/Border/Padding
nsMargin margin = aFrame->GetUsedMargin();
if (isLeftMost)
aLeft += margin.left;
LogicalMargin margin(frameWM, aFrame->GetUsedMargin());
if (isFirst) {
aStart += margin.IStart(frameWM);
}
nscoord start = aLeft;
nscoord start = aStart;
nscoord frameWidth = aFrame->GetSize().width;
if (!IsBidiLeaf(aFrame))
{
nscoord x = 0;
nsMargin borderPadding = aFrame->GetUsedBorderAndPadding();
if (isLeftMost) {
x += borderPadding.left;
nscoord iCoord = 0;
LogicalMargin borderPadding(frameWM, aFrame->GetUsedBorderAndPadding());
if (isFirst) {
iCoord += borderPadding.IStart(frameWM);
}
// If aIsOddLevel is true, so we need to traverse the child list
// in reverse order, to make it O(n) we store the list locally and
// iterate the list reversely
// If the resolved direction of the container is different from the
// direction of the frame, we need to traverse the child list in reverse
// order, to make it O(n) we store the list locally and iterate the list
// in reverse
bool reverseOrder = aIsEvenLevel != frameWM.IsBidiLTR();
nsTArray<nsIFrame*> childList;
nsIFrame *frame = aFrame->GetFirstPrincipalChild();
if (frame && aIsOddLevel) {
if (frame && reverseOrder) {
childList.AppendElement((nsIFrame*)nullptr);
while (frame) {
childList.AppendElement(frame);
@ -1439,27 +1443,33 @@ nsBidiPresUtils::RepositionFrame(nsIFrame* aFrame,
int32_t index = 0;
while (frame) {
RepositionFrame(frame,
aIsOddLevel,
x,
aContinuationStates);
aIsEvenLevel,
iCoord,
aContinuationStates,
frameWM,
frameWidth);
index++;
frame = aIsOddLevel ?
frame = reverseOrder ?
childList[childList.Length() - index - 1] :
frame->GetNextSibling();
}
if (isRightMost) {
x += borderPadding.right;
if (isLast) {
iCoord += borderPadding.IEnd(frameWM);
}
aLeft += x;
aStart += iCoord;
} else {
aLeft += aFrame->GetSize().width;
aStart += frameWidth;
}
nsRect rect = aFrame->GetRect();
aFrame->SetRect(nsRect(start, rect.y, aLeft - start, rect.height));
if (isRightMost)
aLeft += margin.right;
LogicalRect logicalRect(aLineWM, aFrame->GetRect(), aLineWidth);
logicalRect.IStart(aLineWM) = start;
logicalRect.ISize(aLineWM) = aStart - start;
aFrame->SetRect(aLineWM, logicalRect, aLineWidth);
if (isLast) {
aStart += margin.IEnd(frameWM);
}
}
void
@ -1484,21 +1494,23 @@ nsBidiPresUtils::InitContinuationStates(nsIFrame* aFrame,
void
nsBidiPresUtils::RepositionInlineFrames(BidiLineData *aBld,
nsIFrame* aFirstChild)
nsIFrame* aFirstChild,
WritingMode aLineWM,
nscoord& aLineWidth)
{
const nsStyleVisibility* vis = aFirstChild->StyleVisibility();
bool isLTR = (NS_STYLE_DIRECTION_LTR == vis->mDirection);
nscoord leftSpace = 0;
nscoord startSpace = 0;
// This method is called from nsBlockFrame::PlaceLine via the call to
// bidiUtils->ReorderFrames, so this is guaranteed to be after the inlines
// have been reflowed, which is required for GetUsedMargin/Border/Padding
nsMargin margin = aFirstChild->GetUsedMargin();
WritingMode frameWM = aFirstChild->GetWritingMode();
LogicalMargin margin(frameWM, aFirstChild->GetUsedMargin());
if (!aFirstChild->GetPrevContinuation() &&
!aFirstChild->FrameIsNonFirstInIBSplit())
leftSpace = isLTR ? margin.left : margin.right;
startSpace = margin.IStart(frameWM);
nscoord left = aFirstChild->GetPosition().x - leftSpace;
nscoord start = LogicalRect(aLineWM, aFirstChild->GetRect(),
aLineWidth).IStart(aLineWM) - startSpace;
nsIFrame* frame;
int32_t count = aBld->mVisualFrames.Length();
int32_t index;
@ -1511,13 +1523,25 @@ nsBidiPresUtils::RepositionInlineFrames(BidiLineData *aBld,
}
// Reposition frames in visual order
for (index = 0; index < count; index++) {
int32_t step, limit;
if (aLineWM.IsBidiLTR()) {
index = 0;
step = 1;
limit = count;
} else {
index = count - 1;
step = -1;
limit = -1;
}
for (; index != limit; index += step) {
frame = aBld->VisualFrameAt(index);
RepositionFrame(frame,
(aBld->mLevels[aBld->mIndexMap[index]] & 1),
left,
&continuationStates);
} // for
!(aBld->mLevels[aBld->mIndexMap[index]] & 1),
start,
&continuationStates,
aLineWM,
aLineWidth);
}
}
bool

View File

@ -27,6 +27,7 @@ class nsRenderingContext;
class nsBlockInFlowLineIterator;
class nsStyleContext;
template<class T> class nsTHashtable;
namespace mozilla { class WritingMode; }
/**
* A structure representing some continuation state for each frame on the line,
@ -159,7 +160,9 @@ public:
* @lina 05/02/2000
*/
static void ReorderFrames(nsIFrame* aFirstFrameOnLine,
int32_t aNumFramesOnLine);
int32_t aNumFramesOnLine,
mozilla::WritingMode aLineWM,
nscoord& aLineWidth);
/**
* Format Unicode text, taking into account bidi capabilities
@ -377,24 +380,27 @@ private:
nsBlockInFlowLineIterator* aLineIter,
nsIFrame* aCurrentFrame,
BidiParagraphData* aBpd);
/*
* Position aFrame and it's descendants to their visual places. Also if aFrame
* is not leaf, resize it to embrace it's children.
* Position aFrame and its descendants to their visual places. Also if aFrame
* is not leaf, resize it to embrace its children.
*
* @param aFrame The frame which itself and its children are going
* to be repositioned
* @param aIsOddLevel TRUE means the embedding level of this frame is odd
* @param[in,out] aLeft IN value is the starting position of aFrame(without
* considering its left margin)
* OUT value will be the ending position of aFrame(after
* adding its right margin)
* @param aFrame The frame which itself and its children are
* going to be repositioned
* @param aIsEvenLevel TRUE means the embedding level of this frame
* is even (LTR)
* @param[in,out] aStart IN value is the starting position of aFrame
* (without considering its inline-start margin)
* OUT value will be the ending position of aFrame
* (after adding its inline-end margin)
* @param aContinuationStates A map from nsIFrame* to nsFrameContinuationState
*/
static void RepositionFrame(nsIFrame* aFrame,
bool aIsOddLevel,
nscoord& aLeft,
nsContinuationStates* aContinuationStates);
bool aIsEvenLevel,
nscoord& aStart,
nsContinuationStates* aContinuationStates,
mozilla::WritingMode aLineWM,
nscoord& aLineWidth);
/*
* Initialize the continuation state(nsFrameContinuationState) to
@ -422,10 +428,10 @@ private:
* @param[out] aIsLeftMost TRUE means aFrame is leftmost frame or continuation
* @param[out] aIsRightMost TRUE means aFrame is rightmost frame or continuation
*/
static void IsLeftOrRightMost(nsIFrame* aFrame,
nsContinuationStates* aContinuationStates,
bool& aIsLeftMost /* out */,
bool& aIsRightMost /* out */);
static void IsFirstOrLast(nsIFrame* aFrame,
nsContinuationStates* aContinuationStates,
bool& aIsFirst /* out */,
bool& aIsLast /* out */);
/**
* Adjust frame positions following their visual order
@ -435,7 +441,9 @@ private:
* @lina 04/11/2000
*/
static void RepositionInlineFrames(BidiLineData* aBld,
nsIFrame* aFirstChild);
nsIFrame* aFirstChild,
mozilla::WritingMode aLineWM,
nscoord& aLineWidth);
/**
* Helper method for Resolve()

View File

@ -833,6 +833,12 @@ public:
*this : LogicalMargin(aToMode, GetPhysicalMargin(aFromMode));
}
bool IsEmpty() const
{
return (mMargin.left == 0 && mMargin.top == 0 &&
mMargin.right == 0 && mMargin.bottom == 0);
}
private:
friend class LogicalRect;
@ -1123,6 +1129,17 @@ public:
return aWritingMode.IsVertical() ? mRect.XMost() : mRect.YMost();
}
bool IsEmpty() const
{
return (mRect.x == 0 && mRect.y == 0 &&
mRect.width == 0 && mRect.height == 0);
}
bool IsZeroSize() const
{
return (mRect.width == 0 && mRect.height == 0);
}
/* XXX are these correct?
nscoord ILeft(WritingMode aWritingMode) const
{

View File

@ -1450,7 +1450,7 @@ nsBlockFrame::ComputeFinalSize(const nsHTMLReflowState& aReflowState,
*aBottomEdgeOfChildren = bottomEdgeOfChildren;
#ifdef DEBUG_blocks
if (CRAZY_WIDTH(aMetrics.Width()) || CRAZY_HEIGHT(aMetrics.Height())) {
if (CRAZY_SIZE(aMetrics.Width()) || CRAZY_SIZE(aMetrics.Height())) {
ListTag(stdout);
printf(": WARNING: desired:%d,%d\n", aMetrics.Width(), aMetrics.Height());
}
@ -3448,35 +3448,32 @@ nsBlockFrame::DoReflowInlineFrames(nsBlockReflowState& aState,
this, aFloatAvailableSpace.mHasFloats);
#endif
nscoord x = aFloatAvailableSpace.mRect.x;
nscoord availWidth = aFloatAvailableSpace.mRect.width;
nscoord availHeight;
WritingMode wm = GetWritingMode(aLine->mFirstChild);
nscoord lineWidth = aFloatAvailableSpace.mRect.width +
aState.BorderPadding().LeftRight();
LogicalRect lineRect(wm, aFloatAvailableSpace.mRect, lineWidth);
nscoord iStart = lineRect.IStart(wm);
nscoord availISize = lineRect.ISize(wm);
nscoord availBSize;
if (aState.GetFlag(BRS_UNCONSTRAINEDHEIGHT)) {
availHeight = NS_UNCONSTRAINEDSIZE;
availBSize = NS_UNCONSTRAINEDSIZE;
}
else {
/* XXX get the height right! */
availHeight = aFloatAvailableSpace.mRect.height;
availBSize = lineRect.BSize(wm);
}
// Make sure to enable resize optimization before we call BeginLineReflow
// because it might get disabled there
aLine->EnableResizeReflowOptimization();
// For unicode-bidi: plaintext, we need to get the direction of the line from
// the resolved paragraph level of the first frame on the line, not the block
// frame, because the block frame could be split by hard line breaks into
// multiple paragraphs with different base direction
uint8_t direction =
(StyleTextReset()->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_PLAINTEXT) ?
nsBidiPresUtils::GetFrameBaseLevel(aLine->mFirstChild) & 1 :
StyleVisibility()->mDirection;
aLineLayout.BeginLineReflow(x, aState.mY,
availWidth, availHeight,
aLineLayout.BeginLineReflow(iStart, aState.mY,
availISize, availBSize,
aFloatAvailableSpace.mHasFloats,
false, /*XXX isTopOfPage*/
direction);
wm, lineWidth);
aState.SetFlag(BRS_LINE_LAYOUT_EMPTY, false);
@ -4052,7 +4049,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState,
bool addedBullet = false;
if (HasOutsideBullet() &&
((aLine == mLines.front() &&
(!aLineLayout.IsZeroHeight() || (aLine == mLines.back()))) ||
(!aLineLayout.IsZeroBSize() || (aLine == mLines.back()))) ||
(mLines.front() != mLines.back() &&
0 == mLines.front()->mBounds.height &&
aLine == mLines.begin().next()))) {
@ -4064,7 +4061,7 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState,
aLineLayout.AddBulletFrame(bullet, metrics);
addedBullet = true;
}
aLineLayout.VerticalAlignLine();
aLineLayout.BlockDirAlignLine();
// We want to compare to the available space that we would have had in
// the line's height *before* we placed any floats in the line itself.
@ -4092,9 +4089,9 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState,
#ifdef DEBUG
{
static nscoord lastHeight = 0;
if (CRAZY_HEIGHT(aLine->mBounds.y)) {
if (CRAZY_SIZE(aLine->mBounds.y)) {
lastHeight = aLine->mBounds.y;
if (abs(aLine->mBounds.y - lastHeight) > CRAZY_H/10) {
if (abs(aLine->mBounds.y - lastHeight) > CRAZY_COORD/10) {
nsFrame::ListTag(stdout);
printf(": line=%p y=%d line.bounds.height=%d\n",
static_cast<void*>(aLine.get()),
@ -4125,20 +4122,9 @@ nsBlockFrame::PlaceLine(nsBlockReflowState& aState,
NS_STYLE_TEXT_ALIGN_JUSTIFY == styleText->mTextAlign) &&
(aLineLayout.GetLineEndsInBR() ||
IsLastLine(aState, aLine)));
aLineLayout.HorizontalAlignFrames(aLine->mBounds, isLastLine);
// XXX: not only bidi: right alignment can be broken after
// RelativePositionFrames!!!
// XXXldb Is something here considering relatively positioned frames at
// other than their original positions?
#ifdef IBMBIDI
// XXXldb Why don't we do this earlier?
if (aState.mPresContext->BidiEnabled()) {
if (!aState.mPresContext->IsVisualMode() ||
StyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL) {
nsBidiPresUtils::ReorderFrames(aLine->mFirstChild, aLine->GetChildCount());
} // not visual mode
} // bidi enabled
#endif // IBMBIDI
aLineLayout.InlineDirAlignFrames(aLine->mBounds, isLastLine,
aLine->GetChildCount());
// From here on, pfd->mBounds rectangles are incorrect because bidi
// might have moved frames around!

View File

@ -262,7 +262,7 @@ nsBlockReflowContext::ReflowBlock(const nsRect& aSpace,
#ifdef DEBUG
if (!NS_INLINE_IS_BREAK_BEFORE(aFrameReflowStatus)) {
if (CRAZY_WIDTH(mMetrics.Width()) || CRAZY_HEIGHT(mMetrics.Height())) {
if (CRAZY_SIZE(mMetrics.Width()) || CRAZY_SIZE(mMetrics.Height())) {
printf("nsBlockReflowContext: ");
nsFrame::ListTag(stdout, mFrame);
printf(" metrics=%d,%d!\n", mMetrics.Width(), mMetrics.Height());

View File

@ -34,11 +34,8 @@ class FramePropertyTable;
// dependency on nsDeviceContext.h. It doesn't matter if it's a
// little off.
#ifdef DEBUG
#define CRAZY_W (1000000*60)
#define CRAZY_H CRAZY_W
#define CRAZY_WIDTH(_x) (((_x) < -CRAZY_W) || ((_x) > CRAZY_W))
#define CRAZY_HEIGHT(_y) (((_y) < -CRAZY_H) || ((_y) > CRAZY_H))
#define CRAZY_COORD (1000000*60)
#define CRAZY_SIZE(_x) (((_x) < -CRAZY_COORD) || ((_x) > CRAZY_COORD))
#endif
/**

View File

@ -188,21 +188,10 @@ nsFirstLetterFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowState rs(aPresContext, aReflowState, kid, availSize);
nsLineLayout ll(aPresContext, nullptr, &aReflowState, nullptr);
// For unicode-bidi: plaintext, we need to get the direction of the line
// from the resolved paragraph level of the child, not the block frame,
// because the block frame could be split by hard line breaks into
// multiple paragraphs with different base direction
uint8_t direction;
nsIFrame* containerFrame = ll.LineContainerFrame();
if (containerFrame->StyleTextReset()->mUnicodeBidi &
NS_STYLE_UNICODE_BIDI_PLAINTEXT) {
FramePropertyTable *propTable = aPresContext->PropertyTable();
direction = NS_PTR_TO_INT32(propTable->Get(kid, BaseLevelProperty())) & 1;
} else {
direction = containerFrame->StyleVisibility()->mDirection;
}
ll.BeginLineReflow(bp.left, bp.top, availSize.width, NS_UNCONSTRAINEDSIZE,
false, true, direction);
false, true,
ll.LineContainerFrame()->GetWritingMode(kid),
aReflowState.AvailableWidth());
rs.mLineLayout = &ll;
ll.SetInFirstLetter(true);
ll.SetFirstLetterStyleOK(true);

View File

@ -975,6 +975,20 @@ nsIFrame::GetPaddingRect() const
return GetPaddingRectRelativeToSelf() + GetPosition();
}
WritingMode
nsIFrame::GetWritingMode(nsIFrame* aSubFrame) const
{
WritingMode writingMode = GetWritingMode();
if (!writingMode.IsVertical() &&
(StyleTextReset()->mUnicodeBidi & NS_STYLE_UNICODE_BIDI_PLAINTEXT)) {
nsBidiLevel frameLevel = nsBidiPresUtils::GetFrameBaseLevel(aSubFrame);
writingMode.SetDirectionFromBidiLevel(frameLevel);
}
return writingMode;
}
nsRect
nsIFrame::GetMarginRectRelativeToSelf() const
{

View File

@ -672,6 +672,15 @@ public:
return mozilla::WritingMode(StyleVisibility());
}
/**
* Get the writing mode of this frame, but if it is styled with
* unicode-bidi: plaintext, reset the direction to the resolved paragraph
* level of the given subframe (typically the first frame on the line),
* not this frame's writing mode, because the container frame could be split
* by hard line breaks into multiple paragraphs with different base direction.
*/
mozilla::WritingMode GetWritingMode(nsIFrame* aSubFrame) const;
/**
* Bounding rect of the frame. The values are in app units, and the origin is
* relative to the upper-left of the geometric parent. The size includes the

View File

@ -487,23 +487,21 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
nsLineLayout* lineLayout = aReflowState.mLineLayout;
bool inFirstLine = aReflowState.mLineLayout->GetInFirstLine();
RestyleManager* restyleManager = aPresContext->RestyleManager();
bool ltr = (NS_STYLE_DIRECTION_LTR == aReflowState.mStyleVisibility->mDirection);
nscoord leftEdge = 0;
WritingMode wm = aReflowState.GetWritingMode();
nscoord startEdge = 0;
// Don't offset by our start borderpadding if we have a prev continuation or
// if we're in a part of an {ib} split other than the first one.
if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) {
leftEdge = ltr ? aReflowState.ComputedPhysicalBorderPadding().left
: aReflowState.ComputedPhysicalBorderPadding().right;
startEdge = aReflowState.ComputedLogicalBorderPadding().IStart(wm);
}
nscoord availableWidth = aReflowState.AvailableWidth();
NS_ASSERTION(availableWidth != NS_UNCONSTRAINEDSIZE,
nscoord availableISize = aReflowState.AvailableISize();
NS_ASSERTION(availableISize != NS_UNCONSTRAINEDSIZE,
"should no longer use available widths");
// Subtract off left and right border+padding from availableWidth
availableWidth -= leftEdge;
availableWidth -= ltr ? aReflowState.ComputedPhysicalBorderPadding().right
: aReflowState.ComputedPhysicalBorderPadding().left;
lineLayout->BeginSpan(this, &aReflowState, leftEdge,
leftEdge + availableWidth, &mBaseline);
// Subtract off inline axis border+padding from availableISize
availableISize -= startEdge;
availableISize -= aReflowState.ComputedLogicalBorderPadding().IEnd(wm);
lineLayout->BeginSpan(this, &aReflowState, startEdge,
startEdge + availableISize, &mBaseline);
// First reflow our principal children.
nsIFrame* frame = mFrames.FirstChild();
@ -646,7 +644,7 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
// line-height calculations. However, continuations of an inline
// that are empty we force to empty so that things like collapsed
// whitespace in an inline element don't affect the line-height.
aMetrics.Width() = lineLayout->EndSpan(this);
aMetrics.ISize() = lineLayout->EndSpan(this);
// Compute final width.
@ -654,8 +652,7 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
// continuation or if we're in a part of an {ib} split other than the first
// one.
if (!GetPrevContinuation() && !FrameIsNonFirstInIBSplit()) {
aMetrics.Width() += ltr ? aReflowState.ComputedPhysicalBorderPadding().left
: aReflowState.ComputedPhysicalBorderPadding().right;
aMetrics.ISize() += aReflowState.ComputedLogicalBorderPadding().IStart(wm);
}
/*
@ -668,8 +665,7 @@ nsInlineFrame::ReflowFrames(nsPresContext* aPresContext,
if (NS_FRAME_IS_COMPLETE(aStatus) &&
!LastInFlow()->GetNextContinuation() &&
!FrameIsNonLastInIBSplit()) {
aMetrics.Width() += ltr ? aReflowState.ComputedPhysicalBorderPadding().right
: aReflowState.ComputedPhysicalBorderPadding().left;
aMetrics.Width() += aReflowState.ComputedLogicalBorderPadding().IEnd(wm);
}
nsRefPtr<nsFontMetrics> fm;

File diff suppressed because it is too large Load Diff

View File

@ -21,6 +21,7 @@
#include "nsBlockReflowState.h"
#include "plarena.h"
#include "gfxTypes.h"
#include "WritingModes.h"
class nsFloatManager;
struct nsStyleText;
@ -33,10 +34,10 @@ public:
const nsLineList::iterator* aLine);
~nsLineLayout();
void Init(nsBlockReflowState* aState, nscoord aMinLineHeight,
void Init(nsBlockReflowState* aState, nscoord aMinLineBSize,
int32_t aLineNumber) {
mBlockRS = aState;
mMinLineHeight = aMinLineHeight;
mMinLineBSize = aMinLineBSize;
mLineNumber = aLineNumber;
}
@ -44,11 +45,12 @@ public:
return mLineNumber;
}
void BeginLineReflow(nscoord aX, nscoord aY,
nscoord aWidth, nscoord aHeight,
void BeginLineReflow(nscoord aICoord, nscoord aBCoord,
nscoord aISize, nscoord aBSize,
bool aImpactedByFloats,
bool aIsTopOfPage,
uint8_t aDirection);
mozilla::WritingMode aWritingMode,
nscoord aContainerWidth);
void EndLineReflow();
@ -73,7 +75,7 @@ public:
void SplitLineTo(int32_t aNewCount);
bool IsZeroHeight();
bool IsZeroBSize();
// Reflows the frame and returns the reflow status. aPushedFrame is true
// if the frame is pushed to the next line because it doesn't fit
@ -88,11 +90,12 @@ public:
PushFrame(aFrame);
}
void VerticalAlignLine();
void BlockDirAlignLine();
bool TrimTrailingWhiteSpace();
void HorizontalAlignFrames(nsRect& aLineBounds, bool aIsLastLine);
void InlineDirAlignFrames(nsRect& aLineBounds, bool aIsLastLine,
int32_t aFrameCount);
/**
* Handle all the relative positioning in the line, compute the
@ -303,10 +306,10 @@ public:
* the right edge for RTL blocks and from the left edge for LTR blocks.
* In other words, the current frame's distance from the line container's
* start content edge is:
* <code>GetCurrentFrameXDistanceFromBlock() - lineContainer->GetUsedBorderAndPadding().left</code>
* <code>GetCurrentFrameInlineDistanceFromBlock() - lineContainer->GetUsedBorderAndPadding().left</code>
* Note the use of <code>.left</code> for both LTR and RTL line containers.
*/
nscoord GetCurrentFrameXDistanceFromBlock();
nscoord GetCurrentFrameInlineDistanceFromBlock();
protected:
// This state is constant for a given block frame doing line layout
@ -326,14 +329,22 @@ protected:
// Per-frame data recorded by the line-layout reflow logic. This
// state is the state needed to post-process the line after reflow
// has completed (vertical alignment, horizontal alignment,
// has completed (block-direction alignment, inline-direction alignment,
// justification and relative positioning).
struct PerSpanData;
struct PerFrameData;
friend struct PerSpanData;
friend struct PerFrameData;
struct PerFrameData {
struct PerFrameData
{
PerFrameData(mozilla::WritingMode aWritingMode)
: mBounds(aWritingMode)
, mMargin(aWritingMode)
, mBorderPadding(aWritingMode)
, mOffsets(aWritingMode)
{}
// link to next/prev frame in same span
PerFrameData* mNext;
PerFrameData* mPrev;
@ -346,20 +357,23 @@ protected:
// From metrics
nscoord mAscent;
nsRect mBounds;
// note that mBounds is a logical rect in the *line*'s writing mode.
// When setting frame coordinates, we have to convert to the frame's
// writing mode
mozilla::LogicalRect mBounds;
nsOverflowAreas mOverflowAreas;
// From reflow-state
nsMargin mMargin;
nsMargin mBorderPadding;
nsMargin mOffsets;
mozilla::LogicalMargin mMargin;
mozilla::LogicalMargin mBorderPadding;
mozilla::LogicalMargin mOffsets;
// state for text justification
int32_t mJustificationNumSpaces;
int32_t mJustificationNumLetters;
// Other state we use
uint8_t mVerticalAlign;
uint8_t mBlockDirAlign;
// PerFrameData flags
#define PFD_RELATIVEPOS 0x00000001
@ -414,19 +428,18 @@ protected:
const nsHTMLReflowState* mReflowState;
bool mNoWrap;
uint8_t mDirection;
bool mChangedFrameDirection;
mozilla::WritingMode mWritingMode;
bool mZeroEffectiveSpanBox;
bool mContainsFloat;
bool mHasNonemptyContent;
nscoord mLeftEdge;
nscoord mX;
nscoord mRightEdge;
nscoord mIStart;
nscoord mICoord;
nscoord mIEnd;
nscoord mTopLeading, mBottomLeading;
nscoord mLogicalHeight;
nscoord mMinY, mMaxY;
nscoord mBStartLeading, mBEndLeading;
nscoord mLogicalBSize;
nscoord mMinBCoord, mMaxBCoord;
nscoord* mBaseline;
void AppendFrame(PerFrameData* pfd) {
@ -448,7 +461,7 @@ protected:
int32_t mLastOptionalBreakContentOffset;
int32_t mForceBreakContentOffset;
nscoord mMinLineHeight;
nscoord mMinLineBSize;
// The amount of text indent that we applied to this line, needed for
// max-element-size calculation.
@ -462,19 +475,21 @@ protected:
int32_t mTotalPlacedFrames;
nscoord mTopEdge;
nscoord mMaxTopBoxHeight;
nscoord mMaxBottomBoxHeight;
nscoord mBStartEdge;
nscoord mMaxStartBoxBSize;
nscoord mMaxEndBoxBSize;
nscoord mInflationMinFontSize;
// Final computed line-height value after VerticalAlignFrames for
// Final computed line-bSize value after BlockDirAlignFrames for
// the block has been called.
nscoord mFinalLineHeight;
nscoord mFinalLineBSize;
// Amount of trimmable whitespace width for the trailing text frame, if any
nscoord mTrimmableWidth;
nscoord mContainerWidth;
bool mFirstLetterStyleOK : 1;
bool mIsTopOfPage : 1;
bool mImpactedByFloats : 1;
@ -499,7 +514,7 @@ protected:
/**
* Allocate a PerFrameData from the mArena pool. The allocation is infallible.
*/
PerFrameData* NewPerFrameData();
PerFrameData* NewPerFrameData(nsIFrame* aFrame);
/**
* Allocate a PerSpanData from the mArena pool. The allocation is infallible.
@ -518,7 +533,6 @@ protected:
nsHTMLReflowState& aReflowState);
bool CanPlaceFrame(PerFrameData* pfd,
uint8_t aFrameDirection,
bool aNotSafeToBreak,
bool aFrameCanContinueTextRun,
bool aCanRollBackBeforeFrame,
@ -529,15 +543,15 @@ protected:
void PlaceFrame(PerFrameData* pfd,
nsHTMLReflowMetrics& aMetrics);
void VerticalAlignFrames(PerSpanData* psd);
void BlockDirAlignFrames(PerSpanData* psd);
void PlaceTopBottomFrames(PerSpanData* psd,
nscoord aDistanceFromTop,
nscoord aLineHeight);
void PlaceStartEndFrames(PerSpanData* psd,
nscoord aDistanceFromStart,
nscoord aLineBSize);
void RelativePositionFrames(PerSpanData* psd, nsOverflowAreas& aOverflowAreas);
bool TrimTrailingWhiteSpaceIn(PerSpanData* psd, nscoord* aDeltaWidth);
bool TrimTrailingWhiteSpaceIn(PerSpanData* psd, nscoord* aDeltaISize);
void ComputeJustificationWeights(PerSpanData* psd, int32_t* numSpaces, int32_t* numLetters);

View File

@ -7841,7 +7841,7 @@ nsTextFrame::ReflowText(nsLineLayout& aLineLayout, nscoord aAvailableWidth,
iter.SetOriginalOffset(offset);
nscoord xOffsetForTabs = (mTextRun->GetFlags() & nsTextFrameUtils::TEXT_HAS_TAB) ?
(aLineLayout.GetCurrentFrameXDistanceFromBlock() -
(aLineLayout.GetCurrentFrameInlineDistanceFromBlock() -
lineContainer->GetUsedBorderAndPadding().left)
: -1;
PropertyProvider provider(mTextRun, textStyle, frag, this, iter, length,