2013-02-25 04:00:05 +00: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/. */
|
|
|
|
|
|
|
|
#ifndef WinIMEHandler_h_
|
|
|
|
#define WinIMEHandler_h_
|
|
|
|
|
|
|
|
#include "nscore.h"
|
2017-06-07 02:42:27 +00:00
|
|
|
#include "nsWindowBase.h"
|
2015-12-29 13:57:38 +00:00
|
|
|
#include "npapi.h"
|
2013-02-25 04:00:05 +00:00
|
|
|
#include <windows.h>
|
2013-04-29 15:41:45 +00:00
|
|
|
#include <inputscope.h>
|
2013-02-25 04:00:05 +00:00
|
|
|
|
2013-02-25 04:00:07 +00:00
|
|
|
#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
|
|
|
|
#define NS_WM_IMELAST WM_IME_KEYUP
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
class nsWindow;
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2013-07-18 08:12:31 +00:00
|
|
|
struct MSGResult;
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
/**
|
|
|
|
* IMEHandler class is a mediator class. On Windows, there are two IME API
|
|
|
|
* sets: One is IMM which is legacy API set. The other is TSF which is modern
|
|
|
|
* API set. By using this class, non-IME handler classes don't need to worry
|
|
|
|
* that we're in which mode.
|
|
|
|
*/
|
2015-03-21 16:28:04 +00:00
|
|
|
class IMEHandler final {
|
2017-09-08 07:26:54 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Initialize() initializes both TSF modules and IMM modules. Some TIPs
|
|
|
|
* may require a normal window (i.e., not message window) belonging to
|
|
|
|
* this process. Therefore, this is called immediately after first normal
|
|
|
|
* window is created.
|
|
|
|
*/
|
2013-02-25 04:00:05 +00:00
|
|
|
static void Initialize();
|
2017-09-08 07:26:54 +00:00
|
|
|
|
|
|
|
public:
|
2013-02-25 04:00:05 +00:00
|
|
|
static void Terminate();
|
|
|
|
|
2013-02-25 04:00:07 +00:00
|
|
|
/**
|
2015-12-11 06:15:57 +00:00
|
|
|
* Returns TSF related native data or native IME context.
|
2013-02-25 04:00:07 +00:00
|
|
|
*/
|
2015-12-11 06:15:57 +00:00
|
|
|
static void* GetNativeData(nsWindow* aWindow, uint32_t aDataType);
|
2013-02-25 04:00:07 +00:00
|
|
|
|
2013-03-18 04:41:24 +00:00
|
|
|
/**
|
|
|
|
* ProcessRawKeyMessage() message is called before calling TranslateMessage()
|
|
|
|
* and DispatchMessage(). If this returns true, the message is consumed.
|
|
|
|
* Then, caller must not perform TranslateMessage() nor DispatchMessage().
|
|
|
|
*/
|
|
|
|
static bool ProcessRawKeyMessage(const MSG& aMsg);
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
/**
|
|
|
|
* When the message is not needed to handle anymore by the caller, this
|
|
|
|
* returns true. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool ProcessMessage(nsWindow* aWindow, UINT aMessage, WPARAM& aWParam,
|
2013-07-18 08:12:31 +00:00
|
|
|
LPARAM& aLParam, MSGResult& aResult);
|
2013-02-25 04:00:05 +00:00
|
|
|
|
2018-12-18 10:40:50 +00:00
|
|
|
/**
|
|
|
|
* IsA11yHandlingNativeCaret() returns true if a11y is handling
|
|
|
|
* native caret. In such case, IME modules shouldn't touch native caret.
|
|
|
|
**/
|
|
|
|
static bool IsA11yHandlingNativeCaret();
|
|
|
|
|
2018-12-18 08:38:23 +00:00
|
|
|
/**
|
|
|
|
* NeedsToCreateNativeCaret() returns true if IME handler needs to create
|
|
|
|
* native caret for other applications which requests OBJID_CARET with
|
|
|
|
* WM_GETOBJECT and a11y module isn't active (if a11y module is active,
|
|
|
|
* it always creates native caret, i.e., even if no editor has focus).
|
|
|
|
*/
|
|
|
|
static bool NeedsToCreateNativeCaret() {
|
|
|
|
return sHasNativeCaretBeenRequested && !IsA11yHandlingNativeCaret();
|
|
|
|
}
|
|
|
|
|
2018-12-18 08:38:22 +00:00
|
|
|
/**
|
|
|
|
* CreateNativeCaret() create native caret if this has been created it.
|
|
|
|
*
|
|
|
|
* @param aWindow The window which owns the caret.
|
|
|
|
* @param aCaretRect The caret rect relative to aWindow.
|
|
|
|
*/
|
|
|
|
static bool CreateNativeCaret(nsWindow* aWindow,
|
|
|
|
const LayoutDeviceIntRect& aCaretRect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MaybeDestroyNativeCaret() destroies native caret if it has been created
|
|
|
|
* by IMEHandler.
|
|
|
|
*/
|
|
|
|
static void MaybeDestroyNativeCaret();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HasNativeCaret() returns true if there is native caret and it was created
|
|
|
|
* by IMEHandler.
|
|
|
|
*/
|
|
|
|
static bool HasNativeCaret() { return sNativeCaretIsCreated; }
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
/**
|
|
|
|
* When there is a composition, returns true. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool IsComposing();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When there is a composition and it's in the window, returns true.
|
|
|
|
* Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool IsComposingOn(nsWindow* aWindow);
|
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
|
|
|
* Notifies IME of the notification (a request or an event).
|
|
|
|
*/
|
|
|
|
static nsresult NotifyIME(nsWindow* aWindow,
|
2014-02-18 00:00:15 +00:00
|
|
|
const IMENotification& aIMENotification);
|
2013-02-25 04:00:06 +00:00
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
2017-04-11 12:24:55 +00:00
|
|
|
* Returns notification requests of IME.
|
2013-02-25 04:00:06 +00:00
|
|
|
*/
|
2017-04-11 12:24:55 +00:00
|
|
|
static IMENotificationRequests GetIMENotificationRequests();
|
2013-02-25 04:00:06 +00:00
|
|
|
|
2016-03-16 04:47:48 +00:00
|
|
|
/**
|
|
|
|
* Returns native text event dispatcher listener.
|
|
|
|
*/
|
|
|
|
static TextEventDispatcherListener* GetNativeTextEventDispatcherListener();
|
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
2013-02-25 04:00:06 +00:00
|
|
|
* Returns IME open state on the window.
|
2013-02-25 04:00:06 +00:00
|
|
|
*/
|
|
|
|
static bool GetOpenState(nsWindow* aWindow);
|
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
|
|
|
* Called when the window is destroying.
|
|
|
|
*/
|
|
|
|
static void OnDestroyWindow(nsWindow* aWindow);
|
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
|
|
|
* Called when nsIWidget::SetInputContext() is called before the window's
|
|
|
|
* InputContext is modified actually.
|
|
|
|
*/
|
2013-03-27 00:04:02 +00:00
|
|
|
static void SetInputContext(nsWindow* aWindow, InputContext& aInputContext,
|
|
|
|
const InputContextAction& aAction);
|
2013-02-25 04:00:06 +00:00
|
|
|
|
2014-01-14 02:00:59 +00:00
|
|
|
/**
|
2017-06-07 02:42:27 +00:00
|
|
|
* Associate or disassociate IME context to/from the aWindowBase.
|
2014-01-14 02:00:59 +00:00
|
|
|
*/
|
2017-06-07 02:42:27 +00:00
|
|
|
static void AssociateIMEContext(nsWindowBase* aWindowBase, bool aEnable);
|
2014-01-14 02:00:59 +00:00
|
|
|
|
2013-02-25 04:00:06 +00:00
|
|
|
/**
|
|
|
|
* Called when the window is created.
|
|
|
|
*/
|
|
|
|
static void InitInputContext(nsWindow* aWindow, InputContext& aInputContext);
|
|
|
|
|
2015-12-29 13:57:38 +00:00
|
|
|
/*
|
|
|
|
* For windowless plugin helper.
|
|
|
|
*/
|
|
|
|
static void SetCandidateWindow(nsWindow* aWindow, CANDIDATEFORM* aForm);
|
|
|
|
|
2015-12-29 13:57:38 +00:00
|
|
|
/*
|
|
|
|
* For WM_IME_*COMPOSITION messages and e10s with windowless plugin
|
|
|
|
*/
|
|
|
|
static void DefaultProcOfPluginEvent(nsWindow* aWindow,
|
|
|
|
const NPEvent* aPluginEvent);
|
|
|
|
|
2017-06-07 02:42:27 +00:00
|
|
|
#ifdef NS_ENABLE_TSF
|
|
|
|
/**
|
|
|
|
* This is called by TSFStaticSink when active IME is changed.
|
|
|
|
*/
|
|
|
|
static void OnKeyboardLayoutChanged();
|
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
/**
|
|
|
|
* Returns true when current keyboard layout has IME. Otherwise, false.
|
|
|
|
*/
|
|
|
|
static bool CurrentKeyboardLayoutHasIME();
|
|
|
|
#endif // #ifdef DEBUG
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
private:
|
2015-11-17 07:47:06 +00:00
|
|
|
static nsWindow* sFocusedWindow;
|
2015-11-12 16:36:19 +00:00
|
|
|
static InputContextAction::Cause sLastContextActionCause;
|
|
|
|
|
Bug 1504963 - part 4: Make IMEHandler create native caret over our caret if it's necessary r=Jamie,m_kato
IMMHandler and TSFTextStore are good class to put native caret when they have
enough information. However, for example, IMMHandler may not have its singleton
instance until first composition of IMM-IME starts. Therefore, typically,
IMEHandler is a good class to put native caret without composition.
This patch adds IMEHandler::MaybeCreateNativeCaret(), and if it won't create
native caret because not yet received WM_GETOBJCT for OBJID_CARET, we should
fire window event for MSAA applications. If there is new MSAA application
retrieves OBJID_CARET, we'll receive WM_GETOBJECT for OBJID_CARET
asynchronously. Then, we should start to put native caret for such
applications.
Note that if we create native caret, some versions of ATOK refers the native
caret and the behavior becomes worse than usual. Therefore, we need to
keep not using native caret as far as possible.
Differential Revision: https://phabricator.services.mozilla.com/D13962
--HG--
extra : moz-landing-system : lando
2018-12-18 08:38:23 +00:00
|
|
|
static bool sMaybeEditable;
|
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 14:51:27 +00:00
|
|
|
static bool sForceDisableCurrentIMM_IME;
|
2015-11-17 07:47:06 +00:00
|
|
|
static bool sPluginHasFocus;
|
2018-12-18 08:38:22 +00:00
|
|
|
static bool sNativeCaretIsCreated;
|
2018-12-18 08:38:23 +00:00
|
|
|
static bool sHasNativeCaretBeenRequested;
|
2015-11-17 07:47:06 +00:00
|
|
|
|
Bug 1504963 - part 4: Make IMEHandler create native caret over our caret if it's necessary r=Jamie,m_kato
IMMHandler and TSFTextStore are good class to put native caret when they have
enough information. However, for example, IMMHandler may not have its singleton
instance until first composition of IMM-IME starts. Therefore, typically,
IMEHandler is a good class to put native caret without composition.
This patch adds IMEHandler::MaybeCreateNativeCaret(), and if it won't create
native caret because not yet received WM_GETOBJCT for OBJID_CARET, we should
fire window event for MSAA applications. If there is new MSAA application
retrieves OBJID_CARET, we'll receive WM_GETOBJECT for OBJID_CARET
asynchronously. Then, we should start to put native caret for such
applications.
Note that if we create native caret, some versions of ATOK refers the native
caret and the behavior becomes worse than usual. Therefore, we need to
keep not using native caret as far as possible.
Differential Revision: https://phabricator.services.mozilla.com/D13962
--HG--
extra : moz-landing-system : lando
2018-12-18 08:38:23 +00:00
|
|
|
/**
|
|
|
|
* MaybeCreateNativeCaret() may create native caret over our caret if
|
|
|
|
* focused content is text editable and we need to create native caret
|
|
|
|
* for other applications.
|
|
|
|
*
|
|
|
|
* @param aWindow The window which owns the native caret.
|
|
|
|
*/
|
|
|
|
static bool MaybeCreateNativeCaret(nsWindow* aWindow);
|
|
|
|
|
2013-02-25 04:00:05 +00:00
|
|
|
#ifdef NS_ENABLE_TSF
|
2014-02-17 22:32:52 +00:00
|
|
|
static decltype(SetInputScopes)* sSetInputScopes;
|
2013-04-29 15:41:45 +00:00
|
|
|
static void SetInputScopeForIMM32(nsWindow* aWindow,
|
2016-02-01 17:57:29 +00:00
|
|
|
const nsAString& aHTMLInputType,
|
|
|
|
const nsAString& aHTMLInputInputmode);
|
2013-02-25 04:00:05 +00:00
|
|
|
static bool sIsInTSFMode;
|
2014-01-14 02:00:59 +00:00
|
|
|
// 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;
|
2017-06-07 02:42:27 +00:00
|
|
|
static bool sAssociateIMCOnlyWhenIMM_IMEActive;
|
2013-02-25 04:00:07 +00:00
|
|
|
|
|
|
|
static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
|
2014-10-16 01:02:29 +00:00
|
|
|
static bool IsIMMActive();
|
2015-08-05 14:38:51 +00:00
|
|
|
|
|
|
|
static void MaybeShowOnScreenKeyboard();
|
2016-01-18 12:14:43 +00:00
|
|
|
static void MaybeDismissOnScreenKeyboard(nsWindow* aWindow);
|
2015-08-05 14:38:51 +00:00
|
|
|
static bool WStringStartsWithCaseInsensitive(const std::wstring& aHaystack,
|
|
|
|
const std::wstring& aNeedle);
|
2016-02-09 19:39:55 +00:00
|
|
|
static bool NeedOnScreenKeyboard();
|
2015-08-05 14:38:51 +00:00
|
|
|
static bool IsKeyboardPresentOnSlate();
|
2015-09-02 16:12:10 +00:00
|
|
|
static bool IsInTabletMode();
|
|
|
|
static bool AutoInvokeOnScreenKeyboardInDesktopMode();
|
2017-06-07 02:42:27 +00:00
|
|
|
static bool NeedsToAssociateIMC();
|
2015-08-05 14:38:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the Windows on-screen keyboard. Only allowed for
|
|
|
|
* chrome documents and Windows 8 and higher.
|
|
|
|
*/
|
|
|
|
static void ShowOnScreenKeyboard();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dismiss the Windows on-screen keyboard. Only allowed for
|
|
|
|
* Windows 8 and higher.
|
|
|
|
*/
|
|
|
|
static void DismissOnScreenKeyboard();
|
2015-12-16 12:48:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the HWND for the on-screen keyboard, if it's up. Only
|
|
|
|
* allowed for Windows 8 and higher.
|
|
|
|
*/
|
|
|
|
static HWND GetOnScreenKeyboardWindow();
|
2013-02-25 04:00:05 +00:00
|
|
|
#endif // #ifdef NS_ENABLE_TSF
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // #ifndef WinIMEHandler_h_
|