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 1369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::SetCanAcceptDrops(Id window_id, bool accepts_drops) { |
| 1391 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
| 1392 if (!window || !access_policy_->CanSetAcceptDrops(window)) { |
| 1393 DVLOG(1) << "SetAcceptsDrops failed"; |
| 1394 return; |
| 1395 } |
| 1396 |
| 1397 window->SetCanAcceptDrops(accepts_drops); |
| 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 Loading... |
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 int32_t drag_pointer, |
| 1469 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data, |
| 1470 uint32_t drag_operation) { |
| 1471 ServerWindow* window = GetWindowByClientId(ClientWindowId(source_window_id)); |
| 1472 bool success = window && access_policy_->CanInitiateMoveLoop(window); |
| 1473 if (!success || !ShouldRouteToWindowManager(window)) { |
| 1474 // We need to fail this move loop change, otherwise the client will just be |
| 1475 // waiting for |change_id|. |
| 1476 OnChangeCompleted(change_id, false); |
| 1477 return; |
| 1478 } |
| 1479 |
| 1480 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
| 1481 if (!display_root) { |
| 1482 // The window isn't parented. There's nothing to do. |
| 1483 OnChangeCompleted(change_id, false); |
| 1484 return; |
| 1485 } |
| 1486 |
| 1487 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) { |
| 1488 // Either the window manager is servicing a window drag or we're servicing |
| 1489 // a drag and drop operation. We can't start a second drag. |
| 1490 OnChangeCompleted(change_id, false); |
| 1491 return; |
| 1492 } |
| 1493 |
| 1494 // TODO(erg): Dealing with |drag_representation| is hard, so we're going to |
| 1495 // deal with that later. |
| 1496 |
| 1497 // Here, we need to dramatically change how the mouse pointer works. Once |
| 1498 // we've started a drag drop operation, cursor events don't go to windows as |
| 1499 // normal. |
| 1500 WindowManagerState* wms = display_root->window_manager_state(); |
| 1501 window_server_->StartDragLoop(change_id, window, this); |
| 1502 wms->SetDragDropSourceWindow(this, window, drag_pointer, std::move(drag_data), |
| 1503 drag_operation); |
| 1504 } |
| 1505 |
1455 void WindowTree::PerformWindowMove(uint32_t change_id, | 1506 void WindowTree::PerformWindowMove(uint32_t change_id, |
1456 Id window_id, | 1507 Id window_id, |
1457 ui::mojom::MoveLoopSource source, | 1508 ui::mojom::MoveLoopSource source, |
1458 const gfx::Point& cursor) { | 1509 const gfx::Point& cursor) { |
1459 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); | 1510 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); |
1460 bool success = window && access_policy_->CanInitiateMoveLoop(window); | 1511 bool success = window && access_policy_->CanInitiateMoveLoop(window); |
1461 if (!success || !ShouldRouteToWindowManager(window)) { | 1512 if (!success || !ShouldRouteToWindowManager(window)) { |
1462 // We need to fail this move loop change, otherwise the client will just be | 1513 // We need to fail this move loop change, otherwise the client will just be |
1463 // waiting for |change_id|. | 1514 // waiting for |change_id|. |
1464 OnChangeCompleted(change_id, false); | 1515 OnChangeCompleted(change_id, false); |
1465 return; | 1516 return; |
1466 } | 1517 } |
1467 | 1518 |
1468 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); | 1519 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
1469 if (!display_root) { | 1520 if (!display_root) { |
1470 // The window isn't parented. There's nothing to do. | 1521 // The window isn't parented. There's nothing to do. |
1471 OnChangeCompleted(change_id, false); | 1522 OnChangeCompleted(change_id, false); |
1472 return; | 1523 return; |
1473 } | 1524 } |
1474 | 1525 |
1475 if (window_server_->in_move_loop()) { | 1526 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 | 1527 // Either the window manager is servicing a window drag or we're servicing |
1477 // second one. | 1528 // a drag and drop operation. We can't start a second drag. |
1478 OnChangeCompleted(change_id, false); | 1529 OnChangeCompleted(change_id, false); |
1479 return; | 1530 return; |
1480 } | 1531 } |
1481 | 1532 |
1482 // When we perform a window move loop, we give the window manager non client | 1533 // 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, | 1534 // capture. Because of how the capture public interface currently works, |
1484 // SetCapture() will check whether the mouse cursor is currently in the | 1535 // SetCapture() will check whether the mouse cursor is currently in the |
1485 // non-client area and if so, will redirect messages to the window | 1536 // non-client area and if so, will redirect messages to the window |
1486 // manager. (And normal window movement relies on this behaviour.) | 1537 // manager. (And normal window movement relies on this behaviour.) |
1487 WindowManagerState* wms = display_root->window_manager_state(); | 1538 WindowManagerState* wms = display_root->window_manager_state(); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 const ServerWindow* window) const { | 1725 const ServerWindow* window) const { |
1675 return IsWindowKnown(window); | 1726 return IsWindowKnown(window); |
1676 } | 1727 } |
1677 | 1728 |
1678 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( | 1729 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( |
1679 const ServerWindow* window) const { | 1730 const ServerWindow* window) const { |
1680 WindowTree* tree = window_server_->GetTreeWithRoot(window); | 1731 WindowTree* tree = window_server_->GetTreeWithRoot(window); |
1681 return tree && tree != this; | 1732 return tree && tree != this; |
1682 } | 1733 } |
1683 | 1734 |
| 1735 void WindowTree::OnDragCompleted(bool success) { |
| 1736 DCHECK(window_server_->in_drag_loop()); |
| 1737 DCHECK_EQ(this, window_server_->GetCurrentDragLoopInitiator()); |
| 1738 |
| 1739 uint32_t change_id = window_server_->GetCurrentDragLoopChangeId(); |
| 1740 ServerWindow* window = window_server_->GetCurrentDragLoopWindow(); |
| 1741 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
| 1742 if (!display_root) |
| 1743 return; |
| 1744 |
| 1745 window_server_->EndDragLoop(); |
| 1746 WindowManagerState* wms = display_root->window_manager_state(); |
| 1747 wms->EndDragDrop(); |
| 1748 |
| 1749 client()->OnChangeCompleted(change_id, success); |
| 1750 } |
| 1751 |
| 1752 ServerWindow* WindowTree::GetWindowById(const WindowId& id) { |
| 1753 return GetWindow(id); |
| 1754 } |
| 1755 |
| 1756 DragTargetConnection* WindowTree::GetDragTargetWithRoot( |
| 1757 const ServerWindow* window) { |
| 1758 return window_server_->GetTreeWithRoot(window); |
| 1759 } |
| 1760 |
| 1761 void WindowTree::PerformOnDragStart( |
| 1762 const ServerWindow* window, |
| 1763 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { |
| 1764 ClientWindowId client_window_id; |
| 1765 if (!IsWindowKnown(window, &client_window_id)) { |
| 1766 NOTREACHED(); |
| 1767 return; |
| 1768 } |
| 1769 client()->OnDragStart(client_window_id.id, std::move(mime_data)); |
| 1770 } |
| 1771 |
| 1772 void WindowTree::PerformOnDragEnter( |
| 1773 const ServerWindow* window, |
| 1774 uint32_t key_state, |
| 1775 const gfx::Point& cursor_offset, |
| 1776 uint32_t effect_bitmask, |
| 1777 const base::Callback<void(uint32_t)>& callback) { |
| 1778 ClientWindowId client_window_id; |
| 1779 if (!IsWindowKnown(window, &client_window_id)) { |
| 1780 NOTREACHED(); |
| 1781 callback.Run(0); |
| 1782 return; |
| 1783 } |
| 1784 client()->OnDragEnter(client_window_id.id, key_state, cursor_offset, |
| 1785 effect_bitmask, callback); |
| 1786 } |
| 1787 |
| 1788 void WindowTree::PerformOnDragOver( |
| 1789 const ServerWindow* window, |
| 1790 uint32_t key_state, |
| 1791 const gfx::Point& cursor_offset, |
| 1792 uint32_t effect_bitmask, |
| 1793 const base::Callback<void(uint32_t)>& callback) { |
| 1794 ClientWindowId client_window_id; |
| 1795 if (!IsWindowKnown(window, &client_window_id)) { |
| 1796 NOTREACHED(); |
| 1797 callback.Run(0); |
| 1798 return; |
| 1799 } |
| 1800 client()->OnDragOver(client_window_id.id, key_state, cursor_offset, |
| 1801 effect_bitmask, callback); |
| 1802 } |
| 1803 |
| 1804 void WindowTree::PerformOnDragLeave(const ServerWindow* window) { |
| 1805 ClientWindowId client_window_id; |
| 1806 if (!IsWindowKnown(window, &client_window_id)) { |
| 1807 NOTREACHED(); |
| 1808 return; |
| 1809 } |
| 1810 client()->OnDragLeave(client_window_id.id); |
| 1811 } |
| 1812 |
| 1813 void WindowTree::PerformOnDragDrop( |
| 1814 const ServerWindow* window, |
| 1815 uint32_t key_state, |
| 1816 const gfx::Point& cursor_offset, |
| 1817 uint32_t effect_bitmask, |
| 1818 const base::Callback<void(uint32_t)>& callback) { |
| 1819 ClientWindowId client_window_id; |
| 1820 if (!IsWindowKnown(window, &client_window_id)) { |
| 1821 NOTREACHED(); |
| 1822 callback.Run(0); |
| 1823 return; |
| 1824 } |
| 1825 client()->OnDragDrop(client_window_id.id, key_state, cursor_offset, |
| 1826 effect_bitmask, callback); |
| 1827 } |
| 1828 |
| 1829 void WindowTree::PerformOnDragFinish(const ServerWindow* window) { |
| 1830 ClientWindowId client_window_id; |
| 1831 if (!IsWindowKnown(window, &client_window_id)) { |
| 1832 NOTREACHED(); |
| 1833 return; |
| 1834 } |
| 1835 client()->OnDragFinish(client_window_id.id); |
| 1836 } |
| 1837 |
1684 } // namespace ws | 1838 } // namespace ws |
1685 } // namespace ui | 1839 } // namespace ui |
OLD | NEW |