Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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_
9 #include "nscore.h"
10 #include "nsIWidget.h"
11 #include <windows.h>
12 #include <inputscope.h>
14 #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
15 #define NS_WM_IMELAST WM_IME_KEYUP
17 class nsWindow;
19 namespace mozilla {
20 namespace widget {
22 struct MSGResult;
24 /**
25 * IMEHandler class is a mediator class. On Windows, there are two IME API
26 * sets: One is IMM which is legacy API set. The other is TSF which is modern
27 * API set. By using this class, non-IME handler classes don't need to worry
28 * that we're in which mode.
29 */
30 class IMEHandler MOZ_FINAL
31 {
32 public:
33 static void Initialize();
34 static void Terminate();
36 /**
37 * Returns TSF related native data.
38 */
39 static void* GetNativeData(uint32_t aDataType);
41 /**
42 * ProcessRawKeyMessage() message is called before calling TranslateMessage()
43 * and DispatchMessage(). If this returns true, the message is consumed.
44 * Then, caller must not perform TranslateMessage() nor DispatchMessage().
45 */
46 static bool ProcessRawKeyMessage(const MSG& aMsg);
48 /**
49 * When the message is not needed to handle anymore by the caller, this
50 * returns true. Otherwise, false.
51 */
52 static bool ProcessMessage(nsWindow* aWindow, UINT aMessage,
53 WPARAM& aWParam, LPARAM& aLParam,
54 MSGResult& aResult);
56 /**
57 * When there is a composition, returns true. Otherwise, false.
58 */
59 static bool IsComposing();
61 /**
62 * When there is a composition and it's in the window, returns true.
63 * Otherwise, false.
64 */
65 static bool IsComposingOn(nsWindow* aWindow);
67 /**
68 * Notifies IME of the notification (a request or an event).
69 */
70 static nsresult NotifyIME(nsWindow* aWindow,
71 const IMENotification& aIMENotification);
73 /**
74 * Returns update preferences.
75 */
76 static nsIMEUpdatePreference GetUpdatePreference();
78 /**
79 * Returns IME open state on the window.
80 */
81 static bool GetOpenState(nsWindow* aWindow);
83 /**
84 * Called when the window is destroying.
85 */
86 static void OnDestroyWindow(nsWindow* aWindow);
88 /**
89 * Called when nsIWidget::SetInputContext() is called before the window's
90 * InputContext is modified actually.
91 */
92 static void SetInputContext(nsWindow* aWindow,
93 InputContext& aInputContext,
94 const InputContextAction& aAction);
96 /**
97 * Associate or disassociate IME context to/from the aWindow.
98 */
99 static void AssociateIMEContext(nsWindow* aWindow, bool aEnable);
101 /**
102 * Called when the window is created.
103 */
104 static void InitInputContext(nsWindow* aWindow, InputContext& aInputContext);
106 #ifdef DEBUG
107 /**
108 * Returns true when current keyboard layout has IME. Otherwise, false.
109 */
110 static bool CurrentKeyboardLayoutHasIME();
111 #endif // #ifdef DEBUG
113 private:
114 #ifdef NS_ENABLE_TSF
115 static decltype(SetInputScopes)* sSetInputScopes;
116 static void SetInputScopeForIMM32(nsWindow* aWindow,
117 const nsAString& aHTMLInputType);
118 static bool sIsInTSFMode;
119 // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
120 // Additionally, IME context is always disassociated from focused window.
121 static bool sIsIMMEnabled;
122 static bool sPluginHasFocus;
124 static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
125 #endif // #ifdef NS_ENABLE_TSF
126 };
128 } // namespace widget
129 } // namespace mozilla
131 #endif // #ifndef WinIMEHandler_h_