From c914c4063c95ebf760961d6ead78ee70bf007e84 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Tue, 17 Feb 2015 14:25:18 +1300 Subject: [PATCH] Bug 1132008 part 1 - Calculate bsize of rtc according to its children. r=dbaron --HG-- extra : source : e07fd183c24ea7133faa62bc5837e6d30589f05e --- layout/generic/nsRubyBaseContainerFrame.cpp | 3 +- layout/generic/nsRubyTextContainerFrame.cpp | 44 ++++++++++++++++----- layout/generic/nsRubyTextContainerFrame.h | 8 ++-- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/layout/generic/nsRubyBaseContainerFrame.cpp b/layout/generic/nsRubyBaseContainerFrame.cpp index 438671df9a8c..66f9de3c808d 100644 --- a/layout/generic/nsRubyBaseContainerFrame.cpp +++ b/layout/generic/nsRubyBaseContainerFrame.cpp @@ -464,8 +464,7 @@ nsRubyBaseContainerFrame::Reflow(nsPresContext* aPresContext, } lineLayout->VerticalAlignLine(); - LogicalSize lineSize(lineWM, rtcISize, lineLayout->GetFinalLineBSize()); - textContainer->SetLineSize(lineSize); + textContainer->SetISize(rtcISize); lineLayout->EndLineReflow(); } diff --git a/layout/generic/nsRubyTextContainerFrame.cpp b/layout/generic/nsRubyTextContainerFrame.cpp index e071a1912fed..70b340057f0e 100644 --- a/layout/generic/nsRubyTextContainerFrame.cpp +++ b/layout/generic/nsRubyTextContainerFrame.cpp @@ -130,17 +130,43 @@ nsRubyTextContainerFrame::Reflow(nsPresContext* aPresContext, // will take care of our continuations. aStatus = NS_FRAME_COMPLETE; WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode(); - aDesiredSize.SetSize(lineWM, mLineSize); - if (lineWM.IsVerticalRL()) { - nscoord deltaWidth = -mLineSize.Width(lineWM); - LogicalPoint translation(lineWM, 0, deltaWidth); + nscoord minBCoord = nscoord_MAX; + nscoord maxBCoord = nscoord_MIN; + for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) { + nsIFrame* child = e.get(); + MOZ_ASSERT(child->GetType() == nsGkAtoms::rubyTextFrame); + // The container width is still unknown yet. + LogicalRect rect = child->GetLogicalRect(lineWM, 0); + LogicalMargin margin = child->GetLogicalUsedMargin(lineWM); + nscoord blockStart = rect.BStart(lineWM) - margin.BStart(lineWM); + minBCoord = std::min(minBCoord, blockStart); + nscoord blockEnd = rect.BEnd(lineWM) + margin.BEnd(lineWM); + maxBCoord = std::max(maxBCoord, blockEnd); + } - for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) { - nsIFrame* child = e.get(); - MOZ_ASSERT(child->GetType() == nsGkAtoms::rubyTextFrame); - child->MovePositionBy(lineWM, translation); - nsContainerFrame::PlaceFrameView(child); + MOZ_ASSERT(minBCoord <= maxBCoord || mFrames.IsEmpty()); + LogicalSize size(lineWM, mISize, 0); + if (!mFrames.IsEmpty()) { + size.BSize(lineWM) = maxBCoord - minBCoord; + nscoord deltaBCoord = -minBCoord; + if (lineWM.IsVerticalRL()) { + deltaBCoord -= size.BSize(lineWM); + } + + if (deltaBCoord != 0) { + nscoord containerWidth = size.Width(lineWM); + for (nsFrameList::Enumerator e(mFrames); !e.AtEnd(); e.Next()) { + nsIFrame* child = e.get(); + LogicalPoint pos = child->GetLogicalPosition(lineWM, containerWidth); + pos.B(lineWM) += deltaBCoord; + // Relative positioning hasn't happened yet. + // So MovePositionBy should be used here. + child->SetPosition(lineWM, pos, containerWidth); + nsContainerFrame::PlaceFrameView(child); + } } } + + aDesiredSize.SetSize(lineWM, size); } diff --git a/layout/generic/nsRubyTextContainerFrame.h b/layout/generic/nsRubyTextContainerFrame.h index ce79f6242f4c..41c1fc1863c5 100644 --- a/layout/generic/nsRubyTextContainerFrame.h +++ b/layout/generic/nsRubyTextContainerFrame.h @@ -63,17 +63,17 @@ protected: nsStyleContext* aContext); explicit nsRubyTextContainerFrame(nsStyleContext* aContext) : nsRubyTextContainerFrameSuper(aContext) - , mLineSize(mozilla::WritingMode(aContext)) {} + , mISize(0) {} void UpdateSpanFlag(); friend class nsRubyBaseContainerFrame; - void SetLineSize(const mozilla::LogicalSize& aSize) { mLineSize = aSize; } + void SetISize(nscoord aISize) { mISize = aISize; } - // The intended dimensions of the ruby text container. It is set by + // The intended inline size of the ruby text container. It is set by // the corresponding ruby base container when the segment is reflowed, // and used when the ruby text container is reflowed by its parent. - mozilla::LogicalSize mLineSize; + nscoord mISize; }; #endif /* nsRubyTextContainerFrame_h___ */