Bug 1275528 part.4 IMMHandler should use insertion point relative query for getting character rect and caret rect r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 15 Jun 2016 13:52:03 +0900
changeset 380003 28e01a70279ca2619a3d04efe978733d90e8235f
parent 380002 05228f50107c2030ab6c442e57a8a8bd851524a1
child 380004 c4a42d69f9092bb3b29c9bb03709b01167f80f3a
push id21107
push usermasayuki@d-toybox.com
push dateMon, 20 Jun 2016 10:09:39 +0000
reviewersm_kato
bugs1275528
milestone50.0a1
Bug 1275528 part.4 IMMHandler should use insertion point relative query for getting character rect and caret rect r?m_kato IMM always queries character rect or caret rect relative to insertion point. Therefore, it makes sense to use the new feature, insertion point relative query content events for them. Then, IMMHandler doesn't need to care mismatch between its cache and actual content information. MozReview-Commit-ID: LCCrJkR77I8
widget/windows/IMMHandler.cpp
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -2167,75 +2167,59 @@ IMMHandler::GetCharacterRectOfSelectedTe
   Selection& selection = GetSelection();
   if (!selection.EnsureValidSelection(aWindow)) {
     MOZ_LOG(gIMMLog, LogLevel::Error,
       ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to "
        "Selection::EnsureValidSelection() failure"));
     return false;
   }
 
-  // The base offset of aOffset is the start of composition string during
-  // composing or the start of selected string not during composing.
-  uint32_t baseOffset =
-    mIsComposing ? mCompositionStart : selection.mOffset;
-
-  CheckedInt<uint32_t> checkingOffset =
-    CheckedInt<uint32_t>(baseOffset) + aOffset;
-  if (NS_WARN_IF(!checkingOffset.isValid()) ||
-      checkingOffset.value() == UINT32_MAX) {
-    MOZ_LOG(gIMMLog, LogLevel::Error,
-      ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to "
-       "aOffset is too large (aOffset=%u, baseOffset=%u, mIsComposing=%s)",
-       aOffset, baseOffset, GetBoolName(mIsComposing)));
-    return false;
-  }
-
   // If the offset is larger than the end of composition string or selected
   // string, we should return false since such case must be a bug of the caller
   // or the active IME.  If it's an IME's bug, we need to set targetLength to
   // aOffset.
   uint32_t targetLength =
     mIsComposing ? mCompositionString.Length() : selection.Length();
   if (NS_WARN_IF(aOffset > targetLength)) {
     MOZ_LOG(gIMMLog, LogLevel::Error,
       ("IMM: GetCharacterRectOfSelectedTextAt, FAILED, due to "
        "aOffset is too large (aOffset=%u, targetLength=%u, mIsComposing=%s)",
        aOffset, targetLength, GetBoolName(mIsComposing)));
     return false;
   }
 
-  uint32_t offset = checkingOffset.value();
-
   // If there is caret, we might be able to use caret rect.
   uint32_t caretOffset = UINT32_MAX;
   // There is a caret only when the normal selection is collapsed.
   if (selection.Collapsed()) {
     if (mIsComposing) {
       // If it's composing, mCursorPosition is the offset to caret in
       // the composition string.
       if (mCursorPosition != NO_IME_CARET) {
         MOZ_ASSERT(mCursorPosition >= 0);
-        caretOffset = mCompositionStart + mCursorPosition;
+        caretOffset = mCursorPosition;
       } else if (!ShouldDrawCompositionStringOurselves() ||
                  mCompositionString.IsEmpty()) {
         // Otherwise, if there is no composition string, we should assume that
         // there is a caret at the start of composition string.
-        caretOffset = mCompositionStart;
+        caretOffset = 0;
       }
     } else {
       // If there is no composition, the selection offset is the caret offset.
-      caretOffset = selection.mOffset;
+      caretOffset = 0;
     }
   }
 
   // If there is a caret and retrieving offset is same as the caret offset,
   // we should use the caret rect.
-  if (offset != caretOffset) {
+  if (aOffset != caretOffset) {
     WidgetQueryContentEvent charRect(true, eQueryTextRect, aWindow);
-    charRect.InitForQueryTextRect(offset, 1);
+    WidgetQueryContentEvent::Options options;
+    options.mRelativeToInsertionPoint = true;
+    charRect.InitForQueryTextRect(aOffset, 1, options);
     aWindow->InitEvent(charRect, &point);
     DispatchEvent(aWindow, charRect);
     if (charRect.mSucceeded) {
       aCharRect = charRect.mReply.mRect;
       if (aWritingMode) {
         *aWritingMode = charRect.GetWritingMode();
       }
       MOZ_LOG(gIMMLog, LogLevel::Debug,
@@ -2253,26 +2237,20 @@ IMMHandler::GetCharacterRectOfSelectedTe
 
 bool
 IMMHandler::GetCaretRect(nsWindow* aWindow,
                          LayoutDeviceIntRect& aCaretRect,
                          WritingMode* aWritingMode)
 {
   LayoutDeviceIntPoint point(0, 0);
 
-  Selection& selection = GetSelection();
-  if (!selection.EnsureValidSelection(aWindow)) {
-    MOZ_LOG(gIMMLog, LogLevel::Error,
-      ("IMM: GetCaretRect, FAILED, due to "
-       "Selection::EnsureValidSelection() failure"));
-    return false;
-  }
-
   WidgetQueryContentEvent caretRect(true, eQueryCaretRect, aWindow);
-  caretRect.InitForQueryCaretRect(selection.mOffset);
+  WidgetQueryContentEvent::Options options;
+  options.mRelativeToInsertionPoint = true;
+  caretRect.InitForQueryCaretRect(0, options);
   aWindow->InitEvent(caretRect, &point);
   DispatchEvent(aWindow, caretRect);
   if (!caretRect.mSucceeded) {
     MOZ_LOG(gIMMLog, LogLevel::Info,
       ("IMM: GetCaretRect, FAILED, due to eQueryCaretRect failure"));
     return false;
   }
   aCaretRect = caretRect.mReply.mRect;