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

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: sky comments 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::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
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,
sky 2016/09/13 18:15:32 uint32_t -> 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);
sky 2016/09/13 18:15:32 Please add a new function, CanInitiateDragLoop?
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);
sky 2016/09/13 18:15:32 Please DVLOG the failures.
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, this, drag_pointer,
sky 2016/09/13 18:15:32 optional: it's mildly weird that WindowServer::Sta
1503 std::move(drag_data), 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
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);
sky 2016/09/13 18:15:32 This returns the WindowTree that has |window| as o
1759 }
1760
1761 void WindowTree::PerformOnDragMimeTypes(
1762 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) {
1763 client()->OnDragMimeTypes(std::move(mime_data));
1764 }
1765
1766 void WindowTree::PerformOnDragEnter(
1767 const ServerWindow* window,
1768 uint32_t event_flags,
1769 const gfx::Point& cursor_offset,
1770 uint32_t effect_bitmask,
1771 const base::Callback<void(uint32_t)>& callback) {
1772 ClientWindowId client_window_id;
1773 if (!IsWindowKnown(window, &client_window_id)) {
1774 NOTREACHED();
1775 callback.Run(0);
1776 return;
1777 }
1778 client()->OnDragEnter(client_window_id.id, event_flags, cursor_offset,
1779 effect_bitmask, callback);
1780 }
1781
1782 void WindowTree::PerformOnDragOver(
1783 const ServerWindow* window,
1784 uint32_t event_flags,
1785 const gfx::Point& cursor_offset,
1786 uint32_t effect_bitmask,
1787 const base::Callback<void(uint32_t)>& callback) {
1788 ClientWindowId client_window_id;
1789 if (!IsWindowKnown(window, &client_window_id)) {
1790 NOTREACHED();
1791 callback.Run(0);
1792 return;
1793 }
1794 client()->OnDragOver(client_window_id.id, event_flags, cursor_offset,
1795 effect_bitmask, callback);
1796 }
1797
1798 void WindowTree::PerformOnDragLeave(const ServerWindow* window) {
1799 ClientWindowId client_window_id;
1800 if (!IsWindowKnown(window, &client_window_id)) {
1801 NOTREACHED();
1802 return;
1803 }
1804 client()->OnDragLeave(client_window_id.id);
1805 }
1806
1807 void WindowTree::PerformOnCompleteDrop(
1808 const ServerWindow* window,
1809 uint32_t event_flags,
1810 const gfx::Point& cursor_offset,
1811 uint32_t effect_bitmask,
1812 const base::Callback<void(uint32_t)>& callback) {
1813 ClientWindowId client_window_id;
1814 if (!IsWindowKnown(window, &client_window_id)) {
1815 NOTREACHED();
1816 callback.Run(0);
1817 return;
1818 }
1819 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset,
1820 effect_bitmask, callback);
1821 }
1822
1823 void WindowTree::PerformOnDragFinish() {
1824 client()->OnDragFinish();
1825 }
1826
1684 } // namespace ws 1827 } // namespace ws
1685 } // namespace ui 1828 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698