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/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 break; | 1410 break; |
1411 default: | 1411 default: |
1412 break; | 1412 break; |
1413 } | 1413 } |
1414 } | 1414 } |
1415 | 1415 |
1416 //////////////////////////////////////////////////////////////////////////////// | 1416 //////////////////////////////////////////////////////////////////////////////// |
1417 // WebContentsViewAura, aura::client::DragDropDelegate implementation: | 1417 // WebContentsViewAura, aura::client::DragDropDelegate implementation: |
1418 | 1418 |
1419 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { | 1419 void WebContentsViewAura::OnDragEntered(const ui::DropTargetEvent& event) { |
1420 if (drag_dest_delegate_) | 1420 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); |
1421 drag_dest_delegate_->DragInitialize(web_contents_); | |
1422 | |
1423 current_drop_data_.reset(new DropData()); | 1421 current_drop_data_.reset(new DropData()); |
1424 | 1422 |
1425 PrepareDropData(current_drop_data_.get(), event.data()); | 1423 PrepareDropData(current_drop_data_.get(), event.data()); |
1426 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 1424 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
1427 | 1425 |
| 1426 // Give the delegate an opportunity to cancel the drag. |
| 1427 if (!web_contents_->GetDelegate()->CanDragEnter(web_contents_, |
| 1428 *current_drop_data_.get(), |
| 1429 op)) { |
| 1430 current_drop_data_.reset(NULL); |
| 1431 return; |
| 1432 } |
| 1433 |
| 1434 if (drag_dest_delegate_) |
| 1435 drag_dest_delegate_->DragInitialize(web_contents_); |
| 1436 |
1428 gfx::Point screen_pt = | 1437 gfx::Point screen_pt = |
1429 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); | 1438 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); |
1430 current_rvh_for_drag_ = web_contents_->GetRenderViewHost(); | |
1431 web_contents_->GetRenderViewHost()->DragTargetDragEnter( | 1439 web_contents_->GetRenderViewHost()->DragTargetDragEnter( |
1432 *current_drop_data_.get(), event.location(), screen_pt, op, | 1440 *current_drop_data_.get(), event.location(), screen_pt, op, |
1433 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1441 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1434 | 1442 |
1435 if (drag_dest_delegate_) { | 1443 if (drag_dest_delegate_) { |
1436 drag_dest_delegate_->OnReceiveDragData(event.data()); | 1444 drag_dest_delegate_->OnReceiveDragData(event.data()); |
1437 drag_dest_delegate_->OnDragEnter(); | 1445 drag_dest_delegate_->OnDragEnter(); |
1438 } | 1446 } |
1439 } | 1447 } |
1440 | 1448 |
1441 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { | 1449 int WebContentsViewAura::OnDragUpdated(const ui::DropTargetEvent& event) { |
1442 DCHECK(current_rvh_for_drag_); | 1450 DCHECK(current_rvh_for_drag_); |
1443 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 1451 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
1444 OnDragEntered(event); | 1452 OnDragEntered(event); |
1445 | 1453 |
| 1454 if (!current_drop_data_) |
| 1455 return ui::DragDropTypes::DRAG_NONE; |
| 1456 |
1446 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); | 1457 blink::WebDragOperationsMask op = ConvertToWeb(event.source_operations()); |
1447 gfx::Point screen_pt = | 1458 gfx::Point screen_pt = |
1448 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); | 1459 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(); |
1449 web_contents_->GetRenderViewHost()->DragTargetDragOver( | 1460 web_contents_->GetRenderViewHost()->DragTargetDragOver( |
1450 event.location(), screen_pt, op, | 1461 event.location(), screen_pt, op, |
1451 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1462 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1452 | 1463 |
1453 if (drag_dest_delegate_) | 1464 if (drag_dest_delegate_) |
1454 drag_dest_delegate_->OnDragOver(); | 1465 drag_dest_delegate_->OnDragOver(); |
1455 | 1466 |
1456 return ConvertFromWeb(current_drag_op_); | 1467 return ConvertFromWeb(current_drag_op_); |
1457 } | 1468 } |
1458 | 1469 |
1459 void WebContentsViewAura::OnDragExited() { | 1470 void WebContentsViewAura::OnDragExited() { |
1460 DCHECK(current_rvh_for_drag_); | 1471 DCHECK(current_rvh_for_drag_); |
1461 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 1472 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
1462 return; | 1473 return; |
1463 | 1474 |
| 1475 if (!current_drop_data_) |
| 1476 return; |
| 1477 |
1464 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); | 1478 web_contents_->GetRenderViewHost()->DragTargetDragLeave(); |
1465 if (drag_dest_delegate_) | 1479 if (drag_dest_delegate_) |
1466 drag_dest_delegate_->OnDragLeave(); | 1480 drag_dest_delegate_->OnDragLeave(); |
1467 | 1481 |
1468 current_drop_data_.reset(); | 1482 current_drop_data_.reset(); |
1469 } | 1483 } |
1470 | 1484 |
1471 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { | 1485 int WebContentsViewAura::OnPerformDrop(const ui::DropTargetEvent& event) { |
1472 DCHECK(current_rvh_for_drag_); | 1486 DCHECK(current_rvh_for_drag_); |
1473 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) | 1487 if (current_rvh_for_drag_ != web_contents_->GetRenderViewHost()) |
1474 OnDragEntered(event); | 1488 OnDragEntered(event); |
1475 | 1489 |
| 1490 if (!current_drop_data_) |
| 1491 return ui::DragDropTypes::DRAG_NONE; |
| 1492 |
1476 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1493 web_contents_->GetRenderViewHost()->DragTargetDrop( |
1477 event.location(), | 1494 event.location(), |
1478 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1495 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1479 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1496 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1480 if (drag_dest_delegate_) | 1497 if (drag_dest_delegate_) |
1481 drag_dest_delegate_->OnDrop(); | 1498 drag_dest_delegate_->OnDrop(); |
1482 current_drop_data_.reset(); | 1499 current_drop_data_.reset(); |
1483 return ConvertFromWeb(current_drag_op_); | 1500 return ConvertFromWeb(current_drag_op_); |
1484 } | 1501 } |
1485 | 1502 |
1486 } // namespace content | 1503 } // namespace content |
OLD | NEW |