Bug 555642 part.2 IME handlers on Windows shouldn't append caret range if the caret is in the target clause which doesn't have specific style r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Mon, 17 Aug 2015 20:58:38 +0900
changeset 257996 77f71a695592baff88cc3084dfd41ca3f2830bf7
parent 257995 f84b3c91aeceeeefd94cdf13cd5955d89342d13d
child 257997 d26083c393bf37faeb38d47f330e5d8e3ce0fbd0
push id63789
push usermasayuki@d-toybox.com
push dateMon, 17 Aug 2015 11:58:51 +0000
treeherdermozilla-inbound@77f71a695592 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs555642
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 555642 part.2 IME handlers on Windows shouldn't append caret range if the caret is in the target clause which doesn't have specific style r=m_kato
widget/windows/IMMHandler.cpp
widget/windows/TSFTextStore.cpp
--- a/widget/windows/IMMHandler.cpp
+++ b/widget/windows/IMMHandler.cpp
@@ -1966,25 +1966,37 @@ IMMHandler::CreateTextRangeArray()
   }
 
   if (mCursorPosition == NO_IME_CARET) {
     MOZ_LOG(gIMMLog, LogLevel::Info,
       ("IMM: CreateTextRangeArray, no caret"));
     return textRangeArray.forget();
   }
 
-  int32_t cursor = mCursorPosition;
-  if (uint32_t(cursor) > mCompositionString.Length()) {
+  uint32_t cursor = static_cast<uint32_t>(mCursorPosition);
+  if (cursor > mCompositionString.Length()) {
     MOZ_LOG(gIMMLog, LogLevel::Info,
       ("IMM: CreateTextRangeArray, mCursorPosition=%ld. "
        "This is larger than mCompositionString.Length()=%lu",
        mCursorPosition, mCompositionString.Length()));
     cursor = mCompositionString.Length();
   }
 
+  // If caret is in the target clause, the target clause will be painted as
+  // normal selection range.  Since caret shouldn't be in selection range on
+  // Windows, we shouldn't append caret range in such case.
+  const TextRange* targetClause = textRangeArray->GetTargetClause();
+  if (targetClause &&
+      cursor >= targetClause->mStartOffset &&
+      cursor <= targetClause->mEndOffset) {
+    MOZ_LOG(gIMMLog, LogLevel::Info,
+      ("IMM: CreateTextRangeArray, no caret due to it's in the target clause"));
+    return textRangeArray.forget();
+  }
+
   range.mStartOffset = range.mEndOffset = cursor;
   range.mRangeType = NS_TEXTRANGE_CARETPOSITION;
   textRangeArray->AppendElement(range);
 
   MOZ_LOG(gIMMLog, LogLevel::Info,
     ("IMM: CreateTextRangeArray, caret position=%ld",
      range.mStartOffset));
 
--- a/widget/windows/TSFTextStore.cpp
+++ b/widget/windows/TSFTextStore.cpp
@@ -2576,22 +2576,32 @@ TSFTextStore::RecordCompositionUpdateAct
         range.mRangeStyle.IsNoChangeStyle()) {
       range.mRangeStyle.Clear();
       // The looks of selected type is better than others.
       range.mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT;
     }
   }
 
   // The caret position has to be collapsed.
-  LONG caretPosition = currentSel.MaxOffset();
-  caretPosition -= mComposition.mStart;
-  TextRange caretRange;
-  caretRange.mStartOffset = caretRange.mEndOffset = uint32_t(caretPosition);
-  caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
-  action->mRanges->AppendElement(caretRange);
+  uint32_t caretPosition =
+    static_cast<uint32_t>(currentSel.MaxOffset() - mComposition.mStart);
+
+  // If caret is in the target clause and it doesn't have specific style,
+  // the target clause will be painted as normal selection range.  Since caret
+  // shouldn't be in selection range on Windows, we shouldn't append caret
+  // range in such case.
+  const TextRange* targetClause = action->mRanges->GetTargetClause();
+  if (!targetClause || targetClause->mRangeStyle.IsDefined() ||
+      caretPosition < targetClause->mStartOffset ||
+      caretPosition > targetClause->mEndOffset) {
+    TextRange caretRange;
+    caretRange.mStartOffset = caretRange.mEndOffset = caretPosition;
+    caretRange.mRangeType = NS_TEXTRANGE_CARETPOSITION;
+    action->mRanges->AppendElement(caretRange);
+  }
 
   action->mIncomplete = false;
 
   MOZ_LOG(sTextStoreLog, LogLevel::Info,
          ("TSF: 0x%p   TSFTextStore::RecordCompositionUpdateAction() "
           "succeeded", this));
 
   return S_OK;