Bug 1055667 part 3 - Suppress border/padding space on rbc/rtc frames. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 15 Jan 2015 20:02:11 +1100
changeset 223954 d220304dc8dd
parent 223953 a0ce5974c7dd
child 223955 f6f6cfd31f00
push id28112
push usercbook@mozilla.com
push date2015-01-15 13:19 +0000
treeherdermozilla-central@206bf1a98cd7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1055667
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1055667 part 3 - Suppress border/padding space on rbc/rtc frames. r=dbaron
layout/generic/nsRubyBaseContainerFrame.cpp
--- a/layout/generic/nsRubyBaseContainerFrame.cpp
+++ b/layout/generic/nsRubyBaseContainerFrame.cpp
@@ -386,48 +386,43 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
     lineLayouts.AppendElement(lineLayout);
 
     // Line number is useless for ruby text
     // XXX nullptr here may cause problem, see comments for
     //     nsLineLayout::mBlockRS and nsLineLayout::AddFloat
     lineLayout->Init(nullptr, reflowState->CalcLineHeight(), -1);
     reflowState->mLineLayout = lineLayout;
 
-    LogicalMargin borderPadding = reflowState->ComputedLogicalBorderPadding();
+    // Border and padding are suppressed on ruby text containers.
     // If the writing mode is vertical-rl, the horizontal position of
     // rt frames will be updated when reflowing this text container,
     // hence leave container width 0 here for now.
-    lineLayout->BeginLineReflow(borderPadding.IStart(lineWM),
-                                borderPadding.BStart(lineWM),
-                                reflowState->ComputedISize(),
+    lineLayout->BeginLineReflow(0, 0, reflowState->ComputedISize(),
                                 NS_UNCONSTRAINEDSIZE,
                                 false, false, lineWM, 0);
     lineLayout->AttachRootFrameToBaseLineLayout();
   }
 
-  WritingMode frameWM = aReflowState.GetWritingMode();
-  LogicalMargin borderPadding = aReflowState.ComputedLogicalBorderPadding();
-  nscoord startEdge = borderPadding.IStart(frameWM);
-  nscoord endEdge = aReflowState.AvailableISize() - borderPadding.IEnd(frameWM);
   aReflowState.mLineLayout->BeginSpan(this, &aReflowState,
-                                      startEdge, endEdge, &mBaseline);
+                                      0, aReflowState.AvailableISize(),
+                                      &mBaseline);
 
   nsIFrame* parent = GetParent();
   bool inNestedRuby = parent->StyleContext()->IsInlineDescendantOfRuby();
   // Allow line break between ruby bases when white-space allows,
   // we are not inside a nested ruby, and there is no span.
   bool allowLineBreak = !inNestedRuby && StyleText()->WhiteSpaceCanWrap(this);
   bool allowInitialLineBreak = allowLineBreak;
   if (!GetPrevInFlow()) {
     allowInitialLineBreak = !inNestedRuby &&
       parent->StyleText()->WhiteSpaceCanWrap(parent);
   }
   if (allowInitialLineBreak && aReflowState.mLineLayout->LineIsBreakable() &&
       aReflowState.mLineLayout->NotifyOptionalBreakPosition(
-        this, 0, startEdge <= aReflowState.AvailableISize(),
+        this, 0, 0 <= aReflowState.AvailableISize(),
         gfxBreakPriority::eNormalBreak)) {
     aStatus = NS_INLINE_LINE_BREAK_BEFORE();
   }
 
   nscoord isize = 0;
   if (aStatus == NS_FRAME_COMPLETE) {
     // Reflow columns excluding any span
     ReflowState reflowState = {
@@ -462,17 +457,17 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
         isize = spanISize;
       }
     }
     // When there are spans, ReflowColumns and ReflowOneColumn won't
     // record any optional break position. We have to record one
     // at the end of this segment.
     if (!NS_INLINE_IS_BREAK(aStatus) && allowLineBreak &&
         aReflowState.mLineLayout->NotifyOptionalBreakPosition(
-          this, INT32_MAX, startEdge + isize <= aReflowState.AvailableISize(),
+          this, INT32_MAX, isize <= aReflowState.AvailableISize(),
           gfxBreakPriority::eNormalBreak)) {
       aStatus = NS_INLINE_LINE_BREAK_AFTER(aStatus);
     }
   }
 
   for (uint32_t i = 0; i < rtcCount; i++) {
     // It happens before the ruby text container is reflowed, and that
     // when it is reflowed, it will just use this size.
@@ -492,16 +487,20 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
     }
 
     lineLayout->VerticalAlignLine();
     LogicalSize lineSize(lineWM, rtcISize, lineLayout->GetFinalLineBSize());
     textContainer->SetLineSize(lineSize);
     lineLayout->EndLineReflow();
   }
 
+  // Border and padding are suppressed on ruby base container,
+  // create a fake borderPadding for setting BSize.
+  WritingMode frameWM = aReflowState.GetWritingMode();
+  LogicalMargin borderPadding(frameWM);
   nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize,
                                          borderPadding, lineWM, frameWM);
 }
 
 /**
  * This struct stores the continuations after this frame and
  * corresponding text containers. It is used to speed up looking
  * ahead for nonempty continuations.
@@ -517,18 +516,18 @@ struct MOZ_STACK_CLASS nsRubyBaseContain
 };
 
 nscoord
 nsRubyBaseContainerFrame::ReflowColumns(const ReflowState& aReflowState,
                                         nsReflowStatus& aStatus)
 {
   nsLineLayout* lineLayout = aReflowState.mBaseReflowState.mLineLayout;
   const uint32_t rtcCount = aReflowState.mTextContainers.Length();
-  nscoord istart = lineLayout->GetCurrentICoord();
-  nscoord icoord = istart;
+  nscoord icoord = lineLayout->GetCurrentICoord();
+  MOZ_ASSERT(icoord == 0, "border/padding of rbc should have been suppressed");
   nsReflowStatus reflowStatus = NS_FRAME_COMPLETE;
   aStatus = NS_FRAME_COMPLETE;
 
   uint32_t columnIndex = 0;
   RubyColumn column;
   column.mTextFrames.SetCapacity(rtcCount);
   RubyColumnEnumerator e(this, aReflowState.mTextContainers);
   for (; !e.AtEnd(); e.Next()) {
@@ -617,29 +616,28 @@ nsRubyBaseContainerFrame::ReflowColumns(
     // |reflowStatus| being break after here may only happen when
     // there is a break after the column just pulled, or the whole
     // segment has been completely reflowed. In those cases, we do
     // not need to push anything.
     MOZ_ASSERT(e.AtEnd());
     aStatus = NS_INLINE_LINE_BREAK_AFTER(aStatus);
   }
 
-  return icoord - istart;
+  return icoord;
 }
 
 nscoord
 nsRubyBaseContainerFrame::ReflowOneColumn(const ReflowState& aReflowState,
                                           uint32_t aColumnIndex,
                                           const RubyColumn& aColumn,
                                           nsReflowStatus& aStatus)
 {
   const nsHTMLReflowState& baseReflowState = aReflowState.mBaseReflowState;
   const auto& textReflowStates = aReflowState.mTextReflowStates;
 
-  WritingMode lineWM = baseReflowState.mLineLayout->GetWritingMode();
   const uint32_t rtcCount = aReflowState.mTextContainers.Length();
   MOZ_ASSERT(aColumn.mTextFrames.Length() == rtcCount);
   MOZ_ASSERT(textReflowStates.Length() == rtcCount);
   nscoord istart = baseReflowState.mLineLayout->GetCurrentICoord();
   nscoord columnISize = 0;
 
   nsAutoString baseText;
   if (aColumn.mBaseFrame) {
@@ -819,33 +817,29 @@ nsRubyBaseContainerFrame::PullOneColumn(
     // We pulled frames from the next line, hence mark it dirty.
     aLineLayout->SetDirtyNextLine();
   }
 }
 
 nscoord
 nsRubyBaseContainerFrame::ReflowSpans(const ReflowState& aReflowState)
 {
-  WritingMode lineWM =
-    aReflowState.mBaseReflowState.mLineLayout->GetWritingMode();
   nscoord spanISize = 0;
-
   for (uint32_t i = 0, iend = aReflowState.mTextContainers.Length();
        i < iend; i++) {
     nsRubyTextContainerFrame* container = aReflowState.mTextContainers[i];
     if (!container->IsSpanContainer()) {
       continue;
     }
 
     nsIFrame* rtFrame = container->GetFirstPrincipalChild();
     nsReflowStatus reflowStatus;
     bool pushedFrame;
     nsLineLayout* lineLayout = aReflowState.mTextReflowStates[i]->mLineLayout;
-    nscoord istart = lineLayout->GetCurrentICoord();
+    MOZ_ASSERT(lineLayout->GetCurrentICoord() == 0,
+               "border/padding of rtc should have been suppressed");
     lineLayout->ReflowFrame(rtFrame, reflowStatus, nullptr, pushedFrame);
     MOZ_ASSERT(!NS_INLINE_IS_BREAK(reflowStatus) && !pushedFrame,
                "Any line break inside ruby box should has been suppressed");
-    nscoord isize = lineLayout->GetCurrentICoord() - istart;
-    spanISize = std::max(spanISize, isize);
+    spanISize = std::max(spanISize, lineLayout->GetCurrentICoord());
   }
-
   return spanISize;
 }