Bug 1226145 - actually check whether the on-screen keyboard is up rather than relying on internal state, r=masayuki

This commit is contained in:
Gijs Kruitbosch 2015-12-16 12:48:12 +00:00
parent b5c7694426
commit 86a420be8d
2 changed files with 23 additions and 13 deletions

View File

@ -46,7 +46,6 @@ bool IMEHandler::sPluginHasFocus = false;
#ifdef NS_ENABLE_TSF
bool IMEHandler::sIsInTSFMode = false;
bool IMEHandler::sIsIMMEnabled = true;
bool IMEHandler::sShowingOnScreenKeyboard = false;
decltype(SetInputScopes)* IMEHandler::sSetInputScopes = nullptr;
#endif // #ifdef NS_ENABLE_TSF
@ -567,7 +566,7 @@ IMEHandler::MaybeShowOnScreenKeyboard()
if (sPluginHasFocus ||
!IsWin8OrLater() ||
!Preferences::GetBool(kOskEnabled, true) ||
sShowingOnScreenKeyboard ||
GetOnScreenKeyboardWindow() ||
IMEHandler::IsKeyboardPresentOnSlate()) {
return;
}
@ -592,8 +591,7 @@ void
IMEHandler::MaybeDismissOnScreenKeyboard()
{
if (sPluginHasFocus ||
!IsWin8OrLater() ||
!sShowingOnScreenKeyboard) {
!IsWin8OrLater()) {
return;
}
@ -915,7 +913,6 @@ IMEHandler::ShowOnScreenKeyboard()
nullptr,
nullptr,
SW_SHOW);
sShowingOnScreenKeyboard = true;
}
// Based on DismissVirtualKeyboard() in Chromium's base/win/win_util.cc.
@ -923,16 +920,24 @@ IMEHandler::ShowOnScreenKeyboard()
void
IMEHandler::DismissOnScreenKeyboard()
{
sShowingOnScreenKeyboard = false;
// Dismiss the virtual keyboard by generating the ESC keystroke
// programmatically.
const wchar_t kOSKClassName[] = L"IPTip_Main_Window";
HWND osk = ::FindWindowW(kOSKClassName, nullptr);
if (::IsWindow(osk) && ::IsWindowEnabled(osk)) {
// Dismiss the virtual keyboard if it's open
HWND osk = GetOnScreenKeyboardWindow();
if (osk) {
::PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
// static
HWND
IMEHandler::GetOnScreenKeyboardWindow()
{
const wchar_t kOSKClassName[] = L"IPTip_Main_Window";
HWND osk = ::FindWindowW(kOSKClassName, nullptr);
if (::IsWindow(osk) && ::IsWindowEnabled(osk)) {
return osk;
}
return nullptr;
}
} // namespace widget
} // namespace mozilla

View File

@ -124,7 +124,6 @@ private:
// If sIMMEnabled is false, any IME messages are not handled in TSF mode.
// Additionally, IME context is always disassociated from focused window.
static bool sIsIMMEnabled;
static bool sShowingOnScreenKeyboard;
static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
static bool IsIMMActive();
@ -148,6 +147,12 @@ private:
* Windows 8 and higher.
*/
static void DismissOnScreenKeyboard();
/**
* Get the HWND for the on-screen keyboard, if it's up. Only
* allowed for Windows 8 and higher.
*/
static HWND GetOnScreenKeyboardWindow();
#endif // #ifdef NS_ENABLE_TSF
};