| 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 #include "views/ime/input_method_gtk.h" | 5 #include "views/ime/input_method_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void InputMethodGtk::FocusedViewDidChange() { | 201 void InputMethodGtk::FocusedViewDidChange() { |
| 202 UpdateContextFocusState(); | 202 UpdateContextFocusState(); |
| 203 | 203 |
| 204 // Force to update caret bounds, in case the View thinks that the caret | 204 // Force to update caret bounds, in case the View thinks that the caret |
| 205 // bounds has not changed. | 205 // bounds has not changed. |
| 206 if (context_focused_) | 206 if (context_focused_) |
| 207 OnCaretBoundsChanged(focused_view()); | 207 OnCaretBoundsChanged(focused_view()); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void InputMethodGtk::ConfirmCompositionText() { | 210 void InputMethodGtk::ConfirmCompositionText() { |
| 211 TextInputClient* client = GetTextInputClient(); | 211 ui::TextInputClient* client = GetTextInputClient(); |
| 212 if (client && client->HasCompositionText()) | 212 if (client && client->HasCompositionText()) |
| 213 client->ConfirmCompositionText(); | 213 client->ConfirmCompositionText(); |
| 214 | 214 |
| 215 ResetContext(); | 215 ResetContext(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void InputMethodGtk::ResetContext() { | 218 void InputMethodGtk::ResetContext() { |
| 219 if (!GetTextInputClient()) | 219 if (!GetTextInputClient()) |
| 220 return; | 220 return; |
| 221 | 221 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // change. | 289 // change. |
| 290 if (old_focused_view != focused_view()) | 290 if (old_focused_view != focused_view()) |
| 291 return; | 291 return; |
| 292 | 292 |
| 293 // If a key event was not filtered by |context_| or |context_simple_|, then | 293 // If a key event was not filtered by |context_| or |context_simple_|, then |
| 294 // it means the key event didn't generate any result text. For some cases, | 294 // it means the key event didn't generate any result text. For some cases, |
| 295 // the key event may still generate a valid character, eg. a control-key | 295 // the key event may still generate a valid character, eg. a control-key |
| 296 // event (ctrl-a, return, tab, etc.). We need to send the character to the | 296 // event (ctrl-a, return, tab, etc.). We need to send the character to the |
| 297 // focused text input client by calling TextInputClient::InsertChar(). | 297 // focused text input client by calling TextInputClient::InsertChar(). |
| 298 char16 ch = key.GetCharacter(); | 298 char16 ch = key.GetCharacter(); |
| 299 TextInputClient* client = GetTextInputClient(); | 299 ui::TextInputClient* client = GetTextInputClient(); |
| 300 if (ch && client) | 300 if (ch && client) |
| 301 client->InsertChar(ch, key.flags()); | 301 client->InsertChar(ch, key.flags()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 void InputMethodGtk::ProcessInputMethodResult(const KeyEvent& key, | 304 void InputMethodGtk::ProcessInputMethodResult(const KeyEvent& key, |
| 305 bool filtered) { | 305 bool filtered) { |
| 306 TextInputClient* client = GetTextInputClient(); | 306 ui::TextInputClient* client = GetTextInputClient(); |
| 307 DCHECK(client); | 307 DCHECK(client); |
| 308 | 308 |
| 309 if (result_text_.length()) { | 309 if (result_text_.length()) { |
| 310 if (filtered && NeedInsertChar()) { | 310 if (filtered && NeedInsertChar()) { |
| 311 for (string16::const_iterator i = result_text_.begin(); | 311 for (string16::const_iterator i = result_text_.begin(); |
| 312 i != result_text_.end(); ++i) { | 312 i != result_text_.end(); ++i) { |
| 313 client->InsertChar(*i, key.flags()); | 313 client->InsertChar(*i, key.flags()); |
| 314 } | 314 } |
| 315 } else { | 315 } else { |
| 316 client->InsertText(result_text_); | 316 client->InsertText(result_text_); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 } | 419 } |
| 420 | 420 |
| 421 void InputMethodGtk::OnPreeditEnd(GtkIMContext* context) { | 421 void InputMethodGtk::OnPreeditEnd(GtkIMContext* context) { |
| 422 if (composition_.text.empty() || IsTextInputTypeNone()) | 422 if (composition_.text.empty() || IsTextInputTypeNone()) |
| 423 return; | 423 return; |
| 424 | 424 |
| 425 composition_changed_ = true; | 425 composition_changed_ = true; |
| 426 composition_.Clear(); | 426 composition_.Clear(); |
| 427 | 427 |
| 428 if (!handling_key_event_) { | 428 if (!handling_key_event_) { |
| 429 TextInputClient* client = GetTextInputClient(); | 429 ui::TextInputClient* client = GetTextInputClient(); |
| 430 if (client && client->HasCompositionText()) | 430 if (client && client->HasCompositionText()) |
| 431 client->ClearCompositionText(); | 431 client->ClearCompositionText(); |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 | 434 |
| 435 void InputMethodGtk::OnWidgetRealize(GtkWidget* widget) { | 435 void InputMethodGtk::OnWidgetRealize(GtkWidget* widget) { |
| 436 // We should only set im context's client window once, because when setting | 436 // We should only set im context's client window once, because when setting |
| 437 // client window, im context may destroy and recreate its internal states and | 437 // client window, im context may destroy and recreate its internal states and |
| 438 // objects. | 438 // objects. |
| 439 if (widget->window) { | 439 if (widget->window) { |
| 440 gtk_im_context_set_client_window(context_, widget->window); | 440 gtk_im_context_set_client_window(context_, widget->window); |
| 441 gtk_im_context_set_client_window(context_simple_, widget->window); | 441 gtk_im_context_set_client_window(context_simple_, widget->window); |
| 442 } | 442 } |
| 443 } | 443 } |
| 444 | 444 |
| 445 void InputMethodGtk::OnWidgetUnrealize(GtkWidget* widget) { | 445 void InputMethodGtk::OnWidgetUnrealize(GtkWidget* widget) { |
| 446 gtk_im_context_set_client_window(context_, NULL); | 446 gtk_im_context_set_client_window(context_, NULL); |
| 447 gtk_im_context_set_client_window(context_simple_, NULL); | 447 gtk_im_context_set_client_window(context_simple_, NULL); |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace views | 450 } // namespace views |
| OLD | NEW |