michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef WinIMEHandler_h_ michael@0: #define WinIMEHandler_h_ michael@0: michael@0: #include "nscore.h" michael@0: #include "nsIWidget.h" michael@0: #include michael@0: #include michael@0: michael@0: #define NS_WM_IMEFIRST WM_IME_SETCONTEXT michael@0: #define NS_WM_IMELAST WM_IME_KEYUP michael@0: michael@0: class nsWindow; michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: michael@0: struct MSGResult; michael@0: michael@0: /** michael@0: * IMEHandler class is a mediator class. On Windows, there are two IME API michael@0: * sets: One is IMM which is legacy API set. The other is TSF which is modern michael@0: * API set. By using this class, non-IME handler classes don't need to worry michael@0: * that we're in which mode. michael@0: */ michael@0: class IMEHandler MOZ_FINAL michael@0: { michael@0: public: michael@0: static void Initialize(); michael@0: static void Terminate(); michael@0: michael@0: /** michael@0: * Returns TSF related native data. michael@0: */ michael@0: static void* GetNativeData(uint32_t aDataType); michael@0: michael@0: /** michael@0: * ProcessRawKeyMessage() message is called before calling TranslateMessage() michael@0: * and DispatchMessage(). If this returns true, the message is consumed. michael@0: * Then, caller must not perform TranslateMessage() nor DispatchMessage(). michael@0: */ michael@0: static bool ProcessRawKeyMessage(const MSG& aMsg); michael@0: michael@0: /** michael@0: * When the message is not needed to handle anymore by the caller, this michael@0: * returns true. Otherwise, false. michael@0: */ michael@0: static bool ProcessMessage(nsWindow* aWindow, UINT aMessage, michael@0: WPARAM& aWParam, LPARAM& aLParam, michael@0: MSGResult& aResult); michael@0: michael@0: /** michael@0: * When there is a composition, returns true. Otherwise, false. michael@0: */ michael@0: static bool IsComposing(); michael@0: michael@0: /** michael@0: * When there is a composition and it's in the window, returns true. michael@0: * Otherwise, false. michael@0: */ michael@0: static bool IsComposingOn(nsWindow* aWindow); michael@0: michael@0: /** michael@0: * Notifies IME of the notification (a request or an event). michael@0: */ michael@0: static nsresult NotifyIME(nsWindow* aWindow, michael@0: const IMENotification& aIMENotification); michael@0: michael@0: /** michael@0: * Returns update preferences. michael@0: */ michael@0: static nsIMEUpdatePreference GetUpdatePreference(); michael@0: michael@0: /** michael@0: * Returns IME open state on the window. michael@0: */ michael@0: static bool GetOpenState(nsWindow* aWindow); michael@0: michael@0: /** michael@0: * Called when the window is destroying. michael@0: */ michael@0: static void OnDestroyWindow(nsWindow* aWindow); michael@0: michael@0: /** michael@0: * Called when nsIWidget::SetInputContext() is called before the window's michael@0: * InputContext is modified actually. michael@0: */ michael@0: static void SetInputContext(nsWindow* aWindow, michael@0: InputContext& aInputContext, michael@0: const InputContextAction& aAction); michael@0: michael@0: /** michael@0: * Associate or disassociate IME context to/from the aWindow. michael@0: */ michael@0: static void AssociateIMEContext(nsWindow* aWindow, bool aEnable); michael@0: michael@0: /** michael@0: * Called when the window is created. michael@0: */ michael@0: static void InitInputContext(nsWindow* aWindow, InputContext& aInputContext); michael@0: michael@0: #ifdef DEBUG michael@0: /** michael@0: * Returns true when current keyboard layout has IME. Otherwise, false. michael@0: */ michael@0: static bool CurrentKeyboardLayoutHasIME(); michael@0: #endif // #ifdef DEBUG michael@0: michael@0: private: michael@0: #ifdef NS_ENABLE_TSF michael@0: static decltype(SetInputScopes)* sSetInputScopes; michael@0: static void SetInputScopeForIMM32(nsWindow* aWindow, michael@0: const nsAString& aHTMLInputType); michael@0: static bool sIsInTSFMode; michael@0: // If sIMMEnabled is false, any IME messages are not handled in TSF mode. michael@0: // Additionally, IME context is always disassociated from focused window. michael@0: static bool sIsIMMEnabled; michael@0: static bool sPluginHasFocus; michael@0: michael@0: static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); } michael@0: #endif // #ifdef NS_ENABLE_TSF michael@0: }; michael@0: michael@0: } // namespace widget michael@0: } // namespace mozilla michael@0: michael@0: #endif // #ifndef WinIMEHandler_h_