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

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: aura_win fix Created 9 years, 1 month 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 "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
14 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/desktop.h" 16 #include "ui/aura/desktop.h"
16 #include "ui/aura/event.h" 17 #include "ui/aura/event.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 #include "ui/aura/window_types.h" 19 #include "ui/aura/window_types.h"
19 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
21 #include "ui/base/ime/input_method.h"
20 #include "ui/base/ui_base_types.h" 22 #include "ui/base/ui_base_types.h"
21 #include "ui/gfx/canvas.h" 23 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/compositor/layer.h" 24 #include "ui/gfx/compositor/layer.h"
23 #include "ui/gfx/screen.h" 25 #include "ui/gfx/screen.h"
24 26
25 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 27 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
26 #include "base/bind.h" 28 #include "base/bind.h"
27 #include "content/browser/renderer_host/accelerated_surface_container_linux.h" 29 #include "content/browser/renderer_host/accelerated_surface_container_linux.h"
28 #include "ui/gfx/gl/gl_bindings.h" 30 #include "ui/gfx/gl/gl_bindings.h"
29 #endif 31 #endif
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 87
86 //////////////////////////////////////////////////////////////////////////////// 88 ////////////////////////////////////////////////////////////////////////////////
87 // RenderWidgetHostViewAura, public: 89 // RenderWidgetHostViewAura, public:
88 90
89 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host) 91 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
90 : host_(host), 92 : host_(host),
91 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))), 93 ALLOW_THIS_IN_INITIALIZER_LIST(window_(new aura::Window(this))),
92 is_fullscreen_(false), 94 is_fullscreen_(false),
93 popup_parent_host_view_(NULL), 95 popup_parent_host_view_(NULL),
94 is_loading_(false), 96 is_loading_(false),
97 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
98 has_composition_text_(false),
95 skip_schedule_paint_(false) { 99 skip_schedule_paint_(false) {
96 host_->SetView(this); 100 host_->SetView(this);
97 window_->SetProperty(aura::kTooltipTextKey, &tooltip_); 101 window_->SetProperty(aura::kTooltipTextKey, &tooltip_);
98 } 102 }
99 103
100 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() { 104 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
101 } 105 }
102 106
103 void RenderWidgetHostViewAura::InitAsChild() { 107 void RenderWidgetHostViewAura::InitAsChild() {
104 window_->Init(ui::Layer::LAYER_HAS_TEXTURE); 108 window_->Init(ui::Layer::LAYER_HAS_TEXTURE);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 223 }
220 224
221 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) { 225 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
222 is_loading_ = is_loading; 226 is_loading_ = is_loading;
223 UpdateCursorIfOverSelf(); 227 UpdateCursorIfOverSelf();
224 } 228 }
225 229
226 void RenderWidgetHostViewAura::TextInputStateChanged( 230 void RenderWidgetHostViewAura::TextInputStateChanged(
227 ui::TextInputType type, 231 ui::TextInputType type,
228 bool can_compose_inline) { 232 bool can_compose_inline) {
229 // http://crbug.com/102569 233 // TODO(kinaba): currently, can_compose_inline is ignored and always treated
230 NOTIMPLEMENTED(); 234 // as true. We need to support "can_compose_inline=false" for PPAPI plugins
235 // that may want to avoid drawing composition-text by themselves and pass
236 // the responsibility to the browser.
237 if (text_input_type_ != type) {
238 text_input_type_ = type;
239 // TODO(yusukes): Should we call ImeCancelComposition() here?
240 GetInputMethod()->OnTextInputTypeChanged(this);
241 }
231 } 242 }
232 243
233 void RenderWidgetHostViewAura::ImeCancelComposition() { 244 void RenderWidgetHostViewAura::ImeCancelComposition() {
234 // http://crbug.com/102569 245 GetInputMethod()->CancelComposition(this);
235 NOTIMPLEMENTED(); 246 has_composition_text_ = false;
236 } 247 }
237 248
238 void RenderWidgetHostViewAura::DidUpdateBackingStore( 249 void RenderWidgetHostViewAura::DidUpdateBackingStore(
239 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 250 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
240 const std::vector<gfx::Rect>& copy_rects) { 251 const std::vector<gfx::Rect>& copy_rects) {
241 if (!window_->IsVisible() || skip_schedule_paint_) 252 if (!window_->IsVisible() || skip_schedule_paint_)
242 return; 253 return;
243 254
244 if (!scroll_rect.IsEmpty()) 255 if (!scroll_rect.IsEmpty())
245 window_->SchedulePaintInRect(scroll_rect); 256 window_->SchedulePaintInRect(scroll_rect);
(...skipping 14 matching lines...) Expand all
260 } 271 }
261 272
262 void RenderWidgetHostViewAura::Destroy() { 273 void RenderWidgetHostViewAura::Destroy() {
263 delete window_; 274 delete window_;
264 } 275 }
265 276
266 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) { 277 void RenderWidgetHostViewAura::SetTooltipText(const string16& tooltip_text) {
267 tooltip_ = tooltip_text; 278 tooltip_ = tooltip_text;
268 } 279 }
269 280
281 void RenderWidgetHostViewAura::SelectionBoundsChanged(
282 const gfx::Rect& start_rect,
283 const gfx::Rect& end_rect) {
284 if (selection_start_rect_ == start_rect && selection_end_rect_ == end_rect)
285 return;
286
287 selection_start_rect_ = start_rect;
288 selection_end_rect_ = end_rect;
289
290 GetInputMethod()->OnCaretBoundsChanged(this);
291 }
292
270 BackingStore* RenderWidgetHostViewAura::AllocBackingStore( 293 BackingStore* RenderWidgetHostViewAura::AllocBackingStore(
271 const gfx::Size& size) { 294 const gfx::Size& size) {
272 return new BackingStoreSkia(host_, size); 295 return new BackingStoreSkia(host_, size);
273 } 296 }
274 297
275 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() { 298 void RenderWidgetHostViewAura::OnAcceleratedCompositingStateChange() {
276 } 299 }
277 300
278 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT) 301 #if defined(UI_COMPOSITOR_IMAGE_TRANSPORT)
279 void RenderWidgetHostViewAura::AcceleratedSurfaceNew( 302 void RenderWidgetHostViewAura::AcceleratedSurfaceNew(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 return false; 410 return false;
388 } 411 }
389 412
390 void RenderWidgetHostViewAura::UnlockMouse() { 413 void RenderWidgetHostViewAura::UnlockMouse() {
391 // http://crbug.com/102563 414 // http://crbug.com/102563
392 NOTIMPLEMENTED(); 415 NOTIMPLEMENTED();
393 host_->LostMouseLock(); 416 host_->LostMouseLock();
394 } 417 }
395 418
396 //////////////////////////////////////////////////////////////////////////////// 419 ////////////////////////////////////////////////////////////////////////////////
420 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
421 void RenderWidgetHostViewAura::SetCompositionText(
422 const ui::CompositionText& composition) {
423 if (!host_)
424 return;
425
426 // ui::CompositionUnderline should be identical to
427 // WebKit::WebCompositionUnderline, so that we can do reinterpret_cast safely.
428 COMPILE_ASSERT(sizeof(ui::CompositionUnderline) ==
429 sizeof(WebKit::WebCompositionUnderline),
430 ui_CompositionUnderline__WebKit_WebCompositionUnderline_diff);
431
432 // TODO(suzhe): convert both renderer_host and renderer to use
433 // ui::CompositionText.
434 const std::vector<WebKit::WebCompositionUnderline>& underlines =
435 reinterpret_cast<const std::vector<WebKit::WebCompositionUnderline>&>(
436 composition.underlines);
437
438 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
439 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
440 host_->ImeSetComposition(composition.text, underlines,
441 composition.selection.end(),
442 composition.selection.end());
443
444 has_composition_text_ = !composition.text.empty();
445 }
446
447 void RenderWidgetHostViewAura::ConfirmCompositionText() {
448 if (host_ && has_composition_text_)
449 host_->ImeConfirmComposition();
450 has_composition_text_ = false;
451 }
452
453 void RenderWidgetHostViewAura::ClearCompositionText() {
454 if (host_ && has_composition_text_)
455 host_->ImeCancelComposition();
456 has_composition_text_ = false;
457 }
458
459 void RenderWidgetHostViewAura::InsertText(const string16& text) {
460 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE);
461 if (host_)
462 host_->ImeConfirmComposition(text);
463 has_composition_text_ = false;
464 }
465
466 void RenderWidgetHostViewAura::InsertChar(char16 ch, int flags) {
467 if (host_) {
468 // Send a WebKit::WebInputEvent::Char event to |host_|.
469 NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
470 true /* is_char */,
471 ch,
472 flags,
473 base::Time::Now().ToDoubleT());
474 host_->ForwardKeyboardEvent(webkit_event);
475 }
476 }
477
478 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
479 return text_input_type_;
480 }
481
482 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() {
483 const gfx::Rect rect = selection_start_rect_.Union(selection_end_rect_);
484 gfx::Point origin = rect.origin();
485 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
486
487 aura::Desktop* desktop = aura::Desktop::GetInstance();
488 aura::Window::ConvertPointToWindow(window_, desktop, &origin);
489 aura::Window::ConvertPointToWindow(window_, desktop, &end);
490 // TODO(yusukes): Unlike Chrome OS, |desktop| origin might not be the same as
491 // the system screen origin on Windows and Linux. Probably we should
492 // (implement and) use something like ConvertPointToScreen().
493
494 return gfx::Rect(origin.x(),
495 origin.y(),
496 end.x() - origin.x(),
497 end.y() - origin.y());
498 }
499
500 bool RenderWidgetHostViewAura::HasCompositionText() {
501 return has_composition_text_;
502 }
503
504 bool RenderWidgetHostViewAura::GetTextRange(ui::Range* range) {
505 range->set_start(selection_text_offset_);
506 range->set_end(selection_text_offset_ + selection_text_.length());
507 return true;
508 }
509
510 bool RenderWidgetHostViewAura::GetCompositionTextRange(ui::Range* range) {
511 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
512 NOTIMPLEMENTED();
513 return false;
514 }
515
516 bool RenderWidgetHostViewAura::GetSelectionRange(ui::Range* range) {
517 range->set_start(selection_range_.start());
518 range->set_end(selection_range_.end());
519 return true;
520 }
521
522 bool RenderWidgetHostViewAura::SetSelectionRange(const ui::Range& range) {
523 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
524 NOTIMPLEMENTED();
525 return false;
526 }
527
528 bool RenderWidgetHostViewAura::DeleteRange(const ui::Range& range) {
529 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
530 NOTIMPLEMENTED();
531 return false;
532 }
533
534 bool RenderWidgetHostViewAura::GetTextFromRange(
535 const ui::Range& range,
536 string16* text) {
537 ui::Range selection_text_range(selection_text_offset_,
538 selection_text_offset_ + selection_text_.length());
539
540 if (!selection_text_range.Contains(range)) {
541 text->clear();
542 return false;
543 }
544 if (selection_text_range.EqualsIgnoringDirection(range)) {
545 // Avoid calling substr whose performance is low.
546 *text = selection_text_;
547 } else {
548 *text = selection_text_.substr(
549 range.GetMin() - selection_text_offset_,
550 range.length());
551 }
552 return true;
553 }
554
555 void RenderWidgetHostViewAura::OnInputMethodChanged() {
556 if (!host_)
557 return;
558
559 host_->SetInputMethodActive(GetInputMethod()->IsActive());
560
561 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
562 // TextEvent.
563 }
564
565 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
566 base::i18n::TextDirection direction) {
567 if (!host_)
568 return false;
569 host_->UpdateTextDirection(
570 direction == base::i18n::RIGHT_TO_LEFT ?
571 WebKit::WebTextDirectionRightToLeft :
572 WebKit::WebTextDirectionLeftToRight);
573 host_->NotifyTextDirection();
574 return true;
575 }
576
577 ////////////////////////////////////////////////////////////////////////////////
397 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 578 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
398 579
399 void RenderWidgetHostViewAura::OnBoundsChanging(gfx::Rect* new_bounds) { 580 void RenderWidgetHostViewAura::OnBoundsChanging(gfx::Rect* new_bounds) {
400 } 581 }
401 582
402 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 583 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
403 const gfx::Rect& new_bounds) { 584 const gfx::Rect& new_bounds) {
404 // We don't care about this one, we are always sized via SetSize() or 585 // We don't care about this one, we are always sized via SetSize() or
405 // SetBounds(). 586 // SetBounds().
406 } 587 }
407 588
408 void RenderWidgetHostViewAura::OnFocus() { 589 void RenderWidgetHostViewAura::OnFocus() {
409 host_->GotFocus(); 590 host_->GotFocus();
591
592 ui::InputMethod* input_method = GetInputMethod();
593 // Ask the system-wide IME to send all TextInputClient messages to |this|
594 // object.
595 input_method->SetFocusedTextInputClient(this);
596 // TODO(yusukes): Should we call ImeCancelComposition() here? Or, can we
597 // remove the OnTextInputTypeChanged() call below?
598 input_method->OnTextInputTypeChanged(this);
599
600 host_->SetInputMethodActive(input_method->IsActive());
601 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI.
410 } 602 }
411 603
412 void RenderWidgetHostViewAura::OnBlur() { 604 void RenderWidgetHostViewAura::OnBlur() {
413 host_->Blur(); 605 host_->Blur();
606
607 ui::InputMethod* input_method = GetInputMethod();
608 if (input_method->GetTextInputClient() == this)
609 input_method->SetFocusedTextInputClient(NULL);
610 host_->SetInputMethodActive(false);
414 } 611 }
415 612
416 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 613 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
417 // We need to handle the Escape key for Pepper Flash. 614 // We need to handle the Escape key for Pepper Flash.
418 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 615 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
419 host_->Shutdown(); 616 host_->Shutdown();
420 } else { 617 } else {
421 NativeWebKeyboardEvent webkit_event(event); 618 // We don't have to communicate with an input method here. It has already
422 host_->ForwardKeyboardEvent(webkit_event); 619 // been done by aura/desktop_host_<platform>.cc.
620 #if defined(USE_X11)
621 if (!event->native_event()) {
622 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
623 NativeWebKeyboardEvent webkit_event(event->type(),
624 false /* is_char */,
625 event->GetCharacter(),
626 event->flags(),
627 base::Time::Now().ToDoubleT());
628 host_->ForwardKeyboardEvent(webkit_event);
629 } else
630 #endif
631 {
632 NativeWebKeyboardEvent webkit_event(event);
633 host_->ForwardKeyboardEvent(webkit_event);
634 }
423 } 635 }
424 return true; 636 return true;
425 } 637 }
426 638
427 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 639 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
428 return current_cursor_.GetNativeCursor(); 640 return current_cursor_.GetNativeCursor();
429 } 641 }
430 642
431 int RenderWidgetHostViewAura::GetNonClientComponent( 643 int RenderWidgetHostViewAura::GetNonClientComponent(
432 const gfx::Point& point) const { 644 const gfx::Point& point) const {
433 return HTCLIENT; 645 return HTCLIENT;
434 } 646 }
435 647
436 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 648 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
437 if (event->type() == ui::ET_MOUSEWHEEL) 649 if (event->type() == ui::ET_MOUSEWHEEL)
438 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 650 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
439 else if (CanRendererHandleEvent(event->native_event())) 651 else if (CanRendererHandleEvent(event->native_event()))
440 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 652 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
441 653
654 // TODO(yusukes): Confirm existing composition text on mouse click events.
655
442 // Return true so that we receive released/drag events. 656 // Return true so that we receive released/drag events.
443 return true; 657 return true;
444 } 658 }
445 659
446 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( 660 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent(
447 aura::TouchEvent* event) { 661 aura::TouchEvent* event) {
448 // Update the touch event first. 662 // Update the touch event first.
449 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event, 663 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event,
450 &touch_event_); 664 &touch_event_);
451 665
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // static 749 // static
536 void RenderWidgetHostView::GetDefaultScreenInfo( 750 void RenderWidgetHostView::GetDefaultScreenInfo(
537 WebKit::WebScreenInfo* results) { 751 WebKit::WebScreenInfo* results) {
538 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 752 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
539 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 753 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
540 results->availableRect = results->rect; 754 results->availableRect = results->rect;
541 // TODO(derat): Don't hardcode this? 755 // TODO(derat): Don't hardcode this?
542 results->depth = 24; 756 results->depth = 24;
543 results->depthPerComponent = 8; 757 results->depthPerComponent = 8;
544 } 758 }
759
760 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() {
761 aura::Desktop* desktop = aura::Desktop::GetInstance();
762 return desktop->GetInputMethod();
763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698