| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "content/browser/renderer_host/dip_util.h" | 8 #include "content/browser/renderer_host/dip_util.h" |
| 9 #include "content/browser/renderer_host/render_view_host_factory.h" | 9 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 10 #include "content/browser/web_contents/interstitial_page_impl.h" | 10 #include "content/browser/web_contents/interstitial_page_impl.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (web_contents_->GetInterstitialPage()) | 259 if (web_contents_->GetInterstitialPage()) |
| 260 web_contents_->GetInterstitialPage()->SetSize(size); | 260 web_contents_->GetInterstitialPage()->SetSize(size); |
| 261 content::RenderWidgetHostView* rwhv = | 261 content::RenderWidgetHostView* rwhv = |
| 262 web_contents_->GetRenderWidgetHostView(); | 262 web_contents_->GetRenderWidgetHostView(); |
| 263 if (rwhv) | 263 if (rwhv) |
| 264 rwhv->SetSize(size); | 264 rwhv->SetSize(size); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { | 267 void WebContentsViewAura::EndDrag(WebKit::WebDragOperationsMask ops) { |
| 268 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); | 268 aura::RootWindow* root_window = GetNativeView()->GetRootWindow(); |
| 269 gfx::Point screen_loc = gfx::Screen::GetCursorScreenPoint(); | 269 gfx::Point screen_loc = |
| 270 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); |
| 270 gfx::Point client_loc = screen_loc; | 271 gfx::Point client_loc = screen_loc; |
| 271 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); | 272 content::RenderViewHost* rvh = web_contents_->GetRenderViewHost(); |
| 272 aura::Window* window = rvh->GetView()->GetNativeView(); | 273 aura::Window* window = rvh->GetView()->GetNativeView(); |
| 273 aura::Window::ConvertPointToTarget(root_window, window, &client_loc); | 274 aura::Window::ConvertPointToTarget(root_window, window, &client_loc); |
| 274 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 275 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |
| 275 screen_loc.y(), ops); | 276 screen_loc.y(), ops); |
| 276 } | 277 } |
| 277 | 278 |
| 278 //////////////////////////////////////////////////////////////////////////////// | 279 //////////////////////////////////////////////////////////////////////////////// |
| 279 // WebContentsViewAura, WebContentsView implementation: | 280 // WebContentsViewAura, WebContentsView implementation: |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 new WebDragSourceAura(GetNativeView(), web_contents_)); | 456 new WebDragSourceAura(GetNativeView(), web_contents_)); |
| 456 | 457 |
| 457 // We need to enable recursive tasks on the message loop so we can get | 458 // We need to enable recursive tasks on the message loop so we can get |
| 458 // updates while in the system DoDragDrop loop. | 459 // updates while in the system DoDragDrop loop. |
| 459 int result_op = 0; | 460 int result_op = 0; |
| 460 { | 461 { |
| 461 // TODO(sad): Avoid using GetCursorScreenPoint here, since the drag may not | 462 // TODO(sad): Avoid using GetCursorScreenPoint here, since the drag may not |
| 462 // always start from a mouse-event (e.g. a touch or gesture event could | 463 // always start from a mouse-event (e.g. a touch or gesture event could |
| 463 // initiate the drag). The location information should be carried over from | 464 // initiate the drag). The location information should be carried over from |
| 464 // webkit. http://crbug.com/114754 | 465 // webkit. http://crbug.com/114754 |
| 465 gfx::Point location(gfx::Screen::GetCursorScreenPoint()); | 466 gfx::Point location( |
| 467 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint()); |
| 466 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 468 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 467 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( | 469 result_op = aura::client::GetDragDropClient(root_window)->StartDragAndDrop( |
| 468 data, root_window, location, ConvertFromWeb(operations)); | 470 data, root_window, location, ConvertFromWeb(operations)); |
| 469 } | 471 } |
| 470 | 472 |
| 471 // Bail out immediately if the contents view window is gone. Note that it is | 473 // Bail out immediately if the contents view window is gone. Note that it is |
| 472 // not safe to access any class members after system drag-and-drop returns | 474 // not safe to access any class members after system drag-and-drop returns |
| 473 // since the class instance might be gone. The local variable |drag_source| | 475 // since the class instance might be gone. The local variable |drag_source| |
| 474 // is still valid and we can check its window property that is set to NULL | 476 // is still valid and we can check its window property that is set to NULL |
| 475 // when the contents are gone. | 477 // when the contents are gone. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 ui::EventResult WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { | 598 ui::EventResult WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { |
| 597 if (!web_contents_->GetDelegate()) | 599 if (!web_contents_->GetDelegate()) |
| 598 return ui::ER_UNHANDLED; | 600 return ui::ER_UNHANDLED; |
| 599 | 601 |
| 600 switch (event->type()) { | 602 switch (event->type()) { |
| 601 case ui::ET_MOUSE_PRESSED: | 603 case ui::ET_MOUSE_PRESSED: |
| 602 web_contents_->GetDelegate()->ActivateContents(web_contents_); | 604 web_contents_->GetDelegate()->ActivateContents(web_contents_); |
| 603 break; | 605 break; |
| 604 case ui::ET_MOUSE_MOVED: | 606 case ui::ET_MOUSE_MOVED: |
| 605 web_contents_->GetDelegate()->ContentsMouseEvent( | 607 web_contents_->GetDelegate()->ContentsMouseEvent( |
| 606 web_contents_, gfx::Screen::GetCursorScreenPoint(), true); | 608 web_contents_, |
| 609 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 610 true); |
| 607 break; | 611 break; |
| 608 default: | 612 default: |
| 609 break; | 613 break; |
| 610 } | 614 } |
| 611 return ui::ER_UNHANDLED; | 615 return ui::ER_UNHANDLED; |
| 612 } | 616 } |
| 613 | 617 |
| 614 ui::EventResult WebContentsViewAura::OnTouchEvent(ui::TouchEvent* event) { | 618 ui::EventResult WebContentsViewAura::OnTouchEvent(ui::TouchEvent* event) { |
| 615 return ui::ER_UNHANDLED; | 619 return ui::ER_UNHANDLED; |
| 616 } | 620 } |
| 617 | 621 |
| 618 ui::EventResult WebContentsViewAura::OnGestureEvent( | 622 ui::EventResult WebContentsViewAura::OnGestureEvent( |
| 619 ui::GestureEvent* event) { | 623 ui::GestureEvent* event) { |
| 620 return ui::ER_UNHANDLED; | 624 return ui::ER_UNHANDLED; |
| 621 } | 625 } |
| 622 | 626 |
| 623 //////////////////////////////////////////////////////////////////////////////// | 627 //////////////////////////////////////////////////////////////////////////////// |
| 624 // WebContentsViewAura, aura::client::DragDropDelegate implementation: | 628 // WebContentsViewAura, aura::client::DragDropDelegate implementation: |
| 625 | 629 |
| 626 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { | 630 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { |
| 627 if (drag_dest_delegate_) | 631 if (drag_dest_delegate_) |
| 628 drag_dest_delegate_->DragInitialize(web_contents_); | 632 drag_dest_delegate_->DragInitialize(web_contents_); |
| 629 | 633 |
| 630 WebDropData drop_data; | 634 WebDropData drop_data; |
| 631 PrepareWebDropData(&drop_data, event.data()); | 635 PrepareWebDropData(&drop_data, event.data()); |
| 632 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 636 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 633 | 637 |
| 634 gfx::Point screen_pt = gfx::Screen::GetCursorScreenPoint(); | 638 gfx::Point screen_pt = |
| 639 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); |
| 635 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); | 640 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); |
| 636 web_contents_->GetRenderViewHost()->DragTargetDragEnter( | 641 web_contents_->GetRenderViewHost()->DragTargetDragEnter( |
| 637 drop_data, event.location(), screen_pt, op, | 642 drop_data, event.location(), screen_pt, op, |
| 638 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 643 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 639 | 644 |
| 640 if (drag_dest_delegate_) { | 645 if (drag_dest_delegate_) { |
| 641 drag_dest_delegate_->OnReceiveDragData(event.data()); | 646 drag_dest_delegate_->OnReceiveDragData(event.data()); |
| 642 drag_dest_delegate_->OnDragEnter(); | 647 drag_dest_delegate_->OnDragEnter(); |
| 643 } | 648 } |
| 644 } | 649 } |
| 645 | 650 |
| 646 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { | 651 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { |
| 647 DCHECK(current_rvh_for_drag_); | 652 DCHECK(current_rvh_for_drag_); |
| 648 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 653 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
| 649 OnDragEntered(event); | 654 OnDragEntered(event); |
| 650 | 655 |
| 651 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 656 WebKit::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 652 gfx::Point screen_pt = gfx::Screen::GetCursorScreenPoint(); | 657 gfx::Point screen_pt = |
| 658 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); |
| 653 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 659 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
| 654 event.location(), screen_pt, op, | 660 event.location(), screen_pt, op, |
| 655 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 661 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 656 | 662 |
| 657 if (drag_dest_delegate_) | 663 if (drag_dest_delegate_) |
| 658 drag_dest_delegate_->OnDragOver(); | 664 drag_dest_delegate_->OnDragOver(); |
| 659 | 665 |
| 660 return ConvertFromWeb(current_drag_op_); | 666 return ConvertFromWeb(current_drag_op_); |
| 661 } | 667 } |
| 662 | 668 |
| 663 void WebContentsViewAura::OnDragExited() { | 669 void WebContentsViewAura::OnDragExited() { |
| 664 DCHECK(current_rvh_for_drag_); | 670 DCHECK(current_rvh_for_drag_); |
| 665 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 671 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
| 666 return; | 672 return; |
| 667 | 673 |
| 668 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 674 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); |
| 669 if (drag_dest_delegate_) | 675 if (drag_dest_delegate_) |
| 670 drag_dest_delegate_->OnDragLeave(); | 676 drag_dest_delegate_->OnDragLeave(); |
| 671 } | 677 } |
| 672 | 678 |
| 673 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { | 679 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { |
| 674 DCHECK(current_rvh_for_drag_); | 680 DCHECK(current_rvh_for_drag_); |
| 675 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 681 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
| 676 OnDragEntered(event); | 682 OnDragEntered(event); |
| 677 | 683 |
| 678 web_contents_->GetRenderViewHost()->DragTargetDrop( | 684 web_contents_->GetRenderViewHost()->DragTargetDrop( |
| 679 event.location(), | 685 event.location(), |
| 680 gfx::Screen::GetCursorScreenPoint(), | 686 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 681 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 687 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 682 if (drag_dest_delegate_) | 688 if (drag_dest_delegate_) |
| 683 drag_dest_delegate_->OnDrop(); | 689 drag_dest_delegate_->OnDrop(); |
| 684 return current_drag_op_; | 690 return current_drag_op_; |
| 685 } | 691 } |
| OLD | NEW |