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

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

Issue 8659033: IME (input method editor) support for Aura, part 1 of 3: Add ui/base/ime/ classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, review fix Created 9 years 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
« no previous file with comments | « ui/base/ime/input_method_delegate.h ('k') | ui/base/ime/input_method_ibus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef UI_BASE_IME_INPUT_METHOD_IBUS_H_
6 #define UI_BASE_IME_INPUT_METHOD_IBUS_H_
7 #pragma once
8
9 #include <set>
10 #include <string>
11
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "ui/base/glib/glib_integers.h"
16 #include "ui/base/glib/glib_signal.h"
17 #include "ui/base/ime/character_composer.h"
18 #include "ui/base/ime/composition_text.h"
19 #include "ui/base/ime/input_method_base.h"
20
21 // Forward declarations, so that we don't need to include ibus.h in this file.
22 typedef struct _GAsyncResult GAsyncResult;
23 typedef struct _IBusBus IBusBus;
24 typedef struct _IBusInputContext IBusInputContext;
25 typedef struct _IBusText IBusText;
26
27 namespace ui {
28
29 // A ui::InputMethod implementation based on IBus.
30 class UI_EXPORT InputMethodIBus : public InputMethodBase {
31 public:
32 explicit InputMethodIBus(internal::InputMethodDelegate* delegate);
33 virtual ~InputMethodIBus();
34
35 // Overridden from InputMethod:
36 virtual void OnFocus() OVERRIDE;
37 virtual void OnBlur() OVERRIDE;
38 virtual void Init(bool focused) OVERRIDE;
39 virtual void DispatchKeyEvent(
40 const base::NativeEvent& native_key_event) 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;
44 virtual std::string GetInputLocale() OVERRIDE;
45 virtual base::i18n::TextDirection GetInputTextDirection() OVERRIDE;
46 virtual bool IsActive() OVERRIDE;
47
48 private:
49 // A class to hold all data related to a key event being processed by the
50 // input method but still has no result back yet.
51 class PendingKeyEvent;
52
53 // A class to hold information of a pending request for creating an ibus input
54 // context.
55 class PendingCreateICRequest;
56
57 // Overridden from InputMethodBase:
58 virtual void OnWillChangeFocusedClient(TextInputClient* focused_before,
59 TextInputClient* focused) OVERRIDE;
60 virtual void OnDidChangeFocusedClient(TextInputClient* focused_before,
61 TextInputClient* focused) OVERRIDE;
62
63 // Creates |context_| instance asynchronously.
64 void CreateContext();
65
66 // Sets |context_| and hooks necessary signals.
67 void SetContext(IBusInputContext* ic);
68
69 // Destroys |context_| instance.
70 void DestroyContext();
71
72 // Asks the client to confirm current composition text.
73 void ConfirmCompositionText();
74
75 // Resets |context_| and abandon all pending results and key events.
76 void ResetContext();
77
78 // Checks the availability of focused text input client and update focus state
79 // of |context_|.
80 void UpdateContextFocusState();
81
82 // Process a key returned from the input method.
83 void ProcessKeyEventPostIME(const base::NativeEvent& native_key_event,
84 guint32 ibus_keycode,
85 bool handled);
86
87 // Processes a key event that was already filtered by the input method.
88 // A VKEY_PROCESSKEY may be dispatched to the focused View.
89 void ProcessFilteredKeyPressEvent(const base::NativeEvent& native_key_event);
90
91 // Processes a key event that was not filtered by the input method.
92 void ProcessUnfilteredKeyPressEvent(const base::NativeEvent& native_key_event,
93 guint32 ibus_keycode);
94 void ProcessUnfilteredFabricatedKeyPressEvent(EventType type,
95 KeyboardCode key_code,
96 int flags,
97 guint32 ibus_keyval);
98
99 // Sends input method result caused by the given key event to the focused text
100 // input client.
101 void ProcessInputMethodResult(const base::NativeEvent& native_key_event,
102 bool filtered);
103
104 // Checks if the pending input method result needs inserting into the focused
105 // text input client as a single character.
106 bool NeedInsertChar() const;
107
108 // Checks if there is pending input method result.
109 bool HasInputMethodResult() const;
110
111 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to
112 // the focused View.
113 void SendFakeProcessKeyEvent(bool pressed) const;
114
115 // Called when a pending key event has finished. The event will be removed
116 // from |pending_key_events_|.
117 void FinishPendingKeyEvent(PendingKeyEvent* pending_key);
118
119 // Abandons all pending key events. It usually happends when we lose keyboard
120 // focus, the text input type is changed or we are destroyed.
121 void AbandonAllPendingKeyEvents();
122
123 // Event handlers for IBusInputContext:
124 CHROMEG_CALLBACK_1(InputMethodIBus, void, OnCommitText,
125 IBusInputContext*, IBusText*);
126 CHROMEG_CALLBACK_3(InputMethodIBus, void, OnForwardKeyEvent,
127 IBusInputContext*, guint, guint, guint);
128 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnShowPreeditText,
129 IBusInputContext*);
130 CHROMEG_CALLBACK_3(InputMethodIBus, void, OnUpdatePreeditText,
131 IBusInputContext*, IBusText*, guint, gboolean);
132 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnHidePreeditText,
133 IBusInputContext*);
134 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnDestroy, IBusInputContext*);
135
136 // Event handlers for IBusBus:
137 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnIBusConnected, IBusBus*);
138 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnIBusDisconnected, IBusBus*);
139
140 // Returns the global IBusBus instance.
141 static IBusBus* GetIBus();
142
143 // Callback function for ibus_input_context_process_key_event_async().
144 static void ProcessKeyEventDone(IBusInputContext* context,
145 GAsyncResult* res,
146 PendingKeyEvent* data);
147
148 // Callback function for ibus_bus_create_input_context_async().
149 static void CreateInputContextDone(IBusBus* bus,
150 GAsyncResult* res,
151 PendingCreateICRequest* data);
152
153 // The input context for actual text input. Note that we don't have to support
154 // a "fake" IBus input context anymore since the latest Chrome for Chrome OS
155 // can handle input method hot keys (e.g. Shift+Alt) by itself.
156 IBusInputContext* context_;
157
158 // 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.
160 // They will be deleted in ProcessKeyEventDone().
161 std::set<PendingKeyEvent*> pending_key_events_;
162
163 // The pending request for creating the |context_| instance. We need to keep
164 // this pointer so that we can receive or abandon the result.
165 PendingCreateICRequest* pending_create_ic_request_;
166
167 // 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
169 // processing result of the pending key event.
170 CompositionText composition_;
171
172 // 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
174 // processing result of the pending key event.
175 string16 result_text_;
176
177 // Indicates if |context_| is focused or not.
178 bool context_focused_;
179
180 // Indicates if there is an ongoing composition text.
181 bool composing_text_;
182
183 // Indicates if the composition text is changed or deleted.
184 bool composition_changed_;
185
186 // If it's true then all input method result received before the next key
187 // event will be discarded.
188 bool suppress_next_result_;
189
190 // An object to compose a character from a sequence of key presses
191 // including dead key etc.
192 CharacterComposer character_composer_;
193
194 DISALLOW_COPY_AND_ASSIGN(InputMethodIBus);
195 };
196
197 } // namespace ui
198
199 #endif // UI_BASE_IME_INPUT_METHOD_IBUS_H_
OLDNEW
« no previous file with comments | « ui/base/ime/input_method_delegate.h ('k') | ui/base/ime/input_method_ibus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698