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

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: moving IME code to aura_shell. not ready for 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 } 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 return false; 478 return false;
449 } 479 }
450 480
451 void RenderWidgetHostViewAura::UnlockMouse() { 481 void RenderWidgetHostViewAura::UnlockMouse() {
452 // http://crbug.com/102563 482 // http://crbug.com/102563
453 NOTIMPLEMENTED(); 483 NOTIMPLEMENTED();
454 host_->LostMouseLock(); 484 host_->LostMouseLock();
455 } 485 }
456 486
457 //////////////////////////////////////////////////////////////////////////////// 487 ////////////////////////////////////////////////////////////////////////////////
488 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
489 void RenderWidgetHostViewAura::SetCompositionText(
490 const ui::CompositionText& composition) {
491 if (!host_)
492 return;
493
494 // ui::CompositionUnderline should be identical to
495 // WebKit::WebCompositionUnderline, so that we can do reinterpret_cast safely.
496 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) ==
497 sizeof(WebKit::WebCompositionUnderline),
498 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff);
499
500 // TODO(suzhe): convert both renderer_host and renderer to use
501 // ui::CompositionText.
502 const std::vector<WebKit::WebCompositionUnderline>& underlines =
503 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>(
504 composition.underlines);
505
506 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
507 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
508 host_->ImeSetComposition(composition.text, underlines,
509 composition.selection.end(),
510 composition.selection.end());
511
512 has_composition_text_ = !composition.text.empty();
513 }
514
515 void RenderWidgetHostViewAura::ConfirmCompositionText() {
516 if (host_ && has_composition_text_)
517 host_->ImeConfirmComposition();
518 has_composition_text_ = false;
519 }
520
521 void RenderWidgetHostViewAura::ClearCompositionText() {
522 if (host_ && has_composition_text_)
523 host_->ImeCancelComposition();
524 has_composition_text_ = false;
525 }
526
527 void RenderWidgetHostViewAura::InsertText(const string16& text) {
528 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE);
529 if (host_)
530 host_->ImeConfirmComposition(text);
531 has_composition_text_ = false;
532 }
533
534 void RenderWidgetHostViewAura::InsertChar(char16 ch, int flags) {
535 if (host_) {
536 // Send a WebKit::WebInputEvent::Char event to |host_|.
537 NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
538 true /* is_char */,
539 ch,
540 flags,
541 base::Time::Now().ToDoubleT());
542 host_->ForwardKeyboardEvent(webkit_event);
543 }
544 }
545
546 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
547 return text_input_type_;
548 }
549
550 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() {
551 const gfx::Rect rect = selection_start_rect_.Union(selection_end_rect_);
552 gfx::Point origin = rect.origin();
553 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
554
555 aura::RootWindow* root_window = aura::RootWindow::GetInstance();
556 aura::Window::ConvertPointToWindow(window_, root_window, &origin);
557 aura::Window::ConvertPointToWindow(window_, root_window, &end);
558 // TODO(yusukes): Unlike Chrome OS, |root_window| origin might not be the
559 // same as the system screen origin on Windows and Linux. Probably we should
560 // (implement and) use something like ConvertPointToScreen().
561
562 return gfx::Rect(origin.x(),
563 origin.y(),
564 end.x() - origin.x(),
565 end.y() - origin.y());
566 }
567
568 bool RenderWidgetHostViewAura::HasCompositionText() {
569 return has_composition_text_;
570 }
571
572 bool RenderWidgetHostViewAura::GetTextRange(ui::Range* range) {
573 range->set_start(selection_text_offset_);
574 range->set_end(selection_text_offset_ + selection_text_.length());
575 return true;
576 }
577
578 bool RenderWidgetHostViewAura::GetCompositionTextRange(ui::Range* range) {
579 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
580 NOTIMPLEMENTED();
581 return false;
582 }
583
584 bool RenderWidgetHostViewAura::GetSelectionRange(ui::Range* range) {
585 range->set_start(selection_range_.start());
586 range->set_end(selection_range_.end());
587 return true;
588 }
589
590 bool RenderWidgetHostViewAura::SetSelectionRange(const ui::Range& range) {
591 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
592 NOTIMPLEMENTED();
593 return false;
594 }
595
596 bool RenderWidgetHostViewAura::DeleteRange(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::GetTextFromRange(
603 const ui::Range& range,
604 string16* text) {
605 ui::Range selection_text_range(selection_text_offset_,
606 selection_text_offset_ + selection_text_.length());
607
608 if (!selection_text_range.Contains(range)) {
609 text->clear();
610 return false;
611 }
612 if (selection_text_range.EqualsIgnoringDirection(range)) {
613 // Avoid calling substr whose performance is low.
614 *text = selection_text_;
615 } else {
616 *text = selection_text_.substr(
617 range.GetMin() - selection_text_offset_,
618 range.length());
619 }
620 return true;
621 }
622
623 void RenderWidgetHostViewAura::OnInputMethodChanged() {
624 if (!host_)
625 return;
626
627 host_->SetInputMethodActive(GetInputMethod()->IsActive());
628
629 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
630 // TextEvent.
631 }
632
633 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
634 base::i18n::TextDirection direction) {
635 if (!host_)
636 return false;
637 host_->UpdateTextDirection(
638 direction == base::i18n::RIGHT_TO_LEFT ?
639 WebKit::WebTextDirectionRightToLeft :
640 WebKit::WebTextDirectionLeftToRight);
641 host_->NotifyTextDirection();
642 return true;
643 }
644
645 ////////////////////////////////////////////////////////////////////////////////
458 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 646 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
459 647
460 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const { 648 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
461 return gfx::Size(); 649 return gfx::Size();
462 } 650 }
463 651
464 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 652 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
465 const gfx::Rect& new_bounds) { 653 const gfx::Rect& new_bounds) {
466 // We don't care about this one, we are always sized via SetSize() or 654 // We don't care about this one, we are always sized via SetSize() or
467 // SetBounds(). 655 // SetBounds().
468 } 656 }
469 657
470 void RenderWidgetHostViewAura::OnFocus() { 658 void RenderWidgetHostViewAura::OnFocus() {
471 host_->GotFocus(); 659 host_->GotFocus();
660
661 ui::InputMethod* input_method = GetInputMethod();
662 // Ask the system-wide IME to send all TextInputClient messages to |this|
663 // object.
664 input_method->SetFocusedTextInputClient(this);
665
666 host_->SetInputMethodActive(input_method->IsActive());
472 } 667 }
473 668
474 void RenderWidgetHostViewAura::OnBlur() { 669 void RenderWidgetHostViewAura::OnBlur() {
475 host_->Blur(); 670 host_->Blur();
671
672 ui::InputMethod* input_method = GetInputMethod();
673 if (input_method->GetTextInputClient() == this)
674 input_method->SetFocusedTextInputClient(NULL);
675 host_->SetInputMethodActive(false);
476 } 676 }
477 677
478 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 678 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
479 // We need to handle the Escape key for Pepper Flash. 679 // We need to handle the Escape key for Pepper Flash.
480 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 680 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
481 host_->Shutdown(); 681 host_->Shutdown();
482 } else { 682 } else {
483 NativeWebKeyboardEvent webkit_event(event); 683 // We don't have to communicate with an input method here.
484 host_->ForwardKeyboardEvent(webkit_event); 684 #if defined(USE_X11)
685 if (!event->native_event()) {
686 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
687 NativeWebKeyboardEvent webkit_event(event->type(),
688 false /* is_char */,
689 event->GetCharacter(),
690 event->flags(),
691 base::Time::Now().ToDoubleT());
692 host_->ForwardKeyboardEvent(webkit_event);
693 } else
694 #endif
695 {
696 NativeWebKeyboardEvent webkit_event(event);
697 host_->ForwardKeyboardEvent(webkit_event);
698 }
485 } 699 }
486 return true; 700 return true;
487 } 701 }
488 702
489 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 703 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
490 return current_cursor_.GetNativeCursor(); 704 return current_cursor_.GetNativeCursor();
491 } 705 }
492 706
493 int RenderWidgetHostViewAura::GetNonClientComponent( 707 int RenderWidgetHostViewAura::GetNonClientComponent(
494 const gfx::Point& point) const { 708 const gfx::Point& point) const {
495 return HTCLIENT; 709 return HTCLIENT;
496 } 710 }
497 711
498 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 712 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
499 if (event->type() == ui::ET_MOUSEWHEEL) 713 if (event->type() == ui::ET_MOUSEWHEEL)
500 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 714 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
501 else if (CanRendererHandleEvent(event->native_event())) 715 else if (CanRendererHandleEvent(event->native_event()))
502 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 716 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
503 717
504 switch (event->type()) { 718 switch (event->type()) {
505 case ui::ET_MOUSE_PRESSED: 719 case ui::ET_MOUSE_PRESSED:
506 window_->SetCapture(); 720 window_->SetCapture();
721 // Confirm existing composition text on mouse click events, to make sure
722 // the input caret won't be moved with an ongoing composition text.
723 FinishImeCompositionSession();
507 break; 724 break;
508 case ui::ET_MOUSE_RELEASED: 725 case ui::ET_MOUSE_RELEASED:
509 window_->ReleaseCapture(); 726 window_->ReleaseCapture();
510 break; 727 break;
511 default: 728 default:
512 break; 729 break;
513 } 730 }
514 731
515 // Return true so that we receive released/drag events. 732 // Return true so that we receive released/drag events.
516 return true; 733 return true;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 // static 829 // static
613 void RenderWidgetHostView::GetDefaultScreenInfo( 830 void RenderWidgetHostView::GetDefaultScreenInfo(
614 WebKit::WebScreenInfo* results) { 831 WebKit::WebScreenInfo* results) {
615 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 832 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
616 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 833 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
617 results->availableRect = results->rect; 834 results->availableRect = results->rect;
618 // TODO(derat): Don't hardcode this? 835 // TODO(derat): Don't hardcode this?
619 results->depth = 24; 836 results->depth = 24;
620 results->depthPerComponent = 8; 837 results->depthPerComponent = 8;
621 } 838 }
839
840 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const {
841 ui::InputMethod* input_method =
842 aura::RootWindow::GetInstance()->input_method();
843 DCHECK(input_method);
844 return input_method;
845 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.h ('k') | content/public/browser/native_web_keyboard_event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698