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
& aHTMLInputMode
,
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 * Return focused window if this receives focus notification and has not
180 * received blur notification yet.
182 static nsWindow
* GetFocusedWindow() { return sFocusedWindow
; }
185 static nsWindow
* sFocusedWindow
;
186 static InputContextAction::Cause sLastContextActionCause
;
188 static bool sMaybeEditable
;
189 static bool sForceDisableCurrentIMM_IME
;
190 static bool sNativeCaretIsCreated
;
191 static bool sHasNativeCaretBeenRequested
;
194 * MaybeCreateNativeCaret() may create native caret over our caret if
195 * focused content is text editable and we need to create native caret
196 * for other applications.
198 * @param aWindow The window which owns the native caret.
200 static bool MaybeCreateNativeCaret(nsWindow
* aWindow
);
202 static decltype(SetInputScopes
)* sSetInputScopes
;
203 static void SetInputScopeForIMM32(nsWindow
* aWindow
,
204 const nsAString
& aHTMLInputType
,
205 const nsAString
& aHTMLInputMode
,
206 bool aInPrivateBrowsing
);
207 static bool sIsInTSFMode
;
208 // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
209 // Additionally, IME context is always disassociated from focused window.
210 static bool sIsIMMEnabled
;
212 static bool IsTSFAvailable() { return sIsInTSFMode
; }
213 static bool IsIMMActive();
215 static bool IsOnScreenKeyboardSupported();
217 static void MaybeShowOnScreenKeyboard(nsWindow
* aWindow
,
218 const InputContext
& aInputContext
);
219 enum class Sync
{ Yes
, No
};
220 static void MaybeDismissOnScreenKeyboard(nsWindow
* aWindow
,
221 Sync aSync
= Sync::No
);
222 static bool WStringStartsWithCaseInsensitive(const std::wstring
& aHaystack
,
223 const std::wstring
& aNeedle
);
224 static bool NeedOnScreenKeyboard();
225 static bool IsKeyboardPresentOnSlate();
226 static bool IsInWin10TabletMode();
227 static bool AutoInvokeOnScreenKeyboardInDesktopMode();
228 static bool NeedsToAssociateIMC();
229 static bool NeedsSearchInputScope();
232 * Show the Windows on-screen keyboard. Only allowed for
233 * chrome documents and Windows 8 and higher.
235 static void ShowOnScreenKeyboard(nsWindow
* aWindow
);
238 * Dismiss the Windows on-screen keyboard. Only allowed for
239 * Windows 8 and higher.
241 static void DismissOnScreenKeyboard(nsWindow
* aWindow
);
244 } // namespace widget
245 } // namespace mozilla
247 #endif // #ifndef WinIMEHandler_h_