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