2013-02-25 08:00:05 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "WinIMEHandler.h"
|
2014-01-14 06:00:59 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
#include "IMMHandler.h"
|
2014-01-14 06:00:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2017-06-07 05:42:27 +03:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2013-07-18 12:12:31 +04:00
|
|
|
#include "nsWindowDefs.h"
|
2016-03-16 07:47:48 +03:00
|
|
|
#include "WinTextEventDispatcherListener.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2015-07-24 08:07:39 +03:00
|
|
|
#include "TSFTextStore.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-08-05 17:38:51 +03:00
|
|
|
#include "nsLookAndFeel.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
#include "nsWindow.h"
|
2013-03-18 08:41:24 +04:00
|
|
|
#include "WinUtils.h"
|
2015-09-02 19:12:10 +03:00
|
|
|
#include "nsIWindowsRegKey.h"
|
2015-08-13 21:23:54 +03:00
|
|
|
#include "nsIWindowsUIUtils.h"
|
2013-02-25 08:00:05 +04:00
|
|
|
|
2015-08-05 17:38:51 +03:00
|
|
|
#include "shellapi.h"
|
2015-08-13 18:37:57 +03:00
|
|
|
#include "shlobj.h"
|
|
|
|
#include "powrprof.h"
|
|
|
|
#include "setupapi.h"
|
2015-08-05 17:38:51 +03:00
|
|
|
#include "cfgmgr32.h"
|
|
|
|
|
|
|
|
const char* kOskPathPrefName = "ui.osk.on_screen_keyboard_path";
|
|
|
|
const char* kOskEnabled = "ui.osk.enabled";
|
|
|
|
const char* kOskDetectPhysicalKeyboard = "ui.osk.detect_physical_keyboard";
|
2015-10-16 18:28:13 +03:00
|
|
|
const char* kOskRequireWin10 = "ui.osk.require_win10";
|
2015-10-08 18:51:47 +03:00
|
|
|
const char* kOskDebugReason = "ui.osk.debug.keyboardDisplayReason";
|
2015-08-05 17:38:51 +03:00
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* IMEHandler
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-11-17 10:47:06 +03:00
|
|
|
nsWindow* IMEHandler::sFocusedWindow = nullptr;
|
2015-11-12 19:36:19 +03:00
|
|
|
InputContextAction::Cause IMEHandler::sLastContextActionCause =
|
|
|
|
InputContextAction::CAUSE_UNKNOWN;
|
Bug 1409155 - IMEHandler should not associate IMC with any window if active IME is ATOK 2010 or earlier with x64 build on Win8 or later r=m_kato
ATOK started to be TIP of TSF since 2011. Older than it, i.e., ATOK 2010 and
earlier have a lot of problems even for daily use. Perhaps, the reason is
Win 8 has a lot of changes around IMM-IME support and TSF, and ATOK 2010 is
released earlier than Win 8.
ATOK 2006 crashes while converting a word with candidate window.
ATOK 2007 doesn't paint and resize suggest window and candidate window
correctly (showing white window or too big window).
ATOK 2008 and ATOK 2009 crash when user just opens their open state.
ATOK 2010 isn't installable newly on Win 7 or later, but we have a lot of
crash reports.
Note that ATOK 2006 is the first version supporting Win XP x64. So, ATOK 2005
must not support x64 apps.
Unfortunately, we cannot block loading DLLs of them. Therefore, IMEHandler
should disassociate IMC from active window when user changes active keyboard
layout to the legacy ATOK and not associate IME with any window when
SetInputContext() is called even with "enabled". Additionally, when user
changes active keyboard layout from the legacy ATOK to one of the other
keyboard layouts, IMEHandler should associate IMC with current window for
new active IME.
MozReview-Commit-ID: RVYwmYxzO7
--HG--
extra : rebase_source : c237a3aca6ceb6a1f7251bd9421e4b905be5bc6c
2017-10-25 17:51:27 +03:00
|
|
|
bool IMEHandler::sForceDisableCurrentIMM_IME = false;
|
2015-11-17 10:47:06 +03:00
|
|
|
bool IMEHandler::sPluginHasFocus = false;
|
2015-11-12 19:36:19 +03:00
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
bool IMEHandler::sIsInTSFMode = false;
|
2014-01-14 06:00:59 +04:00
|
|
|
bool IMEHandler::sIsIMMEnabled = true;
|
2017-06-07 05:42:27 +03:00
|
|
|
bool IMEHandler::sAssociateIMCOnlyWhenIMM_IMEActive = false;
|
2014-02-18 02:32:52 +04:00
|
|
|
decltype(SetInputScopes)* IMEHandler::sSetInputScopes = nullptr;
|
2013-02-25 08:00:05 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-10-16 19:47:25 +03:00
|
|
|
static POWER_PLATFORM_ROLE sPowerPlatformRole = PlatformRoleUnspecified;
|
|
|
|
static bool sDeterminedPowerPlatformRole = false;
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::Initialize()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::Initialize();
|
|
|
|
sIsInTSFMode = TSFTextStore::IsInTSFMode();
|
2014-01-14 06:00:59 +04:00
|
|
|
sIsIMMEnabled =
|
|
|
|
!sIsInTSFMode || Preferences::GetBool("intl.tsf.support_imm", true);
|
2017-06-07 05:42:27 +03:00
|
|
|
sAssociateIMCOnlyWhenIMM_IMEActive =
|
|
|
|
sIsIMMEnabled &&
|
|
|
|
Preferences::GetBool("intl.tsf.associate_imc_only_when_imm_ime_is_active",
|
|
|
|
false);
|
2013-04-29 19:41:45 +04:00
|
|
|
if (!sIsInTSFMode) {
|
2015-07-24 08:07:39 +03:00
|
|
|
// When full TSFTextStore is not available, try to use SetInputScopes API
|
2013-06-27 20:06:45 +04:00
|
|
|
// to enable at least InputScope. Use GET_MODULE_HANDLE_EX_FLAG_PIN to
|
|
|
|
// ensure that msctf.dll will not be unloaded.
|
|
|
|
HMODULE module = nullptr;
|
|
|
|
if (GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_PIN, L"msctf.dll",
|
|
|
|
&module)) {
|
2014-02-18 02:32:52 +04:00
|
|
|
sSetInputScopes = reinterpret_cast<decltype(SetInputScopes)*>(
|
2013-06-27 20:06:45 +04:00
|
|
|
GetProcAddress(module, "SetInputScopes"));
|
|
|
|
}
|
2013-04-29 19:41:45 +04:00
|
|
|
}
|
2013-02-25 08:00:05 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Initialize();
|
Bug 1409155 - IMEHandler should not associate IMC with any window if active IME is ATOK 2010 or earlier with x64 build on Win8 or later r=m_kato
ATOK started to be TIP of TSF since 2011. Older than it, i.e., ATOK 2010 and
earlier have a lot of problems even for daily use. Perhaps, the reason is
Win 8 has a lot of changes around IMM-IME support and TSF, and ATOK 2010 is
released earlier than Win 8.
ATOK 2006 crashes while converting a word with candidate window.
ATOK 2007 doesn't paint and resize suggest window and candidate window
correctly (showing white window or too big window).
ATOK 2008 and ATOK 2009 crash when user just opens their open state.
ATOK 2010 isn't installable newly on Win 7 or later, but we have a lot of
crash reports.
Note that ATOK 2006 is the first version supporting Win XP x64. So, ATOK 2005
must not support x64 apps.
Unfortunately, we cannot block loading DLLs of them. Therefore, IMEHandler
should disassociate IMC from active window when user changes active keyboard
layout to the legacy ATOK and not associate IME with any window when
SetInputContext() is called even with "enabled". Additionally, when user
changes active keyboard layout from the legacy ATOK to one of the other
keyboard layouts, IMEHandler should associate IMC with current window for
new active IME.
MozReview-Commit-ID: RVYwmYxzO7
--HG--
extra : rebase_source : c237a3aca6ceb6a1f7251bd9421e4b905be5bc6c
2017-10-25 17:51:27 +03:00
|
|
|
|
|
|
|
sForceDisableCurrentIMM_IME = IMMHandler::IsActiveIMEInBlockList();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::Terminate()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::Terminate();
|
2013-02-25 08:00:05 +04:00
|
|
|
sIsInTSFMode = false;
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::Terminate();
|
2016-03-16 07:47:48 +03:00
|
|
|
WinTextEventDispatcherListener::Shutdown();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:07 +04:00
|
|
|
// static
|
|
|
|
void*
|
2015-12-11 09:15:57 +03:00
|
|
|
IMEHandler::GetNativeData(nsWindow* aWindow, uint32_t aDataType)
|
2013-02-25 08:00:07 +04:00
|
|
|
{
|
2015-12-11 09:15:57 +03:00
|
|
|
if (aDataType == NS_RAW_NATIVE_IME_CONTEXT) {
|
2015-12-11 09:15:57 +03:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (IsTSFAvailable()) {
|
|
|
|
return TSFTextStore::GetThreadManager();
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
IMEContext context(aWindow);
|
|
|
|
if (context.IsValid()) {
|
|
|
|
return context.get();
|
|
|
|
}
|
|
|
|
// If IMC isn't associated with the window, IME is disabled on the window
|
|
|
|
// now. In such case, we should return default IMC instead.
|
|
|
|
const IMEContext& defaultIMC = aWindow->DefaultIMC();
|
|
|
|
if (defaultIMC.IsValid()) {
|
|
|
|
return defaultIMC.get();
|
|
|
|
}
|
|
|
|
// If there is no default IMC, we should return the pointer to the window
|
|
|
|
// since if we return nullptr, IMEStateManager cannot manage composition
|
|
|
|
// with TextComposition instance. This is possible if no IME is installed,
|
|
|
|
// but composition may occur with dead key sequence.
|
|
|
|
return aWindow;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:07 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2015-07-24 08:07:39 +03:00
|
|
|
void* result = TSFTextStore::GetNativeData(aDataType);
|
2013-02-25 08:00:07 +04:00
|
|
|
if (!result || !(*(static_cast<void**>(result)))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// XXX During the TSF module test, sIsInTSFMode must be true. After that,
|
|
|
|
// the value should be restored but currently, there is no way for that.
|
|
|
|
// When the TSF test is enabled again, we need to fix this. Perhaps,
|
|
|
|
// sending a message can fix this.
|
|
|
|
sIsInTSFMode = true;
|
|
|
|
return result;
|
|
|
|
#else // #ifdef NS_ENABLE_TSF
|
|
|
|
return nullptr;
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF #else
|
|
|
|
}
|
|
|
|
|
2013-03-18 08:41:24 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::ProcessRawKeyMessage(const MSG& aMsg)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (IsTSFAvailable()) {
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::ProcessRawKeyMessage(aMsg);
|
2013-03-18 08:41:24 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
return false; // noting to do in IMM mode.
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::ProcessMessage(nsWindow* aWindow, UINT aMessage,
|
|
|
|
WPARAM& aWParam, LPARAM& aLParam,
|
2013-07-18 12:12:31 +04:00
|
|
|
MSGResult& aResult)
|
2013-02-25 08:00:05 +04:00
|
|
|
{
|
2016-01-18 15:14:43 +03:00
|
|
|
if (aMessage == MOZ_WM_DISMISS_ONSCREEN_KEYBOARD) {
|
|
|
|
if (!sFocusedWindow) {
|
|
|
|
DismissOnScreenKeyboard();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult);
|
2014-01-14 06:01:00 +04:00
|
|
|
if (aResult.mConsumed) {
|
2013-02-25 08:00:05 +04:00
|
|
|
return true;
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
// If we don't support IMM in TSF mode, we don't use IMMHandler.
|
2014-01-14 06:01:00 +04:00
|
|
|
if (!sIsIMMEnabled) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
// IME isn't implemented with IMM, IMMHandler shouldn't handle any
|
2014-01-14 06:01:00 +04:00
|
|
|
// messages.
|
2017-06-08 17:55:57 +03:00
|
|
|
if (!IsIMMActive()) {
|
2014-01-14 06:01:00 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
Bug 1409155 - IMEHandler should not associate IMC with any window if active IME is ATOK 2010 or earlier with x64 build on Win8 or later r=m_kato
ATOK started to be TIP of TSF since 2011. Older than it, i.e., ATOK 2010 and
earlier have a lot of problems even for daily use. Perhaps, the reason is
Win 8 has a lot of changes around IMM-IME support and TSF, and ATOK 2010 is
released earlier than Win 8.
ATOK 2006 crashes while converting a word with candidate window.
ATOK 2007 doesn't paint and resize suggest window and candidate window
correctly (showing white window or too big window).
ATOK 2008 and ATOK 2009 crash when user just opens their open state.
ATOK 2010 isn't installable newly on Win 7 or later, but we have a lot of
crash reports.
Note that ATOK 2006 is the first version supporting Win XP x64. So, ATOK 2005
must not support x64 apps.
Unfortunately, we cannot block loading DLLs of them. Therefore, IMEHandler
should disassociate IMC from active window when user changes active keyboard
layout to the legacy ATOK and not associate IME with any window when
SetInputContext() is called even with "enabled". Additionally, when user
changes active keyboard layout from the legacy ATOK to one of the other
keyboard layouts, IMEHandler should associate IMC with current window for
new active IME.
MozReview-Commit-ID: RVYwmYxzO7
--HG--
extra : rebase_source : c237a3aca6ceb6a1f7251bd9421e4b905be5bc6c
2017-10-25 17:51:27 +03:00
|
|
|
bool keepGoing =
|
|
|
|
IMMHandler::ProcessMessage(aWindow, aMessage, aWParam, aLParam, aResult);
|
|
|
|
|
|
|
|
// If user changes active IME to an IME which is listed in our block list,
|
|
|
|
// we should disassociate IMC from the window for preventing the IME to work
|
|
|
|
// and crash.
|
|
|
|
if (aMessage == WM_INPUTLANGCHANGE) {
|
|
|
|
bool disableIME = IMMHandler::IsActiveIMEInBlockList();
|
|
|
|
if (disableIME != sForceDisableCurrentIMM_IME) {
|
|
|
|
bool enable =
|
|
|
|
!disableIME && WinUtils::IsIMEEnabled(aWindow->InputContextRef());
|
|
|
|
AssociateIMEContext(aWindow, enable);
|
|
|
|
sForceDisableCurrentIMM_IME = disableIME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return keepGoing;
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
2014-10-16 05:02:29 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsIMMActive()
|
|
|
|
{
|
2017-06-07 05:42:27 +03:00
|
|
|
return TSFTextStore::IsIMM_IMEActive();
|
2014-10-16 05:02:29 +04:00
|
|
|
}
|
2017-06-07 05:42:27 +03:00
|
|
|
|
2014-10-16 05:02:29 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsComposing()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::IsComposing() || IMMHandler::IsComposing();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
return IMMHandler::IsComposing();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsComposingOn(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::IsComposingOn(aWindow) ||
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::IsComposingOn(aWindow);
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
return IMMHandler::IsComposingOn(aWindow);
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
nsresult
|
|
|
|
IMEHandler::NotifyIME(nsWindow* aWindow,
|
2014-02-18 04:00:15 +04:00
|
|
|
const IMENotification& aIMENotification)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2014-02-18 04:00:15 +04:00
|
|
|
switch (aIMENotification.mMessage) {
|
2014-10-16 05:02:29 +04:00
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE: {
|
2015-07-24 08:07:39 +03:00
|
|
|
nsresult rv = TSFTextStore::OnSelectionChange(aIMENotification);
|
2015-07-23 06:31:28 +03:00
|
|
|
// If IMM IME is active, we need to notify IMMHandler of updating
|
2014-10-16 05:02:29 +04:00
|
|
|
// composition change. It will adjust candidate window position or
|
|
|
|
// composition window position.
|
2015-07-22 06:40:32 +03:00
|
|
|
bool isIMMActive = IsIMMActive();
|
|
|
|
if (isIMMActive) {
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnUpdateComposition(aWindow);
|
2014-10-16 05:02:29 +04:00
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnSelectionChange(aWindow, aIMENotification, isIMMActive);
|
2014-10-16 05:02:29 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2016-05-31 05:39:15 +03:00
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
2015-07-23 06:31:28 +03:00
|
|
|
// If IMM IME is active, we need to notify IMMHandler of updating
|
2014-10-16 05:02:29 +04:00
|
|
|
// composition change. It will adjust candidate window position or
|
|
|
|
// composition window position.
|
|
|
|
if (IsIMMActive()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnUpdateComposition(aWindow);
|
2015-06-17 08:00:33 +03:00
|
|
|
} else {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::OnUpdateComposition();
|
2014-10-16 05:02:29 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2014-02-18 04:00:15 +04:00
|
|
|
case NOTIFY_IME_OF_TEXT_CHANGE:
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::OnTextChange(aIMENotification);
|
2015-08-05 17:38:51 +03:00
|
|
|
case NOTIFY_IME_OF_FOCUS: {
|
2015-11-17 10:47:06 +03:00
|
|
|
sFocusedWindow = aWindow;
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnFocusChange(true, aWindow);
|
2015-08-05 17:38:51 +03:00
|
|
|
nsresult rv =
|
|
|
|
TSFTextStore::OnFocusChange(true, aWindow,
|
|
|
|
aWindow->GetInputContext());
|
|
|
|
IMEHandler::MaybeShowOnScreenKeyboard();
|
|
|
|
return rv;
|
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
case NOTIFY_IME_OF_BLUR:
|
2015-11-17 10:47:06 +03:00
|
|
|
sFocusedWindow = nullptr;
|
2016-01-18 15:14:43 +03:00
|
|
|
IMEHandler::MaybeDismissOnScreenKeyboard(aWindow);
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnFocusChange(false, aWindow);
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::OnFocusChange(false, aWindow,
|
|
|
|
aWindow->GetInputContext());
|
2014-08-29 14:08:43 +04:00
|
|
|
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
|
2014-10-16 05:02:29 +04:00
|
|
|
// If IMM IME is active, we should send a mouse button event via IMM.
|
|
|
|
if (IsIMMActive()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
return IMMHandler::OnMouseButtonEvent(aWindow, aIMENotification);
|
2014-10-16 05:02:29 +04:00
|
|
|
}
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::OnMouseButtonEvent(aIMENotification);
|
2013-02-25 08:00:06 +04:00
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
2015-07-24 08:07:39 +03:00
|
|
|
if (TSFTextStore::IsComposingOn(aWindow)) {
|
|
|
|
TSFTextStore::CommitComposition(false);
|
2014-10-16 05:02:29 +04:00
|
|
|
} else if (IsIMMActive()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::CommitComposition(aWindow);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
2015-07-24 08:07:39 +03:00
|
|
|
if (TSFTextStore::IsComposingOn(aWindow)) {
|
|
|
|
TSFTextStore::CommitComposition(true);
|
2014-10-16 05:02:29 +04:00
|
|
|
} else if (IsIMMActive()) {
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::CancelComposition(aWindow);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2014-02-28 11:45:16 +04:00
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::OnLayoutChange();
|
2013-02-25 08:00:06 +04:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
2014-02-18 04:00:15 +04:00
|
|
|
switch (aIMENotification.mMessage) {
|
2013-02-25 08:00:06 +04:00
|
|
|
case REQUEST_TO_COMMIT_COMPOSITION:
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::CommitComposition(aWindow);
|
2013-02-25 08:00:06 +04:00
|
|
|
return NS_OK;
|
|
|
|
case REQUEST_TO_CANCEL_COMPOSITION:
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::CancelComposition(aWindow);
|
2013-02-25 08:00:06 +04:00
|
|
|
return NS_OK;
|
2014-03-06 10:13:50 +04:00
|
|
|
case NOTIFY_IME_OF_POSITION_CHANGE:
|
2016-05-31 05:39:15 +03:00
|
|
|
case NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED:
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnUpdateComposition(aWindow);
|
2014-01-16 14:05:09 +04:00
|
|
|
return NS_OK;
|
2015-05-15 04:18:08 +03:00
|
|
|
case NOTIFY_IME_OF_SELECTION_CHANGE:
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnSelectionChange(aWindow, aIMENotification, true);
|
2015-05-15 04:18:08 +03:00
|
|
|
return NS_OK;
|
2014-09-11 07:41:15 +04:00
|
|
|
case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
|
2015-07-23 06:31:28 +03:00
|
|
|
return IMMHandler::OnMouseButtonEvent(aWindow, aIMENotification);
|
2015-07-22 06:40:32 +03:00
|
|
|
case NOTIFY_IME_OF_FOCUS:
|
2016-01-18 15:14:43 +03:00
|
|
|
sFocusedWindow = aWindow;
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnFocusChange(true, aWindow);
|
2015-08-05 17:38:51 +03:00
|
|
|
IMEHandler::MaybeShowOnScreenKeyboard();
|
2015-07-22 06:40:32 +03:00
|
|
|
return NS_OK;
|
2013-02-25 08:00:07 +04:00
|
|
|
case NOTIFY_IME_OF_BLUR:
|
2016-01-18 15:14:43 +03:00
|
|
|
sFocusedWindow = nullptr;
|
|
|
|
IMEHandler::MaybeDismissOnScreenKeyboard(aWindow);
|
2015-07-23 06:31:28 +03:00
|
|
|
IMMHandler::OnFocusChange(false, aWindow);
|
2015-07-22 06:40:32 +03:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
// If a plugin gets focus while TSF has focus, we need to notify TSF of
|
|
|
|
// the blur.
|
2015-07-24 08:07:39 +03:00
|
|
|
if (TSFTextStore::ThinksHavingFocus()) {
|
|
|
|
return TSFTextStore::OnFocusChange(false, aWindow,
|
|
|
|
aWindow->GetInputContext());
|
2013-02-25 08:00:07 +04:00
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
2015-07-22 06:40:32 +03:00
|
|
|
return NS_OK;
|
2013-02-25 08:00:06 +04:00
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
2017-04-11 15:24:55 +03:00
|
|
|
IMENotificationRequests
|
|
|
|
IMEHandler::GetIMENotificationRequests()
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2015-10-10 04:21:02 +03:00
|
|
|
// While a plugin has focus, neither TSFTextStore nor IMMHandler needs
|
|
|
|
// notifications.
|
|
|
|
if (sPluginHasFocus) {
|
2017-04-11 15:24:55 +03:00
|
|
|
return IMENotificationRequests();
|
2015-10-10 04:21:02 +03:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2015-12-22 08:58:48 +03:00
|
|
|
if (!sIsIMMEnabled) {
|
2017-04-11 15:24:55 +03:00
|
|
|
return TSFTextStore::GetIMENotificationRequests();
|
2015-12-22 08:58:48 +03:00
|
|
|
}
|
|
|
|
// Even if TSF is available, the active IME may be an IMM-IME.
|
2017-04-11 15:24:55 +03:00
|
|
|
// Unfortunately, changing the result of GetIMENotificationRequests() while
|
|
|
|
// an editor has focus isn't supported by IMEContentObserver nor
|
2015-12-22 08:58:48 +03:00
|
|
|
// ContentCacheInParent. Therefore, we need to request whole notifications
|
|
|
|
// which are necessary either IMMHandler or TSFTextStore.
|
2017-04-11 15:24:55 +03:00
|
|
|
return IMMHandler::GetIMENotificationRequests() |
|
|
|
|
TSFTextStore::GetIMENotificationRequests();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
2017-04-11 15:24:55 +03:00
|
|
|
return IMMHandler::GetIMENotificationRequests();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:47:48 +03:00
|
|
|
// static
|
|
|
|
TextEventDispatcherListener*
|
|
|
|
IMEHandler::GetNativeTextEventDispatcherListener()
|
|
|
|
{
|
|
|
|
return WinTextEventDispatcherListener::GetInstance();
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::GetOpenState(nsWindow* aWindow)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
2014-10-16 05:02:29 +04:00
|
|
|
if (IsTSFAvailable() && !IsIMMActive()) {
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::GetIMEOpenState();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
#endif //NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
|
|
|
return context.GetOpenState();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2013-02-25 08:00:06 +04:00
|
|
|
void
|
|
|
|
IMEHandler::OnDestroyWindow(nsWindow* aWindow)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2015-11-17 10:47:06 +03:00
|
|
|
// When focus is in remote process, but the window is being destroyed, we
|
|
|
|
// need to clean up TSFTextStore here since NOTIFY_IME_OF_BLUR won't reach
|
|
|
|
// here because TabParent already lost the reference to the nsWindow when
|
|
|
|
// it receives from the remote process.
|
|
|
|
if (sFocusedWindow == aWindow) {
|
2017-07-05 18:47:40 +03:00
|
|
|
MOZ_ASSERT(aWindow->GetInputContext().IsOriginContentProcess(),
|
|
|
|
"input context of focused widget should've been set by a remote process "
|
|
|
|
"if IME focus isn't cleared before destroying the widget");
|
2015-11-17 10:47:06 +03:00
|
|
|
NotifyIME(aWindow, IMENotification(NOTIFY_IME_OF_BLUR));
|
|
|
|
}
|
|
|
|
|
2013-04-29 19:41:45 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:06 +04:00
|
|
|
// We need to do nothing here for TSF. Just restore the default context
|
|
|
|
// if it's been disassociated.
|
2013-04-29 19:41:45 +04:00
|
|
|
if (!sIsInTSFMode) {
|
|
|
|
// MSDN says we need to set IS_DEFAULT to avoid memory leak when we use
|
|
|
|
// SetInputScopes API. Use an empty string to do this.
|
2016-02-01 20:57:29 +03:00
|
|
|
SetInputScopeForIMM32(aWindow, EmptyString(), EmptyString());
|
2013-04-29 19:41:45 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
2014-01-14 06:00:59 +04:00
|
|
|
AssociateIMEContext(aWindow, true);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2017-06-07 05:42:27 +03:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::NeedsToAssociateIMC()
|
|
|
|
{
|
Bug 1409155 - IMEHandler should not associate IMC with any window if active IME is ATOK 2010 or earlier with x64 build on Win8 or later r=m_kato
ATOK started to be TIP of TSF since 2011. Older than it, i.e., ATOK 2010 and
earlier have a lot of problems even for daily use. Perhaps, the reason is
Win 8 has a lot of changes around IMM-IME support and TSF, and ATOK 2010 is
released earlier than Win 8.
ATOK 2006 crashes while converting a word with candidate window.
ATOK 2007 doesn't paint and resize suggest window and candidate window
correctly (showing white window or too big window).
ATOK 2008 and ATOK 2009 crash when user just opens their open state.
ATOK 2010 isn't installable newly on Win 7 or later, but we have a lot of
crash reports.
Note that ATOK 2006 is the first version supporting Win XP x64. So, ATOK 2005
must not support x64 apps.
Unfortunately, we cannot block loading DLLs of them. Therefore, IMEHandler
should disassociate IMC from active window when user changes active keyboard
layout to the legacy ATOK and not associate IME with any window when
SetInputContext() is called even with "enabled". Additionally, when user
changes active keyboard layout from the legacy ATOK to one of the other
keyboard layouts, IMEHandler should associate IMC with current window for
new active IME.
MozReview-Commit-ID: RVYwmYxzO7
--HG--
extra : rebase_source : c237a3aca6ceb6a1f7251bd9421e4b905be5bc6c
2017-10-25 17:51:27 +03:00
|
|
|
return !sForceDisableCurrentIMM_IME &&
|
|
|
|
(!sAssociateIMCOnlyWhenIMM_IMEActive || !IsIMMActive());
|
2017-06-07 05:42:27 +03:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
void
|
2013-03-27 04:04:02 +04:00
|
|
|
IMEHandler::SetInputContext(nsWindow* aWindow,
|
|
|
|
InputContext& aInputContext,
|
|
|
|
const InputContextAction& aAction)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2015-11-12 19:36:19 +03:00
|
|
|
sLastContextActionCause = aAction.mCause;
|
2013-02-25 08:00:06 +04:00
|
|
|
// FYI: If there is no composition, this call will do nothing.
|
2014-02-18 04:00:15 +04:00
|
|
|
NotifyIME(aWindow, IMENotification(REQUEST_TO_COMMIT_COMPOSITION));
|
2013-02-25 08:00:06 +04:00
|
|
|
|
2014-01-14 06:00:59 +04:00
|
|
|
const InputContext& oldInputContext = aWindow->GetInputContext();
|
|
|
|
|
2013-02-25 08:00:07 +04:00
|
|
|
// Assume that SetInputContext() is called only when aWindow has focus.
|
|
|
|
sPluginHasFocus = (aInputContext.mIMEState.mEnabled == IMEState::PLUGIN);
|
|
|
|
|
2015-12-08 17:56:27 +03:00
|
|
|
if (aAction.UserMightRequestOpenVKB()) {
|
|
|
|
IMEHandler::MaybeShowOnScreenKeyboard();
|
|
|
|
}
|
|
|
|
|
2013-05-29 10:34:49 +04:00
|
|
|
bool enable = WinUtils::IsIMEEnabled(aInputContext);
|
2013-02-25 08:00:06 +04:00
|
|
|
bool adjustOpenState = (enable &&
|
|
|
|
aInputContext.mIMEState.mOpen != IMEState::DONT_CHANGE_OPEN_STATE);
|
|
|
|
bool open = (adjustOpenState &&
|
|
|
|
aInputContext.mIMEState.mOpen == IMEState::OPEN);
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:07 +04:00
|
|
|
// Note that even while a plugin has focus, we need to notify TSF of that.
|
2013-02-25 08:00:06 +04:00
|
|
|
if (sIsInTSFMode) {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::SetInputContext(aWindow, aInputContext, aAction);
|
2013-02-25 08:00:07 +04:00
|
|
|
if (IsTSFAvailable()) {
|
2014-01-14 06:00:59 +04:00
|
|
|
if (sIsIMMEnabled) {
|
2017-06-07 05:42:27 +03:00
|
|
|
// Associate IMC with aWindow only when it's necessary.
|
|
|
|
AssociateIMEContext(aWindow, enable && NeedsToAssociateIMC());
|
2014-01-14 06:00:59 +04:00
|
|
|
} else if (oldInputContext.mIMEState.mEnabled == IMEState::PLUGIN) {
|
|
|
|
// Disassociate the IME context from the window when plugin loses focus
|
|
|
|
// in pure TSF mode.
|
|
|
|
AssociateIMEContext(aWindow, false);
|
|
|
|
}
|
2013-03-27 04:04:02 +04:00
|
|
|
if (adjustOpenState) {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::SetIMEOpenState(open);
|
2013-03-27 04:04:02 +04:00
|
|
|
}
|
|
|
|
return;
|
2013-02-25 08:00:07 +04:00
|
|
|
}
|
2013-06-27 20:06:45 +04:00
|
|
|
} else {
|
|
|
|
// Set at least InputScope even when TextStore is not available.
|
2016-02-01 20:57:29 +03:00
|
|
|
SetInputScopeForIMM32(aWindow, aInputContext.mHTMLInputType,
|
|
|
|
aInputContext.mHTMLInputInputmode);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
2013-02-25 08:00:06 +04:00
|
|
|
|
2014-01-14 06:00:59 +04:00
|
|
|
AssociateIMEContext(aWindow, enable);
|
2013-02-25 08:00:06 +04:00
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
2013-02-25 08:00:06 +04:00
|
|
|
if (adjustOpenState) {
|
2015-07-23 06:31:28 +03:00
|
|
|
context.SetOpenState(open);
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
2014-01-14 06:00:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2017-06-07 05:42:27 +03:00
|
|
|
IMEHandler::AssociateIMEContext(nsWindowBase* aWindowBase, bool aEnable)
|
2014-01-14 06:00:59 +04:00
|
|
|
{
|
2017-06-07 05:42:27 +03:00
|
|
|
IMEContext context(aWindowBase);
|
2014-01-14 06:00:59 +04:00
|
|
|
if (aEnable) {
|
2015-07-23 06:31:28 +03:00
|
|
|
context.AssociateDefaultContext();
|
2014-01-14 06:00:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Don't disassociate the context after the window is destroyed.
|
2017-06-07 05:42:27 +03:00
|
|
|
if (aWindowBase->Destroyed()) {
|
2014-01-14 06:00:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-07-23 06:31:28 +03:00
|
|
|
context.Disassociate();
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// static
|
|
|
|
void
|
2013-02-25 08:00:06 +04:00
|
|
|
IMEHandler::InitInputContext(nsWindow* aWindow, InputContext& aInputContext)
|
2013-02-25 08:00:06 +04:00
|
|
|
{
|
2017-09-08 10:26:54 +03:00
|
|
|
MOZ_ASSERT(aWindow);
|
|
|
|
MOZ_ASSERT(aWindow->GetWindowHandle(),
|
|
|
|
"IMEHandler::SetInputContext() requires non-nullptr HWND");
|
|
|
|
|
|
|
|
static bool sInitialized = false;
|
|
|
|
if (!sInitialized) {
|
|
|
|
sInitialized = true;
|
|
|
|
// Some TIPs like QQ Input (Simplified Chinese) may need normal window
|
|
|
|
// (i.e., windows except message window) when initializing themselves.
|
|
|
|
// Therefore, we need to initialize TSF/IMM modules after first normal
|
|
|
|
// window is created. InitInputContext() should be called immediately
|
|
|
|
// after creating each normal window, so, here is a good place to
|
|
|
|
// initialize these modules.
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:06 +04:00
|
|
|
// For a11y, the default enabled state should be 'enabled'.
|
|
|
|
aInputContext.mIMEState.mEnabled = IMEState::ENABLED;
|
|
|
|
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
2015-07-24 08:07:39 +03:00
|
|
|
TSFTextStore::SetInputContext(aWindow, aInputContext,
|
2013-03-27 04:04:02 +04:00
|
|
|
InputContextAction(InputContextAction::CAUSE_UNKNOWN,
|
2017-05-19 09:52:59 +03:00
|
|
|
InputContextAction::WIDGET_CREATED));
|
2014-01-14 06:00:59 +04:00
|
|
|
// IME context isn't necessary in pure TSF mode.
|
|
|
|
if (!sIsIMMEnabled) {
|
|
|
|
AssociateIMEContext(aWindow, false);
|
|
|
|
}
|
2013-02-25 08:00:06 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-12-11 09:15:57 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// NOTE: IMC may be null if IMM module isn't installed.
|
2015-07-23 06:31:28 +03:00
|
|
|
IMEContext context(aWindow);
|
2015-12-11 09:15:57 +03:00
|
|
|
MOZ_ASSERT(context.IsValid() || !CurrentKeyboardLayoutHasIME());
|
|
|
|
#endif // #ifdef DEBUG
|
2013-02-25 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::CurrentKeyboardLayoutHasIME()
|
|
|
|
{
|
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
if (sIsInTSFMode) {
|
2015-07-24 08:07:39 +03:00
|
|
|
return TSFTextStore::CurrentKeyboardLayoutHasIME();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2015-07-23 06:31:28 +03:00
|
|
|
return IMMHandler::IsIMEAvailable();
|
2013-02-25 08:00:05 +04:00
|
|
|
}
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
2017-06-07 05:42:27 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::OnKeyboardLayoutChanged()
|
|
|
|
{
|
2017-06-08 17:55:57 +03:00
|
|
|
// Be aware, this method won't be called until TSFStaticSink starts to
|
|
|
|
// observe active TIP change. If you need to be notified of this, you
|
|
|
|
// need to create TSFStaticSink::Observe() or something and call it
|
|
|
|
// TSFStaticSink::EnsureInitActiveTIPKeyboard() forcibly.
|
|
|
|
|
2017-06-07 05:42:27 +03:00
|
|
|
if (!sIsIMMEnabled || !IsTSFAvailable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-31 18:13:57 +03:00
|
|
|
// We don't need to do anything when sAssociateIMCOnlyWhenIMM_IMEActive is
|
|
|
|
// false because IMContext won't be associated/disassociated when changing
|
|
|
|
// active keyboard layout/IME.
|
|
|
|
if (!sAssociateIMCOnlyWhenIMM_IMEActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-07 05:42:27 +03:00
|
|
|
// If there is no TSFTextStore which has focus, i.e., no editor has focus,
|
|
|
|
// nothing to do here.
|
|
|
|
nsWindowBase* windowBase = TSFTextStore::GetEnabledWindowBase();
|
|
|
|
if (!windowBase) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If IME isn't available, nothing to do here.
|
|
|
|
InputContext inputContext = windowBase->GetInputContext();
|
|
|
|
if (!WinUtils::IsIMEEnabled(inputContext)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Associate or Disassociate IMC if it's necessary.
|
|
|
|
// Note that this does nothing if the window has already associated with or
|
|
|
|
// disassociated from the window.
|
|
|
|
AssociateIMEContext(windowBase, NeedsToAssociateIMC());
|
|
|
|
}
|
|
|
|
|
2013-04-29 19:41:45 +04:00
|
|
|
// static
|
2013-06-27 20:06:45 +04:00
|
|
|
void
|
2013-04-29 19:41:45 +04:00
|
|
|
IMEHandler::SetInputScopeForIMM32(nsWindow* aWindow,
|
2016-02-01 20:57:29 +03:00
|
|
|
const nsAString& aHTMLInputType,
|
|
|
|
const nsAString& aHTMLInputInputmode)
|
2013-04-29 19:41:45 +04:00
|
|
|
{
|
|
|
|
if (sIsInTSFMode || !sSetInputScopes || aWindow->Destroyed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
UINT arraySize = 0;
|
|
|
|
const InputScope* scopes = nullptr;
|
2013-06-27 20:06:45 +04:00
|
|
|
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html
|
|
|
|
if (aHTMLInputType.IsEmpty() || aHTMLInputType.EqualsLiteral("text")) {
|
2016-02-01 20:57:29 +03:00
|
|
|
if (aHTMLInputInputmode.EqualsLiteral("url")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_URL };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
2017-09-29 09:15:14 +03:00
|
|
|
} else if (aHTMLInputInputmode.EqualsLiteral("mozAwesomebar")) {
|
|
|
|
// Even if Awesomebar has focus, user may not input URL directly.
|
|
|
|
// However, on-screen keyboard for URL should be shown because it has
|
|
|
|
// some useful additional keys like ".com" and they are not hindrances
|
|
|
|
// even when inputting non-URL text, e.g., words to search something in
|
|
|
|
// the web. On the other hand, MS-IME for Japanese and Google Japanese
|
|
|
|
// Input make their open state "closed" automatically if we notify them
|
|
|
|
// of URL as the input scope. However, this is very annoying for the
|
|
|
|
// users when they try to input some words to search the web or
|
|
|
|
// bookmark/history items. Therefore, if they are active, we need to
|
|
|
|
// notify them of the default input scope for avoiding this issue.
|
|
|
|
// FYI: We cannot check active TIP without TSF. Therefore, if it's
|
|
|
|
// not in TSF mode, we can check only if active IMM-IME is Google
|
|
|
|
// Japanese Input. Google Japanese Input is a TIP of TSF basically.
|
|
|
|
// However, if the OS is Win7 or it's installed on Win7 but has not
|
|
|
|
// been updated yet even after the OS is upgraded to Win8 or later,
|
|
|
|
// it's installed as IMM-IME.
|
|
|
|
if (IMMHandler::IsGoogleJapaneseInputActive()) {
|
|
|
|
static const InputScope inputScopes[] = { IS_DEFAULT };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else {
|
|
|
|
static const InputScope inputScopes[] = { IS_URL };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
}
|
2016-02-01 20:57:29 +03:00
|
|
|
} else if (aHTMLInputInputmode.EqualsLiteral("email")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputInputmode.EqualsLiteral("tel")) {
|
|
|
|
static const InputScope inputScopes[] =
|
|
|
|
{IS_TELEPHONE_LOCALNUMBER, IS_TELEPHONE_FULLTELEPHONENUMBER};
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputInputmode.EqualsLiteral("numeric")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_NUMBER };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else {
|
|
|
|
static const InputScope inputScopes[] = { IS_DEFAULT };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
}
|
2013-06-27 20:06:45 +04:00
|
|
|
} else if (aHTMLInputType.EqualsLiteral("url")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_URL };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("search")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_SEARCH };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("email")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_EMAIL_SMTPEMAILADDRESS };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("password")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_PASSWORD };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("datetime") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("datetime-local")) {
|
|
|
|
static const InputScope inputScopes[] = {
|
|
|
|
IS_DATE_FULLDATE, IS_TIME_FULLTIME };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("date") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("month") ||
|
|
|
|
aHTMLInputType.EqualsLiteral("week")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_DATE_FULLDATE };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("time")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_TIME_FULLTIME };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("tel")) {
|
|
|
|
static const InputScope inputScopes[] = {
|
|
|
|
IS_TELEPHONE_FULLTELEPHONENUMBER, IS_TELEPHONE_LOCALNUMBER };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
|
|
|
} else if (aHTMLInputType.EqualsLiteral("number")) {
|
|
|
|
static const InputScope inputScopes[] = { IS_NUMBER };
|
|
|
|
scopes = &inputScopes[0];
|
|
|
|
arraySize = ArrayLength(inputScopes);
|
2013-04-29 19:41:45 +04:00
|
|
|
}
|
|
|
|
if (scopes && arraySize > 0) {
|
|
|
|
sSetInputScopes(aWindow->GetWindowHandle(), scopes, arraySize, nullptr, 0,
|
|
|
|
nullptr, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:38:51 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::MaybeShowOnScreenKeyboard()
|
|
|
|
{
|
2015-08-13 21:23:54 +03:00
|
|
|
if (sPluginHasFocus ||
|
2015-10-16 18:28:13 +03:00
|
|
|
!IsWin8OrLater() ||
|
2015-08-13 21:23:54 +03:00
|
|
|
!Preferences::GetBool(kOskEnabled, true) ||
|
2015-12-16 15:48:12 +03:00
|
|
|
GetOnScreenKeyboardWindow() ||
|
2016-02-09 22:39:55 +03:00
|
|
|
!IMEHandler::NeedOnScreenKeyboard()) {
|
2015-08-05 17:38:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-13 21:23:54 +03:00
|
|
|
|
2015-10-16 18:28:13 +03:00
|
|
|
// On Windows 10 we require tablet mode, unless the user has set the relevant
|
|
|
|
// Windows setting to enable the on-screen keyboard in desktop mode.
|
|
|
|
// We might be disabled specifically on Win8(.1), so we check that afterwards.
|
|
|
|
if (IsWin10OrLater()) {
|
|
|
|
if (!IsInTabletMode() && !AutoInvokeOnScreenKeyboardInDesktopMode()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Preferences::GetBool(kOskRequireWin10, true)) {
|
2015-09-02 19:12:10 +03:00
|
|
|
return;
|
2015-08-13 21:23:54 +03:00
|
|
|
}
|
|
|
|
|
2015-10-08 18:51:47 +03:00
|
|
|
IMEHandler::ShowOnScreenKeyboard();
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2016-01-18 15:14:43 +03:00
|
|
|
IMEHandler::MaybeDismissOnScreenKeyboard(nsWindow* aWindow)
|
2015-08-05 17:38:51 +03:00
|
|
|
{
|
2015-08-13 21:23:54 +03:00
|
|
|
if (sPluginHasFocus ||
|
2015-12-16 15:48:12 +03:00
|
|
|
!IsWin8OrLater()) {
|
2015-08-05 17:38:51 +03:00
|
|
|
return;
|
|
|
|
}
|
2015-08-13 21:23:54 +03:00
|
|
|
|
2016-01-18 15:14:43 +03:00
|
|
|
::PostMessage(aWindow->GetWindowHandle(), MOZ_WM_DISMISS_ONSCREEN_KEYBOARD,
|
|
|
|
0, 0);
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::WStringStartsWithCaseInsensitive(const std::wstring& aHaystack,
|
|
|
|
const std::wstring& aNeedle)
|
|
|
|
{
|
|
|
|
std::wstring lowerCaseHaystack(aHaystack);
|
|
|
|
std::wstring lowerCaseNeedle(aNeedle);
|
|
|
|
std::transform(lowerCaseHaystack.begin(), lowerCaseHaystack.end(),
|
|
|
|
lowerCaseHaystack.begin(), ::tolower);
|
|
|
|
std::transform(lowerCaseNeedle.begin(), lowerCaseNeedle.end(),
|
|
|
|
lowerCaseNeedle.begin(), ::tolower);
|
|
|
|
return wcsstr(lowerCaseHaystack.c_str(),
|
|
|
|
lowerCaseNeedle.c_str()) == lowerCaseHaystack.c_str();
|
|
|
|
}
|
|
|
|
|
2016-02-09 22:39:55 +03:00
|
|
|
// Returns false if a physical keyboard is detected on Windows 8 and up,
|
|
|
|
// or there is some other reason why an onscreen keyboard is not necessary.
|
|
|
|
// Returns true if no keyboard is found and this device looks like it needs
|
|
|
|
// an on-screen keyboard for text input.
|
2015-08-05 17:38:51 +03:00
|
|
|
// static
|
|
|
|
bool
|
2016-02-09 22:39:55 +03:00
|
|
|
IMEHandler::NeedOnScreenKeyboard()
|
2015-08-05 17:38:51 +03:00
|
|
|
{
|
|
|
|
// This function is only supported for Windows 8 and up.
|
|
|
|
if (!IsWin8OrLater()) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason, L"IKPOS: Requires Win8+.");
|
2016-02-09 22:39:55 +03:00
|
|
|
return false;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!Preferences::GetBool(kOskDetectPhysicalKeyboard, true)) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason, L"IKPOS: Detection disabled.");
|
2016-02-09 22:39:55 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the last focus cause was not user-initiated (ie a result of code
|
|
|
|
// setting focus to an element) then don't auto-show a keyboard. This
|
|
|
|
// avoids cases where the keyboard would pop up "just" because e.g. a
|
|
|
|
// web page chooses to focus a search field on the page, even when that
|
|
|
|
// really isn't what the user is trying to do at that moment.
|
|
|
|
if (!InputContextAction::IsUserAction(sLastContextActionCause)) {
|
2015-08-05 17:38:51 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function should be only invoked for machines with touch screens.
|
|
|
|
if ((::GetSystemMetrics(SM_DIGITIZER) & NID_INTEGRATED_TOUCH)
|
|
|
|
!= NID_INTEGRATED_TOUCH) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"IKPOS: Touch screen not found.");
|
2016-02-09 22:39:55 +03:00
|
|
|
return false;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the device is docked, the user is treating the device as a PC.
|
|
|
|
if (::GetSystemMetrics(SM_SYSTEMDOCKED) != 0) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason, L"IKPOS: System docked.");
|
2016-02-09 22:39:55 +03:00
|
|
|
return false;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// To determine whether a keyboard is present on the device, we do the
|
|
|
|
// following:-
|
2016-07-12 15:00:28 +03:00
|
|
|
// 1. If the platform role is that of a mobile or slate device, check the
|
|
|
|
// system metric SM_CONVERTIBLESLATEMODE to see if it is being used
|
|
|
|
// in slate mode. If it is, also check that the last input was a touch.
|
|
|
|
// If all of this is true, then we should show the on-screen keyboard.
|
2015-08-05 17:38:51 +03:00
|
|
|
|
2016-07-12 15:00:28 +03:00
|
|
|
// 2. If step 1 didn't determine we should show the keyboard, we check if
|
2016-02-09 22:39:55 +03:00
|
|
|
// this device has keyboards attached to it.
|
2015-08-05 17:38:51 +03:00
|
|
|
|
|
|
|
// Check if the device is being used as a laptop or a tablet. This can be
|
|
|
|
// checked by first checking the role of the device and then the
|
|
|
|
// corresponding system metric (SM_CONVERTIBLESLATEMODE). If it is being
|
|
|
|
// used as a tablet then we want the OSK to show up.
|
2015-10-16 19:47:25 +03:00
|
|
|
typedef POWER_PLATFORM_ROLE (WINAPI* PowerDeterminePlatformRoleEx)(ULONG Version);
|
|
|
|
if (!sDeterminedPowerPlatformRole) {
|
|
|
|
sDeterminedPowerPlatformRole = true;
|
|
|
|
PowerDeterminePlatformRoleEx power_determine_platform_role =
|
|
|
|
reinterpret_cast<PowerDeterminePlatformRoleEx>(::GetProcAddress(
|
|
|
|
::LoadLibraryW(L"PowrProf.dll"), "PowerDeterminePlatformRoleEx"));
|
|
|
|
if (power_determine_platform_role) {
|
|
|
|
sPowerPlatformRole = power_determine_platform_role(POWER_PLATFORM_ROLE_V2);
|
|
|
|
} else {
|
|
|
|
sPowerPlatformRole = PlatformRoleUnspecified;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 15:00:28 +03:00
|
|
|
// If this a mobile or slate (tablet) device, check if it is in slate mode.
|
|
|
|
// If the last input was touch, ignore whether or not a keyboard is present.
|
|
|
|
if ((sPowerPlatformRole == PlatformRoleMobile ||
|
|
|
|
sPowerPlatformRole == PlatformRoleSlate) &&
|
|
|
|
::GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0 &&
|
|
|
|
sLastContextActionCause == InputContextAction::CAUSE_TOUCH) {
|
|
|
|
Preferences::SetString(kOskDebugReason, L"IKPOS: Mobile/Slate Platform role, in slate mode with touch event.");
|
2016-02-09 22:39:55 +03:00
|
|
|
return true;
|
2015-11-12 19:36:19 +03:00
|
|
|
}
|
2016-07-12 15:00:28 +03:00
|
|
|
|
2016-02-09 22:39:55 +03:00
|
|
|
return !IMEHandler::IsKeyboardPresentOnSlate();
|
|
|
|
}
|
2015-11-12 19:36:19 +03:00
|
|
|
|
2016-02-09 22:39:55 +03:00
|
|
|
// Uses the Setup APIs to enumerate the attached keyboards and returns true
|
|
|
|
// if the keyboard count is 1 or more. While this will work in most cases
|
|
|
|
// it won't work if there are devices which expose keyboard interfaces which
|
|
|
|
// are attached to the machine.
|
|
|
|
// Based on IsKeyboardPresentOnSlate() in Chromium's base/win/win_util.cc.
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsKeyboardPresentOnSlate()
|
|
|
|
{
|
2015-08-05 17:38:51 +03:00
|
|
|
const GUID KEYBOARD_CLASS_GUID =
|
|
|
|
{ 0x4D36E96B, 0xE325, 0x11CE,
|
|
|
|
{ 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } };
|
|
|
|
|
|
|
|
// Query for all the keyboard devices.
|
|
|
|
HDEVINFO device_info =
|
|
|
|
::SetupDiGetClassDevs(&KEYBOARD_CLASS_GUID, nullptr,
|
|
|
|
nullptr, DIGCF_PRESENT);
|
|
|
|
if (device_info == INVALID_HANDLE_VALUE) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason, L"IKPOS: No keyboard info.");
|
2015-08-13 21:23:54 +03:00
|
|
|
return false;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enumerate all keyboards and look for ACPI\PNP and HID\VID devices. If
|
|
|
|
// the count is more than 1 we assume that a keyboard is present. This is
|
|
|
|
// under the assumption that there will always be one keyboard device.
|
|
|
|
for (DWORD i = 0;; ++i) {
|
|
|
|
SP_DEVINFO_DATA device_info_data = { 0 };
|
|
|
|
device_info_data.cbSize = sizeof(device_info_data);
|
|
|
|
if (!::SetupDiEnumDeviceInfo(device_info, i, &device_info_data)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the device ID.
|
|
|
|
wchar_t device_id[MAX_DEVICE_ID_LEN];
|
|
|
|
CONFIGRET status = ::CM_Get_Device_ID(device_info_data.DevInst,
|
|
|
|
device_id,
|
|
|
|
MAX_DEVICE_ID_LEN,
|
|
|
|
0);
|
|
|
|
if (status == CR_SUCCESS) {
|
2016-01-18 16:07:55 +03:00
|
|
|
static const std::wstring BT_HID_DEVICE = L"HID\\{00001124";
|
|
|
|
static const std::wstring BT_HOGP_DEVICE = L"HID\\{00001812";
|
2015-08-05 17:38:51 +03:00
|
|
|
// To reduce the scope of the hack we only look for ACPI and HID\\VID
|
|
|
|
// prefixes in the keyboard device ids.
|
|
|
|
if (IMEHandler::WStringStartsWithCaseInsensitive(device_id,
|
|
|
|
L"ACPI") ||
|
|
|
|
IMEHandler::WStringStartsWithCaseInsensitive(device_id,
|
2016-01-18 16:07:55 +03:00
|
|
|
L"HID\\VID") ||
|
|
|
|
IMEHandler::WStringStartsWithCaseInsensitive(device_id,
|
|
|
|
BT_HID_DEVICE) ||
|
|
|
|
IMEHandler::WStringStartsWithCaseInsensitive(device_id,
|
|
|
|
BT_HOGP_DEVICE)) {
|
2015-08-05 17:38:51 +03:00
|
|
|
// The heuristic we are using is to check the count of keyboards and
|
|
|
|
// return true if the API's report one or more keyboards. Please note
|
|
|
|
// that this will break for non keyboard devices which expose a
|
|
|
|
// keyboard PDO.
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"IKPOS: Keyboard presence confirmed.");
|
2015-08-13 21:23:54 +03:00
|
|
|
return true;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"IKPOS: Lack of keyboard confirmed.");
|
2015-08-13 21:23:54 +03:00
|
|
|
return false;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
2015-09-02 19:12:10 +03:00
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::IsInTabletMode()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIWindowsUIUtils>
|
|
|
|
uiUtils(do_GetService("@mozilla.org/windows-ui-utils;1"));
|
|
|
|
if (NS_WARN_IF(!uiUtils)) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"IITM: nsIWindowsUIUtils not available.");
|
2015-09-02 19:12:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool isInTabletMode = false;
|
|
|
|
uiUtils->GetInTabletMode(&isInTabletMode);
|
2015-10-08 18:51:47 +03:00
|
|
|
if (isInTabletMode) {
|
|
|
|
Preferences::SetString(kOskDebugReason, L"IITM: GetInTabletMode=true.");
|
|
|
|
} else {
|
|
|
|
Preferences::SetString(kOskDebugReason, L"IITM: GetInTabletMode=false.");
|
|
|
|
}
|
2015-09-02 19:12:10 +03:00
|
|
|
return isInTabletMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
bool
|
|
|
|
IMEHandler::AutoInvokeOnScreenKeyboardInDesktopMode()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWindowsRegKey> regKey
|
|
|
|
(do_CreateInstance("@mozilla.org/windows-registry-key;1", &rv));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason, L"AIOSKIDM: "
|
|
|
|
L"nsIWindowsRegKey not available");
|
2015-09-02 19:12:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CURRENT_USER,
|
|
|
|
NS_LITERAL_STRING("SOFTWARE\\Microsoft\\TabletTip\\1.7"),
|
|
|
|
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"AIOSKIDM: failed opening regkey.");
|
2015-09-02 19:12:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// EnableDesktopModeAutoInvoke is an opt-in option from the Windows
|
|
|
|
// Settings to "Automatically show the touch keyboard in windowed apps
|
|
|
|
// when there's no keyboard attached to your device." If the user has
|
|
|
|
// opted-in to this behavior, the tablet-mode requirement is skipped.
|
|
|
|
uint32_t value;
|
|
|
|
rv = regKey->ReadIntValue(NS_LITERAL_STRING("EnableDesktopModeAutoInvoke"),
|
|
|
|
&value);
|
|
|
|
if (NS_FAILED(rv)) {
|
2015-10-08 18:51:47 +03:00
|
|
|
Preferences::SetString(kOskDebugReason,
|
|
|
|
L"AIOSKIDM: failed reading value of regkey.");
|
2015-09-02 19:12:10 +03:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-08 18:51:47 +03:00
|
|
|
if (!!value) {
|
|
|
|
Preferences::SetString(kOskDebugReason, L"AIOSKIDM: regkey value=true.");
|
|
|
|
} else {
|
|
|
|
Preferences::SetString(kOskDebugReason, L"AIOSKIDM: regkey value=false.");
|
|
|
|
}
|
2015-09-02 19:12:10 +03:00
|
|
|
return !!value;
|
|
|
|
}
|
|
|
|
|
2015-08-05 17:38:51 +03:00
|
|
|
// Based on DisplayVirtualKeyboard() in Chromium's base/win/win_util.cc.
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::ShowOnScreenKeyboard()
|
|
|
|
{
|
|
|
|
nsAutoString cachedPath;
|
2017-07-31 03:52:51 +03:00
|
|
|
nsresult result = Preferences::GetString(kOskPathPrefName, cachedPath);
|
2015-08-05 17:38:51 +03:00
|
|
|
if (NS_FAILED(result) || cachedPath.IsEmpty()) {
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
// The path to TabTip.exe is defined at the following registry key.
|
|
|
|
// This is pulled out of the 64-bit registry hive directly.
|
|
|
|
const wchar_t kRegKeyName[] =
|
|
|
|
L"Software\\Classes\\CLSID\\"
|
|
|
|
L"{054AAE20-4BEA-4347-8A35-64A533254A9D}\\LocalServer32";
|
|
|
|
if (!WinUtils::GetRegistryKey(HKEY_LOCAL_MACHINE,
|
|
|
|
kRegKeyName,
|
2015-08-10 02:24:57 +03:00
|
|
|
nullptr,
|
2015-08-05 17:38:51 +03:00
|
|
|
path,
|
|
|
|
sizeof path)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::wstring wstrpath(path);
|
|
|
|
// The path provided by the registry will often contain
|
|
|
|
// %CommonProgramFiles%, which will need to be replaced if it is present.
|
|
|
|
size_t commonProgramFilesOffset = wstrpath.find(L"%CommonProgramFiles%");
|
|
|
|
if (commonProgramFilesOffset != std::wstring::npos) {
|
|
|
|
// The path read from the registry contains the %CommonProgramFiles%
|
|
|
|
// environment variable prefix. On 64 bit Windows the
|
|
|
|
// SHGetKnownFolderPath function returns the common program files path
|
|
|
|
// with the X86 suffix for the FOLDERID_ProgramFilesCommon value.
|
|
|
|
// To get the correct path to TabTip.exe we first read the environment
|
|
|
|
// variable CommonProgramW6432 which points to the desired common
|
|
|
|
// files path. Failing that we fallback to the SHGetKnownFolderPath API.
|
|
|
|
|
|
|
|
// We then replace the %CommonProgramFiles% value with the actual common
|
|
|
|
// files path found in the process.
|
|
|
|
std::wstring commonProgramFilesPath;
|
|
|
|
std::vector<wchar_t> commonProgramFilesPathW6432;
|
|
|
|
DWORD bufferSize = ::GetEnvironmentVariableW(L"CommonProgramW6432",
|
|
|
|
nullptr, 0);
|
|
|
|
if (bufferSize) {
|
|
|
|
commonProgramFilesPathW6432.resize(bufferSize);
|
|
|
|
::GetEnvironmentVariableW(L"CommonProgramW6432",
|
|
|
|
commonProgramFilesPathW6432.data(),
|
|
|
|
bufferSize);
|
|
|
|
commonProgramFilesPath =
|
|
|
|
std::wstring(commonProgramFilesPathW6432.data());
|
|
|
|
} else {
|
|
|
|
PWSTR path = nullptr;
|
|
|
|
HRESULT hres =
|
2017-02-10 06:06:23 +03:00
|
|
|
SHGetKnownFolderPath(FOLDERID_ProgramFilesCommon, 0,
|
|
|
|
nullptr, &path);
|
2015-08-05 17:38:51 +03:00
|
|
|
if (FAILED(hres) || !path) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-10 02:24:57 +03:00
|
|
|
commonProgramFilesPath =
|
|
|
|
static_cast<const wchar_t*>(nsDependentString(path).get());
|
2015-08-05 17:38:51 +03:00
|
|
|
::CoTaskMemFree(path);
|
|
|
|
}
|
|
|
|
wstrpath.replace(commonProgramFilesOffset,
|
|
|
|
wcslen(L"%CommonProgramFiles%"),
|
|
|
|
commonProgramFilesPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedPath.Assign(wstrpath.data());
|
|
|
|
Preferences::SetString(kOskPathPrefName, cachedPath);
|
|
|
|
}
|
|
|
|
|
2015-08-10 02:24:57 +03:00
|
|
|
const char16_t *cachedPathPtr;
|
2015-08-05 17:38:51 +03:00
|
|
|
cachedPath.GetData(&cachedPathPtr);
|
2015-08-10 02:24:57 +03:00
|
|
|
ShellExecuteW(nullptr,
|
|
|
|
L"",
|
|
|
|
char16ptr_t(cachedPathPtr),
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
SW_SHOW);
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Based on DismissVirtualKeyboard() in Chromium's base/win/win_util.cc.
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::DismissOnScreenKeyboard()
|
|
|
|
{
|
2015-12-16 15:48:12 +03:00
|
|
|
// Dismiss the virtual keyboard if it's open
|
|
|
|
HWND osk = GetOnScreenKeyboardWindow();
|
|
|
|
if (osk) {
|
|
|
|
::PostMessage(osk, WM_SYSCOMMAND, SC_CLOSE, 0);
|
|
|
|
}
|
|
|
|
}
|
2015-08-05 17:38:51 +03:00
|
|
|
|
2015-12-16 15:48:12 +03:00
|
|
|
// static
|
|
|
|
HWND
|
|
|
|
IMEHandler::GetOnScreenKeyboardWindow()
|
|
|
|
{
|
2015-08-05 17:38:51 +03:00
|
|
|
const wchar_t kOSKClassName[] = L"IPTip_Main_Window";
|
|
|
|
HWND osk = ::FindWindowW(kOSKClassName, nullptr);
|
2016-02-02 12:40:35 +03:00
|
|
|
if (::IsWindow(osk) && ::IsWindowEnabled(osk) && ::IsWindowVisible(osk)) {
|
2015-12-16 15:48:12 +03:00
|
|
|
return osk;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
2015-12-16 15:48:12 +03:00
|
|
|
return nullptr;
|
2015-08-05 17:38:51 +03:00
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::SetCandidateWindow(nsWindow* aWindow, CANDIDATEFORM* aForm)
|
|
|
|
{
|
|
|
|
if (!sPluginHasFocus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMMHandler::SetCandidateWindow(aWindow, aForm);
|
|
|
|
}
|
|
|
|
|
2015-12-29 16:57:38 +03:00
|
|
|
// static
|
|
|
|
void
|
|
|
|
IMEHandler::DefaultProcOfPluginEvent(nsWindow* aWindow,
|
|
|
|
const NPEvent* aPluginEvent)
|
|
|
|
{
|
|
|
|
if (!sPluginHasFocus) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IMMHandler::DefaultProcOfPluginEvent(aWindow, aPluginEvent);
|
|
|
|
}
|
|
|
|
|
2013-02-25 08:00:05 +04:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|