From 5c0f3e03ce4e3a31753808f593d3d1f27185a8bb Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 6 Mar 2013 15:14:34 +0900 Subject: [PATCH] Bug 558976 part.4 Implement nsIWidget::NotifyIME() on GTK r=karlt --- widget/gtk2/nsGtkIMModule.cpp | 7 ++--- widget/gtk2/nsGtkIMModule.h | 2 +- widget/gtk2/nsWindow.cpp | 48 ++++++++++++++++++++++------------- widget/gtk2/nsWindow.h | 4 +-- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/widget/gtk2/nsGtkIMModule.cpp b/widget/gtk2/nsGtkIMModule.cpp index b68d7c473126..902ab4dd53ee 100644 --- a/widget/gtk2/nsGtkIMModule.cpp +++ b/widget/gtk2/nsGtkIMModule.cpp @@ -455,14 +455,15 @@ nsGtkIMModule::ResetIME() } nsresult -nsGtkIMModule::ResetInputState(nsWindow* aCaller) +nsGtkIMModule::CommitIMEComposition(nsWindow* aCaller) { if (MOZ_UNLIKELY(IsDestroyed())) { return NS_OK; } PR_LOG(gGtkIMLog, PR_LOG_ALWAYS, - ("GtkIMModule(%p): ResetInputState, aCaller=%p, mCompositionState=%s", + ("GtkIMModule(%p): CommitIMEComposition, aCaller=%p, " + "mCompositionState=%s", this, aCaller, GetCompositionStateName())); if (aCaller != mLastFocusedWindow) { @@ -558,7 +559,7 @@ nsGtkIMModule::SetInputContext(nsWindow* aCaller, // Release current IME focus if IME is enabled. if (changingEnabledState && IsEditable()) { - ResetInputState(mLastFocusedWindow); + CommitIMEComposition(mLastFocusedWindow); Blur(); } diff --git a/widget/gtk2/nsGtkIMModule.h b/widget/gtk2/nsGtkIMModule.h index c22cde1b1f1c..e53c50b8a908 100644 --- a/widget/gtk2/nsGtkIMModule.h +++ b/widget/gtk2/nsGtkIMModule.h @@ -84,7 +84,7 @@ public: bool aKeyDownEventWasSent = false); // IME related nsIWidget methods. - nsresult ResetInputState(nsWindow* aCaller); + nsresult CommitIMEComposition(nsWindow* aCaller); void SetInputContext(nsWindow* aCaller, const InputContext* aContext, const InputContextAction* aAction); diff --git a/widget/gtk2/nsWindow.cpp b/widget/gtk2/nsWindow.cpp index de13998abea9..518ade3113ba 100644 --- a/widget/gtk2/nsWindow.cpp +++ b/widget/gtk2/nsWindow.cpp @@ -5845,9 +5845,38 @@ nsChildWindow::~nsChildWindow() } NS_IMETHODIMP -nsWindow::ResetInputState() +nsWindow::NotifyIME(NotificationToIME aNotification) { - return mIMModule ? mIMModule->ResetInputState(this) : NS_OK; + if (MOZ_UNLIKELY(!mIMModule)) { + switch (aNotification) { + case NOTIFY_IME_OF_CURSOR_POS_CHANGED: + case REQUEST_TO_COMMIT_COMPOSITION: + case REQUEST_TO_CANCEL_COMPOSITION: + case NOTIFY_IME_OF_FOCUS: + case NOTIFY_IME_OF_BLUR: + return NS_ERROR_NOT_AVAILABLE; + default: + break; + } + } + switch (aNotification) { + // TODO: We should replace NOTIFY_IME_OF_CURSOR_POS_CHANGED with + // NOTIFY_IME_OF_SELECTION_CHANGE. The required behavior is + // really different from committing composition. + case NOTIFY_IME_OF_CURSOR_POS_CHANGED: + case REQUEST_TO_COMMIT_COMPOSITION: + return mIMModule->CommitIMEComposition(this); + case REQUEST_TO_CANCEL_COMPOSITION: + return mIMModule->CancelIMEComposition(this); + case NOTIFY_IME_OF_FOCUS: + mIMModule->OnFocusChangeInGecko(true); + return NS_OK; + case NOTIFY_IME_OF_BLUR: + mIMModule->OnFocusChangeInGecko(false); + return NS_OK; + default: + return NS_ERROR_NOT_IMPLEMENTED; + } } NS_IMETHODIMP_(void) @@ -5878,21 +5907,6 @@ nsWindow::GetInputContext() return context; } -NS_IMETHODIMP -nsWindow::CancelIMEComposition() -{ - return mIMModule ? mIMModule->CancelIMEComposition(this) : NS_OK; -} - -NS_IMETHODIMP -nsWindow::OnIMEFocusChange(bool aFocus) -{ - if (mIMModule) { - mIMModule->OnFocusChangeInGecko(aFocus); - } - return NS_OK; -} - NS_IMETHODIMP nsWindow::GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) { diff --git a/widget/gtk2/nsWindow.h b/widget/gtk2/nsWindow.h index 0bf01979fa90..eda1c932f648 100644 --- a/widget/gtk2/nsWindow.h +++ b/widget/gtk2/nsWindow.h @@ -255,12 +255,10 @@ public: bool DispatchKeyDownEvent(GdkEventKey *aEvent, bool *aIsCancelled); - NS_IMETHOD ResetInputState(); + NS_IMETHOD NotifyIME(NotificationToIME aNotification) MOZ_OVERRIDE; NS_IMETHOD_(void) SetInputContext(const InputContext& aContext, const InputContextAction& aAction); NS_IMETHOD_(InputContext) GetInputContext(); - NS_IMETHOD CancelIMEComposition(); - NS_IMETHOD OnIMEFocusChange(bool aFocus); NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState); // These methods are for toplevel windows only.