Bug 1286464 ContentEventHandler::OnQueryTextRectArray() should support <br> frame handling r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 13 Jul 2016 16:55:06 +0900
changeset 387186 c0ca10455364f315a5b8c09418ee1cdb796de7a9
parent 386985 a2c358ded986e008d8e0f3ee3d8632862b55816e
child 387187 ae96f0dd48ec2525ceac22a6aa48e83663d46f04
push id22909
push usermasayuki@d-toybox.com
push dateWed, 13 Jul 2016 15:14:34 +0000
reviewersm_kato
bugs1286464
milestone50.0a1
Bug 1286464 ContentEventHandler::OnQueryTextRectArray() should support <br> frame handling r?m_kato Currently, ContentEventHandler::OnQueryTextRectArray() supports only text frames. That means that it doesn't support <br> nodes. This causes odd behavior in contentediable editor. It should support <br> frames in special path.
dom/events/ContentEventHandler.cpp
--- a/dom/events/ContentEventHandler.cpp
+++ b/dom/events/ContentEventHandler.cpp
@@ -1442,22 +1442,39 @@ 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;
     }
 
+    int32_t remainingLength =
+      aEvent->mInput.mLength - aEvent->mReply.mRectArray.Length();
+    if (firstFrame->GetType() == nsGkAtoms::brFrame) {
+      rect = LayoutDeviceIntRect::FromUnknownRect(
+               frameRect.ToOutsidePixels(mPresContext->AppUnitsPerDevPixel()));
+      // Ensure at least 1px width and height for avoiding empty rect.
+      rect.height = std::max(1, rect.height);
+      rect.width = std::max(1, rect.width);
+
+      // Append same rects to every character meaning a linebreak.
+      int32_t brLength = static_cast<int32_t>(GetBRLength(lineBreakType));
+      int32_t appendingLength = std::min(brLength, remainingLength);
+      for (int32_t i = 0; i < appendingLength; i++) {
+        aEvent->mReply.mRectArray.AppendElement(rect);
+      }
+      offset += appendingLength;
+      continue;
+    }
+
     int32_t nodeOffset = range->StartOffset();
     AutoTArray<nsRect, 16> charRects;
-    rv = firstFrame->GetCharacterRectsInRange(
-           nodeOffset,
-           aEvent->mInput.mLength - aEvent->mReply.mRectArray.Length(),
-           charRects);
+    rv = firstFrame->GetCharacterRectsInRange(nodeOffset, remainingLength,
+                                              charRects);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     for (size_t i = 0; i < charRects.Length(); i++) {
       nsRect charRect = charRects[i];
       charRect.x += frameRect.x;
       charRect.y += frameRect.y;