diff --git a/widget/windows/WinIMEHandler.cpp b/widget/windows/WinIMEHandler.cpp index 1f81ad23ba2e..702caa98537a 100644 --- a/widget/windows/WinIMEHandler.cpp +++ b/widget/windows/WinIMEHandler.cpp @@ -168,6 +168,34 @@ IMEHandler::GetUpdatePreference() return nsIMEUpdatePreference(false, false); } +void +IMEHandler::SetOpenState(nsWindow* aWindow, bool aOpen) +{ +#ifdef NS_ENABLE_TSF + if (sIsInTSFMode) { + nsTextStore::SetIMEOpenState(aOpen); + return; + } +#endif //NS_ENABLE_TSF + + nsIMEContext IMEContext(aWindow->GetWindowHandle()); + IMEContext.SetOpenState(aOpen); +} + +// static +bool +IMEHandler::GetOpenState(nsWindow* aWindow) +{ +#ifdef NS_ENABLE_TSF + if (sIsInTSFMode) { + return nsTextStore::GetIMEOpenState(); + } +#endif //NS_ENABLE_TSF + + nsIMEContext IMEContext(aWindow->GetWindowHandle()); + return IMEContext.GetOpenState(); +} + #ifdef DEBUG // static bool diff --git a/widget/windows/WinIMEHandler.h b/widget/windows/WinIMEHandler.h index 58fc57c047cc..cfacfd12cc97 100644 --- a/widget/windows/WinIMEHandler.h +++ b/widget/windows/WinIMEHandler.h @@ -67,6 +67,12 @@ public: */ static nsIMEUpdatePreference GetUpdatePreference(); + /** + * Sets and Gets IME open state. + */ + static void SetOpenState(nsWindow* aWindow, bool aOpen); + static bool GetOpenState(nsWindow* aWindow); + /** * "Kakutei-Undo" of ATOK or WXG (both of them are Japanese IME) causes * strange WM_KEYDOWN/WM_KEYUP/WM_CHAR message pattern. So, when this diff --git a/widget/windows/nsIMM32Handler.h b/widget/windows/nsIMM32Handler.h index ccdd9e002fe9..3dd46bea62a3 100644 --- a/widget/windows/nsIMM32Handler.h +++ b/widget/windows/nsIMM32Handler.h @@ -45,6 +45,22 @@ public: return !!mIMC; } + void SetOpenState(bool aOpen) const + { + if (!mIMC) { + return; + } + ::ImmSetOpenStatus(mIMC, aOpen); + } + + bool GetOpenState() const + { + if (!mIMC) { + return false; + } + return (::ImmGetOpenStatus(mIMC) != FALSE); + } + protected: nsIMEContext() { diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index d53d10dbd0e6..0238e42a1004 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -7417,13 +7417,7 @@ nsWindow::SetInputContext(const InputContext& aContext, if (enable && mInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE) { bool open = (mInputContext.mIMEState.mOpen == IMEState::OPEN); -#ifdef NS_ENABLE_TSF - nsTextStore::SetIMEOpenState(open); -#endif //NS_ENABLE_TSF - nsIMEContext IMEContext(mWnd); - if (IMEContext.IsValid()) { - ::ImmSetOpenStatus(IMEContext.get(), open); - } + IMEHandler::SetOpenState(this, open); } } @@ -7433,20 +7427,11 @@ nsWindow::GetInputContext() mInputContext.mIMEState.mOpen = IMEState::CLOSED; switch (mInputContext.mIMEState.mEnabled) { case IMEState::ENABLED: - case IMEState::PLUGIN: { - nsIMEContext IMEContext(mWnd); - if (IMEContext.IsValid()) { - mInputContext.mIMEState.mOpen = - ::ImmGetOpenStatus(IMEContext.get()) ? IMEState::OPEN : - IMEState::CLOSED; - } -#ifdef NS_ENABLE_TSF - if (mInputContext.mIMEState.mOpen == IMEState::CLOSED && - nsTextStore::GetIMEOpenState()) { + case IMEState::PLUGIN: + if (IMEHandler::GetOpenState(this)) { mInputContext.mIMEState.mOpen = IMEState::OPEN; } -#endif //NS_ENABLE_TSF - } + break; } return mInputContext; }