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