1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef WinIMEHandler_h_
7 #define WinIMEHandler_h_
13 #include <inputscope.h>
15 #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
16 #define NS_WM_IMELAST WM_IME_KEYUP
26 * IMEHandler class is a mediator class. On Windows, there are two IME API
27 * sets: One is IMM which is legacy API set. The other is TSF which is modern
28 * API set. By using this class, non-IME handler classes don't need to worry
29 * that we're in which mode.
31 class IMEHandler final
{
34 * Initialize() initializes both TSF modules and IMM modules. Some TIPs
35 * may require a normal window (i.e., not message window) belonging to
36 * this process. Therefore, this is called immediately after first normal
39 static void Initialize();
42 static void Terminate();
45 * Returns TSF related native data or native IME context.
47 static void* GetNativeData(nsWindow
* aWindow
, uint32_t aDataType
);
50 * ProcessRawKeyMessage() message is called before calling TranslateMessage()
51 * and DispatchMessage(). If this returns true, the message is consumed.
52 * Then, caller must not perform TranslateMessage() nor DispatchMessage().
54 static bool ProcessRawKeyMessage(const MSG
& aMsg
);
57 * When the message is not needed to handle anymore by the caller, this
58 * returns true. Otherwise, false.
60 static bool ProcessMessage(nsWindow
* aWindow
, UINT aMessage
, WPARAM
& aWParam
,
61 LPARAM
& aLParam
, MSGResult
& aResult
);
64 * IsA11yHandlingNativeCaret() returns true if a11y is handling
65 * native caret. In such case, IME modules shouldn't touch native caret.
67 static bool IsA11yHandlingNativeCaret();
70 * NeedsToCreateNativeCaret() returns true if IME handler needs to create
71 * native caret for other applications which requests OBJID_CARET with
72 * WM_GETOBJECT and a11y module isn't active (if a11y module is active,
73 * it always creates native caret, i.e., even if no editor has focus).
75 static bool NeedsToCreateNativeCaret() {
76 return sHasNativeCaretBeenRequested
&& !IsA11yHandlingNativeCaret();
80 * CreateNativeCaret() create native caret if this has been created it.
82 * @param aWindow The window which owns the caret.
83 * @param aCaretRect The caret rect relative to aWindow.
85 static bool CreateNativeCaret(nsWindow
* aWindow
,
86 const LayoutDeviceIntRect
& aCaretRect
);
89 * MaybeDestroyNativeCaret() destroies native caret if it has been created
92 static void MaybeDestroyNativeCaret();
95 * HasNativeCaret() returns true if there is native caret and it was created
98 static bool HasNativeCaret() { return sNativeCaretIsCreated
; }
101 * When there is a composition, returns true. Otherwise, false.
103 static bool IsComposing();
106 * When there is a composition and it's in the window, returns true.
109 static bool IsComposingOn(nsWindow
* aWindow
);
112 * Notifies IME of the notification (a request or an event).
114 static nsresult
NotifyIME(nsWindow
* aWindow
,
115 const IMENotification
& aIMENotification
);
118 * Returns notification requests of IME.
120 static IMENotificationRequests
GetIMENotificationRequests();
123 * Returns native text event dispatcher listener.
125 static TextEventDispatcherListener
* GetNativeTextEventDispatcherListener();
128 * Returns IME open state on the window.
130 static bool GetOpenState(nsWindow
* aWindow
);
133 * Called when the window is destroying.
135 static void OnDestroyWindow(nsWindow
* aWindow
);
138 * Called when nsIWidget::SetInputContext() is called before the window's
139 * InputContext is modified actually.
141 static void SetInputContext(nsWindow
* aWindow
, InputContext
& aInputContext
,
142 const InputContextAction
& aAction
);
145 * Associate or disassociate IME context to/from the aWindowBase.
147 static void AssociateIMEContext(nsWindow
* aWindowBase
, bool aEnable
);
150 * Called when the window is created.
152 static void InitInputContext(nsWindow
* aWindow
, InputContext
& aInputContext
);
155 * This is called by TSFStaticSink when active IME is changed.
157 static void OnKeyboardLayoutChanged();
161 * Returns true when current keyboard layout has IME. Otherwise, false.
163 static bool CurrentKeyboardLayoutHasIME();
164 #endif // #ifdef DEBUG
167 * Append InputScope values from inputmode string.
169 static void AppendInputScopeFromInputmode(const nsAString
& aInputmode
,
170 nsTArray
<InputScope
>& aScopes
);
173 * Append InputScope values from type attreibute string of input element
175 static void AppendInputScopeFromType(const nsAString
& aInputType
,
176 nsTArray
<InputScope
>& aScopes
);
179 static nsWindow
* sFocusedWindow
;
180 static InputContextAction::Cause sLastContextActionCause
;
182 static bool sMaybeEditable
;
183 static bool sForceDisableCurrentIMM_IME
;
184 static bool sNativeCaretIsCreated
;
185 static bool sHasNativeCaretBeenRequested
;
188 * MaybeCreateNativeCaret() may create native caret over our caret if
189 * focused content is text editable and we need to create native caret
190 * for other applications.
192 * @param aWindow The window which owns the native caret.
194 static bool MaybeCreateNativeCaret(nsWindow
* aWindow
);
196 static decltype(SetInputScopes
)* sSetInputScopes
;
197 static void SetInputScopeForIMM32(nsWindow
* aWindow
,
198 const nsAString
& aHTMLInputType
,
199 const nsAString
& aHTMLInputInputmode
,
200 bool aInPrivateBrowsing
);
201 static bool sIsInTSFMode
;
202 // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
203 // Additionally, IME context is always disassociated from focused window.
204 static bool sIsIMMEnabled
;
205 static bool sAssociateIMCOnlyWhenIMM_IMEActive
;
207 static bool IsTSFAvailable() { return sIsInTSFMode
; }
208 static bool IsIMMActive();
210 static bool IsOnScreenKeyboardSupported();
212 static void MaybeShowOnScreenKeyboard(nsWindow
* aWindow
,
213 const InputContext
& aInputContext
);
214 enum class Sync
{ Yes
, No
};
215 static void MaybeDismissOnScreenKeyboard(nsWindow
* aWindow
,
216 Sync aSync
= Sync::No
);
217 static bool WStringStartsWithCaseInsensitive(const std::wstring
& aHaystack
,
218 const std::wstring
& aNeedle
);
219 static bool NeedOnScreenKeyboard();
220 static bool IsKeyboardPresentOnSlate();
221 static bool IsInTabletMode();
222 static bool AutoInvokeOnScreenKeyboardInDesktopMode();
223 static bool NeedsToAssociateIMC();
224 static bool NeedsSearchInputScope();
227 * Show the Windows on-screen keyboard. Only allowed for
228 * chrome documents and Windows 8 and higher.
230 static void ShowOnScreenKeyboard(nsWindow
* aWindow
);
233 * Dismiss the Windows on-screen keyboard. Only allowed for
234 * Windows 8 and higher.
236 static void DismissOnScreenKeyboard(nsWindow
* aWindow
);
239 } // namespace widget
240 } // namespace mozilla
242 #endif // #ifndef WinIMEHandler_h_