widget/windows/WinIMEHandler.h

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef WinIMEHandler_h_
michael@0 7 #define WinIMEHandler_h_
michael@0 8
michael@0 9 #include "nscore.h"
michael@0 10 #include "nsIWidget.h"
michael@0 11 #include <windows.h>
michael@0 12 #include <inputscope.h>
michael@0 13
michael@0 14 #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
michael@0 15 #define NS_WM_IMELAST WM_IME_KEYUP
michael@0 16
michael@0 17 class nsWindow;
michael@0 18
michael@0 19 namespace mozilla {
michael@0 20 namespace widget {
michael@0 21
michael@0 22 struct MSGResult;
michael@0 23
michael@0 24 /**
michael@0 25 * IMEHandler class is a mediator class. On Windows, there are two IME API
michael@0 26 * sets: One is IMM which is legacy API set. The other is TSF which is modern
michael@0 27 * API set. By using this class, non-IME handler classes don't need to worry
michael@0 28 * that we're in which mode.
michael@0 29 */
michael@0 30 class IMEHandler MOZ_FINAL
michael@0 31 {
michael@0 32 public:
michael@0 33 static void Initialize();
michael@0 34 static void Terminate();
michael@0 35
michael@0 36 /**
michael@0 37 * Returns TSF related native data.
michael@0 38 */
michael@0 39 static void* GetNativeData(uint32_t aDataType);
michael@0 40
michael@0 41 /**
michael@0 42 * ProcessRawKeyMessage() message is called before calling TranslateMessage()
michael@0 43 * and DispatchMessage(). If this returns true, the message is consumed.
michael@0 44 * Then, caller must not perform TranslateMessage() nor DispatchMessage().
michael@0 45 */
michael@0 46 static bool ProcessRawKeyMessage(const MSG& aMsg);
michael@0 47
michael@0 48 /**
michael@0 49 * When the message is not needed to handle anymore by the caller, this
michael@0 50 * returns true. Otherwise, false.
michael@0 51 */
michael@0 52 static bool ProcessMessage(nsWindow* aWindow, UINT aMessage,
michael@0 53 WPARAM& aWParam, LPARAM& aLParam,
michael@0 54 MSGResult& aResult);
michael@0 55
michael@0 56 /**
michael@0 57 * When there is a composition, returns true. Otherwise, false.
michael@0 58 */
michael@0 59 static bool IsComposing();
michael@0 60
michael@0 61 /**
michael@0 62 * When there is a composition and it's in the window, returns true.
michael@0 63 * Otherwise, false.
michael@0 64 */
michael@0 65 static bool IsComposingOn(nsWindow* aWindow);
michael@0 66
michael@0 67 /**
michael@0 68 * Notifies IME of the notification (a request or an event).
michael@0 69 */
michael@0 70 static nsresult NotifyIME(nsWindow* aWindow,
michael@0 71 const IMENotification& aIMENotification);
michael@0 72
michael@0 73 /**
michael@0 74 * Returns update preferences.
michael@0 75 */
michael@0 76 static nsIMEUpdatePreference GetUpdatePreference();
michael@0 77
michael@0 78 /**
michael@0 79 * Returns IME open state on the window.
michael@0 80 */
michael@0 81 static bool GetOpenState(nsWindow* aWindow);
michael@0 82
michael@0 83 /**
michael@0 84 * Called when the window is destroying.
michael@0 85 */
michael@0 86 static void OnDestroyWindow(nsWindow* aWindow);
michael@0 87
michael@0 88 /**
michael@0 89 * Called when nsIWidget::SetInputContext() is called before the window's
michael@0 90 * InputContext is modified actually.
michael@0 91 */
michael@0 92 static void SetInputContext(nsWindow* aWindow,
michael@0 93 InputContext& aInputContext,
michael@0 94 const InputContextAction& aAction);
michael@0 95
michael@0 96 /**
michael@0 97 * Associate or disassociate IME context to/from the aWindow.
michael@0 98 */
michael@0 99 static void AssociateIMEContext(nsWindow* aWindow, bool aEnable);
michael@0 100
michael@0 101 /**
michael@0 102 * Called when the window is created.
michael@0 103 */
michael@0 104 static void InitInputContext(nsWindow* aWindow, InputContext& aInputContext);
michael@0 105
michael@0 106 #ifdef DEBUG
michael@0 107 /**
michael@0 108 * Returns true when current keyboard layout has IME. Otherwise, false.
michael@0 109 */
michael@0 110 static bool CurrentKeyboardLayoutHasIME();
michael@0 111 #endif // #ifdef DEBUG
michael@0 112
michael@0 113 private:
michael@0 114 #ifdef NS_ENABLE_TSF
michael@0 115 static decltype(SetInputScopes)* sSetInputScopes;
michael@0 116 static void SetInputScopeForIMM32(nsWindow* aWindow,
michael@0 117 const nsAString& aHTMLInputType);
michael@0 118 static bool sIsInTSFMode;
michael@0 119 // If sIMMEnabled is false, any IME messages are not handled in TSF mode.
michael@0 120 // Additionally, IME context is always disassociated from focused window.
michael@0 121 static bool sIsIMMEnabled;
michael@0 122 static bool sPluginHasFocus;
michael@0 123
michael@0 124 static bool IsTSFAvailable() { return (sIsInTSFMode && !sPluginHasFocus); }
michael@0 125 #endif // #ifdef NS_ENABLE_TSF
michael@0 126 };
michael@0 127
michael@0 128 } // namespace widget
michael@0 129 } // namespace mozilla
michael@0 130
michael@0 131 #endif // #ifndef WinIMEHandler_h_

mercurial