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

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

Issue 8824007: Revert 113224 - IME (input method editor) support for Aura, part 3 of 3: Use ui::InputMethod in u... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
16 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/client/tooltip_client.h" 16 #include "ui/aura/client/tooltip_client.h"
18 #include "ui/aura/desktop.h" 17 #include "ui/aura/desktop.h"
19 #include "ui/aura/event.h" 18 #include "ui/aura/event.h"
20 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
21 #include "ui/aura/window_types.h" 20 #include "ui/aura/window_types.h"
22 #include "ui/base/hit_test.h" 21 #include "ui/base/hit_test.h"
23 #include "ui/base/ime/input_method.h"
24 #include "ui/base/ui_base_types.h" 22 #include "ui/base/ui_base_types.h"
25 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/compositor/layer.h" 24 #include "ui/gfx/compositor/layer.h"
27 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
28 26
29 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 27 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
30 #include "base/bind.h" 28 #include "base/bind.h"
31 #include "content/browser/renderer_host/accelerated_surface_container_linux.h" 29 #include "content/browser/renderer_host/accelerated_surface_container_linux.h"
32 #include "ui/gfx/gl/gl_bindings.h" 30 #include "ui/gfx/gl/gl_bindings.h"
33 #endif 31 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 87
90 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
91 // RenderWidgetHostViewAura, public: 89 // RenderWidgetHostViewAura, public:
92 90
93 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 91 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
94 : host_(host), 92 : host_(host),
95 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 93 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
96 is_fullscreen_(false), 94 is_fullscreen_(false),
97 popup_parent_host_view_(NULL), 95 popup_parent_host_view_(NULL),
98 is_loading_(false), 96 is_loading_(false),
99 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
100 has_composition_text_(false),
101 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 97 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
102 current_surface_(gfx::kNullPluginWindow), 98 current_surface_(gfx::kNullPluginWindow),
103 #endif 99 #endif
104 skip_schedule_paint_(false) { 100 skip_schedule_paint_(false) {
105 host_->SetView(this); 101 host_->SetView(this);
106 window_->SetProperty(aura::kTooltipTextKey, &tooltip_); 102 window_->SetProperty(aura::kTooltipTextKey, &tooltip_);
107 } 103 }
108 104
109 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { 105 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
110 } 106 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 227 }
232 228
233 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 229 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
234 is_loading_ = is_loading; 230 is_loading_ = is_loading;
235 UpdateCursorIfOverSelf(); 231 UpdateCursorIfOverSelf();
236 } 232 }
237 233
238 void RenderWidgetHostViewAura::TextInputStateChanged( 234 void RenderWidgetHostViewAura::TextInputStateChanged(
239 ui::TextInputType type, 235 ui::TextInputType type,
240 bool can_compose_inline) { 236 bool can_compose_inline) {
241 // TODO(kinaba): currently, can_compose_inline is ignored and always treated 237 // http://crbug.com/102569
242 // as true. We need to support "can_compose_inline=false" for PPAPI plugins 238 NOTIMPLEMENTED();
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 }
249 } 239 }
250 240
251 void RenderWidgetHostViewAura::ImeCancelComposition() { 241 void RenderWidgetHostViewAura::ImeCancelComposition() {
252 GetInputMethod()->CancelComposition(this); 242 // http://crbug.com/102569
253 has_composition_text_ = false; 243 NOTIMPLEMENTED();
254 }
255
256 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
257 if (!has_composition_text_)
258 return;
259 if (host_)
260 host_->ImeConfirmComposition();
261 ImeCancelComposition();
262 } 244 }
263 245
264 void RenderWidgetHostViewAura::DidUpdateBackingStore( 246 void RenderWidgetHostViewAura::DidUpdateBackingStore(
265 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 247 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
266 const std::vector<gfx::Rect>& copy_rects) { 248 const std::vector<gfx::Rect>& copy_rects) {
267 if (!window_->IsVisible() || skip_schedule_paint_) 249 if (!window_->IsVisible() || skip_schedule_paint_)
268 return; 250 return;
269 251
270 if (!scroll_rect.IsEmpty()) 252 if (!scroll_rect.IsEmpty())
271 window_->SchedulePaintInRect(scroll_rect); 253 window_->SchedulePaintInRect(scroll_rect);
(...skipping 20 matching lines...) Expand all
292 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) { 274 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) {
293 tooltip_ = tooltip_text; 275 tooltip_ = tooltip_text;
294 void* property = aura::Desktop::GetInstance()->GetProperty( 276 void* property = aura::Desktop::GetInstance()->GetProperty(
295 aura::kDesktopTooltipClientKey); 277 aura::kDesktopTooltipClientKey);
296 if (property) { 278 if (property) {
297 aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property); 279 aura::TooltipClient* tc = static_cast<aura::TooltipClient*>(property);
298 tc->UpdateTooltip(window_); 280 tc->UpdateTooltip(window_);
299 } 281 }
300 } 282 }
301 283
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
314 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( 284 BackingStore* RenderWidgetHostViewAura::AllocBackingStore(
315 const gfx::Size& size) { 285 const gfx::Size& size) {
316 return new BackingStoreSkia(host_, size); 286 return new BackingStoreSkia(host_, size);
317 } 287 }
318 288
319 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { 289 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() {
320 UpdateExternalTexture(); 290 UpdateExternalTexture();
321 } 291 }
322 292
323 void RenderWidgetHostViewAura::UpdateExternalTexture() { 293 void RenderWidgetHostViewAura::UpdateExternalTexture() {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return false; 448 return false;
479 } 449 }
480 450
481 void RenderWidgetHostViewAura::UnlockMouse() { 451 void RenderWidgetHostViewAura::UnlockMouse() {
482 // http://crbug.com/102563 452 // http://crbug.com/102563
483 NOTIMPLEMENTED(); 453 NOTIMPLEMENTED();
484 host_->LostMouseLock(); 454 host_->LostMouseLock();
485 } 455 }
486 456
487 //////////////////////////////////////////////////////////////////////////////// 457 ////////////////////////////////////////////////////////////////////////////////
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::Desktop* desktop = aura::Desktop::GetInstance();
556 aura::Window::ConvertPointToWindow(window_, desktop, &origin);
557 aura::Window::ConvertPointToWindow(window_, desktop, &end);
558 // TODO(yusukes): Unlike Chrome OS, |desktop| origin might not be the same as
559 // 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 ////////////////////////////////////////////////////////////////////////////////
646 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 458 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
647 459
648 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const { 460 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
649 return gfx::Size(); 461 return gfx::Size();
650 } 462 }
651 463
652 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 464 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
653 const gfx::Rect& new_bounds) { 465 const gfx::Rect& new_bounds) {
654 // We don't care about this one, we are always sized via SetSize() or 466 // We don't care about this one, we are always sized via SetSize() or
655 // SetBounds(). 467 // SetBounds().
656 } 468 }
657 469
658 void RenderWidgetHostViewAura::OnFocus() { 470 void RenderWidgetHostViewAura::OnFocus() {
659 host_->GotFocus(); 471 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());
667 } 472 }
668 473
669 void RenderWidgetHostViewAura::OnBlur() { 474 void RenderWidgetHostViewAura::OnBlur() {
670 host_->Blur(); 475 host_->Blur();
671
672 ui::InputMethod* input_method = GetInputMethod();
673 if (input_method->GetTextInputClient() == this)
674 input_method->SetFocusedTextInputClient(NULL);
675 host_->SetInputMethodActive(false);
676 } 476 }
677 477
678 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 478 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
679 // We need to handle the Escape key for Pepper Flash. 479 // We need to handle the Escape key for Pepper Flash.
680 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 480 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
681 host_->Shutdown(); 481 host_->Shutdown();
682 } else { 482 } else {
683 // We don't have to communicate with an input method here. It has already 483 NativeWebKeyboardEvent webkit_event(event);
684 // been done by ui/aura/desktop_host_<platform>.cc. 484 host_->ForwardKeyboardEvent(webkit_event);
685 #if defined(USE_X11)
686 if (!event->native_event()) {
687 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
688 NativeWebKeyboardEvent webkit_event(event->type(),
689 false /* is_char */,
690 event->GetCharacter(),
691 event->flags(),
692 base::Time::Now().ToDoubleT());
693 host_->ForwardKeyboardEvent(webkit_event);
694 } else
695 #endif
696 {
697 NativeWebKeyboardEvent webkit_event(event);
698 host_->ForwardKeyboardEvent(webkit_event);
699 }
700 } 485 }
701 return true; 486 return true;
702 } 487 }
703 488
704 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 489 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
705 return current_cursor_.GetNativeCursor(); 490 return current_cursor_.GetNativeCursor();
706 } 491 }
707 492
708 int RenderWidgetHostViewAura::GetNonClientComponent( 493 int RenderWidgetHostViewAura::GetNonClientComponent(
709 const gfx::Point& point) const { 494 const gfx::Point& point) const {
710 return HTCLIENT; 495 return HTCLIENT;
711 } 496 }
712 497
713 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 498 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
714 if (event->type() == ui::ET_MOUSEWHEEL) 499 if (event->type() == ui::ET_MOUSEWHEEL)
715 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 500 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
716 else if (CanRendererHandleEvent(event->native_event())) 501 else if (CanRendererHandleEvent(event->native_event()))
717 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 502 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
718 503
719 switch (event->type()) { 504 switch (event->type()) {
720 case ui::ET_MOUSE_PRESSED: 505 case ui::ET_MOUSE_PRESSED:
721 window_->SetCapture(); 506 window_->SetCapture();
722 // Confirm existing composition text on mouse click events, to make sure
723 // the input caret won't be moved with an ongoing composition text.
724 FinishImeCompositionSession();
725 break; 507 break;
726 case ui::ET_MOUSE_RELEASED: 508 case ui::ET_MOUSE_RELEASED:
727 window_->ReleaseCapture(); 509 window_->ReleaseCapture();
728 break; 510 break;
729 default: 511 default:
730 break; 512 break;
731 } 513 }
732 514
733 // Return true so that we receive released/drag events. 515 // Return true so that we receive released/drag events.
734 return true; 516 return true;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 // static 612 // static
831 void RenderWidgetHostView::GetDefaultScreenInfo( 613 void RenderWidgetHostView::GetDefaultScreenInfo(
832 WebKit::WebScreenInfo* results) { 614 WebKit::WebScreenInfo* results) {
833 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 615 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
834 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 616 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
835 results->availableRect = results->rect; 617 results->availableRect = results->rect;
836 // TODO(derat): Don't hardcode this? 618 // TODO(derat): Don't hardcode this?
837 results->depth = 24; 619 results->depth = 24;
838 results->depthPerComponent = 8; 620 results->depthPerComponent = 8;
839 } 621 }
840
841 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() {
842 aura::Desktop* desktop = aura::Desktop::GetInstance();
843 return desktop->GetInputMethod();
844 }
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