From 131b78e65eaec948caa94ae1a60603e05e620007 Mon Sep 17 00:00:00 2001 From: KO Myung-Hun Date: Sun, 15 Jul 2012 10:22:54 +0900 Subject: [PATCH] Bug 768742 Fix a buggy process of compositionupdate event. NPOTDB DONTBUILD OS/2 Only. r=masayuki 1. compositionupdate must be fired before dispatching text event 2. compositionupdate must be fired only if a conversion string was changed --- widget/os2/nsWindow.cpp | 49 +++++++++++++++++++++++++++++------------ widget/os2/nsWindow.h | 1 + 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/widget/os2/nsWindow.cpp b/widget/os2/nsWindow.cpp index 280fbfbb076..a45f7c36a27 100644 --- a/widget/os2/nsWindow.cpp +++ b/widget/os2/nsWindow.cpp @@ -2489,6 +2489,8 @@ bool nsWindow::ImeResultString(HIMI himi) } if (!mIsComposing) { + mLastDispatchedCompositionString.Truncate(); + nsCompositionEvent start(true, NS_COMPOSITION_START, this); InitEvent(start); DispatchWindowEvent(&start); @@ -2502,16 +2504,27 @@ bool nsWindow::ImeResultString(HIMI himi) delete pBuf; + nsAutoString compositionString(outBuf.Elements()); + + if (mLastDispatchedCompositionString != compositionString) { + nsCompositionEvent update(true, NS_COMPOSITION_UPDATE, this); + InitEvent(update); + update.data = compositionString; + mLastDispatchedCompositionString = compositionString; + DispatchWindowEvent(&update); + } + nsTextEvent text(true, NS_TEXT_TEXT, this); InitEvent(text); - text.theText = outBuf.Elements(); + text.theText = compositionString; DispatchWindowEvent(&text); nsCompositionEvent end(true, NS_COMPOSITION_END, this); InitEvent(end); - end.data = text.theText; + end.data = compositionString; DispatchWindowEvent(&end); mIsComposing = false; + mLastDispatchedCompositionString.Truncate(); return true; } @@ -2539,6 +2552,8 @@ bool nsWindow::ImeConversionString(HIMI himi) } if (!mIsComposing) { + mLastDispatchedCompositionString.Truncate(); + nsCompositionEvent start(true, NS_COMPOSITION_START, this); InitEvent(start); DispatchWindowEvent(&start); @@ -2552,17 +2567,27 @@ bool nsWindow::ImeConversionString(HIMI himi) delete pBuf; + nsAutoString compositionString(outBuf.Elements()); + + // Is a conversion string changed ? + if (mLastDispatchedCompositionString != compositionString) { + nsCompositionEvent update(true, NS_COMPOSITION_UPDATE, this); + InitEvent(update); + update.data = compositionString; + mLastDispatchedCompositionString = compositionString; + DispatchWindowEvent(&update); + } + nsAutoTArray textRanges; - // Is there a conversion string ? - if (outBufLen) { + if (!compositionString.IsEmpty()) { nsTextRange newRange; newRange.mStartOffset = 0; - newRange.mEndOffset = outBufLen; + newRange.mEndOffset = compositionString.Length(); newRange.mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT; textRanges.AppendElement(newRange); - newRange.mStartOffset = outBufLen; + newRange.mStartOffset = compositionString.Length(); newRange.mEndOffset = newRange.mStartOffset; newRange.mRangeType = NS_TEXTRANGE_CARETPOSITION; textRanges.AppendElement(newRange); @@ -2570,23 +2595,19 @@ bool nsWindow::ImeConversionString(HIMI himi) nsTextEvent text(true, NS_TEXT_TEXT, this); InitEvent(text); - text.theText = outBuf.Elements(); + text.theText = compositionString; text.rangeArray = textRanges.Elements(); text.rangeCount = textRanges.Length(); DispatchWindowEvent(&text); - if (outBufLen) { - nsCompositionEvent update(true, NS_COMPOSITION_UPDATE, this); - InitEvent(update); - update.data = text.theText; - DispatchWindowEvent(&update); - } else { // IME conversion was canceled ? + if (compositionString.IsEmpty()) { // IME conversion was canceled ? nsCompositionEvent end(true, NS_COMPOSITION_END, this); InitEvent(end); - end.data = text.theText; + end.data = compositionString; DispatchWindowEvent(&end); mIsComposing = false; + mLastDispatchedCompositionString.Truncate(); } return true; diff --git a/widget/os2/nsWindow.h b/widget/os2/nsWindow.h index 8a19a4fda62..1d10c3d03f6 100644 --- a/widget/os2/nsWindow.h +++ b/widget/os2/nsWindow.h @@ -271,6 +271,7 @@ protected: nsCOMPtr mCssCursorImg;// saved by SetCursor(imgIContainer*) nsRefPtr mThebesSurface; bool mIsComposing; + nsString mLastDispatchedCompositionString; #ifdef DEBUG_FOCUS int mWindowIdentifier; // a serial number for each new window #endif