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

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

Powered by Google App Engine
This is Rietveld 408576698