Bug 1450208: Change nsRange::ExtractRectFromOffset to use simpler, hopefully safer logic to determine whether text is vertical. r=bz
authorBrad Werth <bwerth@mozilla.com>
Fri, 30 Mar 2018 08:52:53 -0700
changeset 410789 908749c3b8584dcbe7d4dcccf0f4c06921eee68d
parent 410788 18a14e2a17c6fb9d76355a665453bfcb2e08f1d2
child 410790 40f53976a5b8adce2955c72ca952898271c69297
push id33739
push usernbeleuzu@mozilla.com
push dateFri, 30 Mar 2018 21:47:45 +0000
treeherdermozilla-central@10c662d8416e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1450208
milestone61.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 1450208: Change nsRange::ExtractRectFromOffset to use simpler, hopefully safer logic to determine whether text is vertical. r=bz Instead of checking nsIFrame::IsTextFrame() and then casting to nsTextFrame, the new code just checks the writing mode of the frame. Less casts; less chance of pointer errors. MozReview-Commit-ID: LrtthZjwYq6
dom/base/nsRange.cpp
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -2906,26 +2906,25 @@ nsRange::CreateContextualFragment(const 
   return nsContentUtils::CreateContextualFragment(mStart.Container(), aFragment,
                                                   false, aRv);
 }
 
 static void ExtractRectFromOffset(nsIFrame* aFrame,
                                   const int32_t aOffset, nsRect* aR,
                                   bool aFlushToOriginEdge, bool aClampToEdge)
 {
+  MOZ_ASSERT(aFrame);
+  MOZ_ASSERT(aR);
+
   nsPoint point;
   aFrame->GetPointFromOffset(aOffset, &point);
 
-  // Determine if point was generated from a vertical text run, which will change
-  // our math on the output rect.
-  bool isVertical = false;
-  if (aFrame->IsTextFrame()) {
-    nsTextFrame* textFrame = static_cast<nsTextFrame*>(aFrame);
-    isVertical = textFrame->GetTextRun(nsTextFrame::eInflated)->IsVertical();
-  }
+  // Determine if aFrame has a vertical writing mode, which will change our math
+  // on the output rect.
+  bool isVertical = aFrame->GetWritingMode().IsVertical();
 
   if (!aClampToEdge && !aR->Contains(point)) {
     // If point is outside aR, and we aren't clamping, output an empty rect
     // with origin at the point.
     if (isVertical) {
       aR->SetHeight(0);
       aR->y = point.y;
     } else {