widget/windows/WinIMEHandler.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/windows/WinIMEHandler.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef WinIMEHandler_h_
    1.10 +#define WinIMEHandler_h_
    1.11 +
    1.12 +#include "nscore.h"
    1.13 +#include "nsIWidget.h"
    1.14 +#include <windows.h>
    1.15 +#include <inputscope.h>
    1.16 +
    1.17 +#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
    1.18 +#define NS_WM_IMELAST  WM_IME_KEYUP
    1.19 +
    1.20 +class nsWindow;
    1.21 +
    1.22 +namespace mozilla {
    1.23 +namespace widget {
    1.24 +
    1.25 +struct MSGResult;
    1.26 +
    1.27 +/**
    1.28 + * IMEHandler class is a mediator class.  On Windows, there are two IME API
    1.29 + * sets: One is IMM which is legacy API set. The other is TSF which is modern
    1.30 + * API set. By using this class, non-IME handler classes don't need to worry
    1.31 + * that we're in which mode.
    1.32 + */
    1.33 +class IMEHandler MOZ_FINAL
    1.34 +{
    1.35 +public:
    1.36 +  static void Initialize();
    1.37 +  static void Terminate();
    1.38 +
    1.39 +  /**
    1.40 +   * Returns TSF related native data.
    1.41 +   */
    1.42 +  static void* GetNativeData(uint32_t aDataType);
    1.43 +
    1.44 +  /**
    1.45 +   * ProcessRawKeyMessage() message is called before calling TranslateMessage()
    1.46 +   * and DispatchMessage().  If this returns true, the message is consumed.
    1.47 +   * Then, caller must not perform TranslateMessage() nor DispatchMessage().
    1.48 +   */
    1.49 +  static bool ProcessRawKeyMessage(const MSG& aMsg);
    1.50 +
    1.51 +  /**
    1.52 +   * When the message is not needed to handle anymore by the caller, this
    1.53 +   * returns true.  Otherwise, false.
    1.54 +   */
    1.55 +  static bool ProcessMessage(nsWindow* aWindow, UINT aMessage,
    1.56 +                             WPARAM& aWParam, LPARAM& aLParam,
    1.57 +                             MSGResult& aResult);
    1.58 +
    1.59 +  /**
    1.60 +   * When there is a composition, returns true.  Otherwise, false.
    1.61 +   */
    1.62 +  static bool IsComposing();
    1.63 +
    1.64 +  /**
    1.65 +   * When there is a composition and it's in the window, returns true.
    1.66 +   * Otherwise, false.
    1.67 +   */
    1.68 +  static bool IsComposingOn(nsWindow* aWindow);
    1.69 +
    1.70 +  /**
    1.71 +   * Notifies IME of the notification (a request or an event).
    1.72 +   */
    1.73 +  static nsresult NotifyIME(nsWindow* aWindow,
    1.74 +                            const IMENotification& aIMENotification);
    1.75 +
    1.76 +  /**
    1.77 +   * Returns update preferences.
    1.78 +   */
    1.79 +  static nsIMEUpdatePreference GetUpdatePreference();
    1.80 +
    1.81 +  /**
    1.82 +   * Returns IME open state on the window.
    1.83 +   */
    1.84 +  static bool GetOpenState(nsWindow* aWindow);
    1.85 +
    1.86 +  /**
    1.87 +   * Called when the window is destroying.
    1.88 +   */
    1.89 +  static void OnDestroyWindow(nsWindow* aWindow);
    1.90 +
    1.91 +  /**
    1.92 +   * Called when nsIWidget::SetInputContext() is called before the window's
    1.93 +   * InputContext is modified actually.
    1.94 +   */
    1.95 +  static void SetInputContext(nsWindow* aWindow,
    1.96 +                              InputContext& aInputContext,
    1.97 +                              const InputContextAction& aAction);
    1.98 +
    1.99 +  /**
   1.100 +   * Associate or disassociate IME context to/from the aWindow.
   1.101 +   */
   1.102 +  static void AssociateIMEContext(nsWindow* aWindow, bool aEnable);
   1.103 +
   1.104 +  /**
   1.105 +   * Called when the window is created.
   1.106 +   */
   1.107 +  static void InitInputContext(nsWindow* aWindow, InputContext& aInputContext);
   1.108 +
   1.109 +#ifdef DEBUG
   1.110 +  /**
   1.111 +   * Returns true when current keyboard layout has IME.  Otherwise, false.
   1.112 +   */
   1.113 +  static bool CurrentKeyboardLayoutHasIME();
   1.114 +#endif // #ifdef DEBUG
   1.115 +
   1.116 +private:
   1.117 +#ifdef NS_ENABLE_TSF
   1.118 +  static decltype(SetInputScopes)* sSetInputScopes;
   1.119 +  static void SetInputScopeForIMM32(nsWindow* aWindow,
   1.120 +                                    const nsAString& aHTMLInputType);
   1.121 +  static bool sIsInTSFMode;
   1.122 +  // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
   1.123 +  // Additionally, IME context is always disassociated from focused window.
   1.124 +  static bool sIsIMMEnabled;
   1.125 +  static bool sPluginHasFocus;
   1.126 +
   1.127 +  static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
   1.128 +#endif // #ifdef NS_ENABLE_TSF
   1.129 +};
   1.130 +
   1.131 +} // namespace widget
   1.132 +} // namespace mozilla
   1.133 +
   1.134 +#endif // #ifndef WinIMEHandler_h_

mercurial