Bug 1055665 part 3 - Position ruby annotations and set the line size of them correctly. r=dholbert
authorXidorn Quan <quanxunzhen@gmail.com>
Tue, 09 Dec 2014 17:47:26 +1100
changeset 221276 b55ca3e17876484842dacfaf8478f075c7381049
parent 221275 146f3133b1355cbc90b610e0695391aac9f24b16
child 221277 d82e1fe5cfd19910416a4237fdcda7020fe4327e
push id28015
push userphilringnalda@gmail.com
push dateWed, 24 Dec 2014 23:38:54 +0000
treeherdermozilla-central@2acb12da9813 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1055665
milestone37.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 1055665 part 3 - Position ruby annotations and set the line size of them correctly. r=dholbert
layout/generic/nsLineLayout.cpp
layout/generic/nsLineLayout.h
layout/generic/nsRubyBaseContainerFrame.cpp
layout/generic/nsRubyTextContainerFrame.cpp
layout/generic/nsRubyTextContainerFrame.h
layout/generic/nsRubyTextFrame.cpp
layout/reftests/css-ruby/reftest.list
--- a/layout/generic/nsLineLayout.cpp
+++ b/layout/generic/nsLineLayout.cpp
@@ -93,16 +93,19 @@ nsLineLayout::nsLineLayout(nsPresContext
     mStyleText = blockFrame->StyleTextForLineLayout();
   else
     mStyleText = aOuterReflowState->frame->StyleText();
 
   mLineNumber = 0;
   mTotalPlacedFrames = 0;
   mBStartEdge = 0;
   mTrimmableISize = 0;
+#ifdef DEBUG
+  mFinalLineBSize = nscoord_MIN;
+#endif
 
   mInflationMinFontSize =
     nsLayoutUtils::InflationMinFontSizeFor(aOuterReflowState->frame);
 
   // Instead of always pre-initializing the free-lists for frames and
   // spans, we do it on demand so that situations that only use a few
   // frames and spans won't waste a lot of time in unneeded
   // initialization.
--- a/layout/generic/nsLineLayout.h
+++ b/layout/generic/nsLineLayout.h
@@ -111,16 +111,25 @@ public:
     PushFrame(aFrame);
   }
 
   /**
    * Place frames in the block direction (CSS property vertical-align)
    */
   void VerticalAlignLine();
 
+  // Get the final size of the line, in the block direction.
+  // Do not call this until after we've called VerticalAlignLine.
+  nscoord GetFinalLineBSize() const
+  {
+    NS_ASSERTION(mFinalLineBSize != nscoord_MIN,
+                 "VerticalAlignLine should have been called before");
+    return mFinalLineBSize;
+  }
+
   bool TrimTrailingWhiteSpace();
 
   /**
    * Place frames in the inline direction (CSS property text-align).
    */
   void TextAlignLine(nsLineBox* aLine, bool aIsLastLine);
 
   /**
--- a/layout/generic/nsRubyBaseContainerFrame.cpp
+++ b/layout/generic/nsRubyBaseContainerFrame.cpp
@@ -404,30 +404,34 @@ nsRubyBaseContainerFrame::Reflow(nsPresC
   // container could be non-zero because of non-empty ruby annotations.
   MOZ_ASSERT(NS_INLINE_IS_BREAK_BEFORE(aStatus) ||
              isize == lineSpanSize || mFrames.IsEmpty());
   for (uint32_t i = 0; i < totalCount; i++) {
     // It happens before the ruby text container is reflowed, and that
     // when it is reflowed, it will just use this size.
     nsRubyTextContainerFrame* textContainer = i < rtcCount ?
       mTextContainers[i] : mSpanContainers[i - rtcCount];
+    nsLineLayout* lineLayout = lineLayouts[i].get();
+
     RubyUtils::ClearReservedISize(textContainer);
-    textContainer->SetISize(isize);
-
-    nscoord rtcISize = lineLayouts[i]->GetCurrentICoord();
+    nscoord rtcISize = lineLayout->GetCurrentICoord();
     // Only span containers and containers with collapsed annotations
     // need reserving isize. For normal ruby text containers, their
     // children will be expanded properly. We only need to expand their
     // own size.
     if (i < rtcCount) {
       rtcISize = isize;
     } else if (isize > rtcISize) {
       RubyUtils::SetReservedISize(textContainer, isize - rtcISize);
     }
-    lineLayouts[i]->EndLineReflow();
+
+    lineLayout->VerticalAlignLine();
+    LogicalSize lineSize(lineWM, isize, lineLayout->GetFinalLineBSize());
+    textContainer->SetLineSize(lineSize);
+    lineLayout->EndLineReflow();
   }
 
   aDesiredSize.ISize(lineWM) = isize;
   nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize, aReflowState,
                                          borderPadding, lineWM, frameWM);
 }
 
 /**
--- a/layout/generic/nsRubyTextContainerFrame.cpp
+++ b/layout/generic/nsRubyTextContainerFrame.cpp
@@ -66,25 +66,19 @@ nsRubyTextContainerFrame::Reflow(nsPresC
                                  nsHTMLReflowMetrics& aDesiredSize,
                                  const nsHTMLReflowState& aReflowState,
                                  nsReflowStatus& aStatus)
 {
   DO_GLOBAL_REFLOW_COUNT("nsRubyTextContainerFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
 
   // All rt children have already been reflowed. All we need to do is
-  // to report complete and return the desired size.
+  // to report complete and return the desired size provided by the
+  // ruby base container.
 
   // Although a ruby text container may have continuations, returning
   // NS_FRAME_COMPLETE here is still safe, since its parent, ruby frame,
   // ignores the status, and continuations of the ruby base container
   // will take care of our continuations.
   aStatus = NS_FRAME_COMPLETE;
   WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
-  WritingMode frameWM = aReflowState.GetWritingMode();
-  LogicalMargin borderPadding = aReflowState.ComputedLogicalBorderPadding();
-
-  // ISize is provided by the ruby base container
-  // during reflow of that container.
-  aDesiredSize.ISize(lineWM) = mISize;
-  nsLayoutUtils::SetBSizeFromFontMetrics(this, aDesiredSize, aReflowState,
-                                         borderPadding, lineWM, frameWM);
+  aDesiredSize.SetSize(lineWM, mLineSize);
 }
--- a/layout/generic/nsRubyTextContainerFrame.h
+++ b/layout/generic/nsRubyTextContainerFrame.h
@@ -42,20 +42,21 @@ public:
   virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
 #endif
 
 protected:
   friend nsContainerFrame*
     NS_NewRubyTextContainerFrame(nsIPresShell* aPresShell,
                                  nsStyleContext* aContext);
   explicit nsRubyTextContainerFrame(nsStyleContext* aContext)
-    : nsRubyTextContainerFrameSuper(aContext) {}
+    : nsRubyTextContainerFrameSuper(aContext)
+    , mLineSize(mozilla::WritingMode(aContext)) {}
 
   friend class nsRubyBaseContainerFrame;
-  void SetISize(nscoord aISize) { mISize = aISize; }
+  void SetLineSize(const mozilla::LogicalSize& aSize) { mLineSize = aSize; }
 
-  // The intended dimensions of the ruby text container. These are modified
-  // whenever a ruby text box is reflowed and used when the ruby text container
-  // is reflowed.
-  nscoord mISize;
+  // The intended dimensions 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;
 };
 
 #endif /* nsRubyTextContainerFrame_h___ */
--- a/layout/generic/nsRubyTextFrame.cpp
+++ b/layout/generic/nsRubyTextFrame.cpp
@@ -85,12 +85,15 @@ nsRubyTextFrame::Reflow(nsPresContext* a
   // propagated to the ancestors, then it won't be displayed even if
   // the content is no longer the same, until next reflow triggered by
   // some other change. In general, we always reflow all the frames we
   // created. There might be other problems if we don't do that.
   nsRubyTextFrameSuper::Reflow(aPresContext, aDesiredSize,
                                aReflowState, aStatus);
 
   if (GetStateBits() & NS_RUBY_TEXT_FRAME_AUTOHIDE) {
-    aDesiredSize.ClearSize();
+    // Reset the ISize. The BSize is not changed so that it won't
+    // affect vertical positioning in unexpected way.
+    WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode();
+    aDesiredSize.ISize(lineWM) = 0;
     aDesiredSize.SetOverflowAreasToDesiredBounds();
   }
 }
--- a/layout/reftests/css-ruby/reftest.list
+++ b/layout/reftests/css-ruby/reftest.list
@@ -1,13 +1,13 @@
 default-preferences pref(layout.css.ruby.enabled,true)
 
 == autohiding-1.html autohiding-1-ref.html
 == autohiding-2.html autohiding-2-ref.html
-== autohiding-3.html autohiding-3-ref.html
+fails == autohiding-3.html autohiding-3-ref.html # bug 1107701
 == box-generation-1.html box-generation-1-ref.html
 == box-generation-2.html box-generation-2-ref.html
 == box-generation-3.html box-generation-3-ref.html
 == box-generation-4.html box-generation-4-ref.html
 == box-generation-5.html box-generation-5-ref.html
 == dynamic-insertion-1.html dynamic-insertion-1-ref.html
 == dynamic-insertion-2.html dynamic-insertion-2-ref.html
 == dynamic-insertion-3.html dynamic-insertion-3-ref.html