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

Side by Side Diff: ui/views/ime/input_method_bridge.cc

Issue 8687027: IME (input method editor) support for Aura, part 2 of 3: Add views::InputMethodBridge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review 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/views/ime/input_method_bridge.h ('k') | ui/views/ime/input_method_ibus.h » ('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 #include "ui/views/ime/input_method_bridge.h"
6
7 #include "ui/base/ime/input_method.h"
8 #include "ui/gfx/rect.h"
9 #include "views/view.h"
10 #include "ui/views/widget/widget.h"
11
12 namespace views {
13
14 InputMethodBridge::InputMethodBridge(internal::InputMethodDelegate* delegate,
15 ui::InputMethod* host)
16 : host_(host),
17 context_focused_(false) {
18 DCHECK(host_);
19 set_delegate(delegate);
20 }
21
22 InputMethodBridge::~InputMethodBridge() {
23 if (host_->GetTextInputClient() == this)
24 host_->SetFocusedTextInputClient(NULL);
25 }
26
27 void InputMethodBridge::Init(Widget* widget) {
28 InputMethodBase::Init(widget);
29 }
30
31 void InputMethodBridge::OnFocus() {
32 DCHECK(!widget_focused());
33 InputMethodBase::OnFocus();
34
35 // Ask the system-wide IME to send all TextInputClient messages to |this|
36 // object.
37 host_->SetFocusedTextInputClient(this);
38
39 if (GetFocusedView())
40 OnTextInputTypeChanged(GetFocusedView());
James Su 2011/11/30 05:25:40 We don't need to call it anymore once we move text
Yusuke Sato 2011/12/01 04:03:21 Done.
41 }
42
43 void InputMethodBridge::OnBlur() {
44 DCHECK(widget_focused());
45
46 ConfirmCompositionText();
47 InputMethodBase::OnBlur();
48 if (host_->GetTextInputClient() == this)
49 host_->SetFocusedTextInputClient(NULL);
50 }
51
52 void InputMethodBridge::DispatchKeyEvent(const KeyEvent& key) {
53 DCHECK(key.type() == ui::ET_KEY_PRESSED || key.type() == ui::ET_KEY_RELEASED);
54 DCHECK(widget_focused());
55
56 // We can just dispatch the event here since the |key| is already processed by
57 // the system-wide IME.
58 DispatchKeyEventPostIME(key);
59 }
60
61 void InputMethodBridge::OnTextInputTypeChanged(View* view) {
62 if (IsViewFocused(view))
63 host_->OnTextInputTypeChanged(this);
64 InputMethodBase::OnTextInputTypeChanged(view);
65 }
66
67 void InputMethodBridge::OnCaretBoundsChanged(View* view) {
68 if (IsViewFocused(view) && !IsTextInputTypeNone())
69 host_->OnCaretBoundsChanged(this);
70 }
71
72 void InputMethodBridge::CancelComposition(View* view) {
73 if (IsViewFocused(view))
74 host_->CancelComposition(this);
75 }
76
77 std::string InputMethodBridge::GetInputLocale() {
78 return host_->GetInputLocale();
79 }
80
81 base::i18n::TextDirection InputMethodBridge::GetInputTextDirection() {
82 return host_->GetInputTextDirection();
83 }
84
85 bool InputMethodBridge::IsActive() {
86 return host_->IsActive();
87 }
88
89 // Overridden from TextInputClient. Forward an event from the system-wide IME
90 // to the text input |client|, which is e.g. views::NativeTextfieldViews.
91 void InputMethodBridge::SetCompositionText(
92 const ui::CompositionText& composition) {
93 TextInputClient* client = GetTextInputClient();
94 if (client)
95 client->SetCompositionText(composition);
96 }
97
98 void InputMethodBridge::ConfirmCompositionText() {
99 TextInputClient* client = GetTextInputClient();
100 if (client)
101 client->ConfirmCompositionText();
102 }
103
104 void InputMethodBridge::ClearCompositionText() {
105 TextInputClient* client = GetTextInputClient();
106 if (client)
107 client->ClearCompositionText();
108 }
109
110 void InputMethodBridge::InsertText(const string16& text) {
111 TextInputClient* client = GetTextInputClient();
112 if (client)
113 client->InsertText(text);
114 }
115
116 void InputMethodBridge::InsertChar(char16 ch, int flags) {
117 TextInputClient* client = GetTextInputClient();
118 if (client)
119 client->InsertChar(ch, flags);
120 }
121
122 ui::TextInputType InputMethodBridge::GetTextInputType() const {
123 TextInputClient* client = GetTextInputClient();
124 return client ? client->GetTextInputType() : ui::TEXT_INPUT_TYPE_NONE;
125 }
126
127 gfx::Rect InputMethodBridge::GetCaretBounds() {
128 TextInputClient* client = GetTextInputClient();
129 if (!client || !GetFocusedView())
130 return gfx::Rect();
131
132 const gfx::Rect rect = client->GetCaretBounds();
133 gfx::Point origin = rect.origin();
134 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
135 View::ConvertPointToScreen(GetFocusedView(), &origin);
136 View::ConvertPointToScreen(GetFocusedView(), &end);
137 return gfx::Rect(origin.x(),
138 origin.y(),
139 end.x() - origin.x(),
140 end.y() - origin.y());
141 }
142
143 bool InputMethodBridge::HasCompositionText() {
144 TextInputClient* client = GetTextInputClient();
145 return client ? client->HasCompositionText() : false;
146 }
147
148 bool InputMethodBridge::GetTextRange(ui::Range* range) {
149 TextInputClient* client = GetTextInputClient();
150 return client ? client->GetTextRange(range) : false;
151 }
152
153 bool InputMethodBridge::GetCompositionTextRange(ui::Range* range) {
154 TextInputClient* client = GetTextInputClient();
155 return client ? client->GetCompositionTextRange(range) : false;
156 }
157
158 bool InputMethodBridge::GetSelectionRange(ui::Range* range) {
159 TextInputClient* client = GetTextInputClient();
160 return client ? client->GetSelectionRange(range) : false;
161 }
162
163 bool InputMethodBridge::SetSelectionRange(const ui::Range& range) {
164 TextInputClient* client = GetTextInputClient();
165 return client ? client->SetSelectionRange(range) : false;
166 }
167
168 bool InputMethodBridge::DeleteRange(const ui::Range& range) {
169 TextInputClient* client = GetTextInputClient();
170 return client ? client->DeleteRange(range) : false;
171 }
172
173 bool InputMethodBridge::GetTextFromRange(
174 const ui::Range& range, string16* text) {
175 TextInputClient* client = GetTextInputClient();
176 return client ? client->GetTextFromRange(range, text) : false;
177 }
178
179 void InputMethodBridge::OnInputMethodChanged() {
180 TextInputClient* client = GetTextInputClient();
181 if (client)
182 client->OnInputMethodChanged();
183 }
184
185 bool InputMethodBridge::ChangeTextDirectionAndLayoutAlignment(
186 base::i18n::TextDirection direction) {
187 TextInputClient* client = GetTextInputClient();
188 return client ?
189 client->ChangeTextDirectionAndLayoutAlignment(direction) : false;
190 }
191
192 // Overridden from FocusChangeListener.
193 void InputMethodBridge::OnWillChangeFocus(View* focused_before, View* focused) {
194 ConfirmCompositionText();
195 }
196
197 void InputMethodBridge::OnDidChangeFocus(View* focused_before, View* focused) {
198 OnTextInputTypeChanged(GetFocusedView());
199 OnCaretBoundsChanged(GetFocusedView());
200 }
201
202 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/ime/input_method_bridge.h ('k') | ui/views/ime/input_method_ibus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698