Bug 1286464 part.5 ContentEventHandler::OnQueryTextRectArray() shouldn't append same rect for following character of a lien breaker when the query range starts from middle of the line breaker r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 21 Jul 2016 14:04:43 +0900
changeset 391346 81f023b8a00c87d066330165df20d597bb760afd
parent 391345 513968d74f022cd63ff9d8a78ca44ca2bacf0428
child 391347 fb85f42b4d2fe6fb3f3e69d6e48ec0f116f49c0b
push id23879
push usermasayuki@d-toybox.com
push dateFri, 22 Jul 2016 14:31:05 +0000
reviewerssmaug
bugs1286464
milestone50.0a1
Bug 1286464 part.5 ContentEventHandler::OnQueryTextRectArray() shouldn't append same rect for following character of a lien breaker when the query range starts from middle of the line breaker r?smaug MozReview-Commit-ID: H5gdtAakGcP
dom/events/ContentEventHandler.cpp
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1504,26 +1504,40 @@ ContentEventHandler::OnQueryTextRectArra
 
     // 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;
     }
 
+    bool startsBetweenLineBreaker = false;
     AutoTArray<nsRect, 16> charRects;
 
     bool isLineBreaker = ShouldBreakLineBefore(firstContent, mRootContent);
     if (isLineBreaker) {
       // TODO: If the frame isn't <br> and there was previous text frame or
       //       <br>, we can set the rect to caret rect at the end.  Currently,
       //       this sets the rect to caret rect at the start of the node.
       nsRect brRect =
         GetLineBreakerRectBefore(firstFrame) - firstFrame->GetPosition();
       charRects.AppendElement(brRect);
+      if (kBRLength > 1 && offset == aEvent->mInput.mOffset && offset) {
+        // If the first frame for the previous offset of the query range and
+        // the first frame for the start of query range are same, that means
+        // the start offset is between the first line breaker (i.e., \r[\n).
+        rv = SetRangeFromFlatTextOffset(range, aEvent->mInput.mOffset - 1, 1,
+                                        lineBreakType, true, nullptr);
+        if (NS_WARN_IF(NS_FAILED(rv))) {
+          return NS_ERROR_UNEXPECTED;
+        }
+        FrameAndNodeOffset frameForPrevious =
+          GetFirstFrameHavingFlatTextInRange(range);
+        startsBetweenLineBreaker = frameForPrevious.mFrame == firstFrame.mFrame;
+      }
     } else {
       rv = firstFrame->GetCharacterRectsInRange(firstFrame.mStartOffsetInNode,
                                                 kEndOffset - offset, charRects);
       if (NS_WARN_IF(NS_FAILED(rv)) || NS_WARN_IF(charRects.IsEmpty())) {
         // XXX: If the node isn't a text node and does not cause a line break,
         //      we need to recompute with new range, but how?
         return rv;
       }
@@ -1553,18 +1567,24 @@ ContentEventHandler::OnQueryTextRectArra
       MOZ_ASSERT(kBRLength == 2);
 
       // If it's already reached the end of query range, we don't need to do
       // anymore.
       if (offset == kEndOffset) {
         break;
       }
 
-      // TODO: If the query range is stated between a line breaker, i.e., \r[\n,
-      //       We shouldn't append a rect here.
+      // If the query range starts from between a line breaker, i.e., \r[\n,
+      // the appended rect is for the following character.  So, we don't need
+      // to append same rect anymore.
+      if (startsBetweenLineBreaker) {
+        continue;
+      }
+
+      // Let's append same rect for following character in a line breaker.
       aEvent->mReply.mRectArray.AppendElement(rect);
       offset++;
     }
   }
   aEvent->mSucceeded = true;
   return NS_OK;
 }