Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: ui/base/ime/input_method_ibus.h

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

Powered by Google App Engine
This is Rietveld 408576698