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

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: addressed comments 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);
Peng 2011/11/22 16:26:27 Is the desktop origin always same with origin of s
Yusuke Sato 2011/11/23 15:42:47 Good catch. On Chrome OS, I believe they are alway
490
491 return gfx::Rect(origin.x(),
492 origin.y(),
493 end.x() - origin.x(),
494 end.y() - origin.y());
495 }
496
497 bool RenderWidgetHostViewAura::HasCompositionText() {
498 return has_composition_text_;
499 }
500
501 bool RenderWidgetHostViewAura::GetTextRange(ui::Range* range) {
502 range->set_start(selection_text_offset_);
503 range->set_end(selection_text_offset_ + selection_text_.length());
504 return true;
505 }
506
507 bool RenderWidgetHostViewAura::GetCompositionTextRange(ui::Range* range) {
508 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
509 NOTIMPLEMENTED();
510 return false;
511 }
512
513 bool RenderWidgetHostViewAura::GetSelectionRange(ui::Range* range) {
514 range->set_start(selection_range_.start());
515 range->set_end(selection_range_.end());
516 return true;
517 }
518
519 bool RenderWidgetHostViewAura::SetSelectionRange(const ui::Range& range) {
520 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
521 NOTIMPLEMENTED();
522 return false;
523 }
524
525 bool RenderWidgetHostViewAura::DeleteRange(const ui::Range& range) {
526 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
527 NOTIMPLEMENTED();
528 return false;
529 }
530
531 bool RenderWidgetHostViewAura::GetTextFromRange(
532 const ui::Range& range,
533 string16* text) {
534 ui::Range selection_text_range(selection_text_offset_,
535 selection_text_offset_ + selection_text_.length());
536
537 if (!selection_text_range.Contains(range)) {
538 text->clear();
539 return false;
540 }
541 if (selection_text_range.EqualsIgnoringDirection(range)) {
542 // Avoid calling substr whose performance is low.
543 *text = selection_text_;
544 } else {
545 *text = selection_text_.substr(
546 range.GetMin() - selection_text_offset_,
547 range.length());
548 }
549 return true;
550 }
551
552 void RenderWidgetHostViewAura::OnInputMethodChanged() {
553 if (!host_)
554 return;
555
556 host_->SetInputMethodActive(GetInputMethod()->IsActive());
557
558 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
559 // TextEvent.
560 }
561
562 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
563 base::i18n::TextDirection direction) {
564 if (!host_)
565 return false;
566 host_->UpdateTextDirection(
567 direction == base::i18n::RIGHT_TO_LEFT ?
568 WebKit::WebTextDirectionRightToLeft :
569 WebKit::WebTextDirectionLeftToRight);
570 host_->NotifyTextDirection();
571 return true;
572 }
573
574 ////////////////////////////////////////////////////////////////////////////////
397 // RenderWidgetHostViewAura, aura::WindowDelegate implementation: 575 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
398 576
399 void RenderWidgetHostViewAura::OnBoundsChanging(gfx::Rect* new_bounds) { 577 void RenderWidgetHostViewAura::OnBoundsChanging(gfx::Rect* new_bounds) {
400 } 578 }
401 579
402 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, 580 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
403 const gfx::Rect& new_bounds) { 581 const gfx::Rect& new_bounds) {
404 // We don't care about this one, we are always sized via SetSize() or 582 // We don't care about this one, we are always sized via SetSize() or
405 // SetBounds(). 583 // SetBounds().
406 } 584 }
407 585
408 void RenderWidgetHostViewAura::OnFocus() { 586 void RenderWidgetHostViewAura::OnFocus() {
409 host_->GotFocus(); 587 host_->GotFocus();
588
589 ui::InputMethod* input_method = GetInputMethod();
590 // Ask the system-wide IME to send all TextInputClient messages to |this|
591 // object.
592 input_method->SetFocusedTextInputClient(this);
593 // TODO(yusukes): Should we call ImeCancelComposition() here? Or, can we
594 // remove the OnTextInputTypeChanged() call below?
595 input_method->OnTextInputTypeChanged(this);
596
597 host_->SetInputMethodActive(input_method->IsActive());
598 // TODO(yusukes): Support TextInputTypeTracker for TOUCH_UI.
410 } 599 }
411 600
412 void RenderWidgetHostViewAura::OnBlur() { 601 void RenderWidgetHostViewAura::OnBlur() {
413 host_->Blur(); 602 host_->Blur();
603
604 ui::InputMethod* input_method = GetInputMethod();
605 if (input_method->GetTextInputClient() == this)
606 input_method->SetFocusedTextInputClient(NULL);
607 host_->SetInputMethodActive(false);
414 } 608 }
415 609
416 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) { 610 bool RenderWidgetHostViewAura::OnKeyEvent(aura::KeyEvent* event) {
417 // We need to handle the Escape key for Pepper Flash. 611 // We need to handle the Escape key for Pepper Flash.
418 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) { 612 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
419 host_->Shutdown(); 613 host_->Shutdown();
420 } else { 614 } else {
421 NativeWebKeyboardEvent webkit_event(event); 615 // We don't have to communicate with an input method here. It has already
422 host_->ForwardKeyboardEvent(webkit_event); 616 // been done by aura/desktop_host_<platform>.cc.
617 #if defined(USE_X11)
618 if (!event->native_event()) {
619 // Send a fabricated event, which is usually a VKEY_PROCESSKEY IME event.
620 NativeWebKeyboardEvent webkit_event(event->type(),
621 false /* is_char */,
622 event->GetCharacter(),
623 event->flags(),
624 base::Time::Now().ToDoubleT());
625 host_->ForwardKeyboardEvent(webkit_event);
626 } else
627 #endif
628 {
629 NativeWebKeyboardEvent webkit_event(event);
630 host_->ForwardKeyboardEvent(webkit_event);
631 }
423 } 632 }
424 return true; 633 return true;
425 } 634 }
426 635
427 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) { 636 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
428 return current_cursor_.GetNativeCursor(); 637 return current_cursor_.GetNativeCursor();
429 } 638 }
430 639
431 int RenderWidgetHostViewAura::GetNonClientComponent( 640 int RenderWidgetHostViewAura::GetNonClientComponent(
432 const gfx::Point& point) const { 641 const gfx::Point& point) const {
433 return HTCLIENT; 642 return HTCLIENT;
434 } 643 }
435 644
436 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) { 645 bool RenderWidgetHostViewAura::OnMouseEvent(aura::MouseEvent* event) {
437 if (event->type() == ui::ET_MOUSEWHEEL) 646 if (event->type() == ui::ET_MOUSEWHEEL)
438 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event)); 647 host_->ForwardWheelEvent(content::MakeWebMouseWheelEvent(event));
439 else if (CanRendererHandleEvent(event->native_event())) 648 else if (CanRendererHandleEvent(event->native_event()))
440 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event)); 649 host_->ForwardMouseEvent(content::MakeWebMouseEvent(event));
441 650
651 // TODO(yusukes): Confirm existing composition text on mouse click events.
652
442 // Return true so that we receive released/drag events. 653 // Return true so that we receive released/drag events.
443 return true; 654 return true;
444 } 655 }
445 656
446 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent( 657 ui::TouchStatus RenderWidgetHostViewAura::OnTouchEvent(
447 aura::TouchEvent* event) { 658 aura::TouchEvent* event) {
448 // Update the touch event first. 659 // Update the touch event first.
449 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event, 660 WebKit::WebTouchPoint* point = content::UpdateWebTouchEvent(event,
450 &touch_event_); 661 &touch_event_);
451 662
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // static 746 // static
536 void RenderWidgetHostView::GetDefaultScreenInfo( 747 void RenderWidgetHostView::GetDefaultScreenInfo(
537 WebKit::WebScreenInfo* results) { 748 WebKit::WebScreenInfo* results) {
538 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize(); 749 const gfx::Size size = gfx::Screen::GetPrimaryMonitorSize();
539 results->rect = WebKit::WebRect(0, 0, size.width(), size.height()); 750 results->rect = WebKit::WebRect(0, 0, size.width(), size.height());
540 results->availableRect = results->rect; 751 results->availableRect = results->rect;
541 // TODO(derat): Don't hardcode this? 752 // TODO(derat): Don't hardcode this?
542 results->depth = 24; 753 results->depth = 24;
543 results->depthPerComponent = 8; 754 results->depthPerComponent = 8;
544 } 755 }
756
757 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() {
758 aura::Desktop* desktop = aura::Desktop::GetInstance();
759 return desktop->GetInputMethod();
760 }
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