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