| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef UI_BASE_IME_WIN_TSF_BRIDGE_H_ | |
| 6 #define UI_BASE_IME_WIN_TSF_BRIDGE_H_ | |
| 7 | |
| 8 #include <msctf.h> | |
| 9 #include <windows.h> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/win/scoped_comptr.h" | |
| 13 #include "ui/base/ui_base_export.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 class TextInputClient; | |
| 17 | |
| 18 // TSFBridge provides high level IME related operations on top of Text Services | |
| 19 // Framework (TSF). TSFBridge is managed by TLS because TSF related stuff is | |
| 20 // associated with each thread and not allowed to access across thread boundary. | |
| 21 // To be consistent with IMM32 behavior, TSFBridge is shared in the same thread. | |
| 22 // TSFBridge is used by the web content text inputting field, for example | |
| 23 // DisableIME() should be called if a password field is focused. | |
| 24 // | |
| 25 // TSFBridge also manages connectivity between TSFTextStore which is the backend | |
| 26 // of text inputting and current focused TextInputClient. | |
| 27 // | |
| 28 // All methods in this class must be used in UI thread. | |
| 29 class UI_BASE_EXPORT TSFBridge { | |
| 30 public: | |
| 31 virtual ~TSFBridge(); | |
| 32 | |
| 33 // Returns the thread local TSFBridge instance. Initialize() must be called | |
| 34 // first. Do not cache this pointer and use it after TSFBridge Shutdown(). | |
| 35 static TSFBridge* GetInstance(); | |
| 36 | |
| 37 // Sets the thread local instance. Must be called before any calls to | |
| 38 // GetInstance(). | |
| 39 static bool Initialize(); | |
| 40 | |
| 41 // Injects an alternative TSFBridge such as MockTSFBridge for testing. The | |
| 42 // injected object should be released by the caller. This function returns | |
| 43 // previous TSFBridge pointer with ownership. | |
| 44 static TSFBridge* ReplaceForTesting(TSFBridge* bridge); | |
| 45 | |
| 46 // Destroys the thread local instance. | |
| 47 static void Shutdown(); | |
| 48 | |
| 49 // Handles TextInputTypeChanged event. RWHVW is responsible for calling this | |
| 50 // handler whenever renderer's input text type is changed. Does nothing | |
| 51 // unless |client| is focused. | |
| 52 virtual void OnTextInputTypeChanged(const TextInputClient* client) = 0; | |
| 53 | |
| 54 // Sends an event to TSF manager that the text layout should be updated. | |
| 55 virtual void OnTextLayoutChanged() = 0; | |
| 56 | |
| 57 // Cancels the ongoing composition if exists. | |
| 58 // Returns true if there is no composition. | |
| 59 // Returns false if an edit session is on-going. | |
| 60 // Returns false if an error occures. | |
| 61 virtual bool CancelComposition() = 0; | |
| 62 | |
| 63 // Confirms the ongoing composition if exists. | |
| 64 // Returns true if there is no composition. | |
| 65 // Returns false if an edit session is on-going. | |
| 66 // Returns false if an error occures. | |
| 67 virtual bool ConfirmComposition() = 0; | |
| 68 | |
| 69 // Sets currently focused TextInputClient. | |
| 70 // Caller must free |client|. | |
| 71 virtual void SetFocusedClient(HWND focused_window, | |
| 72 TextInputClient* client) = 0; | |
| 73 | |
| 74 // Removes currently focused TextInputClient. | |
| 75 // Caller must free |client|. | |
| 76 virtual void RemoveFocusedClient(TextInputClient* client) = 0; | |
| 77 | |
| 78 // Obtains current thread manager. | |
| 79 virtual base::win::ScopedComPtr<ITfThreadMgr> GetThreadManager() = 0; | |
| 80 | |
| 81 // Returns the focused text input client. | |
| 82 virtual TextInputClient* GetFocusedTextInputClient() const = 0; | |
| 83 | |
| 84 protected: | |
| 85 // Uses GetInstance() instead. | |
| 86 TSFBridge(); | |
| 87 | |
| 88 private: | |
| 89 // Releases TLS instance. | |
| 90 static void Finalize(void* data); | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(TSFBridge); | |
| 93 }; | |
| 94 | |
| 95 } // namespace ui | |
| 96 | |
| 97 #endif // UI_BASE_IME_WIN_TSF_BRIDGE_H_ | |
| OLD | NEW |