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

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: fix RHWVA and ui::InputMethodBase 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;
240 } 250 }
241 251
242 void RenderWidgetHostViewAura::DidUpdateBackingStore( 252 void RenderWidgetHostViewAura::DidUpdateBackingStore(
243 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 253 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
244 const std::vector<gfx::Rect>& copy_rects) { 254 const std::vector<gfx::Rect>& copy_rects) {
245 if (!window_->IsVisible() || skip_schedule_paint_) 255 if (!window_->IsVisible() || skip_schedule_paint_)
246 return; 256 return;
247 257
248 if (!scroll_rect.IsEmpty()) 258 if (!scroll_rect.IsEmpty())
249 window_->SchedulePaintInRect(scroll_rect); 259 window_->SchedulePaintInRect(scroll_rect);
(...skipping 14 matching lines...) Expand all
264 } 274 }
265 275
266 void RenderWidgetHostViewAura::Destroy() { 276 void RenderWidgetHostViewAura::Destroy() {
267 delete window_; 277 delete window_;
268 } 278 }
269 279
270 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) { 280 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) {
271 tooltip_ = tooltip_text; 281 tooltip_ = tooltip_text;
272 } 282 }
273 283
284 void RenderWidgetHostViewAura::SelectionBoundsChanged(
285 const gfx::Rect& start_rect,
286 const gfx::Rect& end_rect) {
287 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
288 return;
289
290 selection_start_rect_ = start_rect;
291 selection_end_rect_ = end_rect;
292
293 GetInputMethod()->OnCaretBoundsChanged(this);
294 }
295
274 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( 296 BackingStore* RenderWidgetHostViewAura::AllocBackingStore(
275 const gfx::Size& size) { 297 const gfx::Size& size) {
276 return new BackingStoreSkia(host_, size); 298 return new BackingStoreSkia(host_, size);
277 } 299 }
278 300
279 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { 301 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() {
280 UpdateExternalTexture(); 302 UpdateExternalTexture();
281 } 303 }
282 304
283 void RenderWidgetHostViewAura::UpdateExternalTexture() { 305 void RenderWidgetHostViewAura::UpdateExternalTexture() {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 return false; 466 return false;
445 } 467 }
446 468
447 void RenderWidgetHostViewAura::UnlockMouse() { 469 void RenderWidgetHostViewAura::UnlockMouse() {
448 // http://crbug.com/102563 470 // http://crbug.com/102563
449 NOTIMPLEMENTED(); 471 NOTIMPLEMENTED();
450 host_->LostMouseLock(); 472 host_->LostMouseLock();
451 } 473 }
452 474
453 //////////////////////////////////////////////////////////////////////////////// 475 ////////////////////////////////////////////////////////////////////////////////
476 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
477 void RenderWidgetHostViewAura::SetCompositionText(
478 const ui::CompositionText& composition) {
479 if (!host_)
480 return;
481
482 // ui::CompositionUnderline should be identical to
483 // WebKit::WebCompositionUnderline, so that we can do reinterpret_cast safely.
484 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) ==
485 sizeof(WebKit::WebCompositionUnderline),
486 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff);
487
488 // TODO(suzhe): convert both renderer_host and renderer to use
489 // ui::CompositionText.
490 const std::vector<WebKit::WebCompositionUnderline>& underlines =
491 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>(
492 composition.underlines);
493
494 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
495 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
496 host_->ImeSetComposition(composition.text, underlines,
497 composition.selection.end(),
498 composition.selection.end());
499
500 has_composition_text_ = !composition.text.empty();
501 }
502
503 void RenderWidgetHostViewAura::ConfirmCompositionText() {
504 if (host_ && has_composition_text_)
505 host_->ImeConfirmComposition();
506 has_composition_text_ = false;
507 }
508
509 void RenderWidgetHostViewAura::ClearCompositionText() {
510 if (host_ && has_composition_text_)
511 host_->ImeCancelComposition();
512 has_composition_text_ = false;
513 }
514
515 void RenderWidgetHostViewAura::InsertText(const string16& text) {
516 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE);
517 if (host_)
518 host_->ImeConfirmComposition(text);
519 has_composition_text_ = false;
520 }
521
522 void RenderWidgetHostViewAura::InsertChar(char16 ch, int flags) {
523 if (host_) {
524 // Send a WebKit::WebInputEvent::Char event to |host_|.
525 NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
526 true /* is_char */,
527 ch,
528 flags,
529 base::Time::Now().ToDoubleT());
530 host_->ForwardKeyboardEvent(webkit_event);
531 }
532 }
533
534 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
535 return text_input_type_;
536 }
537
538 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() {
539 const gfx::Rect rect = selection_start_rect_.Union(selection_end_rect_);
540 gfx::Point origin = rect.origin();
541 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
542
543 aura::Desktop* desktop = aura::Desktop::GetInstance();
544 aura::Window::ConvertPointToWindow(window_, desktop, &origin);
545 aura::Window::ConvertPointToWindow(window_, desktop, &end);
546 // TODO(yusukes): Unlike Chrome OS, |desktop| origin might not be the same as
547 // the system screen origin on Windows and Linux. Probably we should
548 // (implement and) use something like ConvertPointToScreen().
549
550 return gfx::Rect(origin.x(),
551 origin.y(),
552 end.x() - origin.x(),
553 end.y() - origin.y());
554 }
555
556 bool RenderWidgetHostViewAura::HasCompositionText() {
557 return has_composition_text_;
558 }
559
560 bool RenderWidgetHostViewAura::GetTextRange(ui::Range* range) {
561 range->set_start(selection_text_offset_);
562 range->set_end(selection_text_offset_ + selection_text_.length());
563 return true;
564 }
565
566 bool RenderWidgetHostViewAura::GetCompositionTextRange(ui::Range* range) {
567 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
568 NOTIMPLEMENTED();
569 return false;
570 }
571
572 bool RenderWidgetHostViewAura::GetSelectionRange(ui::Range* range) {
573 range->set_start(selection_range_.start());
574 range->set_end(selection_range_.end());
575 return true;
576 }
577
578 bool RenderWidgetHostViewAura::SetSelectionRange(const 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::DeleteRange(const 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::GetTextFromRange(
591 const ui::Range& range,
592 string16* text) {
593 ui::Range selection_text_range(selection_text_offset_,
594 selection_text_offset_ + selection_text_.length());
595
596 if (!selection_text_range.Contains(range)) {
597 text->clear();
598 return false;
599 }
600 if (selection_text_range.EqualsIgnoringDirection(range)) {
601 // Avoid calling substr whose performance is low.
602 *text = selection_text_;
603 } else {
604 *text = selection_text_.substr(
605 range.GetMin() - selection_text_offset_,
606 range.length());
607 }
608 return true;
609 }
610
611 void RenderWidgetHostViewAura::OnInputMethodChanged() {
612 if (!host_)
613 return;
614
615 host_->SetInputMethodActive(GetInputMethod()->IsActive());
616
617 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
618 // TextEvent.
619 }
620
621 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
622 base::i18n::TextDirection direction) {
623 if (!host_)
624 return false;
625 host_->UpdateTextDirection(
626 direction == base::i18n::RIGHT_TO_LEFT ?
627 WebKit::WebTextDirectionRightToLeft :
628 WebKit::WebTextDirectionLeftToRight);
629 host_->NotifyTextDirection();
630 return true;
631 }
632
633 ////////////////////////////////////////////////////////////////////////////////
454 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 634 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
455 635
456 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const { 636 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
457 return gfx::Size(); 637 return gfx::Size();
458 } 638 }
459 639
460 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 640 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
461 const gfx::Rect& new_bounds) { 641 const gfx::Rect& new_bounds) {
462 // We don't care about this one, we are always sized via SetSize() or 642 // We don't care about this one, we are always sized via SetSize() or
463 // SetBounds(). 643 // SetBounds().
464 } 644 }
465 645
466 void RenderWidgetHostViewAura::OnFocus() { 646 void RenderWidgetHostViewAura::OnFocus() {
467 host_->GotFocus(); 647 host_->GotFocus();
648
649 ui::InputMethod* input_method = GetInputMethod();
650 // Ask the system-wide IME to send all TextInputClient messages to |this|
651 // object.
652 input_method->SetFocusedTextInputClient(this);
653
654 host_->SetInputMethodActive(input_method->IsActive());
468 } 655 }
469 656
470 void RenderWidgetHostViewAura::OnBlur() { 657 void RenderWidgetHostViewAura::OnBlur() {
471 host_->Blur(); 658 host_->Blur();
659
660 ui::InputMethod* input_method = GetInputMethod();
661 if (input_method->GetTextInputClient() == this)
662 input_method->SetFocusedTextInputClient(NULL);
663 host_->SetInputMethodActive(false);
472 } 664 }
473 665
474 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 666 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
475 // We need to handle the Escape key for Pepper Flash. 667 // We need to handle the Escape key for Pepper Flash.
476 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 668 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
477 host_->Shutdown(); 669 host_->Shutdown();
478 } else { 670 } else {
479 NativeWebKeyboardEvent webkit_event(event); 671 // We don't have to communicate with an input method here. It has already
480 host_->ForwardKeyboardEvent(webkit_event); 672 // been done by aura/desktop_host_<platform>.cc.
673 #if defined(USE_X11)
674 if (!event->native_event()) {
675 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
676 NativeWebKeyboardEvent webkit_event(event->type(),
677 false /* is_char */,
678 event->GetCharacter(),
679 event->flags(),
680 base::Time::Now().ToDoubleT());
681 host_->ForwardKeyboardEvent(webkit_event);
682 } else
683 #endif
684 {
685 NativeWebKeyboardEvent webkit_event(event);
686 host_->ForwardKeyboardEvent(webkit_event);
687 }
481 } 688 }
482 return true; 689 return true;
483 } 690 }
484 691
485 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 692 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
486 return current_cursor_.GetNativeCursor(); 693 return current_cursor_.GetNativeCursor();
487 } 694 }
488 695
489 int RenderWidgetHostViewAura::GetNonClientComponent( 696 int RenderWidgetHostViewAura::GetNonClientComponent(
490 const gfx::Point& point) const { 697 const gfx::Point& point) const {
491 return HTCLIENT; 698 return HTCLIENT;
492 } 699 }
493 700
494 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 701 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
495 if (event->type() == ui::ET_MOUSEWHEEL) 702 if (event->type() == ui::ET_MOUSEWHEEL)
496 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 703 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
497 else if (CanRendererHandleEvent(event->native_event())) 704 else if (CanRendererHandleEvent(event->native_event()))
498 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 705 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
499 706
707 // TODO(yusukes): Confirm existing composition text on mouse click events.
708
500 // Return true so that we receive released/drag events. 709 // Return true so that we receive released/drag events.
501 return true; 710 return true;
502 } 711 }
503 712
504 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( 713 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent(
505 aura::TouchEvent* event) { 714 aura::TouchEvent* event) {
506 // Update the touch event first. 715 // Update the touch event first.
507 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event, 716 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event,
508 &touch_event_); 717 &touch_event_);
509 718
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // static 802 // static
594 void RenderWidgetHostView::GetDefaultScreenInfo( 803 void RenderWidgetHostView::GetDefaultScreenInfo(
595 WebKit::WebScreenInfo* results) { 804 WebKit::WebScreenInfo* results) {
596 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 805 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
597 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 806 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
598 results->availableRect = results->rect; 807 results->availableRect = results->rect;
599 // TODO(derat): Don't hardcode this? 808 // TODO(derat): Don't hardcode this?
600 results->depth = 24; 809 results->depth = 24;
601 results->depthPerComponent = 8; 810 results->depthPerComponent = 8;
602 } 811 }
812
813 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() {
814 aura::Desktop* desktop = aura::Desktop::GetInstance();
815 return desktop->GetInputMethod();
816 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698