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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 8576005: IME (input method editor) support for Aura, part 3 of 3: Use ui::InputMethod in ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git mv desktop_host_unittest.cc desktop_host_ime_unittest.cc 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
OLDNEW
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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/renderer_host/backing_store_skia.h" 8 #include "content/browser/renderer_host/backing_store_skia.h"
9 #include "content/browser/renderer_host/render_widget_host.h" 9 #include "content/browser/renderer_host/render_widget_host.h"
10 #include "content/browser/renderer_host/web_input_event_aura.h" 10 #include "content/browser/renderer_host/web_input_event_aura.h"
11 #include "content/public/browser/native_web_keyboard_event.h" 11 #include "content/public/browser/native_web_keyboard_event.h"
12 #include "content/common/gpu/gpu_messages.h" 12 #include "content/common/gpu/gpu_messages.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
15 #include "ui/aura/client/aura_constants.h" 16 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/desktop.h" 17 #include "ui/aura/desktop.h"
17 #include "ui/aura/event.h" 18 #include "ui/aura/event.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 #include "ui/aura/window_types.h" 20 #include "ui/aura/window_types.h"
20 #include "ui/base/hit_test.h" 21 #include "ui/base/hit_test.h"
22 #include "ui/base/ime/input_method.h"
21 #include "ui/base/ui_base_types.h" 23 #include "ui/base/ui_base_types.h"
22 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
23 #include "ui/gfx/compositor/layer.h" 25 #include "ui/gfx/compositor/layer.h"
24 #include "ui/gfx/screen.h" 26 #include "ui/gfx/screen.h"
25 27
26 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 28 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
27 #include "base/bind.h" 29 #include "base/bind.h"
28 #include "content/browser/renderer_host/accelerated_surface_container_linux.h" 30 #include "content/browser/renderer_host/accelerated_surface_container_linux.h"
29 #include "ui/gfx/gl/gl_bindings.h" 31 #include "ui/gfx/gl/gl_bindings.h"
30 #endif 32 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 88
87 //////////////////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////////////////
88 // RenderWidgetHostViewAura, public: 90 // RenderWidgetHostViewAura, public:
89 91
90 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 92 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
91 : host_(host), 93 : host_(host),
92 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 94 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
93 is_fullscreen_(false), 95 is_fullscreen_(false),
94 popup_parent_host_view_(NULL), 96 popup_parent_host_view_(NULL),
95 is_loading_(false), 97 is_loading_(false),
98 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
99 has_composition_text_(false),
96 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 100 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
97 current_surface_(gfx::kNullPluginWindow), 101 current_surface_(gfx::kNullPluginWindow),
98 #endif 102 #endif
99 skip_schedule_paint_(false) { 103 skip_schedule_paint_(false) {
100 host_->SetView(this); 104 host_->SetView(this);
101 window_->SetProperty(aura::kTooltipTextKey, &tooltip_); 105 window_->SetProperty(aura::kTooltipTextKey, &tooltip_);
102 } 106 }
103 107
104 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { 108 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
105 } 109 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 227 }
224 228
225 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 229 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
226 is_loading_ = is_loading; 230 is_loading_ = is_loading;
227 UpdateCursorIfOverSelf(); 231 UpdateCursorIfOverSelf();
228 } 232 }
229 233
230 void RenderWidgetHostViewAura::TextInputStateChanged( 234 void RenderWidgetHostViewAura::TextInputStateChanged(
231 ui::TextInputType type, 235 ui::TextInputType type,
232 bool can_compose_inline) { 236 bool can_compose_inline) {
233 // http://crbug.com/102569 237 // TODO(kinaba): currently, can_compose_inline is ignored and always treated
234 NOTIMPLEMENTED(); 238 // as true. We need to support "can_compose_inline=false" for PPAPI plugins
239 // that may want to avoid drawing composition-text by themselves and pass
240 // the responsibility to the browser.
241 if (text_input_type_ != type) {
242 text_input_type_ = type;
243 GetInputMethod()->OnTextInputTypeChanged(this);
244 }
235 } 245 }
236 246
237 void RenderWidgetHostViewAura::ImeCancelComposition() { 247 void RenderWidgetHostViewAura::ImeCancelComposition() {
238 // http://crbug.com/102569 248 GetInputMethod()->CancelComposition(this);
239 NOTIMPLEMENTED(); 249 has_composition_text_ = false;
250 }
251
252 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
253 if (!has_composition_text_)
254 return;
255 if (host_)
256 host_->ImeConfirmComposition();
257 ImeCancelComposition();
240 } 258 }
241 259
242 void RenderWidgetHostViewAura::DidUpdateBackingStore( 260 void RenderWidgetHostViewAura::DidUpdateBackingStore(
243 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 261 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
244 const std::vector<gfx::Rect>& copy_rects) { 262 const std::vector<gfx::Rect>& copy_rects) {
245 if (!window_->IsVisible() || skip_schedule_paint_) 263 if (!window_->IsVisible() || skip_schedule_paint_)
246 return; 264 return;
247 265
248 if (!scroll_rect.IsEmpty()) 266 if (!scroll_rect.IsEmpty())
249 window_->SchedulePaintInRect(scroll_rect); 267 window_->SchedulePaintInRect(scroll_rect);
(...skipping 14 matching lines...) Expand all
264 } 282 }
265 283
266 void RenderWidgetHostViewAura::Destroy() { 284 void RenderWidgetHostViewAura::Destroy() {
267 delete window_; 285 delete window_;
268 } 286 }
269 287
270 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) { 288 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) {
271 tooltip_ = tooltip_text; 289 tooltip_ = tooltip_text;
272 } 290 }
273 291
292 void RenderWidgetHostViewAura::SelectionBoundsChanged(
293 const gfx::Rect& start_rect,
294 const gfx::Rect& end_rect) {
295 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
296 return;
297
298 selection_start_rect_ = start_rect;
299 selection_end_rect_ = end_rect;
300
301 GetInputMethod()->OnCaretBoundsChanged(this);
302 }
303
274 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( 304 BackingStore* RenderWidgetHostViewAura::AllocBackingStore(
275 const gfx::Size& size) { 305 const gfx::Size& size) {
276 return new BackingStoreSkia(host_, size); 306 return new BackingStoreSkia(host_, size);
277 } 307 }
278 308
279 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { 309 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() {
280 UpdateExternalTexture(); 310 UpdateExternalTexture();
281 } 311 }
282 312
283 void RenderWidgetHostViewAura::UpdateExternalTexture() { 313 void RenderWidgetHostViewAura::UpdateExternalTexture() {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 return false; 474 return false;
445 } 475 }
446 476
447 void RenderWidgetHostViewAura::UnlockMouse() { 477 void RenderWidgetHostViewAura::UnlockMouse() {
448 // http://crbug.com/102563 478 // http://crbug.com/102563
449 NOTIMPLEMENTED(); 479 NOTIMPLEMENTED();
450 host_->LostMouseLock(); 480 host_->LostMouseLock();
451 } 481 }
452 482
453 //////////////////////////////////////////////////////////////////////////////// 483 ////////////////////////////////////////////////////////////////////////////////
484 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
485 void RenderWidgetHostViewAura::SetCompositionText(
486 const ui::CompositionText& composition) {
487 if (!host_)
488 return;
489
490 // ui::CompositionUnderline should be identical to
491 // WebKit::WebCompositionUnderline, so that we can do reinterpret_cast safely.
492 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) ==
493 sizeof(WebKit::WebCompositionUnderline),
494 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff);
495
496 // TODO(suzhe): convert both renderer_host and renderer to use
497 // ui::CompositionText.
498 const std::vector<WebKit::WebCompositionUnderline>& underlines =
499 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>(
500 composition.underlines);
501
502 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
503 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
504 host_->ImeSetComposition(composition.text, underlines,
505 composition.selection.end(),
506 composition.selection.end());
507
508 has_composition_text_ = !composition.text.empty();
509 }
510
511 void RenderWidgetHostViewAura::ConfirmCompositionText() {
512 if (host_ && has_composition_text_)
513 host_->ImeConfirmComposition();
514 has_composition_text_ = false;
515 }
516
517 void RenderWidgetHostViewAura::ClearCompositionText() {
518 if (host_ && has_composition_text_)
519 host_->ImeCancelComposition();
520 has_composition_text_ = false;
521 }
522
523 void RenderWidgetHostViewAura::InsertText(const string16& text) {
524 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE);
525 if (host_)
526 host_->ImeConfirmComposition(text);
527 has_composition_text_ = false;
528 }
529
530 void RenderWidgetHostViewAura::InsertChar(char16 ch, int flags) {
531 if (host_) {
532 // Send a WebKit::WebInputEvent::Char event to |host_|.
533 NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
534 true /* is_char */,
535 ch,
536 flags,
537 base::Time::Now().ToDoubleT());
538 host_->ForwardKeyboardEvent(webkit_event);
539 }
540 }
541
542 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
543 return text_input_type_;
544 }
545
546 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() {
547 const gfx::Rect rect = selection_start_rect_.Union(selection_end_rect_);
548 gfx::Point origin = rect.origin();
549 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
550
551 aura::Desktop* desktop = aura::Desktop::GetInstance();
552 aura::Window::ConvertPointToWindow(window_, desktop, &origin);
553 aura::Window::ConvertPointToWindow(window_, desktop, &end);
554 // TODO(yusukes): Unlike Chrome OS, |desktop| origin might not be the same as
555 // the system screen origin on Windows and Linux. Probably we should
556 // (implement and) use something like ConvertPointToScreen().
557
558 return gfx::Rect(origin.x(),
559 origin.y(),
560 end.x() - origin.x(),
561 end.y() - origin.y());
562 }
563
564 bool RenderWidgetHostViewAura::HasCompositionText() {
565 return has_composition_text_;
566 }
567
568 bool RenderWidgetHostViewAura::GetTextRange(ui::Range* range) {
569 range->set_start(selection_text_offset_);
570 range->set_end(selection_text_offset_ + selection_text_.length());
571 return true;
572 }
573
574 bool RenderWidgetHostViewAura::GetCompositionTextRange(ui::Range* range) {
575 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
576 NOTIMPLEMENTED();
577 return false;
578 }
579
580 bool RenderWidgetHostViewAura::GetSelectionRange(ui::Range* range) {
581 range->set_start(selection_range_.start());
582 range->set_end(selection_range_.end());
583 return true;
584 }
585
586 bool RenderWidgetHostViewAura::SetSelectionRange(const ui::Range& range) {
587 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
588 NOTIMPLEMENTED();
589 return false;
590 }
591
592 bool RenderWidgetHostViewAura::DeleteRange(const ui::Range& range) {
593 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
594 NOTIMPLEMENTED();
595 return false;
596 }
597
598 bool RenderWidgetHostViewAura::GetTextFromRange(
599 const ui::Range& range,
600 string16* text) {
601 ui::Range selection_text_range(selection_text_offset_,
602 selection_text_offset_ + selection_text_.length());
603
604 if (!selection_text_range.Contains(range)) {
605 text->clear();
606 return false;
607 }
608 if (selection_text_range.EqualsIgnoringDirection(range)) {
609 // Avoid calling substr whose performance is low.
610 *text = selection_text_;
611 } else {
612 *text = selection_text_.substr(
613 range.GetMin() - selection_text_offset_,
614 range.length());
615 }
616 return true;
617 }
618
619 void RenderWidgetHostViewAura::OnInputMethodChanged() {
620 if (!host_)
621 return;
622
623 host_->SetInputMethodActive(GetInputMethod()->IsActive());
624
625 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
626 // TextEvent.
627 }
628
629 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
630 base::i18n::TextDirection direction) {
631 if (!host_)
632 return false;
633 host_->UpdateTextDirection(
634 direction == base::i18n::RIGHT_TO_LEFT ?
635 WebKit::WebTextDirectionRightToLeft :
636 WebKit::WebTextDirectionLeftToRight);
637 host_->NotifyTextDirection();
638 return true;
639 }
640
641 ////////////////////////////////////////////////////////////////////////////////
454 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 642 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
455 643
456 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const { 644 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
457 return gfx::Size(); 645 return gfx::Size();
458 } 646 }
459 647
460 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 648 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
461 const gfx::Rect& new_bounds) { 649 const gfx::Rect& new_bounds) {
462 // We don't care about this one, we are always sized via SetSize() or 650 // We don't care about this one, we are always sized via SetSize() or
463 // SetBounds(). 651 // SetBounds().
464 } 652 }
465 653
466 void RenderWidgetHostViewAura::OnFocus() { 654 void RenderWidgetHostViewAura::OnFocus() {
467 host_->GotFocus(); 655 host_->GotFocus();
656
657 ui::InputMethod* input_method = GetInputMethod();
658 // Ask the system-wide IME to send all TextInputClient messages to |this|
659 // object.
660 input_method->SetFocusedTextInputClient(this);
661
662 host_->SetInputMethodActive(input_method->IsActive());
468 } 663 }
469 664
470 void RenderWidgetHostViewAura::OnBlur() { 665 void RenderWidgetHostViewAura::OnBlur() {
471 host_->Blur(); 666 host_->Blur();
667
668 ui::InputMethod* input_method = GetInputMethod();
669 if (input_method->GetTextInputClient() == this)
670 input_method->SetFocusedTextInputClient(NULL);
671 host_->SetInputMethodActive(false);
472 } 672 }
473 673
474 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 674 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
475 // We need to handle the Escape key for Pepper Flash. 675 // We need to handle the Escape key for Pepper Flash.
476 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 676 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
477 host_->Shutdown(); 677 host_->Shutdown();
478 } else { 678 } else {
479 NativeWebKeyboardEvent webkit_event(event); 679 // We don't have to communicate with an input method here. It has already
480 host_->ForwardKeyboardEvent(webkit_event); 680 // been done by ui/aura/desktop_host_<platform>.cc.
681 #if defined(USE_X11)
682 if (!event->native_event()) {
683 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
684 NativeWebKeyboardEvent webkit_event(event->type(),
685 false /* is_char */,
686 event->GetCharacter(),
687 event->flags(),
688 base::Time::Now().ToDoubleT());
689 host_->ForwardKeyboardEvent(webkit_event);
690 } else
691 #endif
692 {
693 NativeWebKeyboardEvent webkit_event(event);
694 host_->ForwardKeyboardEvent(webkit_event);
695 }
481 } 696 }
482 return true; 697 return true;
483 } 698 }
484 699
485 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 700 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
486 return current_cursor_.GetNativeCursor(); 701 return current_cursor_.GetNativeCursor();
487 } 702 }
488 703
489 int RenderWidgetHostViewAura::GetNonClientComponent( 704 int RenderWidgetHostViewAura::GetNonClientComponent(
490 const gfx::Point& point) const { 705 const gfx::Point& point) const {
491 return HTCLIENT; 706 return HTCLIENT;
492 } 707 }
493 708
494 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 709 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
495 if (event->type() == ui::ET_MOUSEWHEEL) 710 if (event->type() == ui::ET_MOUSEWHEEL)
496 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 711 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
497 else if (CanRendererHandleEvent(event->native_event())) 712 else if (CanRendererHandleEvent(event->native_event()))
498 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 713 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
499 714
500 switch (event->type()) { 715 switch (event->type()) {
501 case ui::ET_MOUSE_PRESSED: 716 case ui::ET_MOUSE_PRESSED:
502 window_->SetCapture(); 717 window_->SetCapture();
718 // Confirm existing composition text on mouse click events, to make sure
719 // the input caret won't be moved with an ongoing composition text.
720 FinishImeCompositionSession();
503 break; 721 break;
504 case ui::ET_MOUSE_RELEASED: 722 case ui::ET_MOUSE_RELEASED:
505 window_->ReleaseCapture(); 723 window_->ReleaseCapture();
506 break; 724 break;
507 default: 725 default:
508 break; 726 break;
509 } 727 }
510 728
511 // Return true so that we receive released/drag events. 729 // Return true so that we receive released/drag events.
512 return true; 730 return true;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 // static 822 // static
605 void RenderWidgetHostView::GetDefaultScreenInfo( 823 void RenderWidgetHostView::GetDefaultScreenInfo(
606 WebKit::WebScreenInfo* results) { 824 WebKit::WebScreenInfo* results) {
607 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 825 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
608 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 826 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
609 results->availableRect = results->rect; 827 results->availableRect = results->rect;
610 // TODO(derat): Don't hardcode this? 828 // TODO(derat): Don't hardcode this?
611 results->depth = 24; 829 results->depth = 24;
612 results->depthPerComponent = 8; 830 results->depthPerComponent = 8;
613 } 831 }
832
833 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() {
834 aura::Desktop* desktop = aura::Desktop::GetInstance();
835 return desktop->GetInputMethod();
836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698