| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "ui/aura/window_tree_host.h" | 55 #include "ui/aura/window_tree_host.h" |
| 56 #include "ui/aura/window_tree_host_observer.h" | 56 #include "ui/aura/window_tree_host_observer.h" |
| 57 #include "ui/base/clipboard/clipboard.h" | 57 #include "ui/base/clipboard/clipboard.h" |
| 58 #include "ui/base/clipboard/custom_data_helper.h" | 58 #include "ui/base/clipboard/custom_data_helper.h" |
| 59 #include "ui/base/dragdrop/drag_drop_types.h" | 59 #include "ui/base/dragdrop/drag_drop_types.h" |
| 60 #include "ui/base/dragdrop/drag_utils.h" | 60 #include "ui/base/dragdrop/drag_utils.h" |
| 61 #include "ui/base/dragdrop/drop_target_event.h" | 61 #include "ui/base/dragdrop/drop_target_event.h" |
| 62 #include "ui/base/dragdrop/os_exchange_data.h" | 62 #include "ui/base/dragdrop/os_exchange_data.h" |
| 63 #include "ui/base/hit_test.h" | 63 #include "ui/base/hit_test.h" |
| 64 #include "ui/compositor/layer.h" | 64 #include "ui/compositor/layer.h" |
| 65 #include "ui/display/screen.h" |
| 65 #include "ui/events/event.h" | 66 #include "ui/events/event.h" |
| 66 #include "ui/events/event_utils.h" | 67 #include "ui/events/event_utils.h" |
| 67 #include "ui/gfx/canvas.h" | 68 #include "ui/gfx/canvas.h" |
| 68 #include "ui/gfx/image/image.h" | 69 #include "ui/gfx/image/image.h" |
| 69 #include "ui/gfx/image/image_png_rep.h" | 70 #include "ui/gfx/image/image_png_rep.h" |
| 70 #include "ui/gfx/image/image_skia.h" | 71 #include "ui/gfx/image/image_skia.h" |
| 71 #include "ui/gfx/screen.h" | |
| 72 #include "ui/touch_selection/touch_selection_controller.h" | 72 #include "ui/touch_selection/touch_selection_controller.h" |
| 73 #include "ui/wm/public/drag_drop_client.h" | 73 #include "ui/wm/public/drag_drop_client.h" |
| 74 #include "ui/wm/public/drag_drop_delegate.h" | 74 #include "ui/wm/public/drag_drop_delegate.h" |
| 75 | 75 |
| 76 namespace content { | 76 namespace content { |
| 77 WebContentsView* CreateWebContentsView( | 77 WebContentsView* CreateWebContentsView( |
| 78 WebContentsImpl* web_contents, | 78 WebContentsImpl* web_contents, |
| 79 WebContentsViewDelegate* delegate, | 79 WebContentsViewDelegate* delegate, |
| 80 RenderViewHostDelegateView** render_view_host_delegate_view) { | 80 RenderViewHostDelegateView** render_view_host_delegate_view) { |
| 81 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); | 81 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 web_contents_->GetRenderWidgetHostView(); | 531 web_contents_->GetRenderWidgetHostView(); |
| 532 if (rwhv) | 532 if (rwhv) |
| 533 rwhv->SetSize(size); | 533 rwhv->SetSize(size); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void WebContentsViewAura::EndDrag(blink::WebDragOperationsMask ops) { | 536 void WebContentsViewAura::EndDrag(blink::WebDragOperationsMask ops) { |
| 537 if (!web_contents_) | 537 if (!web_contents_) |
| 538 return; | 538 return; |
| 539 | 539 |
| 540 aura::Window* window = GetContentNativeView(); | 540 aura::Window* window = GetContentNativeView(); |
| 541 gfx::Point screen_loc = gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 541 gfx::Point screen_loc = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 542 gfx::Point client_loc = screen_loc; | 542 gfx::Point client_loc = screen_loc; |
| 543 aura::client::ScreenPositionClient* screen_position_client = | 543 aura::client::ScreenPositionClient* screen_position_client = |
| 544 aura::client::GetScreenPositionClient(window->GetRootWindow()); | 544 aura::client::GetScreenPositionClient(window->GetRootWindow()); |
| 545 if (screen_position_client) | 545 if (screen_position_client) |
| 546 screen_position_client->ConvertPointFromScreen(window, &client_loc); | 546 screen_position_client->ConvertPointFromScreen(window, &client_loc); |
| 547 | 547 |
| 548 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), | 548 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), |
| 549 screen_loc.x(), screen_loc.y(), ops); | 549 screen_loc.x(), screen_loc.y(), ops); |
| 550 } | 550 } |
| 551 | 551 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 | 1039 |
| 1040 void WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { | 1040 void WebContentsViewAura::OnMouseEvent(ui::MouseEvent* event) { |
| 1041 if (!web_contents_->GetDelegate()) | 1041 if (!web_contents_->GetDelegate()) |
| 1042 return; | 1042 return; |
| 1043 | 1043 |
| 1044 ui::EventType type = event->type(); | 1044 ui::EventType type = event->type(); |
| 1045 if (type == ui::ET_MOUSE_PRESSED) | 1045 if (type == ui::ET_MOUSE_PRESSED) |
| 1046 web_contents_->GetDelegate()->ActivateContents(web_contents_); | 1046 web_contents_->GetDelegate()->ActivateContents(web_contents_); |
| 1047 | 1047 |
| 1048 web_contents_->GetDelegate()->ContentsMouseEvent( | 1048 web_contents_->GetDelegate()->ContentsMouseEvent( |
| 1049 web_contents_, gfx::Screen::GetScreen()->GetCursorScreenPoint(), | 1049 web_contents_, display::Screen::GetScreen()->GetCursorScreenPoint(), |
| 1050 type == ui::ET_MOUSE_MOVED, type == ui::ET_MOUSE_EXITED); | 1050 type == ui::ET_MOUSE_MOVED, type == ui::ET_MOUSE_EXITED); |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 //////////////////////////////////////////////////////////////////////////////// | 1053 //////////////////////////////////////////////////////////////////////////////// |
| 1054 // WebContentsViewAura, aura::client::DragDropDelegate implementation: | 1054 // WebContentsViewAura, aura::client::DragDropDelegate implementation: |
| 1055 | 1055 |
| 1056 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { | 1056 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { |
| 1057 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); | 1057 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); |
| 1058 current_drop_data_.reset(new DropData()); | 1058 current_drop_data_.reset(new DropData()); |
| 1059 | 1059 |
| 1060 PrepareDropData(current_drop_data_.get(), event.data()); | 1060 PrepareDropData(current_drop_data_.get(), event.data()); |
| 1061 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 1061 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 1062 | 1062 |
| 1063 // Give the delegate an opportunity to cancel the drag. | 1063 // Give the delegate an opportunity to cancel the drag. |
| 1064 if (web_contents_->GetDelegate() && | 1064 if (web_contents_->GetDelegate() && |
| 1065 !web_contents_->GetDelegate()->CanDragEnter( | 1065 !web_contents_->GetDelegate()->CanDragEnter( |
| 1066 web_contents_, *current_drop_data_.get(), op)) { | 1066 web_contents_, *current_drop_data_.get(), op)) { |
| 1067 current_drop_data_.reset(NULL); | 1067 current_drop_data_.reset(NULL); |
| 1068 return; | 1068 return; |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 if (drag_dest_delegate_) | 1071 if (drag_dest_delegate_) |
| 1072 drag_dest_delegate_->DragInitialize(web_contents_); | 1072 drag_dest_delegate_->DragInitialize(web_contents_); |
| 1073 | 1073 |
| 1074 gfx::Point screen_pt = gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 1074 gfx::Point screen_pt = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1075 web_contents_->GetRenderViewHost()->DragTargetDragEnter( | 1075 web_contents_->GetRenderViewHost()->DragTargetDragEnter( |
| 1076 *current_drop_data_.get(), event.location(), screen_pt, op, | 1076 *current_drop_data_.get(), event.location(), screen_pt, op, |
| 1077 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1077 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1078 | 1078 |
| 1079 if (drag_dest_delegate_) { | 1079 if (drag_dest_delegate_) { |
| 1080 drag_dest_delegate_->OnReceiveDragData(event.data()); | 1080 drag_dest_delegate_->OnReceiveDragData(event.data()); |
| 1081 drag_dest_delegate_->OnDragEnter(); | 1081 drag_dest_delegate_->OnDragEnter(); |
| 1082 } | 1082 } |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { | 1085 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { |
| 1086 DCHECK(current_rvh_for_drag_); | 1086 DCHECK(current_rvh_for_drag_); |
| 1087 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 1087 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
| 1088 OnDragEntered(event); | 1088 OnDragEntered(event); |
| 1089 | 1089 |
| 1090 if (!current_drop_data_) | 1090 if (!current_drop_data_) |
| 1091 return ui::DragDropTypes::DRAG_NONE; | 1091 return ui::DragDropTypes::DRAG_NONE; |
| 1092 | 1092 |
| 1093 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 1093 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
| 1094 gfx::Point screen_pt = gfx::Screen::GetScreen()->GetCursorScreenPoint(); | 1094 gfx::Point screen_pt = display::Screen::GetScreen()->GetCursorScreenPoint(); |
| 1095 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 1095 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
| 1096 event.location(), screen_pt, op, | 1096 event.location(), screen_pt, op, |
| 1097 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1097 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1098 | 1098 |
| 1099 if (drag_dest_delegate_) | 1099 if (drag_dest_delegate_) |
| 1100 drag_dest_delegate_->OnDragOver(); | 1100 drag_dest_delegate_->OnDragOver(); |
| 1101 | 1101 |
| 1102 return ConvertFromWeb(current_drag_op_); | 1102 return ConvertFromWeb(current_drag_op_); |
| 1103 } | 1103 } |
| 1104 | 1104 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1119 | 1119 |
| 1120 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { | 1120 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { |
| 1121 DCHECK(current_rvh_for_drag_); | 1121 DCHECK(current_rvh_for_drag_); |
| 1122 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 1122 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
| 1123 OnDragEntered(event); | 1123 OnDragEntered(event); |
| 1124 | 1124 |
| 1125 if (!current_drop_data_) | 1125 if (!current_drop_data_) |
| 1126 return ui::DragDropTypes::DRAG_NONE; | 1126 return ui::DragDropTypes::DRAG_NONE; |
| 1127 | 1127 |
| 1128 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1128 web_contents_->GetRenderViewHost()->DragTargetDrop( |
| 1129 event.location(), gfx::Screen::GetScreen()->GetCursorScreenPoint(), | 1129 event.location(), display::Screen::GetScreen()->GetCursorScreenPoint(), |
| 1130 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1130 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1131 if (drag_dest_delegate_) | 1131 if (drag_dest_delegate_) |
| 1132 drag_dest_delegate_->OnDrop(); | 1132 drag_dest_delegate_->OnDrop(); |
| 1133 current_drop_data_.reset(); | 1133 current_drop_data_.reset(); |
| 1134 return ConvertFromWeb(current_drag_op_); | 1134 return ConvertFromWeb(current_drag_op_); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, | 1137 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, |
| 1138 bool visible) { | 1138 bool visible) { |
| 1139 // Ignore any visibility changes in the hierarchy below. | 1139 // Ignore any visibility changes in the hierarchy below. |
| 1140 if (window != window_.get() && window_->Contains(window)) | 1140 if (window != window_.get() && window_->Contains(window)) |
| 1141 return; | 1141 return; |
| 1142 | 1142 |
| 1143 web_contents_->UpdateWebContentsVisibility(visible); | 1143 web_contents_->UpdateWebContentsVisibility(visible); |
| 1144 } | 1144 } |
| 1145 | 1145 |
| 1146 } // namespace content | 1146 } // namespace content |
| OLD | NEW |