| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/gtk_im_context_wrapper.h" | 5 #include "content/browser/renderer_host/gtk_im_context_wrapper.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 event->state, | 432 event->state, |
| 433 base::Time::Now().ToDoubleT()); | 433 base::Time::Now().ToDoubleT()); |
| 434 char_event.skip_in_browser = true; | 434 char_event.skip_in_browser = true; |
| 435 host_view_->ForwardKeyboardEvent(char_event); | 435 host_view_->ForwardKeyboardEvent(char_event); |
| 436 } else { | 436 } else { |
| 437 committed = true; | 437 committed = true; |
| 438 // Send an IME event. | 438 // Send an IME event. |
| 439 // Unlike a Char event, an IME event is NOT dispatched to onkeypress() | 439 // Unlike a Char event, an IME event is NOT dispatched to onkeypress() |
| 440 // handlers or autofill. | 440 // handlers or autofill. |
| 441 host->ImeConfirmComposition( | 441 host->ImeConfirmComposition( |
| 442 commit_text_,ui::Range::InvalidRange(),false); | 442 commit_text_,gfx::Range::InvalidRange(),false); |
| 443 // Set this flag to false, as this composition session has been | 443 // Set this flag to false, as this composition session has been |
| 444 // finished. | 444 // finished. |
| 445 is_composing_text_ = false; | 445 is_composing_text_ = false; |
| 446 } | 446 } |
| 447 } | 447 } |
| 448 | 448 |
| 449 // Send preedit text only if it's changed. | 449 // Send preedit text only if it's changed. |
| 450 // If a text has been committed, then we don't need to send the empty | 450 // If a text has been committed, then we don't need to send the empty |
| 451 // preedit text again. | 451 // preedit text again. |
| 452 if (is_composition_changed_) { | 452 if (is_composition_changed_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 470 void GtkIMContextWrapper::ConfirmComposition() { | 470 void GtkIMContextWrapper::ConfirmComposition() { |
| 471 if (!is_enabled_) | 471 if (!is_enabled_) |
| 472 return; | 472 return; |
| 473 | 473 |
| 474 DCHECK(!is_in_key_event_handler_); | 474 DCHECK(!is_in_key_event_handler_); |
| 475 | 475 |
| 476 if (is_composing_text_) { | 476 if (is_composing_text_) { |
| 477 if (host_view_->GetRenderWidgetHost()) { | 477 if (host_view_->GetRenderWidgetHost()) { |
| 478 RenderWidgetHostImpl::From( | 478 RenderWidgetHostImpl::From( |
| 479 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( | 479 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( |
| 480 string16(), ui::Range::InvalidRange(), false); | 480 string16(), gfx::Range::InvalidRange(), false); |
| 481 } | 481 } |
| 482 | 482 |
| 483 // Reset the input method. | 483 // Reset the input method. |
| 484 CancelComposition(); | 484 CancelComposition(); |
| 485 } | 485 } |
| 486 } | 486 } |
| 487 | 487 |
| 488 void GtkIMContextWrapper::HandleCommit(const string16& text) { | 488 void GtkIMContextWrapper::HandleCommit(const string16& text) { |
| 489 if (suppress_next_commit_) | 489 if (suppress_next_commit_) |
| 490 return; | 490 return; |
| 491 | 491 |
| 492 // Append the text to the buffer, because commit signal might be fired | 492 // Append the text to the buffer, because commit signal might be fired |
| 493 // multiple times when processing a key event. | 493 // multiple times when processing a key event. |
| 494 commit_text_.append(text); | 494 commit_text_.append(text); |
| 495 // Nothing needs to do, if it's currently in ProcessKeyEvent() | 495 // Nothing needs to do, if it's currently in ProcessKeyEvent() |
| 496 // handler, which will send commit text to webkit later. Otherwise, | 496 // handler, which will send commit text to webkit later. Otherwise, |
| 497 // we need send it here. | 497 // we need send it here. |
| 498 // It's possible that commit signal is fired without a key event, for | 498 // It's possible that commit signal is fired without a key event, for |
| 499 // example when user input via a voice or handwriting recognition software. | 499 // example when user input via a voice or handwriting recognition software. |
| 500 // In this case, the text must be committed directly. | 500 // In this case, the text must be committed directly. |
| 501 if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost()) { | 501 if (!is_in_key_event_handler_ && host_view_->GetRenderWidgetHost()) { |
| 502 // Workaround http://crbug.com/45478 by sending fake key down/up events. | 502 // Workaround http://crbug.com/45478 by sending fake key down/up events. |
| 503 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::RawKeyDown); | 503 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::RawKeyDown); |
| 504 RenderWidgetHostImpl::From( | 504 RenderWidgetHostImpl::From( |
| 505 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( | 505 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( |
| 506 text, ui::Range::InvalidRange(), false); | 506 text, gfx::Range::InvalidRange(), false); |
| 507 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp); | 507 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 void GtkIMContextWrapper::HandlePreeditStart() { | 511 void GtkIMContextWrapper::HandlePreeditStart() { |
| 512 // Ignore preedit related signals triggered by CancelComposition() method. | 512 // Ignore preedit related signals triggered by CancelComposition() method. |
| 513 if (suppress_next_commit_) | 513 if (suppress_next_commit_) |
| 514 return; | 514 return; |
| 515 is_composing_text_ = true; | 515 is_composing_text_ = true; |
| 516 } | 516 } |
| 517 | 517 |
| 518 void GtkIMContextWrapper::HandlePreeditChanged(const gchar* text, | 518 void GtkIMContextWrapper::HandlePreeditChanged(const gchar* text, |
| 519 PangoAttrList* attrs, | 519 PangoAttrList* attrs, |
| 520 int cursor_position) { | 520 int cursor_position) { |
| 521 // Ignore preedit related signals triggered by CancelComposition() method. | 521 // Ignore preedit related signals triggered by CancelComposition() method. |
| 522 if (suppress_next_commit_) | 522 if (suppress_next_commit_) |
| 523 return; | 523 return; |
| 524 | 524 |
| 525 // Don't set is_composition_changed_ to false if there is no change, because | 525 // Don't set is_composition_changed_ to false if there is no change, because |
| 526 // this handler might be called multiple times with the same data. | 526 // this handler might be called multiple times with the same data. |
| 527 is_composition_changed_ = true; | 527 is_composition_changed_ = true; |
| 528 composition_.Clear(); | 528 composition_.Clear(); |
| 529 | 529 |
| 530 ui::ExtractCompositionTextFromGtkPreedit(text, attrs, cursor_position, | 530 ui::ExtractCompositionTextFromGtkPreedit(text, attrs, cursor_position, |
| 531 &composition_); | 531 &composition_); |
| 532 | 532 |
| 533 // TODO(suzhe): due to a bug of webkit, we currently can't use selection range | 533 // TODO(suzhe): due to a bug of webkit, we currently can't use selection range |
| 534 // with composition string. See: https://bugs.webkit.org/show_bug.cgi?id=40805 | 534 // with composition string. See: https://bugs.webkit.org/show_bug.cgi?id=40805 |
| 535 composition_.selection = ui::Range(cursor_position); | 535 composition_.selection = gfx::Range(cursor_position); |
| 536 | 536 |
| 537 // In case we are using a buggy input method which doesn't fire | 537 // In case we are using a buggy input method which doesn't fire |
| 538 // "preedit_start" signal. | 538 // "preedit_start" signal. |
| 539 if (composition_.text.length()) | 539 if (composition_.text.length()) |
| 540 is_composing_text_ = true; | 540 is_composing_text_ = true; |
| 541 | 541 |
| 542 // Nothing needs to do, if it's currently in ProcessKeyEvent() | 542 // Nothing needs to do, if it's currently in ProcessKeyEvent() |
| 543 // handler, which will send preedit text to webkit later. | 543 // handler, which will send preedit text to webkit later. |
| 544 // Otherwise, we need send it here if it's been changed. | 544 // Otherwise, we need send it here if it's been changed. |
| 545 if (!is_in_key_event_handler_ && is_composing_text_ && | 545 if (!is_in_key_event_handler_ && is_composing_text_ && |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 GtkWidget* widget, GtkIMContextWrapper* self) { | 656 GtkWidget* widget, GtkIMContextWrapper* self) { |
| 657 self->HandleHostViewRealize(widget); | 657 self->HandleHostViewRealize(widget); |
| 658 } | 658 } |
| 659 | 659 |
| 660 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( | 660 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( |
| 661 GtkWidget* widget, GtkIMContextWrapper* self) { | 661 GtkWidget* widget, GtkIMContextWrapper* self) { |
| 662 self->HandleHostViewUnrealize(); | 662 self->HandleHostViewUnrealize(); |
| 663 } | 663 } |
| 664 | 664 |
| 665 } // namespace content | 665 } // namespace content |
| OLD | NEW |