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

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: Cherry-picked patchset #9 and #10 in http://codereview.chromium.org/8576005/ 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
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(const base::NativeWindow& system_toplevel_window) 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(
59 TextInputClient* focused_before, TextInputClient* focused) OVERRIDE;
60 virtual void OnDidChangeFocusedClient(
61 TextInputClient* focused_before, 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(
95 EventType type, KeyboardCode key_code, int flags, guint32 ibus_keyval);
96
97 // Sends input method result caused by the given key event to the focused text
98 // input client.
99 void ProcessInputMethodResult(const base::NativeEvent& native_key_event,
100 bool filtered);
101
102 // Checks if the pending input method result needs inserting into the focused
103 // text input client as a single character.
104 bool NeedInsertChar() const;
105
106 // Checks if there is pending input method result.
107 bool HasInputMethodResult() const;
108
109 // Fabricates a key event with VKEY_PROCESSKEY key code and dispatches it to
110 // the focused View.
111 void SendFakeProcessKeyEvent(bool pressed) const;
112
113 // Called when a pending key event has finished. The event will be removed
114 // from |pending_key_events_|.
115 void FinishPendingKeyEvent(PendingKeyEvent* pending_key);
116
117 // Abandons all pending key events. It usually happends when we lose keyboard
118 // focus, the text input type is changed or we are destroyed.
119 void AbandonAllPendingKeyEvents();
120
121 // Event handlers for IBusInputContext:
122 CHROMEG_CALLBACK_1(InputMethodIBus, void, OnCommitText,
123 IBusInputContext*, IBusText*);
124 CHROMEG_CALLBACK_3(InputMethodIBus, void, OnForwardKeyEvent,
125 IBusInputContext*, guint, guint, guint);
126 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnShowPreeditText,
127 IBusInputContext*);
128 CHROMEG_CALLBACK_3(InputMethodIBus, void, OnUpdatePreeditText,
129 IBusInputContext*, IBusText*, guint, gboolean);
130 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnHidePreeditText,
131 IBusInputContext*);
132 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnDestroy, IBusInputContext*);
133
134 // Event handlers for IBusBus:
135 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnIBusConnected, IBusBus*);
136 CHROMEG_CALLBACK_0(InputMethodIBus, void, OnIBusDisconnected, IBusBus*);
137
138 // Returns the global IBusBus instance.
139 static IBusBus* GetIBus();
140
141 // Callback function for ibus_input_context_process_key_event_async().
142 static void ProcessKeyEventDone(IBusInputContext* context,
143 GAsyncResult* res,
144 PendingKeyEvent* data);
145
146 // Callback function for ibus_bus_create_input_context_async().
147 static void CreateInputContextDone(IBusBus* bus,
148 GAsyncResult* res,
149 PendingCreateICRequest* data);
150
151 // The input context for actual text input. Note that we don't have to support
152 // a "fake" IBus input context anymore since the latest Chrome for Chrome OS
153 // can handle input method hot keys (e.g. Shift+Alt) by itself.
154 IBusInputContext* context_;
155
156 // All pending key events. Note: we do not own these object, we just save
157 // pointers to these object so that we can abandon them when necessary.
158 // They will be deleted in ProcessKeyEventDone().
159 std::set<PendingKeyEvent*> pending_key_events_;
160
161 // The pending request for creating the |context_| instance. We need to keep
162 // this pointer so that we can receive or abandon the result.
163 PendingCreateICRequest* pending_create_ic_request_;
164
165 // Pending composition text generated by the current pending key event.
166 // It'll be sent to the focused text input client as soon as we receive the
167 // processing result of the pending key event.
168 CompositionText composition_;
169
170 // Pending result text generated by the current pending key event.
171 // It'll be sent to the focused text input client as soon as we receive the
172 // processing result of the pending key event.
173 string16 result_text_;
174
175 // Indicates if |context_| is focused or not.
176 bool context_focused_;
177
178 // Indicates if there is an ongoing composition text.
179 bool composing_text_;
180
181 // Indicates if the composition text is changed or deleted.
182 bool composition_changed_;
183
184 // If it's true then all input method result received before the next key
185 // event will be discarded.
186 bool suppress_next_result_;
187
188 // An object to compose a character from a sequence of key presses
189 // including dead key etc.
190 CharacterComposer character_composer_;
191
192 DISALLOW_COPY_AND_ASSIGN(InputMethodIBus);
193 };
194
195 } // namespace ui
196
197 #endif // UI_BASE_IME_INPUT_METHOD_IBUS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698