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 23 matching lines...) Expand all Loading... |
34 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx | 34 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx |
35 // - How the IME System Works | 35 // - How the IME System Works |
36 // http://msdn.microsoft.com/en-us/library/cc194848.aspx | 36 // http://msdn.microsoft.com/en-us/library/cc194848.aspx |
37 // - ImmGetVirtualKey Function | 37 // - ImmGetVirtualKey Function |
38 // http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx | 38 // http://msdn.microsoft.com/en-us/library/dd318570(VS.85).aspx |
39 const int kCompositionEventKeyCode = 229; | 39 const int kCompositionEventKeyCode = 229; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 // ui::CompositionUnderline should be identical to | 43 // ui::CompositionUnderline should be identical to |
44 // WebKit::WebCompositionUnderline, so that we can do reinterpret_cast safely. | 44 // blink::WebCompositionUnderline, so that we can do reinterpret_cast safely. |
45 // TODO(suzhe): remove it after migrating all code in chrome to use | 45 // TODO(suzhe): remove it after migrating all code in chrome to use |
46 // ui::CompositionUnderline. | 46 // ui::CompositionUnderline. |
47 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) == | 47 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) == |
48 sizeof(WebKit::WebCompositionUnderline), | 48 sizeof(blink::WebCompositionUnderline), |
49 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff); | 49 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff); |
50 | 50 |
51 GtkIMContextWrapper::GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view) | 51 GtkIMContextWrapper::GtkIMContextWrapper(RenderWidgetHostViewGtk* host_view) |
52 : host_view_(host_view), | 52 : host_view_(host_view), |
53 context_(gtk_im_multicontext_new()), | 53 context_(gtk_im_multicontext_new()), |
54 context_simple_(gtk_im_context_simple_new()), | 54 context_simple_(gtk_im_context_simple_new()), |
55 is_focused_(false), | 55 is_focused_(false), |
56 is_composing_text_(false), | 56 is_composing_text_(false), |
57 is_enabled_(false), | 57 is_enabled_(false), |
58 is_in_key_event_handler_(false), | 58 is_in_key_event_handler_(false), |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // 1. The given key event is a control-key event, (e.g. return, page up, | 395 // 1. The given key event is a control-key event, (e.g. return, page up, |
396 // page down, tab, arrows, etc.) or; | 396 // page down, tab, arrows, etc.) or; |
397 // 2. The given key event is not a control-key event but printable | 397 // 2. The given key event is not a control-key event but printable |
398 // characters aren't assigned to the event, (e.g. alt+d, etc.) | 398 // characters aren't assigned to the event, (e.g. alt+d, etc.) |
399 // Create a Char event manually from this key event and send it to the | 399 // Create a Char event manually from this key event and send it to the |
400 // renderer when this Char event contains a printable character which | 400 // renderer when this Char event contains a printable character which |
401 // should be processed by WebKit. | 401 // should be processed by WebKit. |
402 // isSystemKey will be set to true if this key event has Alt modifier, | 402 // isSystemKey will be set to true if this key event has Alt modifier, |
403 // see WebInputEventFactory::keyboardEvent() for details. | 403 // see WebInputEventFactory::keyboardEvent() for details. |
404 if (wke->text[0]) { | 404 if (wke->text[0]) { |
405 wke->type = WebKit::WebInputEvent::Char; | 405 wke->type = blink::WebInputEvent::Char; |
406 wke->skip_in_browser = true; | 406 wke->skip_in_browser = true; |
407 host_view_->ForwardKeyboardEvent(*wke); | 407 host_view_->ForwardKeyboardEvent(*wke); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 void GtkIMContextWrapper::ProcessInputMethodResult(const GdkEventKey* event, | 411 void GtkIMContextWrapper::ProcessInputMethodResult(const GdkEventKey* event, |
412 bool filtered) { | 412 bool filtered) { |
413 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( | 413 RenderWidgetHostImpl* host = RenderWidgetHostImpl::From( |
414 host_view_->GetRenderWidgetHost()); | 414 host_view_->GetRenderWidgetHost()); |
415 if (!host) | 415 if (!host) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_) { |
453 if (composition_.text.length()) { | 453 if (composition_.text.length()) { |
454 // Another composition session has been started. | 454 // Another composition session has been started. |
455 is_composing_text_ = true; | 455 is_composing_text_ = true; |
456 // TODO(suzhe): convert both renderer_host and renderer to use | 456 // TODO(suzhe): convert both renderer_host and renderer to use |
457 // ui::CompositionText. | 457 // ui::CompositionText. |
458 const std::vector<WebKit::WebCompositionUnderline>& underlines = | 458 const std::vector<blink::WebCompositionUnderline>& underlines = |
459 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>( | 459 reinterpret_cast<const std::vector<blink::WebCompositionUnderline>&>( |
460 composition_.underlines); | 460 composition_.underlines); |
461 host->ImeSetComposition(composition_.text, underlines, | 461 host->ImeSetComposition(composition_.text, underlines, |
462 composition_.selection.start(), | 462 composition_.selection.start(), |
463 composition_.selection.end()); | 463 composition_.selection.end()); |
464 } else if (!committed) { | 464 } else if (!committed) { |
465 host->ImeCancelComposition(); | 465 host->ImeCancelComposition(); |
466 } | 466 } |
467 } | 467 } |
468 } | 468 } |
469 | 469 |
(...skipping 23 matching lines...) Expand all Loading... |
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(blink::WebInputEvent::RawKeyDown); |
504 RenderWidgetHostImpl::From( | 504 RenderWidgetHostImpl::From( |
505 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( | 505 host_view_->GetRenderWidgetHost())->ImeConfirmComposition( |
506 text, gfx::Range::InvalidRange(), false); | 506 text, gfx::Range::InvalidRange(), false); |
507 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp); | 507 SendFakeCompositionKeyEvent(blink::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 |
(...skipping 20 matching lines...) Expand all Loading... |
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_ && |
546 host_view_->GetRenderWidgetHost()) { | 546 host_view_->GetRenderWidgetHost()) { |
547 // Workaround http://crbug.com/45478 by sending fake key down/up events. | 547 // Workaround http://crbug.com/45478 by sending fake key down/up events. |
548 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::RawKeyDown); | 548 SendFakeCompositionKeyEvent(blink::WebInputEvent::RawKeyDown); |
549 // TODO(suzhe): convert both renderer_host and renderer to use | 549 // TODO(suzhe): convert both renderer_host and renderer to use |
550 // ui::CompositionText. | 550 // ui::CompositionText. |
551 const std::vector<WebKit::WebCompositionUnderline>& underlines = | 551 const std::vector<blink::WebCompositionUnderline>& underlines = |
552 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>( | 552 reinterpret_cast<const std::vector<blink::WebCompositionUnderline>&>( |
553 composition_.underlines); | 553 composition_.underlines); |
554 RenderWidgetHostImpl::From( | 554 RenderWidgetHostImpl::From( |
555 host_view_->GetRenderWidgetHost())->ImeSetComposition( | 555 host_view_->GetRenderWidgetHost())->ImeSetComposition( |
556 composition_.text, underlines, composition_.selection.start(), | 556 composition_.text, underlines, composition_.selection.start(), |
557 composition_.selection.end()); | 557 composition_.selection.end()); |
558 SendFakeCompositionKeyEvent(WebKit::WebInputEvent::KeyUp); | 558 SendFakeCompositionKeyEvent(blink::WebInputEvent::KeyUp); |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 void GtkIMContextWrapper::HandlePreeditEnd() { | 562 void GtkIMContextWrapper::HandlePreeditEnd() { |
563 if (composition_.text.length()) { | 563 if (composition_.text.length()) { |
564 // The composition session has been finished. | 564 // The composition session has been finished. |
565 composition_.Clear(); | 565 composition_.Clear(); |
566 is_composition_changed_ = true; | 566 is_composition_changed_ = true; |
567 | 567 |
568 // If there is still a preedit text when firing "preedit-end" signal, | 568 // If there is still a preedit text when firing "preedit-end" signal, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 gtk_im_context_set_client_window(context_simple_, gdk_window); | 606 gtk_im_context_set_client_window(context_simple_, gdk_window); |
607 } | 607 } |
608 } | 608 } |
609 | 609 |
610 void GtkIMContextWrapper::HandleHostViewUnrealize() { | 610 void GtkIMContextWrapper::HandleHostViewUnrealize() { |
611 gtk_im_context_set_client_window(context_, NULL); | 611 gtk_im_context_set_client_window(context_, NULL); |
612 gtk_im_context_set_client_window(context_simple_, NULL); | 612 gtk_im_context_set_client_window(context_simple_, NULL); |
613 } | 613 } |
614 | 614 |
615 void GtkIMContextWrapper::SendFakeCompositionKeyEvent( | 615 void GtkIMContextWrapper::SendFakeCompositionKeyEvent( |
616 WebKit::WebInputEvent::Type type) { | 616 blink::WebInputEvent::Type type) { |
617 NativeWebKeyboardEvent fake_event; | 617 NativeWebKeyboardEvent fake_event; |
618 fake_event.windowsKeyCode = kCompositionEventKeyCode; | 618 fake_event.windowsKeyCode = kCompositionEventKeyCode; |
619 fake_event.skip_in_browser = true; | 619 fake_event.skip_in_browser = true; |
620 fake_event.type = type; | 620 fake_event.type = type; |
621 host_view_->ForwardKeyboardEvent(fake_event); | 621 host_view_->ForwardKeyboardEvent(fake_event); |
622 } | 622 } |
623 | 623 |
624 void GtkIMContextWrapper::HandleCommitThunk( | 624 void GtkIMContextWrapper::HandleCommitThunk( |
625 GtkIMContext* context, gchar* text, GtkIMContextWrapper* self) { | 625 GtkIMContext* context, gchar* text, GtkIMContextWrapper* self) { |
626 self->HandleCommit(UTF8ToUTF16(text)); | 626 self->HandleCommit(UTF8ToUTF16(text)); |
(...skipping 29 matching lines...) Expand all 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 |