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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 2505113002: Drag-and-drop: Target drag messages to specific RenderWidgets. (Closed)
Patch Set: Created 4 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
OLDNEW
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"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "content/browser/browser_plugin/browser_plugin_guest.h" 16 #include "content/browser/browser_plugin/browser_plugin_guest.h"
17 #include "content/browser/download/drag_download_util.h" 17 #include "content/browser/download/drag_download_util.h"
18 #include "content/browser/frame_host/interstitial_page_impl.h" 18 #include "content/browser/frame_host/interstitial_page_impl.h"
19 #include "content/browser/frame_host/navigation_entry_impl.h" 19 #include "content/browser/frame_host/navigation_entry_impl.h"
20 #include "content/browser/renderer_host/dip_util.h" 20 #include "content/browser/renderer_host/dip_util.h"
21 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" 21 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h"
22 #include "content/browser/renderer_host/overscroll_controller.h" 22 #include "content/browser/renderer_host/overscroll_controller.h"
23 #include "content/browser/renderer_host/render_view_host_factory.h" 23 #include "content/browser/renderer_host/render_view_host_factory.h"
24 #include "content/browser/renderer_host/render_view_host_impl.h" 24 #include "content/browser/renderer_host/render_view_host_impl.h"
25 #include "content/browser/renderer_host/render_widget_host_impl.h" 25 #include "content/browser/renderer_host/render_widget_host_impl.h"
26 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
26 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 27 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
27 #include "content/browser/web_contents/aura/gesture_nav_simple.h" 28 #include "content/browser/web_contents/aura/gesture_nav_simple.h"
28 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" 29 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h"
29 #include "content/browser/web_contents/web_contents_impl.h" 30 #include "content/browser/web_contents/web_contents_impl.h"
30 #include "content/public/browser/content_browser_client.h" 31 #include "content/public/browser/content_browser_client.h"
31 #include "content/public/browser/notification_observer.h" 32 #include "content/public/browser/notification_observer.h"
32 #include "content/public/browser/notification_registrar.h" 33 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/notification_source.h" 34 #include "content/public/browser/notification_source.h"
34 #include "content/public/browser/notification_types.h" 35 #include "content/public/browser/notification_types.h"
35 #include "content/public/browser/overscroll_configuration.h" 36 #include "content/public/browser/overscroll_configuration.h"
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 }; 507 };
507 508
508 //////////////////////////////////////////////////////////////////////////////// 509 ////////////////////////////////////////////////////////////////////////////////
509 // WebContentsViewAura, public: 510 // WebContentsViewAura, public:
510 511
511 WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents, 512 WebContentsViewAura::WebContentsViewAura(WebContentsImpl* web_contents,
512 WebContentsViewDelegate* delegate) 513 WebContentsViewDelegate* delegate)
513 : web_contents_(web_contents), 514 : web_contents_(web_contents),
514 delegate_(delegate), 515 delegate_(delegate),
515 current_drag_op_(blink::WebDragOperationNone), 516 current_drag_op_(blink::WebDragOperationNone),
516 drag_dest_delegate_(NULL), 517 drag_dest_delegate_(nullptr),
517 current_rvh_for_drag_(NULL), 518 current_rvh_for_drag_(nullptr),
518 current_overscroll_gesture_(OVERSCROLL_NONE), 519 current_overscroll_gesture_(OVERSCROLL_NONE),
519 completed_overscroll_gesture_(OVERSCROLL_NONE), 520 completed_overscroll_gesture_(OVERSCROLL_NONE),
520 navigation_overlay_(nullptr), 521 navigation_overlay_(nullptr),
521 init_rwhv_with_null_parent_for_testing_(false) {} 522 init_rwhv_with_null_parent_for_testing_(false) {}
522 523
523 void WebContentsViewAura::SetDelegateForTesting( 524 void WebContentsViewAura::SetDelegateForTesting(
524 WebContentsViewDelegate* delegate) { 525 WebContentsViewDelegate* delegate) {
525 delegate_.reset(delegate); 526 delegate_.reset(delegate);
526 } 527 }
527 528
(...skipping 24 matching lines...) Expand all
552 void WebContentsViewAura::EndDrag(blink::WebDragOperationsMask ops) { 553 void WebContentsViewAura::EndDrag(blink::WebDragOperationsMask ops) {
553 if (!web_contents_) 554 if (!web_contents_)
554 return; 555 return;
555 556
556 aura::Window* window = GetContentNativeView(); 557 aura::Window* window = GetContentNativeView();
557 gfx::Point screen_loc = display::Screen::GetScreen()->GetCursorScreenPoint(); 558 gfx::Point screen_loc = display::Screen::GetScreen()->GetCursorScreenPoint();
558 gfx::Point client_loc = screen_loc; 559 gfx::Point client_loc = screen_loc;
559 aura::client::ScreenPositionClient* screen_position_client = 560 aura::client::ScreenPositionClient* screen_position_client =
560 aura::client::GetScreenPositionClient(window->GetRootWindow()); 561 aura::client::GetScreenPositionClient(window->GetRootWindow());
561 if (screen_position_client) 562 if (screen_position_client)
562 screen_position_client->ConvertPointFromScreen(window, &client_loc); 563 screen_position_client->ConvertPointFromScreen(window, &client_loc);
563 564
564 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.y(), 565 if (!drag_start_rwh_)
565 screen_loc.x(), screen_loc.y(), ops); 566 return;
567
568 if (drag_start_rwh_.get() ==
569 web_contents_->GetRenderViewHost()->GetWidget()) {
570 web_contents_->DragSourceEndedAt(client_loc.x(), client_loc.x(),
571 screen_loc.x(), screen_loc.y(), ops);
572 }
573
574 // TODO(paulmeyer): In the OOPIF case, should |client_loc| be converted to the
575 // coordinates local to |drag_start_rwh_|? See crbug.com/647249.
576 drag_start_rwh_->DragSourceEndedAt(client_loc, screen_loc, ops);
566 } 577 }
567 578
568 void WebContentsViewAura::InstallOverscrollControllerDelegate( 579 void WebContentsViewAura::InstallOverscrollControllerDelegate(
569 RenderWidgetHostViewAura* view) { 580 RenderWidgetHostViewAura* view) {
570 const std::string value = base::CommandLine::ForCurrentProcess()-> 581 const std::string value = base::CommandLine::ForCurrentProcess()->
571 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation); 582 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation);
572 if (value == "0") { 583 if (value == "0") {
573 navigation_overlay_.reset(); 584 navigation_overlay_.reset();
574 return; 585 return;
575 } 586 }
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
872 delegate_->ShowContextMenu(render_frame_host, params); 883 delegate_->ShowContextMenu(render_frame_host, params);
873 // WARNING: we may have been deleted during the call to ShowContextMenu(). 884 // WARNING: we may have been deleted during the call to ShowContextMenu().
874 } 885 }
875 } 886 }
876 887
877 void WebContentsViewAura::StartDragging( 888 void WebContentsViewAura::StartDragging(
878 const DropData& drop_data, 889 const DropData& drop_data,
879 blink::WebDragOperationsMask operations, 890 blink::WebDragOperationsMask operations,
880 const gfx::ImageSkia& image, 891 const gfx::ImageSkia& image,
881 const gfx::Vector2d& image_offset, 892 const gfx::Vector2d& image_offset,
882 const DragEventSourceInfo& event_info) { 893 const DragEventSourceInfo& event_info,
894 RenderWidgetHost* source_rwh) {
883 aura::Window* root_window = GetNativeView()->GetRootWindow(); 895 aura::Window* root_window = GetNativeView()->GetRootWindow();
884 if (!aura::client::GetDragDropClient(root_window)) { 896 if (!aura::client::GetDragDropClient(root_window)) {
885 web_contents_->SystemDragEnded(); 897 web_contents_->SystemDragEnded();
886 return; 898 return;
887 } 899 }
888 900
901 drag_start_rwh_ =
902 static_cast<RenderWidgetHostImpl*>(source_rwh)->GetWeakPtr();
903
889 ui::TouchSelectionController* selection_controller = GetSelectionController(); 904 ui::TouchSelectionController* selection_controller = GetSelectionController();
890 if (selection_controller) 905 if (selection_controller)
891 selection_controller->HideAndDisallowShowingAutomatically(); 906 selection_controller->HideAndDisallowShowingAutomatically();
892 std::unique_ptr<ui::OSExchangeData::Provider> provider = 907 std::unique_ptr<ui::OSExchangeData::Provider> provider =
893 ui::OSExchangeDataProviderFactory::CreateProvider(); 908 ui::OSExchangeDataProviderFactory::CreateProvider();
894 PrepareDragData(drop_data, provider.get(), web_contents_); 909 PrepareDragData(drop_data, provider.get(), web_contents_);
895 910
896 ui::OSExchangeData data( 911 ui::OSExchangeData data(
897 std::move(provider)); // takes ownership of |provider|. 912 std::move(provider)); // takes ownership of |provider|.
898 913
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 } 1116 }
1102 1117
1103 web_contents_->GetDelegate()->ContentsMouseEvent( 1118 web_contents_->GetDelegate()->ContentsMouseEvent(
1104 web_contents_, display::Screen::GetScreen()->GetCursorScreenPoint(), 1119 web_contents_, display::Screen::GetScreen()->GetCursorScreenPoint(),
1105 type == ui::ET_MOUSE_MOVED, type == ui::ET_MOUSE_EXITED); 1120 type == ui::ET_MOUSE_MOVED, type == ui::ET_MOUSE_EXITED);
1106 } 1121 }
1107 1122
1108 //////////////////////////////////////////////////////////////////////////////// 1123 ////////////////////////////////////////////////////////////////////////////////
1109 // WebContentsViewAura, aura::client::DragDropDelegate implementation: 1124 // WebContentsViewAura, aura::client::DragDropDelegate implementation:
1110 1125
1111 // TODO(paulmeyer): The drag-and-drop calls on GetRenderViewHost()->GetWidget() 1126 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) {
1112 // in the following functions will need to be targeted to specific 1127 gfx::Point transformed_pt;
1113 // RenderWidgetHosts in order to work with OOPIFs. See crbug.com/647249. 1128 current_rwh_for_drag_ =
1129 web_contents_->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
1130 web_contents_->GetRenderViewHost()->GetWidget()->GetView(),
1131 event.location(), &transformed_pt)->GetWeakPtr();
1132 current_rvh_for_drag_ = web_contents_->GetRenderViewHost();
1114 1133
1115 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) {
1116 current_rvh_for_drag_ = web_contents_->GetRenderViewHost();
1117 current_drop_data_.reset(new DropData()); 1134 current_drop_data_.reset(new DropData());
1118
1119 PrepareDropData(current_drop_data_.get(), event.data()); 1135 PrepareDropData(current_drop_data_.get(), event.data());
1120 1136 current_rwh_for_drag_->FilterDropData(current_drop_data_.get());
1121 web_contents_->GetRenderViewHost()->GetWidget()->
1122 FilterDropData(current_drop_data_.get());
1123 1137
1124 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); 1138 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations());
1125 1139
1126 // Give the delegate an opportunity to cancel the drag. 1140 // Give the delegate an opportunity to cancel the drag.
1127 if (web_contents_->GetDelegate() && 1141 if (web_contents_->GetDelegate() &&
1128 !web_contents_->GetDelegate()->CanDragEnter( 1142 !web_contents_->GetDelegate()->CanDragEnter(
1129 web_contents_, *current_drop_data_.get(), op)) { 1143 web_contents_, *current_drop_data_.get(), op)) {
1130 current_drop_data_.reset(NULL); 1144 current_drop_data_.reset(NULL);
1131 return; 1145 return;
1132 } 1146 }
1133 1147
1134 if (drag_dest_delegate_) 1148 if (drag_dest_delegate_)
1135 drag_dest_delegate_->DragInitialize(web_contents_); 1149 drag_dest_delegate_->DragInitialize(web_contents_);
1136 1150
1137 gfx::Point screen_pt = display::Screen::GetScreen()->GetCursorScreenPoint(); 1151 gfx::Point screen_pt = display::Screen::GetScreen()->GetCursorScreenPoint();
1138 web_contents_->GetRenderViewHost()->GetWidget()->DragTargetDragEnter( 1152 current_rwh_for_drag_->DragTargetDragEnter(
1139 *current_drop_data_, event.location(), screen_pt, op, 1153 *current_drop_data_, transformed_pt, screen_pt, op,
1140 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1154 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1141 1155
1142 if (drag_dest_delegate_) { 1156 if (drag_dest_delegate_) {
1143 drag_dest_delegate_->OnReceiveDragData(event.data()); 1157 drag_dest_delegate_->OnReceiveDragData(event.data());
1144 drag_dest_delegate_->OnDragEnter(); 1158 drag_dest_delegate_->OnDragEnter();
1145 } 1159 }
1146 } 1160 }
1147 1161
1148 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { 1162 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) {
1149 DCHECK(current_rvh_for_drag_); 1163 gfx::Point transformed_pt;
1150 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 1164 RenderWidgetHostImpl* target_rwh =
1165 web_contents_->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
1166 web_contents_->GetRenderViewHost()->GetWidget()->GetView(),
1167 event.location(), &transformed_pt);
1168
1169 if (target_rwh != current_rwh_for_drag_.get()) {
1170 if (current_rwh_for_drag_)
1171 current_rwh_for_drag_->DragTargetDragLeave();
1151 OnDragEntered(event); 1172 OnDragEntered(event);
1173 }
1152 1174
1153 if (!current_drop_data_) 1175 if (!current_drop_data_)
1154 return ui::DragDropTypes::DRAG_NONE; 1176 return ui::DragDropTypes::DRAG_NONE;
1155 1177
1156 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); 1178 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations());
1157 gfx::Point screen_pt = event.root_location(); 1179 gfx::Point screen_pt = event.root_location();
1158 web_contents_->GetRenderViewHost()->GetWidget()->DragTargetDragOver( 1180 target_rwh->DragTargetDragOver(
1159 event.location(), screen_pt, op, 1181 transformed_pt, screen_pt, op,
1160 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1182 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1161 1183
1162 if (drag_dest_delegate_) 1184 if (drag_dest_delegate_)
1163 drag_dest_delegate_->OnDragOver(); 1185 drag_dest_delegate_->OnDragOver();
1164 1186
1165 return ConvertFromWeb(current_drag_op_); 1187 return ConvertFromWeb(current_drag_op_);
1166 } 1188 }
1167 1189
1168 void WebContentsViewAura::OnDragExited() { 1190 void WebContentsViewAura::OnDragExited() {
ncarter (slow) 2016/11/16 22:31:23 Was the old DCHECK(current_rvh_for_drag_) bogus, o
paulmeyer 2016/11/16 22:44:21 I wasn't sure how to recreate it using the new wea
1169 DCHECK(current_rvh_for_drag_); 1191 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost() ||
ncarter (slow) 2016/11/16 22:31:23 Is current_rvh_for_drag_ here to stay, or do later
paulmeyer 2016/11/16 22:44:21 I think it may go away (I will try to make it go a
1170 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 1192 !current_drop_data_) {
1171 return; 1193 return;
1194 }
1172 1195
1173 if (!current_drop_data_) 1196 if (current_rwh_for_drag_) {
1174 return; 1197 current_rwh_for_drag_->DragTargetDragLeave();
1198 current_rwh_for_drag_.reset();
1199 }
1175 1200
1176 web_contents_->GetRenderViewHost()->GetWidget()->DragTargetDragLeave();
1177 if (drag_dest_delegate_) 1201 if (drag_dest_delegate_)
1178 drag_dest_delegate_->OnDragLeave(); 1202 drag_dest_delegate_->OnDragLeave();
1179 1203
1180 current_drop_data_.reset(); 1204 current_drop_data_.reset();
1181 } 1205 }
1182 1206
1183 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { 1207 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) {
1184 DCHECK(current_rvh_for_drag_); 1208 gfx::Point transformed_pt;
1185 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) 1209 RenderWidgetHostImpl* target_rwh =
1210 web_contents_->GetInputEventRouter()->GetRenderWidgetHostAtPoint(
1211 web_contents_->GetRenderViewHost()->GetWidget()->GetView(),
1212 event.location(), &transformed_pt);
1213
1214 if (target_rwh != current_rwh_for_drag_.get()) {
1215 if (current_rwh_for_drag_)
1216 current_rwh_for_drag_->DragTargetDragLeave();
1186 OnDragEntered(event); 1217 OnDragEntered(event);
1218 }
1187 1219
1188 if (!current_drop_data_) 1220 if (!current_drop_data_)
1189 return ui::DragDropTypes::DRAG_NONE; 1221 return ui::DragDropTypes::DRAG_NONE;
1190 1222
1191 web_contents_->GetRenderViewHost()->GetWidget()->DragTargetDrop( 1223 target_rwh->DragTargetDrop(
1192 *current_drop_data_, event.location(), 1224 *current_drop_data_, transformed_pt,
1193 display::Screen::GetScreen()->GetCursorScreenPoint(), 1225 display::Screen::GetScreen()->GetCursorScreenPoint(),
1194 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1226 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1195 if (drag_dest_delegate_) 1227 if (drag_dest_delegate_)
1196 drag_dest_delegate_->OnDrop(); 1228 drag_dest_delegate_->OnDrop();
1197 current_drop_data_.reset(); 1229 current_drop_data_.reset();
1198 return ConvertFromWeb(current_drag_op_); 1230 return ConvertFromWeb(current_drag_op_);
1199 } 1231 }
1200 1232
1201 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, 1233 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window,
1202 bool visible) { 1234 bool visible) {
(...skipping 15 matching lines...) Expand all
1218 bool allow_multiple_selection) { 1250 bool allow_multiple_selection) {
1219 NOTIMPLEMENTED() << " show " << items.size() << " menu items"; 1251 NOTIMPLEMENTED() << " show " << items.size() << " menu items";
1220 } 1252 }
1221 1253
1222 void WebContentsViewAura::HidePopupMenu() { 1254 void WebContentsViewAura::HidePopupMenu() {
1223 NOTIMPLEMENTED(); 1255 NOTIMPLEMENTED();
1224 } 1256 }
1225 #endif 1257 #endif
1226 1258
1227 } // namespace content 1259 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698