OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_IME_INPUT_METHOD_IBUS_H_ | 5 #ifndef UI_BASE_IME_INPUT_METHOD_IBUS_H_ |
6 #define UI_VIEWS_IME_INPUT_METHOD_IBUS_H_ | 6 #define UI_BASE_IME_INPUT_METHOD_IBUS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "ui/base/glib/glib_integers.h" | 15 #include "ui/base/glib/glib_integers.h" |
16 #include "ui/base/glib/glib_signal.h" | 16 #include "ui/base/glib/glib_signal.h" |
17 #include "ui/base/ime/character_composer.h" | 17 #include "ui/base/ime/character_composer.h" |
18 #include "ui/base/ime/composition_text.h" | 18 #include "ui/base/ime/composition_text.h" |
19 #include "ui/base/ime/text_input_client.h" | 19 #include "ui/base/ime/input_method_base.h" |
20 #include "ui/views/events/event.h" | |
21 #include "ui/views/ime/input_method_base.h" | |
22 #include "views/view.h" | |
23 | 20 |
24 // Forward declarations, so that we don't need to include ibus.h in this file. | 21 // Forward declarations, so that we don't need to include ibus.h in this file. |
25 typedef struct _GAsyncResult GAsyncResult; | 22 typedef struct _GAsyncResult GAsyncResult; |
26 typedef struct _IBusBus IBusBus; | 23 typedef struct _IBusBus IBusBus; |
27 typedef struct _IBusInputContext IBusInputContext; | 24 typedef struct _IBusInputContext IBusInputContext; |
28 typedef struct _IBusText IBusText; | 25 typedef struct _IBusText IBusText; |
29 | 26 |
30 namespace views { | 27 namespace ui { |
31 | 28 |
32 // An InputMethod implementation based on IBus. | 29 // A ui::InputMethod implementation based on IBus. |
33 class InputMethodIBus : public InputMethodBase { | 30 class UI_EXPORT InputMethodIBus : public InputMethodBase { |
34 public: | 31 public: |
35 explicit InputMethodIBus(internal::InputMethodDelegate* delegate); | 32 explicit InputMethodIBus(internal::InputMethodDelegate* delegate); |
36 virtual ~InputMethodIBus(); | 33 virtual ~InputMethodIBus(); |
37 | 34 |
38 // Overridden from InputMethod: | 35 // Overridden from InputMethod: |
39 virtual void Init(Widget* widget) OVERRIDE; | |
40 virtual void OnFocus() OVERRIDE; | 36 virtual void OnFocus() OVERRIDE; |
41 virtual void OnBlur() OVERRIDE; | 37 virtual void OnBlur() OVERRIDE; |
42 virtual void DispatchKeyEvent(const KeyEvent& key) OVERRIDE; | 38 virtual void Init(const base::NativeWindow& system_toplevel_window) OVERRIDE; |
43 virtual void OnTextInputTypeChanged(View* view) OVERRIDE; | 39 virtual void DispatchKeyEvent( |
44 virtual void OnCaretBoundsChanged(View* view) OVERRIDE; | 40 const base::NativeEvent& native_key_event) OVERRIDE; |
45 virtual void CancelComposition(View* view) OVERRIDE; | 41 virtual void OnTextInputTypeChanged(const TextInputClient* client) OVERRIDE; |
| 42 virtual void OnCaretBoundsChanged(const TextInputClient* client) OVERRIDE; |
| 43 virtual void CancelComposition(const TextInputClient* client) OVERRIDE; |
46 virtual std::string GetInputLocale() OVERRIDE; | 44 virtual std::string GetInputLocale() OVERRIDE; |
47 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; | 45 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE; |
48 virtual bool IsActive() OVERRIDE; | 46 virtual bool IsActive() OVERRIDE; |
49 | 47 |
50 // Returns true when | |
51 // 1) built with GYP_DEFINES="touchui=1" or, | |
52 // 2) enabled by SetEnabledInputMethodIBus or, | |
53 // 3) enabled by command line flag "--enable-inputmethod-ibus" | |
54 static bool IsInputMethodIBusEnabled(); | |
55 // Enable/Disable InputMethodIBus | |
56 static void SetEnableInputMethodIBus(bool enabled); | |
57 | |
58 private: | 48 private: |
59 // A class to hold all data related to a key event being processed by the | 49 // A class to hold all data related to a key event being processed by the |
60 // input method but still has no result back yet. | 50 // input method but still has no result back yet. |
61 class PendingKeyEvent; | 51 class PendingKeyEvent; |
62 | 52 |
63 // A class to hold information of a pending request for creating an ibus input | 53 // A class to hold information of a pending request for creating an ibus input |
64 // context. | 54 // context. |
65 class PendingCreateICRequest; | 55 class PendingCreateICRequest; |
66 | 56 |
67 // Overridden from InputMethodBase: | 57 // Checks the availability of focused text input client and update focus state |
68 virtual void OnWillChangeFocus(View* focused_before, View* focused) OVERRIDE; | 58 // of |context_|. |
69 virtual void OnDidChangeFocus(View* focused_before, View* focused) OVERRIDE; | 59 void UpdateContextFocusState(); |
70 | 60 |
71 // Creates |context_| instance asynchronously. | 61 // Creates |context_| instance asynchronously. |
72 void CreateContext(); | 62 void CreateContext(); |
73 | 63 |
74 // Sets |context_| and hooks necessary signals. | 64 // Sets |context_| and hooks necessary signals. |
75 void SetContext(IBusInputContext* ic); | 65 void SetContext(IBusInputContext* ic); |
76 | 66 |
77 // Destroys |context_| instance. | 67 // Destroys |context_| instance. |
78 void DestroyContext(); | 68 void DestroyContext(); |
79 | 69 |
80 // Asks the client to confirm current composition text. | 70 // Asks the client to confirm current composition text. |
81 void ConfirmCompositionText(); | 71 void ConfirmCompositionText(); |
82 | 72 |
83 // Resets |context_| and abandon all pending results and key events. | 73 // Resets |context_| and abandon all pending results and key events. |
84 void ResetContext(); | 74 void ResetContext(); |
85 | 75 |
86 // Checks the availability of focused text input client and update focus state | |
87 // of |context_| and |context_simple_| accordingly. | |
88 void UpdateContextFocusState(); | |
89 | |
90 // Process a key returned from the input method. | 76 // Process a key returned from the input method. |
91 void ProcessKeyEventPostIME(const KeyEvent& key, guint32 ibus_keycode, | 77 void ProcessKeyEventPostIME(const base::NativeEvent& native_key_event, |
| 78 guint32 ibus_keycode, |
92 bool handled); | 79 bool handled); |
93 | 80 |
94 // Processes a key event that was already filtered by the input method. | 81 // Processes a key event that was already filtered by the input method. |
95 // A VKEY_PROCESSKEY may be dispatched to the focused View. | 82 // A VKEY_PROCESSKEY may be dispatched to the focused View. |
96 void ProcessFilteredKeyPressEvent(const KeyEvent& key); | 83 void ProcessFilteredKeyPressEvent(const base::NativeEvent& native_key_event); |
97 | 84 |
98 // Processes a key event that was not filtered by the input method. | 85 // Processes a key event that was not filtered by the input method. |
99 void ProcessUnfilteredKeyPressEvent(const KeyEvent& key, | 86 void ProcessUnfilteredKeyPressEvent(const base::NativeEvent& native_key_event, |
100 guint32 ibus_keycode); | 87 guint32 ibus_keycode); |
| 88 void ProcessUnfilteredFabricatedKeyPressEvent( |
| 89 EventType type, KeyboardCode key_code, int flags, guint32 ibus_keyval); |
101 | 90 |
102 // Sends input method result caused by the given key event to the focused text | 91 // Sends input method result caused by the given key event to the focused text |
103 // input client. | 92 // input client. |
104 void ProcessInputMethodResult(const KeyEvent& key, bool filtered); | 93 void ProcessInputMethodResult(const base::NativeEvent& native_key_event, |
| 94 bool filtered); |
105 | 95 |
106 // Checks if the pending input method result needs inserting into the focused | 96 // Checks if the pending input method result needs inserting into the focused |
107 // text input client as a single character. | 97 // text input client as a single character. |
108 bool NeedInsertChar() const; | 98 bool NeedInsertChar() const; |
109 | 99 |
110 // Checks if there is pending input method result. | 100 // Checks if there is pending input method result. |
111 bool HasInputMethodResult() const; | 101 bool HasInputMethodResult() const; |
112 | 102 |
113 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to | 103 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to |
114 // the focused View. | 104 // the focused View. |
(...skipping 30 matching lines...) Expand all Loading... |
145 // Callback function for ibus_input_context_process_key_event_async(). | 135 // Callback function for ibus_input_context_process_key_event_async(). |
146 static void ProcessKeyEventDone(IBusInputContext* context, | 136 static void ProcessKeyEventDone(IBusInputContext* context, |
147 GAsyncResult* res, | 137 GAsyncResult* res, |
148 PendingKeyEvent* data); | 138 PendingKeyEvent* data); |
149 | 139 |
150 // Callback function for ibus_bus_create_input_context_async(). | 140 // Callback function for ibus_bus_create_input_context_async(). |
151 static void CreateInputContextDone(IBusBus* bus, | 141 static void CreateInputContextDone(IBusBus* bus, |
152 GAsyncResult* res, | 142 GAsyncResult* res, |
153 PendingCreateICRequest* data); | 143 PendingCreateICRequest* data); |
154 | 144 |
155 // The input context for actual text input. | 145 // The input context for actual text input. Note that we don't have to support |
| 146 // a "fake" IBus input context anymore since the latest Chrome for Chrome OS |
| 147 // can handle input method hot keys (e.g. Shift+Alt) by itself. |
156 IBusInputContext* context_; | 148 IBusInputContext* context_; |
157 | 149 |
158 // All pending key events. Note: we do not own these object, we just save | 150 // All pending key events. Note: we do not own these object, we just save |
159 // pointers to these object so that we can abandon them when necessary. | 151 // pointers to these object so that we can abandon them when necessary. |
160 // They will be deleted in ProcessKeyEventDone(). | 152 // They will be deleted in ProcessKeyEventDone(). |
161 std::set<PendingKeyEvent*> pending_key_events_; | 153 std::set<PendingKeyEvent*> pending_key_events_; |
162 | 154 |
163 // The pending request for creating the |context_| instance. We need to keep | 155 // The pending request for creating the |context_| instance. We need to keep |
164 // this pointer so that we can receive or abandon the result. | 156 // this pointer so that we can receive or abandon the result. |
165 PendingCreateICRequest* pending_create_ic_request_; | 157 PendingCreateICRequest* pending_create_ic_request_; |
166 | 158 |
167 // Pending composition text generated by the current pending key event. | 159 // Pending composition text generated by the current pending key event. |
168 // It'll be sent to the focused text input client as soon as we receive the | 160 // It'll be sent to the focused text input client as soon as we receive the |
169 // processing result of the pending key event. | 161 // processing result of the pending key event. |
170 ui::CompositionText composition_; | 162 CompositionText composition_; |
171 | 163 |
172 // Pending result text generated by the current pending key event. | 164 // Pending result text generated by the current pending key event. |
173 // It'll be sent to the focused text input client as soon as we receive the | 165 // It'll be sent to the focused text input client as soon as we receive the |
174 // processing result of the pending key event. | 166 // processing result of the pending key event. |
175 string16 result_text_; | 167 string16 result_text_; |
176 | 168 |
177 // Indicates if |context_| and |context_simple_| are focused or not. | 169 // Indicates if |context_| is focused or not. |
178 bool context_focused_; | 170 bool context_focused_; |
179 | 171 |
180 // Indicates if there is an ongoing composition text. | 172 // Indicates if there is an ongoing composition text. |
181 bool composing_text_; | 173 bool composing_text_; |
182 | 174 |
183 // Indicates if the composition text is changed or deleted. | 175 // Indicates if the composition text is changed or deleted. |
184 bool composition_changed_; | 176 bool composition_changed_; |
185 | 177 |
186 // If it's true then all input method result received before the next key | 178 // If it's true then all input method result received before the next key |
187 // event will be discarded. | 179 // event will be discarded. |
188 bool suppress_next_result_; | 180 bool suppress_next_result_; |
189 | 181 |
190 // An object to compose a character from a sequence of key presses | 182 // An object to compose a character from a sequence of key presses |
191 // including dead key etc. | 183 // including dead key etc. |
192 ui::CharacterComposer character_composer_; | 184 CharacterComposer character_composer_; |
193 | 185 |
194 DISALLOW_COPY_AND_ASSIGN(InputMethodIBus); | 186 DISALLOW_COPY_AND_ASSIGN(InputMethodIBus); |
195 }; | 187 }; |
196 | 188 |
197 } // namespace views | 189 } // namespace ui |
198 | 190 |
199 #endif // UI_VIEWS_IME_INPUT_METHOD_IBUS_H_ | 191 #endif // UI_BASE_IME_INPUT_METHOD_IBUS_H_ |
OLD | NEW |