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

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: Uploaded for a few comments. Created 4 years, 4 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 if (display) 448 if (display)
449 display->AddActivationParent(window); 449 display->AddActivationParent(window);
450 else 450 else
451 DVLOG(1) << "AddActivationParent window not associated with display"; 451 DVLOG(1) << "AddActivationParent window not associated with display";
452 } else { 452 } else {
453 DVLOG(1) << "AddActivationParent supplied invalid window id"; 453 DVLOG(1) << "AddActivationParent supplied invalid window id";
454 } 454 }
455 } 455 }
456 456
457 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) { 457 void WindowTree::OnChangeCompleted(uint32_t change_id, bool success) {
458 if (window_server_->in_drag_loop() &&
459 change_id == window_server_->GetCurrentDragLoopChangeId()) {
460 window_server_->EndDragLoop();
461 }
462
458 client()->OnChangeCompleted(change_id, success); 463 client()->OnChangeCompleted(change_id, success);
459 } 464 }
460 465
461 void WindowTree::OnAccelerator(uint32_t accelerator_id, 466 void WindowTree::OnAccelerator(uint32_t accelerator_id,
462 const ui::Event& event, 467 const ui::Event& event,
463 bool needs_ack) { 468 bool needs_ack) {
464 DCHECK(window_manager_internal_); 469 DCHECK(window_manager_internal_);
465 if (needs_ack) 470 if (needs_ack)
466 GenerateEventAckId(); 471 GenerateEventAckId();
467 else 472 else
468 DCHECK_EQ(0u, event_ack_id_); 473 DCHECK_EQ(0u, event_ack_id_);
469 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map 474 // TODO(moshayedi): crbug.com/617167. Don't clone even once we map
470 // mojom::Event directly to ui::Event. 475 // mojom::Event directly to ui::Event.
471 window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id, 476 window_manager_internal_->OnAccelerator(event_ack_id_, accelerator_id,
472 ui::Event::Clone(event)); 477 ui::Event::Clone(event));
473 } 478 }
474 479
475 void WindowTree::ClientJankinessChanged(WindowTree* tree) { 480 void WindowTree::ClientJankinessChanged(WindowTree* tree) {
476 tree->janky_ = !tree->janky_; 481 tree->janky_ = !tree->janky_;
477 // Don't inform the client if it is the source of jank (which generally only 482 // Don't inform the client if it is the source of jank (which generally only
478 // happens while debugging). 483 // happens while debugging).
479 if (window_manager_internal_ && tree != this) { 484 if (window_manager_internal_ && tree != this) {
480 window_manager_internal_->WmClientJankinessChanged( 485 window_manager_internal_->WmClientJankinessChanged(
481 tree->id(), tree->janky()); 486 tree->id(), tree->janky());
482 } 487 }
483 } 488 }
484 489
490 void WindowTree::PerformOnDragEnter(
491 const ServerWindow* window,
492 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data,
493 uint32_t key_state,
494 const gfx::Point& cursor_offset,
495 uint32_t effect_bitmask,
496 const base::Callback<void(uint32_t)>& callback) {
497 ClientWindowId client_window_id;
498 if (!IsWindowKnown(window, &client_window_id)) {
499 NOTREACHED();
500 callback.Run(0);
501 return;
502 }
503 client()->OnDragEnter(client_window_id.id, std::move(mime_data), key_state,
504 cursor_offset, effect_bitmask, callback);
505 }
506
507 void WindowTree::PerformOnDragOver(
508 const ServerWindow* window,
509 uint32_t key_state,
510 const gfx::Point& cursor_offset,
511 uint32_t effect_bitmask,
512 const base::Callback<void(uint32_t)>& callback) {
513 ClientWindowId client_window_id;
514 if (!IsWindowKnown(window, &client_window_id)) {
515 NOTREACHED();
516 callback.Run(0);
517 return;
518 }
519 client()->OnDragOver(client_window_id.id, key_state, cursor_offset,
520 effect_bitmask, callback);
521 }
522
523 void WindowTree::PerformOnDragLeave(const ServerWindow* window) {
524 ClientWindowId client_window_id;
525 if (!IsWindowKnown(window, &client_window_id)) {
526 NOTREACHED();
527 return;
528 }
529 client()->OnDragLeave(client_window_id.id);
530 }
531
532 void WindowTree::PerformOnDragDrop(
533 const ServerWindow* window,
534 uint32_t key_state,
535 const gfx::Point& cursor_offset,
536 uint32_t effect_bitmask,
537 const base::Callback<void(uint32_t)>& callback) {
538 ClientWindowId client_window_id;
539 if (!IsWindowKnown(window, &client_window_id)) {
540 NOTREACHED();
541 callback.Run(0);
542 return;
543 }
544 client()->OnDragDrop(client_window_id.id, key_state, cursor_offset,
545 effect_bitmask, callback);
546 }
547
485 void WindowTree::ProcessWindowBoundsChanged(const ServerWindow* window, 548 void WindowTree::ProcessWindowBoundsChanged(const ServerWindow* window,
486 const gfx::Rect& old_bounds, 549 const gfx::Rect& old_bounds,
487 const gfx::Rect& new_bounds, 550 const gfx::Rect& new_bounds,
488 bool originated_change) { 551 bool originated_change) {
489 ClientWindowId client_window_id; 552 ClientWindowId client_window_id;
490 if (originated_change || !IsWindowKnown(window, &client_window_id)) 553 if (originated_change || !IsWindowKnown(window, &client_window_id))
491 return; 554 return;
492 client()->OnWindowBoundsChanged(client_window_id.id, old_bounds, new_bounds); 555 client()->OnWindowBoundsChanged(client_window_id.id, old_bounds, new_bounds);
493 } 556 }
494 557
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 DVLOG(1) << "SetHitTestMask failed"; 1441 DVLOG(1) << "SetHitTestMask failed";
1379 return; 1442 return;
1380 } 1443 }
1381 1444
1382 if (mask) 1445 if (mask)
1383 window->SetHitTestMask(*mask); 1446 window->SetHitTestMask(*mask);
1384 else 1447 else
1385 window->ClearHitTestMask(); 1448 window->ClearHitTestMask();
1386 } 1449 }
1387 1450
1451 void WindowTree::SetCanAcceptDrags(Id window_id, bool accepts_drags) {
1452 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1453 if (!window || !access_policy_->CanSetAcceptDrags(window)) {
1454 DVLOG(1) << "SetAcceptsDrags failed";
1455 return;
1456 }
1457
1458 window->SetCanAcceptDrags(accepts_drags);
1459 }
1460
1388 void WindowTree::Embed(Id transport_window_id, 1461 void WindowTree::Embed(Id transport_window_id,
1389 mojom::WindowTreeClientPtr client, 1462 mojom::WindowTreeClientPtr client,
1390 uint32_t flags, 1463 uint32_t flags,
1391 const EmbedCallback& callback) { 1464 const EmbedCallback& callback) {
1392 callback.Run( 1465 callback.Run(
1393 Embed(ClientWindowId(transport_window_id), std::move(client), flags)); 1466 Embed(ClientWindowId(transport_window_id), std::move(client), flags));
1394 } 1467 }
1395 1468
1396 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) { 1469 void WindowTree::SetFocus(uint32_t change_id, Id transport_window_id) {
1397 client()->OnChangeCompleted(change_id, 1470 client()->OnChangeCompleted(change_id,
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 this, std::move(internal))); 1516 this, std::move(internal)));
1444 } 1517 }
1445 1518
1446 void WindowTree::GetCursorLocationMemory( 1519 void WindowTree::GetCursorLocationMemory(
1447 const GetCursorLocationMemoryCallback& callback) { 1520 const GetCursorLocationMemoryCallback& callback) {
1448 callback.Run( 1521 callback.Run(
1449 window_server_->display_manager()->GetUserDisplayManager(user_id_)-> 1522 window_server_->display_manager()->GetUserDisplayManager(user_id_)->
1450 GetCursorLocationMemory()); 1523 GetCursorLocationMemory());
1451 } 1524 }
1452 1525
1526 void WindowTree::PerformDragDrop(
1527 uint32_t change_id,
1528 uint32_t source_window_id,
1529 mojo::Map<mojo::String, mojo::Array<uint8_t>> drag_data,
1530 uint32_t drag_operation,
1531 const gfx::Point& cursor_offset,
1532 const SkBitmap& drag_representation) {
1533 ServerWindow* window = GetWindowByClientId(ClientWindowId(source_window_id));
1534 bool success = window && access_policy_->CanInitiateMoveLoop(window);
1535 if (!success || !ShouldRouteToWindowManager(window)) {
1536 // We need to fail this move loop change, otherwise the client will just be
1537 // waiting for |change_id|.
1538 OnChangeCompleted(change_id, false);
1539 return;
1540 }
1541
1542 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1543 if (!display_root) {
1544 // The window isn't parented. There's nothing to do.
1545 OnChangeCompleted(change_id, false);
1546 return;
1547 }
1548
1549 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
1550 // Either the window manager is servicing a window drag or we're servicing
1551 // a drag and drop operation. We can't start a second drag.
1552 OnChangeCompleted(change_id, false);
1553 return;
1554 }
1555
1556 // TODO(erg): Dealing with |drag_representation| is hard, so we're going to
1557 // deal with that later.
1558
1559 // Here, we need to dramatically change how the mouse pointer works. Once
1560 // we've started a drag drop operation, cursor events don't go to windows as
1561 // normal.
1562 WindowManagerState* wms = display_root->window_manager_state();
1563 window_server_->StartDragLoop(change_id);
1564 wms->SetDragDropSourceWindow(change_id, std::move(drag_data), drag_operation,
1565 this, window);
1566 }
1567
1453 void WindowTree::PerformWindowMove(uint32_t change_id, 1568 void WindowTree::PerformWindowMove(uint32_t change_id,
1454 Id window_id, 1569 Id window_id,
1455 ui::mojom::MoveLoopSource source, 1570 ui::mojom::MoveLoopSource source,
1456 const gfx::Point& cursor) { 1571 const gfx::Point& cursor) {
1457 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1572 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1458 bool success = window && access_policy_->CanInitiateMoveLoop(window); 1573 bool success = window && access_policy_->CanInitiateMoveLoop(window);
1459 if (!success || !ShouldRouteToWindowManager(window)) { 1574 if (!success || !ShouldRouteToWindowManager(window)) {
1460 // We need to fail this move loop change, otherwise the client will just be 1575 // We need to fail this move loop change, otherwise the client will just be
1461 // waiting for |change_id|. 1576 // waiting for |change_id|.
1462 OnChangeCompleted(change_id, false); 1577 OnChangeCompleted(change_id, false);
1463 return; 1578 return;
1464 } 1579 }
1465 1580
1466 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); 1581 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1467 if (!display_root) { 1582 if (!display_root) {
1468 // The window isn't parented. There's nothing to do. 1583 // The window isn't parented. There's nothing to do.
1469 OnChangeCompleted(change_id, false); 1584 OnChangeCompleted(change_id, false);
1470 return; 1585 return;
1471 } 1586 }
1472 1587
1473 if (window_server_->in_move_loop()) { 1588 if (window_server_->in_move_loop() || window_server_->in_drag_loop()) {
1474 // A window manager is already servicing a move loop; we can't start a 1589 // Either the window manager is servicing a window drag or we're servicing
1475 // second one. 1590 // a drag and drop operation. We can't start a second drag.
1476 OnChangeCompleted(change_id, false); 1591 OnChangeCompleted(change_id, false);
1477 return; 1592 return;
1478 } 1593 }
1479 1594
1480 // When we perform a window move loop, we give the window manager non client 1595 // When we perform a window move loop, we give the window manager non client
1481 // capture. Because of how the capture public interface currently works, 1596 // capture. Because of how the capture public interface currently works,
1482 // SetCapture() will check whether the mouse cursor is currently in the 1597 // SetCapture() will check whether the mouse cursor is currently in the
1483 // non-client area and if so, will redirect messages to the window 1598 // non-client area and if so, will redirect messages to the window
1484 // manager. (And normal window movement relies on this behaviour.) 1599 // manager. (And normal window movement relies on this behaviour.)
1485 WindowManagerState* wms = display_root->window_manager_state(); 1600 WindowManagerState* wms = display_root->window_manager_state();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 } 1789 }
1675 1790
1676 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1791 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1677 const ServerWindow* window) const { 1792 const ServerWindow* window) const {
1678 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1793 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1679 return tree && tree != this; 1794 return tree && tree != this;
1680 } 1795 }
1681 1796
1682 } // namespace ws 1797 } // namespace ws
1683 } // namespace ui 1798 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698