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

Side by Side Diff: services/ui/public/cpp/window_tree_client.cc

Issue 2266603002: mus: Implement interwindow drag and drop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more 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/public/cpp/window_tree_client.h" 5 #include "services/ui/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "services/shell/public/cpp/connector.h" 15 #include "services/shell/public/cpp/connector.h"
16 #include "services/ui/common/util.h" 16 #include "services/ui/common/util.h"
17 #include "services/ui/public/cpp/in_flight_change.h" 17 #include "services/ui/public/cpp/in_flight_change.h"
18 #include "services/ui/public/cpp/input_event_handler.h" 18 #include "services/ui/public/cpp/input_event_handler.h"
19 #include "services/ui/public/cpp/window_drop_target.h"
19 #include "services/ui/public/cpp/window_manager_delegate.h" 20 #include "services/ui/public/cpp/window_manager_delegate.h"
20 #include "services/ui/public/cpp/window_observer.h" 21 #include "services/ui/public/cpp/window_observer.h"
21 #include "services/ui/public/cpp/window_private.h" 22 #include "services/ui/public/cpp/window_private.h"
22 #include "services/ui/public/cpp/window_tracker.h" 23 #include "services/ui/public/cpp/window_tracker.h"
23 #include "services/ui/public/cpp/window_tree_client_delegate.h" 24 #include "services/ui/public/cpp/window_tree_client_delegate.h"
24 #include "services/ui/public/cpp/window_tree_client_observer.h" 25 #include "services/ui/public/cpp/window_tree_client_observer.h"
25 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" 26 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h"
26 #include "ui/events/event.h" 27 #include "ui/events/event.h"
27 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.h"
28 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 76 }
76 Window* window = AddWindowToClient( 77 Window* window = AddWindowToClient(
77 client, !parents.empty() ? parents.back() : NULL, windows[i]); 78 client, !parents.empty() ? parents.back() : NULL, windows[i]);
78 if (!last_window) 79 if (!last_window)
79 root = window; 80 root = window;
80 last_window = window; 81 last_window = window;
81 } 82 }
82 return root; 83 return root;
83 } 84 }
84 85
86 struct WindowTreeClient::CurrentDragState {
87 // The current change id of the current drag an drop ipc.
88 uint32_t change_id;
89
90 // Callback executed when a drag initiated by PerformDragDrop() is completed.
91 base::Callback<void(bool)> on_finished;
92 };
93
85 WindowTreeClient::WindowTreeClient( 94 WindowTreeClient::WindowTreeClient(
86 WindowTreeClientDelegate* delegate, 95 WindowTreeClientDelegate* delegate,
87 WindowManagerDelegate* window_manager_delegate, 96 WindowManagerDelegate* window_manager_delegate,
88 mojo::InterfaceRequest<mojom::WindowTreeClient> request) 97 mojo::InterfaceRequest<mojom::WindowTreeClient> request)
89 : client_id_(0), 98 : client_id_(0),
90 next_window_id_(1), 99 next_window_id_(1),
91 next_change_id_(1), 100 next_change_id_(1),
92 delegate_(delegate), 101 delegate_(delegate),
93 window_manager_delegate_(window_manager_delegate), 102 window_manager_delegate_(window_manager_delegate),
94 capture_window_(nullptr), 103 capture_window_(nullptr),
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 has_pointer_watcher_ = true; 633 has_pointer_watcher_ = true;
625 tree_->StartPointerWatcher(want_moves); 634 tree_->StartPointerWatcher(want_moves);
626 } 635 }
627 636
628 void WindowTreeClient::StopPointerWatcher() { 637 void WindowTreeClient::StopPointerWatcher() {
629 DCHECK(has_pointer_watcher_); 638 DCHECK(has_pointer_watcher_);
630 tree_->StopPointerWatcher(); 639 tree_->StopPointerWatcher();
631 has_pointer_watcher_ = false; 640 has_pointer_watcher_ = false;
632 } 641 }
633 642
643 void WindowTreeClient::PerformDragDrop(
644 Window* window,
645 int drag_pointer,
646 const std::map<std::string, std::vector<uint8_t>>& drag_data,
647 int drag_operation,
648 const gfx::Point& cursor_location,
649 const SkBitmap& bitmap,
650 const base::Callback<void(bool)>& callback) {
651 DCHECK(!current_drag_state_);
652
653 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when
654 // we start showing an image representation of the drag under he cursor.
655
656 if (window->drop_target()) {
657 // To minimize the number of round trips, copy the drag drop data to our
658 // handler here, instead of forcing mus to send this same data back.
659 OnDragDropStart(
660 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data));
661 }
662
663 uint32_t current_drag_change = ScheduleInFlightChange(
664 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP));
665 current_drag_state_.reset(
666 new CurrentDragState{current_drag_change, callback});
667
668 tree_->PerformDragDrop(
669 current_drag_change, window->server_id(), drag_pointer,
670 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data),
671 drag_operation);
672 }
673
634 void WindowTreeClient::PerformWindowMove( 674 void WindowTreeClient::PerformWindowMove(
635 Window* window, 675 Window* window,
636 ui::mojom::MoveLoopSource source, 676 ui::mojom::MoveLoopSource source,
637 const gfx::Point& cursor_location, 677 const gfx::Point& cursor_location,
638 const base::Callback<void(bool)>& callback) { 678 const base::Callback<void(bool)>& callback) {
639 DCHECK(on_current_move_finished_.is_null()); 679 DCHECK(on_current_move_finished_.is_null());
640 on_current_move_finished_ = callback; 680 on_current_move_finished_ = callback;
641 681
642 current_move_loop_change_ = ScheduleInFlightChange( 682 current_move_loop_change_ = ScheduleInFlightChange(
643 base::MakeUnique<InFlightMoveLoopChange>(window)); 683 base::MakeUnique<InFlightDragChange>(window, ChangeType::MOVE_LOOP));
644 // Tell the window manager to take over moving us. 684 // Tell the window manager to take over moving us.
645 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), 685 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
646 source, cursor_location); 686 source, cursor_location);
647 } 687 }
648 688
649 void WindowTreeClient::CancelWindowMove(Window* window) { 689 void WindowTreeClient::CancelWindowMove(Window* window) {
650 tree_->CancelWindowMove(window->server_id()); 690 tree_->CancelWindowMove(window->server_id());
651 } 691 }
652 692
653 Window* WindowTreeClient::NewWindow( 693 Window* WindowTreeClient::NewWindow(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // WindowTreeClient, WindowTreeClient implementation: 731 // WindowTreeClient, WindowTreeClient implementation:
692 732
693 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { 733 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) {
694 observers_.AddObserver(observer); 734 observers_.AddObserver(observer);
695 } 735 }
696 736
697 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { 737 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) {
698 observers_.RemoveObserver(observer); 738 observers_.RemoveObserver(observer);
699 } 739 }
700 740
741 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) {
742 DCHECK(tree_);
743 tree_->SetCanAcceptDrops(window_id, can_accept_drops);
744 }
745
701 void WindowTreeClient::SetCanAcceptEvents(Id window_id, 746 void WindowTreeClient::SetCanAcceptEvents(Id window_id,
702 bool can_accept_events) { 747 bool can_accept_events) {
703 DCHECK(tree_); 748 DCHECK(tree_);
704 tree_->SetCanAcceptEvents(window_id, can_accept_events); 749 tree_->SetCanAcceptEvents(window_id, can_accept_events);
705 } 750 }
706 751
707 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, 752 void WindowTreeClient::OnEmbed(ClientSpecificId client_id,
708 mojom::WindowDataPtr root_data, 753 mojom::WindowDataPtr root_data,
709 mojom::WindowTreePtr tree, 754 mojom::WindowTreePtr tree,
710 int64_t display_id, 755 int64_t display_id,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 if (!window) 1082 if (!window)
1038 return; 1083 return;
1039 1084
1040 InFlightPredefinedCursorChange new_change(window, cursor); 1085 InFlightPredefinedCursorChange new_change(window, cursor);
1041 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1086 if (ApplyServerChangeToExistingInFlightChange(new_change))
1042 return; 1087 return;
1043 1088
1044 WindowPrivate(window).LocalSetPredefinedCursor(cursor); 1089 WindowPrivate(window).LocalSetPredefinedCursor(cursor);
1045 } 1090 }
1046 1091
1092 void WindowTreeClient::OnDragDropStart(
1093 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) {
1094 mime_drag_data_ = std::move(mime_data);
1095 }
1096
1097 void WindowTreeClient::OnDragEnter(Id window_id,
1098 uint32_t key_state,
1099 const gfx::Point& position,
1100 uint32_t effect_bitmask,
1101 const OnDragEnterCallback& callback) {
1102 Window* window = GetWindowByServerId(window_id);
1103 if (!window || !window->drop_target()) {
1104 callback.Run(mojom::kDropEffectNone);
1105 return;
1106 }
1107
1108 if (!base::ContainsKey(drag_entered_windows_, window_id)) {
1109 window->drop_target()->OnDragDropStart(
1110 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>());
1111 drag_entered_windows_.insert(window_id);
1112 }
1113
1114 uint32_t ret =
1115 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask);
1116 callback.Run(ret);
1117 }
1118
1119 void WindowTreeClient::OnDragOver(Id window_id,
1120 uint32_t key_state,
1121 const gfx::Point& position,
1122 uint32_t effect_bitmask,
1123 const OnDragOverCallback& callback) {
1124 Window* window = GetWindowByServerId(window_id);
1125 if (!window || !window->drop_target()) {
1126 callback.Run(mojom::kDropEffectNone);
1127 return;
1128 }
1129
1130 uint32_t ret =
1131 window->drop_target()->OnDragOver(key_state, position, effect_bitmask);
1132 callback.Run(ret);
1133 }
1134
1135 void WindowTreeClient::OnDragLeave(Id window_id) {
1136 Window* window = GetWindowByServerId(window_id);
1137 if (!window || !window->drop_target())
1138 return;
1139
1140 window->drop_target()->OnDragLeave();
1141 }
1142
1143 void WindowTreeClient::OnDragDropDone() {
1144 for (Id id : drag_entered_windows_) {
1145 Window* window = GetWindowByServerId(id);
1146 if (!window || !window->drop_target())
1147 continue;
1148 window->drop_target()->OnDragDropDone();
1149 }
1150 drag_entered_windows_.clear();
1151 }
1152
1153 void WindowTreeClient::OnCompleteDrop(Id window_id,
1154 uint32_t key_state,
1155 const gfx::Point& position,
1156 uint32_t effect_bitmask,
1157 const OnCompleteDropCallback& callback) {
1158 Window* window = GetWindowByServerId(window_id);
1159 if (!window || !window->drop_target()) {
1160 callback.Run(mojom::kDropEffectNone);
1161 return;
1162 }
1163
1164 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position,
1165 effect_bitmask);
1166 callback.Run(ret);
1167 }
1168
1047 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { 1169 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
1048 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 1170 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
1049 in_flight_map_.erase(change_id); 1171 in_flight_map_.erase(change_id);
1050 if (!change) 1172 if (!change)
1051 return; 1173 return;
1052 1174
1053 if (!success) 1175 if (!success)
1054 change->ChangeFailed(); 1176 change->ChangeFailed();
1055 1177
1056 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1178 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1057 if (next_change) { 1179 if (next_change) {
1058 if (!success) 1180 if (!success)
1059 next_change->SetRevertValueFrom(*change); 1181 next_change->SetRevertValueFrom(*change);
1060 } else if (!success) { 1182 } else if (!success) {
1061 change->Revert(); 1183 change->Revert();
1062 } 1184 }
1063 1185
1064 if (change_id == current_move_loop_change_) { 1186 if (change_id == current_move_loop_change_) {
1065 current_move_loop_change_ = 0; 1187 current_move_loop_change_ = 0;
1066 on_current_move_finished_.Run(success); 1188 on_current_move_finished_.Run(success);
1067 on_current_move_finished_.Reset(); 1189 on_current_move_finished_.Reset();
1068 } 1190 }
1191
1192 if (current_drag_state_ && change_id == current_drag_state_->change_id) {
1193 OnDragDropDone();
1194
1195 current_drag_state_->on_finished.Run(success);
1196 current_drag_state_.reset();
1197 }
1069 } 1198 }
1070 1199
1071 void WindowTreeClient::GetWindowManager( 1200 void WindowTreeClient::GetWindowManager(
1072 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1201 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1073 window_manager_internal_.reset( 1202 window_manager_internal_.reset(
1074 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1203 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1075 std::move(internal))); 1204 std::move(internal)));
1076 } 1205 }
1077 1206
1078 void WindowTreeClient::RequestClose(uint32_t window_id) { 1207 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 Window* window, 1382 Window* window,
1254 const gfx::Vector2d& offset, 1383 const gfx::Vector2d& offset,
1255 const gfx::Insets& hit_area) { 1384 const gfx::Insets& hit_area) {
1256 if (window_manager_internal_client_) { 1385 if (window_manager_internal_client_) {
1257 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1386 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1258 server_id(window), offset.x(), offset.y(), hit_area); 1387 server_id(window), offset.x(), offset.y(), hit_area);
1259 } 1388 }
1260 } 1389 }
1261 1390
1262 } // namespace ui 1391 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/window_tree_client.h ('k') | services/ui/public/interfaces/window_tree.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698