From 6622361f7b7bb5d704a5dbd3d850cbe6d319b5fa Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 17 Feb 2015 18:01:49 +1300 Subject: [PATCH] Bug 1055676 part 2 - Move inter-frame justification assignment to an independent function. r=roc --HG-- extra : source : 8e0084f1fcc9daba3780cbef92b73d6234ad5180 --- layout/generic/nsLineLayout.cpp | 79 ++++++++++++++++++++------------- layout/generic/nsLineLayout.h | 4 ++ 2 files changed, 51 insertions(+), 32 deletions(-) diff --git a/layout/generic/nsLineLayout.cpp b/layout/generic/nsLineLayout.cpp index aa7891673149..ab54ee3d2248 100644 --- a/layout/generic/nsLineLayout.cpp +++ b/layout/generic/nsLineLayout.cpp @@ -2616,6 +2616,50 @@ struct nsLineLayout::JustificationComputationState , mCrossingRubyBaseBoundary(false) { } }; +/** + * Assign justification gaps for justification + * opportunities across two frames. + */ +/* static */ int +nsLineLayout::AssignInterframeJustificationGaps( + PerFrameData* aFrame, JustificationComputationState& aState) +{ + PerFrameData* prev = aState.mLastParticipant; + MOZ_ASSERT(prev); + + auto& assign = aFrame->mJustificationAssignment; + auto& prevAssign = prev->mJustificationAssignment; + const auto& info = aFrame->mJustificationInfo; + const auto& prevInfo = prev->mJustificationInfo; + + if (!info.mIsStartJustifiable && + !prevInfo.mIsEndJustifiable && + !aState.mCrossingRubyBaseBoundary) { + return 0; + } + + if (aState.mCrossingRubyBaseBoundary) { + // For ruby alignment with value space-around, there is + // always an expansion opportunity at the boundary of a ruby + // base, and it always generates one gap at each side. If we + // don't do it here, the interaction between text align and + // and ruby align could be strange. + prevAssign.mGapsAtEnd = 1; + assign.mGapsAtStart = 1; + aState.mCrossingRubyBaseBoundary = false; + } else if (!info.mIsStartJustifiable) { + prevAssign.mGapsAtEnd = 2; + assign.mGapsAtStart = 0; + } else if (!prevInfo.mIsEndJustifiable) { + prevAssign.mGapsAtEnd = 0; + assign.mGapsAtStart = 2; + } else { + prevAssign.mGapsAtEnd = 1; + assign.mGapsAtStart = 1; + } + return 1; +} + /** * Compute the justification info of the given span, and store the * number of inner opportunities into the frame's justification info. @@ -2651,43 +2695,14 @@ nsLineLayout::ComputeFrameJustification(PerSpanData* aPSD, extraOpportunities = ComputeFrameJustification(span, aState); innerOpportunities += pfd->mJustificationInfo.mInnerOpportunities; } else { - const auto& info = pfd->mJustificationInfo; if (pfd->mIsTextFrame) { - innerOpportunities += info.mInnerOpportunities; + innerOpportunities += pfd->mJustificationInfo.mInnerOpportunities; } - PerFrameData* prev = aState.mLastParticipant; - if (!prev) { + if (!aState.mLastParticipant) { aState.mFirstParticipant = pfd; } else { - auto& assign = pfd->mJustificationAssignment; - auto& prevAssign = prev->mJustificationAssignment; - const auto& prevInfo = prev->mJustificationInfo; - - if (info.mIsStartJustifiable || - prevInfo.mIsEndJustifiable || - aState.mCrossingRubyBaseBoundary) { - extraOpportunities = 1; - if (aState.mCrossingRubyBaseBoundary) { - // For ruby alignment with value space-around, there is - // always an expansion opportunity at the boundary of a ruby - // base, and it always generates one gap at each side. If we - // don't do it here, the interaction between text align and - // and ruby align could be strange. - prevAssign.mGapsAtEnd = 1; - assign.mGapsAtStart = 1; - aState.mCrossingRubyBaseBoundary = false; - } else if (!info.mIsStartJustifiable) { - prevAssign.mGapsAtEnd = 2; - assign.mGapsAtStart = 0; - } else if (!prevInfo.mIsEndJustifiable) { - prevAssign.mGapsAtEnd = 0; - assign.mGapsAtStart = 2; - } else { - prevAssign.mGapsAtEnd = 1; - assign.mGapsAtStart = 1; - } - } + extraOpportunities = AssignInterframeJustificationGaps(pfd, aState); } aState.mLastParticipant = pfd; diff --git a/layout/generic/nsLineLayout.h b/layout/generic/nsLineLayout.h index 81a4026c6b14..f78061a6b39a 100644 --- a/layout/generic/nsLineLayout.h +++ b/layout/generic/nsLineLayout.h @@ -671,6 +671,10 @@ protected: bool TrimTrailingWhiteSpaceIn(PerSpanData* psd, nscoord* aDeltaISize); struct JustificationComputationState; + + static int AssignInterframeJustificationGaps( + PerFrameData* aFrame, JustificationComputationState& aState); + int32_t ComputeFrameJustification(PerSpanData* psd, JustificationComputationState& aState);