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

Side by Side Diff: services/ui/ws/window_tree.cc

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove stray mark Created 4 years, 3 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "services/ui/ws/window_tree.h" 5 #include "services/ui/ws/window_tree.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1380 DVLOG(1) << "SetHitTestMask failed"; 1380 DVLOG(1) << "SetHitTestMask failed";
1381 return; 1381 return;
1382 } 1382 }
1383 1383
1384 if (mask) 1384 if (mask)
1385 window->SetHitTestMask(*mask); 1385 window->SetHitTestMask(*mask);
1386 else 1386 else
1387 window->ClearHitTestMask(); 1387 window->ClearHitTestMask();
1388 } 1388 }
1389 1389
1390 void WindowTree::SetCanAcceptDrags(Id window_id, bool accepts_drags) {
1391 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1392 if (!window || !access_policy_->CanSetAcceptDrags(window)) {
1393 DVLOG(1) << "SetAcceptsDrags failed";
1394 return;
1395 }
1396
1397 window->SetCanAcceptDrags(accepts_drags);
1398 }
1399
1390 void WindowTree::Embed(Id transport_window_id, 1400 void WindowTree::Embed(Id transport_window_id,
1391 mojom::WindowTreeClientPtr client, 1401 mojom::WindowTreeClientPtr client,
1392 uint32_t flags, 1402 uint32_t flags,
1393 const EmbedCallback& callback) { 1403 const EmbedCallback& callback) {
1394 callback.Run( 1404 callback.Run(
1395 Embed(ClientWindowId(transport_window_id), std::move(client), flags)); 1405 Embed(ClientWindowId(transport_window_id), std::move(client), flags));
1396 } 1406 }
1397 1407
1398 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) { 1408 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) {
1399 client()->OnChangeCompleted(change_id, 1409 client()->OnChangeCompleted(change_id,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 this, std::move(internal))); 1455 this, std::move(internal)));
1446 } 1456 }
1447 1457
1448 void WindowTree::GetCursorLocationMemory( 1458 void WindowTree::GetCursorLocationMemory(
1449 const GetCursorLocationMemoryCallback& callback) { 1459 const GetCursorLocationMemoryCallback& callback) {
1450 callback.Run( 1460 callback.Run(
1451 window_server_->display_manager()->GetUserDisplayManager(user_id_)-> 1461 window_server_->display_manager()->GetUserDisplayManager(user_id_)->
1452 GetCursorLocationMemory()); 1462 GetCursorLocationMemory());
1453 } 1463 }
1454 1464
1465 void WindowTree::PerformDragDrop(
1466 uint32_t change_id,
1467 uint32_t source_window_id,
1468 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data,
1469 uint32_t drag_operation) {
1470 ServerWindow* window = GetWindowByClientId(ClientWindowId(source_window_id));
1471 bool success = window && access_policy_->CanInitiateMoveLoop(window);
1472 if (!success || !ShouldRouteToWindowManager(window)) {
1473 // We need to fail this move loop change, otherwise the client will just be
1474 // waiting for |change_id|.
1475 OnChangeCompleted(change_id, false);
1476 return;
1477 }
1478
1479 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1480 if (!display_root) {
1481 // The window isn't parented. There's nothing to do.
1482 OnChangeCompleted(change_id, false);
1483 return;
1484 }
1485
1486 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
1487 // Either the window manager is servicing a window drag or we're servicing
1488 // a drag and drop operation. We can't start a second drag.
1489 OnChangeCompleted(change_id, false);
1490 return;
1491 }
1492
1493 // TODO(erg): Dealing with |drag_representation| is hard, so we're going to
1494 // deal with that later.
1495
1496 // Here, we need to dramatically change how the mouse pointer works. Once
1497 // we've started a drag drop operation, cursor events don't go to windows as
1498 // normal.
1499 WindowManagerState* wms = display_root->window_manager_state();
1500 window_server_->StartDragLoop(change_id, window, this);
1501 wms->SetDragDropSourceWindow(this, window, std::move(drag_data),
1502 drag_operation);
1503 }
1504
1455 void WindowTree::PerformWindowMove(uint32_t change_id, 1505 void WindowTree::PerformWindowMove(uint32_t change_id,
1456 Id window_id, 1506 Id window_id,
1457 ui::mojom::MoveLoopSource source, 1507 ui::mojom::MoveLoopSource source,
1458 const gfx::Point& cursor) { 1508 const gfx::Point& cursor) {
1459 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1509 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1460 bool success = window && access_policy_->CanInitiateMoveLoop(window); 1510 bool success = window && access_policy_->CanInitiateMoveLoop(window);
1461 if (!success || !ShouldRouteToWindowManager(window)) { 1511 if (!success || !ShouldRouteToWindowManager(window)) {
1462 // We need to fail this move loop change, otherwise the client will just be 1512 // We need to fail this move loop change, otherwise the client will just be
1463 // waiting for |change_id|. 1513 // waiting for |change_id|.
1464 OnChangeCompleted(change_id, false); 1514 OnChangeCompleted(change_id, false);
1465 return; 1515 return;
1466 } 1516 }
1467 1517
1468 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); 1518 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1469 if (!display_root) { 1519 if (!display_root) {
1470 // The window isn't parented. There's nothing to do. 1520 // The window isn't parented. There's nothing to do.
1471 OnChangeCompleted(change_id, false); 1521 OnChangeCompleted(change_id, false);
1472 return; 1522 return;
1473 } 1523 }
1474 1524
1475 if (window_server_->in_move_loop()) { 1525 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
1476 // A window manager is already servicing a move loop; we can't start a 1526 // Either the window manager is servicing a window drag or we're servicing
1477 // second one. 1527 // a drag and drop operation. We can't start a second drag.
1478 OnChangeCompleted(change_id, false); 1528 OnChangeCompleted(change_id, false);
1479 return; 1529 return;
1480 } 1530 }
1481 1531
1482 // When we perform a window move loop, we give the window manager non client 1532 // When we perform a window move loop, we give the window manager non client
1483 // capture. Because of how the capture public interface currently works, 1533 // capture. Because of how the capture public interface currently works,
1484 // SetCapture() will check whether the mouse cursor is currently in the 1534 // SetCapture() will check whether the mouse cursor is currently in the
1485 // non-client area and if so, will redirect messages to the window 1535 // non-client area and if so, will redirect messages to the window
1486 // manager. (And normal window movement relies on this behaviour.) 1536 // manager. (And normal window movement relies on this behaviour.)
1487 WindowManagerState* wms = display_root->window_manager_state(); 1537 WindowManagerState* wms = display_root->window_manager_state();
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 const ServerWindow* window) const { 1724 const ServerWindow* window) const {
1675 return IsWindowKnown(window); 1725 return IsWindowKnown(window);
1676 } 1726 }
1677 1727
1678 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1728 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1679 const ServerWindow* window) const { 1729 const ServerWindow* window) const {
1680 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1730 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1681 return tree && tree != this; 1731 return tree && tree != this;
1682 } 1732 }
1683 1733
1734 void WindowTree::OnDragOver(bool success) {
1735 DCHECK(window_server_->in_drag_loop());
1736 DCHECK_EQ(this, window_server_->GetCurrentDragLoopInitiator());
1737
1738 uint32_t change_id = window_server_->GetCurrentDragLoopChangeId();
1739 ServerWindow* window = window_server_->GetCurrentDragLoopWindow();
1740 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1741 if (!display_root)
1742 return;
1743
1744 window_server_->EndDragLoop();
1745 WindowManagerState* wms = display_root->window_manager_state();
1746 wms->EndDragDrop();
1747
1748 client()->OnChangeCompleted(change_id, success);
1749 }
1750
1751 ServerWindow* WindowTree::GetWindowById(const WindowId& id) {
1752 return GetWindow(id);
1753 }
1754
1755 DragTargetConnection* WindowTree::GetDragTargetWithRoot(
1756 const ServerWindow* window) {
1757 return window_server_->GetTreeWithRoot(window);
1758 }
1759
1760 void WindowTree::PerformOnDragStart(
1761 const ServerWindow* window,
1762 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) {
1763 ClientWindowId client_window_id;
1764 if (!IsWindowKnown(window, &client_window_id)) {
1765 NOTREACHED();
1766 return;
1767 }
1768 client()->OnDragStart(client_window_id.id, std::move(mime_data));
1769 }
1770
1771 void WindowTree::PerformOnDragEnter(
1772 const ServerWindow* window,
1773 uint32_t key_state,
1774 const gfx::Point& cursor_offset,
1775 uint32_t effect_bitmask,
1776 const base::Callback<void(uint32_t)>& callback) {
1777 ClientWindowId client_window_id;
1778 if (!IsWindowKnown(window, &client_window_id)) {
1779 NOTREACHED();
1780 callback.Run(0);
1781 return;
1782 }
1783 client()->OnDragEnter(client_window_id.id, key_state, cursor_offset,
1784 effect_bitmask, callback);
1785 }
1786
1787 void WindowTree::PerformOnDragOver(
1788 const ServerWindow* window,
1789 uint32_t key_state,
1790 const gfx::Point& cursor_offset,
1791 uint32_t effect_bitmask,
1792 const base::Callback<void(uint32_t)>& callback) {
1793 ClientWindowId client_window_id;
1794 if (!IsWindowKnown(window, &client_window_id)) {
1795 NOTREACHED();
1796 callback.Run(0);
1797 return;
1798 }
1799 client()->OnDragOver(client_window_id.id, key_state, cursor_offset,
1800 effect_bitmask, callback);
1801 }
1802
1803 void WindowTree::PerformOnDragLeave(const ServerWindow* window) {
1804 ClientWindowId client_window_id;
1805 if (!IsWindowKnown(window, &client_window_id)) {
1806 NOTREACHED();
1807 return;
1808 }
1809 client()->OnDragLeave(client_window_id.id);
1810 }
1811
1812 void WindowTree::PerformOnDragDrop(
1813 const ServerWindow* window,
1814 uint32_t key_state,
1815 const gfx::Point& cursor_offset,
1816 uint32_t effect_bitmask,
1817 const base::Callback<void(uint32_t)>& callback) {
1818 ClientWindowId client_window_id;
1819 if (!IsWindowKnown(window, &client_window_id)) {
1820 NOTREACHED();
1821 callback.Run(0);
1822 return;
1823 }
1824 client()->OnDragDrop(client_window_id.id, key_state, cursor_offset,
1825 effect_bitmask, callback);
1826 }
1827
1828 void WindowTree::PerformOnDragFinish(const ServerWindow* window) {
1829 ClientWindowId client_window_id;
1830 if (!IsWindowKnown(window, &client_window_id)) {
1831 NOTREACHED();
1832 return;
1833 }
1834 client()->OnDragFinish(client_window_id.id);
1835 }
1836
1684 } // namespace ws 1837 } // namespace ws
1685 } // namespace ui 1838 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698