From 4047998c2a0c635c59f41347f0ec7a558726c179 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Mon, 17 Aug 2015 20:58:38 +0900 Subject: [PATCH] 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 | 16 ++++++++++++++-- widget/windows/TSFTextStore.cpp | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/widget/windows/IMMHandler.cpp b/widget/windows/IMMHandler.cpp index 2be682693e99..67a359e7c02f 100644 --- a/widget/windows/IMMHandler.cpp +++ b/widget/windows/IMMHandler.cpp @@ -1971,8 +1971,8 @@ IMMHandler::CreateTextRangeArray() return textRangeArray.forget(); } - int32_t cursor = mCursorPosition; - if (uint32_t(cursor) > mCompositionString.Length()) { + uint32_t cursor = static_cast(mCursorPosition); + if (cursor > mCompositionString.Length()) { MOZ_LOG(gIMMLog, LogLevel::Info, ("IMM: CreateTextRangeArray, mCursorPosition=%ld. " "This is larger than mCompositionString.Length()=%lu", @@ -1980,6 +1980,18 @@ IMMHandler::CreateTextRangeArray() 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); diff --git a/widget/windows/TSFTextStore.cpp b/widget/windows/TSFTextStore.cpp index c70f9ab39e86..16c003b994fe 100644 --- a/widget/windows/TSFTextStore.cpp +++ b/widget/windows/TSFTextStore.cpp @@ -2581,12 +2581,22 @@ TSFTextStore::RecordCompositionUpdateAction() } // 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(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;