Bug 1450208: Change nsRange::ExtractRectFromOffset to use simpler, hopefully safer logic to determine whether text is vertical. draft
authorBrad Werth <bwerth@mozilla.com>
Fri, 30 Mar 2018 08:52:53 -0700
changeset 775243 56f6cd45973af775fc476b27e9e36a353c40dd07
parent 775208 44aceee694bec3dc6a7757395d25553ae87ab166
push id104665
push userbwerth@mozilla.com
push dateFri, 30 Mar 2018 17:36:24 +0000
bugs1450208
milestone61.0a1
Bug 1450208: Change nsRange::ExtractRectFromOffset to use simpler, hopefully safer logic to determine whether text is vertical. 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 {