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 399831 8d29d282fb08403ee5906a5c42142b74924b47f4
parent 399830 0463821ba70963199be2735fce079b7afa7e747f
child 399832 c037dbc573ea1e9f6fd92b2fd33b7135fb3e3ef6
push id26007
push usermasayuki@d-toybox.com
push dateFri, 12 Aug 2016 06:30:02 +0000
reviewersm_kato
bugs1286464
milestone51.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++) {