diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 42f8c1aee00..f494910b08b 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -2104,30 +2104,35 @@ nsEditor::NotifyIMEOnFocus() { mNeedRecoverIMEOpenState = PR_FALSE; - if(gDontCareForIMEOnFocusPassword - || !(mFlags & nsIPlaintextEditor::eEditorPasswordMask)) - return NS_OK; - nsCOMPtr kb; nsresult res = GetKBStateControl(getter_AddRefs(kb)); if (NS_FAILED(res)) return res; - if (kb) { - PRBool isOpen; - res = kb->GetIMEOpenState(&isOpen); + if (!kb) + return NS_OK; + + res = kb->CancelIMEComposition(); + if (NS_FAILED(res)) + kb->ResetInputState(); + + if(gDontCareForIMEOnFocusPassword + || !(mFlags & nsIPlaintextEditor::eEditorPasswordMask)) + return NS_OK; + + PRBool isOpen; + res = kb->GetIMEOpenState(&isOpen); + if (NS_FAILED(res)) + return res; + + if (isOpen) { + res = kb->SetIMEOpenState(PR_FALSE); if (NS_FAILED(res)) return res; - - if (isOpen) { - res = kb->SetIMEOpenState(PR_FALSE); - if (NS_FAILED(res)) - return res; - } - - mNeedRecoverIMEOpenState = isOpen; } + mNeedRecoverIMEOpenState = isOpen; + return NS_OK; } diff --git a/widget/public/nsIKBStateControl.h b/widget/public/nsIKBStateControl.h index 7d95a8cb079..b288ae6483d 100644 --- a/widget/public/nsIKBStateControl.h +++ b/widget/public/nsIKBStateControl.h @@ -85,6 +85,10 @@ class nsIKBStateControl : public nsISupports { */ NS_IMETHOD GetIMEOpenState(PRBool* aState) = 0; + /* + * Destruct and don't commit the IME composition string. + */ + NS_IMETHOD CancelIMEComposition() = 0; }; #endif // nsIKBStateControl_h__ diff --git a/widget/src/cocoa/nsChildView.h b/widget/src/cocoa/nsChildView.h index 420216dcf82..15536ebf6da 100644 --- a/widget/src/cocoa/nsChildView.h +++ b/widget/src/cocoa/nsChildView.h @@ -247,6 +247,7 @@ public: NS_IMETHOD ResetInputState(); NS_IMETHOD SetIMEOpenState(PRBool aState); NS_IMETHOD GetIMEOpenState(PRBool* aState); + NS_IMETHOD CancelIMEComposition(); protected: diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index 6ffd1ba3256..6053fab2053 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -2047,6 +2047,11 @@ NS_IMETHODIMP nsChildView::GetIMEOpenState(PRBool* aState) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsChildView::CancelIMEComposition() +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + // // GetQuickDrawPort diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 4eaebec92a7..997aacbfc61 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -2355,6 +2355,10 @@ NS_IMETHODIMP nsWidget::GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsWidget::CancelIMEComposition() { + return NS_ERROR_NOT_IMPLEMENTED; +} + /* virtual */ GtkWindow *nsWidget::GetTopLevelWindow(void) { diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index 54074d94896..a3e8be9f17a 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -172,6 +172,7 @@ public: NS_IMETHOD ResetInputState(); NS_IMETHOD SetIMEOpenState(PRBool aState); NS_IMETHOD GetIMEOpenState(PRBool* aState); + NS_IMETHOD CancelIMEComposition(); void InitEvent(nsGUIEvent& event, nsPoint* aPoint = nsnull); diff --git a/widget/src/mac/nsWindow.cpp b/widget/src/mac/nsWindow.cpp index 0343a9ba220..b9025964731 100644 --- a/widget/src/mac/nsWindow.cpp +++ b/widget/src/mac/nsWindow.cpp @@ -2653,6 +2653,10 @@ NS_IMETHODIMP nsWindow::GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsWindow::CancelIMEComposition() { + return NS_ERROR_NOT_IMPLEMENTED; +} + #if !TARGET_CARBON diff --git a/widget/src/mac/nsWindow.h b/widget/src/mac/nsWindow.h index a2f8c6b38dd..289dfbcc66a 100644 --- a/widget/src/mac/nsWindow.h +++ b/widget/src/mac/nsWindow.h @@ -227,6 +227,7 @@ public: NS_IMETHOD ResetInputState(); NS_IMETHOD SetIMEOpenState(PRBool aState); NS_IMETHOD GetIMEOpenState(PRBool* aState); + NS_IMETHOD CancelIMEComposition(); protected: diff --git a/widget/src/photon/nsWidget.cpp b/widget/src/photon/nsWidget.cpp index 90eb07dadc0..d149ea33f0b 100644 --- a/widget/src/photon/nsWidget.cpp +++ b/widget/src/photon/nsWidget.cpp @@ -229,6 +229,10 @@ NS_IMETHODIMP nsWidget::GetIMEOpenState(PRBool* aState) { return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsWidget::CancelIMEComposition() { + return NS_ERROR_NOT_IMPLEMENTED; + } + //------------------------------------------------------------------------- // // Hide or show this component diff --git a/widget/src/photon/nsWidget.h b/widget/src/photon/nsWidget.h index ad49a7de9b4..81cf71b47b7 100644 --- a/widget/src/photon/nsWidget.h +++ b/widget/src/photon/nsWidget.h @@ -215,6 +215,7 @@ public: NS_IMETHOD ResetInputState(); NS_IMETHOD SetIMEOpenState(PRBool aState); NS_IMETHOD GetIMEOpenState(PRBool* aState); + NS_IMETHOD CancelIMEComposition(); inline void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull) { diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 6927fab46cb..631a998f5bc 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -6554,7 +6554,7 @@ NS_IMETHODIMP nsWindow::ResetInputState() NS_IMETHODIMP nsWindow::SetIMEOpenState(PRBool aState) { #ifdef DEBUG_KBSTATE - printf("SetImeOpenState %s\n", (aState ? "Open" : "Close")); + printf("SetIMEOpenState %s\n", (aState ? "Open" : "Close")); #endif HIMC hIMC; NS_IMM_GETCONTEXT(mWnd, hIMC); @@ -6580,6 +6580,22 @@ NS_IMETHODIMP nsWindow::GetIMEOpenState(PRBool* aState) return NS_OK; } +//========================================================================== +NS_IMETHODIMP nsWindow::CancelIMEComposition() +{ +#ifdef DEBUG_KBSTATE + printf("CancelIMEComposition\n"); +#endif + HIMC hIMC; + NS_IMM_GETCONTEXT(mWnd, hIMC); + if (hIMC) { + BOOL ret = FALSE; + NS_IMM_NOTIFYIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, NULL, ret); + NS_IMM_RELEASECONTEXT(mWnd, hIMC); + } + return NS_OK; +} + #define PT_IN_RECT(pt, rc) ((pt).x>(rc).left && (pt).x <(rc).right && (pt).y>(rc).top && (pt).y<(rc).bottom) diff --git a/widget/src/windows/nsWindow.h b/widget/src/windows/nsWindow.h index 18c115abb7f..791445d4a73 100644 --- a/widget/src/windows/nsWindow.h +++ b/widget/src/windows/nsWindow.h @@ -362,6 +362,7 @@ public: NS_IMETHOD ResetInputState(); NS_IMETHOD SetIMEOpenState(PRBool aState); NS_IMETHOD GetIMEOpenState(PRBool* aState); + NS_IMETHOD CancelIMEComposition(); PRBool IMEMouseHandling(PRUint32 aEventType, PRInt32 aAction, LPARAM lParam); PRBool IMECompositionHitTest(PRUint32 aEventType, POINT * ptPos);