Bug 1295354 part.1 ContentEventHandler::GetLastFrameInRangeForTextRect() shouldn't set nextNodeOfRangeEnd to the start node of aRange because the start node should always be in the range r?smaug draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 16 Aug 2016 14:37:40 +0900
changeset 401585 8f6cb8f47211970e20acd3a4b768ab15b2b67931
parent 401500 fe895421dfbe1f1f8f1fc6a39bb20774423a6d74
child 401586 0303775cdadce205fd50a639fbac19fed4e2e50c
push id26499
push usermasayuki@d-toybox.com
push dateWed, 17 Aug 2016 06:15:52 +0000
reviewerssmaug
bugs1295354
milestone51.0a1
Bug 1295354 part.1 ContentEventHandler::GetLastFrameInRangeForTextRect() shouldn't set nextNodeOfRangeEnd to the start node of aRange because the start node should always be in the range r?smaug nextNodeOfRangeEnd is used for excluding unnecessary node for computing text rect. When aRange ends at start of a text node, the frames which are created for the text node shouldn't be used. However, if the end node of aRange is same as the start node of aRange, the node is not outside of aRange. This could occur when it's called with empty range or there are some empty text nodes. MozReview-Commit-ID: C1yCN5WrULe
dom/events/ContentEventHandler.cpp
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1548,17 +1548,21 @@ ContentEventHandler::GetLastFrameInRange
   // +----+
   // So, if this method includes the 2nd text frame's rect to its result, the
   // caller will return too tall rect which includes 2 lines in this case isn't
   // expected by native IME  (e.g., popup of IME will be positioned at bottom
   // of "d" instead of right-bottom of "c").  Therefore, this method shouldn't
   // include the last frame when its content isn't really in aRange.
   nsINode* nextNodeOfRangeEnd = nullptr;
   if (endNode->IsNodeOfType(nsINode::eTEXT)) {
-    if (!endOffset) {
+    // Don't set nextNodeOfRangeEnd to the start node of aRange because if
+    // endNode is same as start node of the range, the text node shouldn't be
+    // next of range end even if the offset is 0.  This could occur with empty
+    // text node.
+    if (!endOffset && aRange->GetStartParent() != endNode) {
       nextNodeOfRangeEnd = endNode;
     }
   } else if (endOffset < endNode->GetChildCount()) {
     nextNodeOfRangeEnd = endNode->GetChildAt(endOffset);
   }
 
   for (iter->Last(); !iter->IsDone(); iter->Prev()) {
     nsINode* node = iter->GetCurrentNode();