diff --git a/widget/src/gtk/nsGtkIMEHelper.cpp b/widget/src/gtk/nsGtkIMEHelper.cpp index c06d8ce02406..35a535df71f5 100644 --- a/widget/src/gtk/nsGtkIMEHelper.cpp +++ b/widget/src/gtk/nsGtkIMEHelper.cpp @@ -54,6 +54,7 @@ static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CI static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); nsIMEStatus *nsIMEGtkIC::gStatus = 0; +nsWindow *nsIMEGtkIC::gGlobalFocusWindow = 0; #endif // USE_XIM nsGtkIMEHelper* nsGtkIMEHelper::gSingleton = nsnull; @@ -987,6 +988,12 @@ nsIMEGtkIC::GetFocusWindow() return mFocusWindow; } +nsWindow * +nsIMEGtkIC::GetGlobalFocusWindow() +{ + return gGlobalFocusWindow; +} + // workaround for kinput2/over-the-spot/ic-per-shell // http://bugzilla.mozilla.org/show_bug.cgi?id=28022 // @@ -1010,6 +1017,8 @@ void nsIMEGtkIC::SetFocusWindow(nsWindow * aFocusWindow) { mFocusWindow = aFocusWindow; + gGlobalFocusWindow = aFocusWindow; + GdkWindow *gdkWindow = (GdkWindow*)aFocusWindow->GetNativeData(NS_NATIVE_WINDOW); if (!gdkWindow) return; diff --git a/widget/src/gtk/nsGtkIMEHelper.h b/widget/src/gtk/nsGtkIMEHelper.h index c9e1bc0cea89..0fbbd6d65f3c 100644 --- a/widget/src/gtk/nsGtkIMEHelper.h +++ b/widget/src/gtk/nsGtkIMEHelper.h @@ -139,6 +139,7 @@ class nsIMEGtkIC { static nsIMEStatus *gStatus; nsWindow *mClientWindow; nsWindow *mFocusWindow; + static nsWindow *gGlobalFocusWindow; nsIMEGtkIC(nsWindow*, GdkFont*, GdkFont*); nsIMEGtkIC(nsWindow*, GdkFont*); GdkICPrivate *mIC; @@ -152,6 +153,7 @@ class nsIMEGtkIC { static nsIMEGtkIC *GetXIC(nsWindow*, GdkFont*); void SetFocusWindow(nsWindow * aFocusWindow); nsWindow* GetFocusWindow(); + nsWindow* GetGlobalFocusWindow(); static void UnsetFocusWindow(); static GdkIMStyle GetInputStyle(); diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index b7455a2c9997..ffc1cf3b4706 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -3746,7 +3746,7 @@ nsWindow::IMEDestroyIC() } // reset parent window for status window - if (xic->mInputStyle & GDK_IM_PREEDIT_CALLBACKS) { + if (xic->mInputStyle & GDK_IM_STATUS_CALLBACKS) { xic->ResetStatusWindow(this); } @@ -3757,11 +3757,26 @@ nsWindow::IMEDestroyIC() delete xic; } else { // xic and mIMEShellWindow are valid - // see discussion in bug 53989 + + nsWindow *gwin = xic->GetGlobalFocusWindow(); nsWindow *fwin = xic->GetFocusWindow(); + + // bug 53989 + // if the current focused widget in xic is being destroyed, + // we need to change focused window to mIMEShellWindow if (fwin && fwin == this) { xic->SetFocusWindow(mIMEShellWindow); xic->UnsetFocusWindow(); + + // bug 142873 + // if focus is already changed before, we need to change + // focus window to the current focused window again for XIC + if (gwin && gwin != this && sFocusWindow == gwin) { + nsIMEGtkIC *focused_xic = gwin->IMEGetInputContext(PR_FALSE); + if (focused_xic) { + focused_xic->SetFocusWindow(gwin); + } + } } } }