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

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

Powered by Google App Engine
This is Rietveld 408576698