Bug 1286464 part.2 GetFirstFrameInRange() should return node offset since it may return different node's frame r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 14 Jul 2016 22:57:00 +0900
changeset 394864 9f4ddc601837649f9a936ce3fc55b6518ab9c28d
parent 394863 db18da2365f89019bdbe597c9148f797e0010762
child 394865 68c791e19e9cf7e37a234950c207556d850485c7
push id24655
push usermasayuki@d-toybox.com
push dateMon, 01 Aug 2016 08:00:00 +0000
reviewersm_kato
bugs1286464
milestone50.0a1
Bug 1286464 part.2 GetFirstFrameInRange() should return node offset since it may return different node's frame r?m_kato GetFirstFrameInRange() uses AdjustTextRectNode() which may return different node before retrieving the result frame. Therefore, the caller may need offset in the new node. MozReview-Commit-ID: 2AQU5WfahT9
dom/events/ContentEventHandler.cpp
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1392,30 +1392,30 @@ static nsINode* AdjustTextRectNode(nsINo
         static_cast<int32_t>(static_cast<nsIContent*>(node)->TextLength()) : 1;
     }
   }
   return node;
 }
 
 static
 nsIFrame*
-GetFirstFrameInRange(nsRange* aRange)
+GetFirstFrameInRange(nsRange* aRange, int32_t& aNodeOffset)
 {
   // used to iterate over all contents and their frames
   nsCOMPtr<nsIContentIterator> iter = NS_NewContentIterator();
   iter->Init(aRange);
 
   // get the starting frame
-  int32_t nodeOffset = aRange->StartOffset();
+  aNodeOffset = aRange->StartOffset();
   nsINode* node = iter->GetCurrentNode();
   if (!node) {
-    node = AdjustTextRectNode(aRange->GetStartParent(), nodeOffset);
+    node = AdjustTextRectNode(aRange->GetStartParent(), aNodeOffset);
   }
   nsIFrame* firstFrame = nullptr;
-  GetFrameForTextRect(node, nodeOffset, true, &firstFrame);
+  GetFrameForTextRect(node, aNodeOffset, true, &firstFrame);
   return firstFrame;
 }
 
 nsresult
 ContentEventHandler::OnQueryTextRectArray(WidgetQueryContentEvent* aEvent)
 {
   nsresult rv = Init(aEvent);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -1431,29 +1431,29 @@ ContentEventHandler::OnQueryTextRectArra
   while (offset < kEndOffset) {
     rv = SetRangeFromFlatTextOffset(range, offset, 1, lineBreakType, true,
                                     nullptr);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // get the starting frame
-    nsIFrame* firstFrame = GetFirstFrameInRange(range);
+    int32_t nodeOffset = -1;
+    nsIFrame* firstFrame = GetFirstFrameInRange(range, nodeOffset);
     if (NS_WARN_IF(!firstFrame)) {
       return NS_ERROR_FAILURE;
     }
 
     // get the starting frame rect
     nsRect frameRect(nsPoint(0, 0), firstFrame->GetRect().Size());
     rv = ConvertToRootRelativeOffset(firstFrame, frameRect);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
-    int32_t nodeOffset = range->StartOffset();
     AutoTArray<nsRect, 16> charRects;
     rv = firstFrame->GetCharacterRectsInRange(nodeOffset, kEndOffset - offset,
                                               charRects);
     if (NS_WARN_IF(NS_FAILED(rv)) || NS_WARN_IF(charRects.IsEmpty())) {
       return rv;
     }
 
     for (size_t i = 0; i < charRects.Length(); i++) {