OLD | NEW |
---|---|
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 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 DVLOG(1) << "SetHitTestMask failed"; | 1381 DVLOG(1) << "SetHitTestMask failed"; |
1382 return; | 1382 return; |
1383 } | 1383 } |
1384 | 1384 |
1385 if (mask) | 1385 if (mask) |
1386 window->SetHitTestMask(*mask); | 1386 window->SetHitTestMask(*mask); |
1387 else | 1387 else |
1388 window->ClearHitTestMask(); | 1388 window->ClearHitTestMask(); |
1389 } | 1389 } |
1390 | 1390 |
1391 void WindowTree::SetCanAcceptDrops(Id window_id, bool accepts_drops) { | |
1392 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | |
1393 if (!window || !access_policy_->CanSetAcceptDrops(window)) { | |
1394 DVLOG(1) << "SetAcceptsDrops failed"; | |
1395 return; | |
1396 } | |
1397 | |
1398 window->SetCanAcceptDrops(accepts_drops); | |
1399 } | |
1400 | |
1391 void WindowTree::Embed(Id transport_window_id, | 1401 void WindowTree::Embed(Id transport_window_id, |
1392 mojom::WindowTreeClientPtr client, | 1402 mojom::WindowTreeClientPtr client, |
1393 uint32_t flags, | 1403 uint32_t flags, |
1394 const EmbedCallback& callback) { | 1404 const EmbedCallback& callback) { |
1395 callback.Run( | 1405 callback.Run( |
1396 Embed(ClientWindowId(transport_window_id), std::move(client), flags)); | 1406 Embed(ClientWindowId(transport_window_id), std::move(client), flags)); |
1397 } | 1407 } |
1398 | 1408 |
1399 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) { | 1409 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) { |
1400 client()->OnChangeCompleted(change_id, | 1410 client()->OnChangeCompleted(change_id, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1446 this, std::move(internal))); | 1456 this, std::move(internal))); |
1447 } | 1457 } |
1448 | 1458 |
1449 void WindowTree::GetCursorLocationMemory( | 1459 void WindowTree::GetCursorLocationMemory( |
1450 const GetCursorLocationMemoryCallback& callback) { | 1460 const GetCursorLocationMemoryCallback& callback) { |
1451 callback.Run( | 1461 callback.Run( |
1452 window_server_->display_manager()->GetUserDisplayManager(user_id_)-> | 1462 window_server_->display_manager()->GetUserDisplayManager(user_id_)-> |
1453 GetCursorLocationMemory()); | 1463 GetCursorLocationMemory()); |
1454 } | 1464 } |
1455 | 1465 |
1466 void WindowTree::PerformDragDrop( | |
1467 uint32_t change_id, | |
1468 Id source_window_id, | |
1469 int32_t drag_pointer, | |
1470 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, | |
1471 uint32_t drag_operation) { | |
1472 ServerWindow* window = GetWindowByClientId(ClientWindowId(source_window_id)); | |
1473 bool success = window && access_policy_->CanInitiateDragLoop(window); | |
1474 if (!success || !ShouldRouteToWindowManager(window)) { | |
1475 // We need to fail this move loop change, otherwise the client will just be | |
1476 // waiting for |change_id|. | |
1477 DVLOG(1) << "PerformDragDrop failed (access denied)."; | |
sky
2016/09/15 18:10:47
Thanks for adding the logs. I think they're helpfu
| |
1478 OnChangeCompleted(change_id, false); | |
1479 return; | |
1480 } | |
1481 | |
1482 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); | |
1483 if (!display_root) { | |
1484 // The window isn't parented. There's nothing to do. | |
1485 DVLOG(1) << "PerformDragDrop failed (window unparented)."; | |
1486 OnChangeCompleted(change_id, false); | |
1487 return; | |
1488 } | |
1489 | |
1490 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) { | |
1491 // Either the window manager is servicing a window drag or we're servicing | |
1492 // a drag and drop operation. We can't start a second drag. | |
1493 DVLOG(1) << "PerformDragDrop failed (already performing a drag)."; | |
1494 OnChangeCompleted(change_id, false); | |
1495 return; | |
1496 } | |
1497 | |
1498 // TODO(erg): Dealing with |drag_representation| is hard, so we're going to | |
1499 // deal with that later. | |
1500 | |
1501 // Here, we need to dramatically change how the mouse pointer works. Once | |
1502 // we've started a drag drop operation, cursor events don't go to windows as | |
1503 // normal. | |
1504 WindowManagerState* wms = display_root->window_manager_state(); | |
1505 window_server_->StartDragLoop(change_id, window, this); | |
1506 wms->SetDragDropSourceWindow(this, window, this, drag_pointer, | |
1507 std::move(drag_data), drag_operation); | |
1508 } | |
1509 | |
1456 void WindowTree::PerformWindowMove(uint32_t change_id, | 1510 void WindowTree::PerformWindowMove(uint32_t change_id, |
1457 Id window_id, | 1511 Id window_id, |
1458 ui::mojom::MoveLoopSource source, | 1512 ui::mojom::MoveLoopSource source, |
1459 const gfx::Point& cursor) { | 1513 const gfx::Point& cursor) { |
1460 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1514 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1461 bool success = window && access_policy_->CanInitiateMoveLoop(window); | 1515 bool success = window && access_policy_->CanInitiateMoveLoop(window); |
1462 if (!success || !ShouldRouteToWindowManager(window)) { | 1516 if (!success || !ShouldRouteToWindowManager(window)) { |
1463 // We need to fail this move loop change, otherwise the client will just be | 1517 // We need to fail this move loop change, otherwise the client will just be |
1464 // waiting for |change_id|. | 1518 // waiting for |change_id|. |
1519 DVLOG(1) << "PerformWindowMove failed (access denied)."; | |
1465 OnChangeCompleted(change_id, false); | 1520 OnChangeCompleted(change_id, false); |
1466 return; | 1521 return; |
1467 } | 1522 } |
1468 | 1523 |
1469 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); | 1524 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
1470 if (!display_root) { | 1525 if (!display_root) { |
1471 // The window isn't parented. There's nothing to do. | 1526 // The window isn't parented. There's nothing to do. |
1527 DVLOG(1) << "PerformWindowMove failed (window unparented)."; | |
1472 OnChangeCompleted(change_id, false); | 1528 OnChangeCompleted(change_id, false); |
1473 return; | 1529 return; |
1474 } | 1530 } |
1475 | 1531 |
1476 if (window_server_->in_move_loop()) { | 1532 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) { |
1477 // A window manager is already servicing a move loop; we can't start a | 1533 // Either the window manager is servicing a window drag or we're servicing |
1478 // second one. | 1534 // a drag and drop operation. We can't start a second drag. |
1535 DVLOG(1) << "PerformWindowMove failed (already performing a drag)."; | |
1479 OnChangeCompleted(change_id, false); | 1536 OnChangeCompleted(change_id, false); |
1480 return; | 1537 return; |
1481 } | 1538 } |
1482 | 1539 |
1483 // When we perform a window move loop, we give the window manager non client | 1540 // When we perform a window move loop, we give the window manager non client |
1484 // capture. Because of how the capture public interface currently works, | 1541 // capture. Because of how the capture public interface currently works, |
1485 // SetCapture() will check whether the mouse cursor is currently in the | 1542 // SetCapture() will check whether the mouse cursor is currently in the |
1486 // non-client area and if so, will redirect messages to the window | 1543 // non-client area and if so, will redirect messages to the window |
1487 // manager. (And normal window movement relies on this behaviour.) | 1544 // manager. (And normal window movement relies on this behaviour.) |
1488 WindowManagerState* wms = display_root->window_manager_state(); | 1545 WindowManagerState* wms = display_root->window_manager_state(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1675 const ServerWindow* window) const { | 1732 const ServerWindow* window) const { |
1676 return IsWindowKnown(window); | 1733 return IsWindowKnown(window); |
1677 } | 1734 } |
1678 | 1735 |
1679 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1736 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1680 const ServerWindow* window) const { | 1737 const ServerWindow* window) const { |
1681 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1738 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1682 return tree && tree != this; | 1739 return tree && tree != this; |
1683 } | 1740 } |
1684 | 1741 |
1742 void WindowTree::OnDragCompleted(bool success) { | |
1743 DCHECK(window_server_->in_drag_loop()); | |
1744 | |
1745 if (window_server_->GetCurrentDragLoopInitiator() != this) | |
1746 return; | |
1747 | |
1748 uint32_t change_id = window_server_->GetCurrentDragLoopChangeId(); | |
1749 ServerWindow* window = window_server_->GetCurrentDragLoopWindow(); | |
1750 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); | |
1751 if (!display_root) | |
1752 return; | |
1753 | |
1754 window_server_->EndDragLoop(); | |
1755 WindowManagerState* wms = display_root->window_manager_state(); | |
1756 wms->EndDragDrop(); | |
1757 | |
1758 client()->OnChangeCompleted(change_id, success); | |
1759 } | |
1760 | |
1761 ServerWindow* WindowTree::GetWindowById(const WindowId& id) { | |
1762 return GetWindow(id); | |
1763 } | |
1764 | |
1765 DragTargetConnection* WindowTree::GetDragTargetForWindow( | |
1766 const ServerWindow* window) { | |
1767 if (!window) | |
1768 return nullptr; | |
1769 DragTargetConnection* connection = window_server_->GetTreeWithRoot(window); | |
1770 if (connection) | |
1771 return connection; | |
1772 return window_server_->GetTreeWithId(window->id().client_id); | |
1773 } | |
1774 | |
1775 void WindowTree::PerformOnDragDropStart( | |
1776 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { | |
1777 client()->OnDragDropStart(std::move(mime_data)); | |
1778 } | |
1779 | |
1780 void WindowTree::PerformOnDragEnter( | |
1781 const ServerWindow* window, | |
1782 uint32_t event_flags, | |
1783 const gfx::Point& cursor_offset, | |
1784 uint32_t effect_bitmask, | |
1785 const base::Callback<void(uint32_t)>& callback) { | |
1786 ClientWindowId client_window_id; | |
1787 if (!IsWindowKnown(window, &client_window_id)) { | |
1788 NOTREACHED(); | |
1789 callback.Run(0); | |
1790 return; | |
1791 } | |
1792 client()->OnDragEnter(client_window_id.id, event_flags, cursor_offset, | |
1793 effect_bitmask, callback); | |
1794 } | |
1795 | |
1796 void WindowTree::PerformOnDragOver( | |
1797 const ServerWindow* window, | |
1798 uint32_t event_flags, | |
1799 const gfx::Point& cursor_offset, | |
1800 uint32_t effect_bitmask, | |
1801 const base::Callback<void(uint32_t)>& callback) { | |
1802 ClientWindowId client_window_id; | |
1803 if (!IsWindowKnown(window, &client_window_id)) { | |
1804 NOTREACHED(); | |
1805 callback.Run(0); | |
1806 return; | |
1807 } | |
1808 client()->OnDragOver(client_window_id.id, event_flags, cursor_offset, | |
1809 effect_bitmask, callback); | |
1810 } | |
1811 | |
1812 void WindowTree::PerformOnDragLeave(const ServerWindow* window) { | |
1813 ClientWindowId client_window_id; | |
1814 if (!IsWindowKnown(window, &client_window_id)) { | |
1815 NOTREACHED(); | |
1816 return; | |
1817 } | |
1818 client()->OnDragLeave(client_window_id.id); | |
1819 } | |
1820 | |
1821 void WindowTree::PerformOnCompleteDrop( | |
1822 const ServerWindow* window, | |
1823 uint32_t event_flags, | |
1824 const gfx::Point& cursor_offset, | |
1825 uint32_t effect_bitmask, | |
1826 const base::Callback<void(uint32_t)>& callback) { | |
1827 ClientWindowId client_window_id; | |
1828 if (!IsWindowKnown(window, &client_window_id)) { | |
1829 NOTREACHED(); | |
1830 callback.Run(0); | |
1831 return; | |
1832 } | |
1833 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset, | |
1834 effect_bitmask, callback); | |
1835 } | |
1836 | |
1837 void WindowTree::PerformOnDragDropDone() { | |
1838 client()->OnDragDropDone(); | |
1839 } | |
1840 | |
1685 } // namespace ws | 1841 } // namespace ws |
1686 } // namespace ui | 1842 } // namespace ui |
OLD | NEW |