Bug 1224013 part 3 - Render text-emphasis outside ruby. r=jfkthame
authorXidorn Quan <quanxunzhen@gmail.com>
Fri, 04 Dec 2015 12:02:41 +1100
changeset 309725 5c44af8f7d6ee6319fb5d82970c8811383036ea9
parent 309724 15113b4231c70ccbc1ce420fd03f1984c5b89d22
child 309726 b0b15e5ed2712aa171dd39ba98a42e831f0d7b1d
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjfkthame
bugs1224013
milestone45.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 1224013 part 3 - Render text-emphasis outside ruby. r=jfkthame
layout/generic/nsTextFrame.cpp
--- a/layout/generic/nsTextFrame.cpp
+++ b/layout/generic/nsTextFrame.cpp
@@ -47,16 +47,17 @@
 #include "nsIMathMLFrame.h"
 #include "nsPlaceholderFrame.h"
 #include "nsTextFrameUtils.h"
 #include "nsTextRunTransformations.h"
 #include "MathMLTextRunFactory.h"
 #include "nsExpirationTracker.h"
 #include "nsUnicodeProperties.h"
 #include "nsStyleUtil.h"
+#include "nsRubyBaseContainerFrame.h"
 
 #include "nsTextFragment.h"
 #include "nsGkAtoms.h"
 #include "nsFrameSelection.h"
 #include "nsRange.h"
 #include "nsCSSRendering.h"
 #include "nsContentUtils.h"
 #include "nsLineBreaker.h"
@@ -5150,16 +5151,29 @@ GenerateTextRunForEmphasisMarks(nsTextFr
     // The emphasis marks should always be rendered upright per spec.
     flags = gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
   }
   return aFontMetrics->GetThebesFontGroup()->
     MakeTextRun<char16_t>(emphasisString.get(), emphasisString.Length(),
                           ctx, appUnitsPerDevUnit, flags, nullptr);
 }
 
+static nsRubyBaseContainerFrame*
+FindRubyBaseContainerAncestor(nsTextFrame* aFrame)
+{
+  for (nsIFrame* frame = aFrame->GetParent();
+       frame && frame->IsFrameOfType(nsIFrame::eLineParticipant);
+       frame = frame->GetParent()) {
+    if (frame->GetType() == nsGkAtoms::rubyBaseContainerFrame) {
+      return static_cast<nsRubyBaseContainerFrame*>(frame);
+    }
+  }
+  return nullptr;
+}
+
 nsRect
 nsTextFrame::UpdateTextEmphasis(WritingMode aWM, PropertyProvider& aProvider)
 {
   const nsStyleText* styleText = StyleText();
   if (!styleText->HasTextEmphasis()) {
     Properties().Delete(EmphasisMarkProperty());
     return nsRect();
   }
@@ -5183,24 +5197,28 @@ nsTextFrame::UpdateTextEmphasis(WritingM
                            /* BStart to be computed below */0,
                            frameSize.ISize(aWM) + info->advance,
                            fm->MaxAscent() + fm->MaxDescent());
   // When the writing mode is vertical-lr the line is inverted, and thus
   // the ascent and descent are swapped.
   nscoord absOffset = (side == eLogicalSideBStart) != aWM.IsLineInverted() ?
     baseFontMetrics->MaxAscent() + fm->MaxDescent() :
     baseFontMetrics->MaxDescent() + fm->MaxAscent();
-  // XXX emphasis marks should be drawn outside ruby, see bug 1224013.
+  nscoord startLeading = 0;
+  nscoord endLeading = 0;
+  if (nsRubyBaseContainerFrame* rbc = FindRubyBaseContainerAncestor(this)) {
+    rbc->GetBlockLeadings(&startLeading, &endLeading);
+  }
   if (side == eLogicalSideBStart) {
-    info->baselineOffset = -absOffset;
-    overflowRect.BStart(aWM) = -overflowRect.BSize(aWM);
+    info->baselineOffset = -absOffset - startLeading;
+    overflowRect.BStart(aWM) = -overflowRect.BSize(aWM) - startLeading;
   } else {
     MOZ_ASSERT(side == eLogicalSideBEnd);
-    info->baselineOffset = absOffset;
-    overflowRect.BStart(aWM) = frameSize.BSize(aWM);
+    info->baselineOffset = absOffset + endLeading;
+    overflowRect.BStart(aWM) = frameSize.BSize(aWM) + endLeading;
   }
 
   Properties().Set(EmphasisMarkProperty(), info);
   return overflowRect.GetPhysicalRect(aWM, frameSize.GetPhysicalSize(aWM));
 }
 
 void
 nsTextFrame::UnionAdditionalOverflow(nsPresContext* aPresContext,