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

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: 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/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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 has_pointer_watcher_ = true; 625 has_pointer_watcher_ = true;
625 tree_->StartPointerWatcher(want_moves); 626 tree_->StartPointerWatcher(want_moves);
626 } 627 }
627 628
628 void WindowTreeClient::StopPointerWatcher() { 629 void WindowTreeClient::StopPointerWatcher() {
629 DCHECK(has_pointer_watcher_); 630 DCHECK(has_pointer_watcher_);
630 tree_->StopPointerWatcher(); 631 tree_->StopPointerWatcher();
631 has_pointer_watcher_ = false; 632 has_pointer_watcher_ = false;
632 } 633 }
633 634
635 void WindowTreeClient::PerformDragDrop(
636 Window* window,
637 int drag_pointer,
638 const std::map<std::string, std::vector<uint8_t>>& drag_data,
639 int drag_operation,
640 const gfx::Point& cursor_location,
641 const SkBitmap& bitmap,
642 const base::Callback<void(bool)>& callback) {
643 DCHECK(on_current_drag_finished_.is_null());
644 on_current_drag_finished_ = callback;
645
646 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when
647 // we start showing an image representation of the drag under he cursor.
648
649 if (window->drop_target()) {
650 // To minimize the number of round trips, copy the drag drop data to our
651 // handler here, instead of forcing mus to send this same data back.
652 window->drop_target()->OnDragStart(drag_data);
653 }
654
655 current_drag_change_ =
656 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window));
657 tree_->PerformDragDrop(
658 current_drag_change_, window->server_id(), drag_pointer,
659 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data),
660 drag_operation);
661 }
662
634 void WindowTreeClient::PerformWindowMove( 663 void WindowTreeClient::PerformWindowMove(
635 Window* window, 664 Window* window,
636 ui::mojom::MoveLoopSource source, 665 ui::mojom::MoveLoopSource source,
637 const gfx::Point& cursor_location, 666 const gfx::Point& cursor_location,
638 const base::Callback<void(bool)>& callback) { 667 const base::Callback<void(bool)>& callback) {
639 DCHECK(on_current_move_finished_.is_null()); 668 DCHECK(on_current_move_finished_.is_null());
640 on_current_move_finished_ = callback; 669 on_current_move_finished_ = callback;
641 670
642 current_move_loop_change_ = ScheduleInFlightChange( 671 current_move_loop_change_ =
643 base::MakeUnique<InFlightMoveLoopChange>(window)); 672 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window));
644 // Tell the window manager to take over moving us. 673 // Tell the window manager to take over moving us.
645 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), 674 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
646 source, cursor_location); 675 source, cursor_location);
647 } 676 }
648 677
649 void WindowTreeClient::CancelWindowMove(Window* window) { 678 void WindowTreeClient::CancelWindowMove(Window* window) {
650 tree_->CancelWindowMove(window->server_id()); 679 tree_->CancelWindowMove(window->server_id());
651 } 680 }
652 681
653 Window* WindowTreeClient::NewWindow( 682 Window* WindowTreeClient::NewWindow(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // WindowTreeClient, WindowTreeClient implementation: 720 // WindowTreeClient, WindowTreeClient implementation:
692 721
693 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { 722 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) {
694 observers_.AddObserver(observer); 723 observers_.AddObserver(observer);
695 } 724 }
696 725
697 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { 726 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) {
698 observers_.RemoveObserver(observer); 727 observers_.RemoveObserver(observer);
699 } 728 }
700 729
730 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) {
731 DCHECK(tree_);
732 tree_->SetCanAcceptDrops(window_id, can_accept_drops);
733 }
734
701 void WindowTreeClient::SetCanAcceptEvents(Id window_id, 735 void WindowTreeClient::SetCanAcceptEvents(Id window_id,
702 bool can_accept_events) { 736 bool can_accept_events) {
703 DCHECK(tree_); 737 DCHECK(tree_);
704 tree_->SetCanAcceptEvents(window_id, can_accept_events); 738 tree_->SetCanAcceptEvents(window_id, can_accept_events);
705 } 739 }
706 740
707 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, 741 void WindowTreeClient::OnEmbed(ClientSpecificId client_id,
708 mojom::WindowDataPtr root_data, 742 mojom::WindowDataPtr root_data,
709 mojom::WindowTreePtr tree, 743 mojom::WindowTreePtr tree,
710 int64_t display_id, 744 int64_t display_id,
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 if (!window) 1071 if (!window)
1038 return; 1072 return;
1039 1073
1040 InFlightPredefinedCursorChange new_change(window, cursor); 1074 InFlightPredefinedCursorChange new_change(window, cursor);
1041 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1075 if (ApplyServerChangeToExistingInFlightChange(new_change))
1042 return; 1076 return;
1043 1077
1044 WindowPrivate(window).LocalSetPredefinedCursor(cursor); 1078 WindowPrivate(window).LocalSetPredefinedCursor(cursor);
1045 } 1079 }
1046 1080
1081 void WindowTreeClient::OnDragMimeTypes(
1082 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) {
1083 mime_drag_data_ = std::move(mime_data);
1084 }
1085
1086 void WindowTreeClient::OnDragEnter(Id window_id,
1087 uint32_t key_state,
1088 const gfx::Point& position,
1089 uint32_t effect_bitmask,
1090 const OnDragEnterCallback& callback) {
1091 Window* window = GetWindowByServerId(window_id);
1092 if (!window || !window->drop_target()) {
1093 callback.Run(mojom::kDropEffectNone);
1094 return;
1095 }
1096
1097 if (!base::ContainsKey(entered_windows_, window_id)) {
1098 window->drop_target()->OnDragStart(
1099 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>());
1100 }
1101
1102 uint32_t ret =
1103 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask);
1104 callback.Run(ret);
1105 }
1106
1107 void WindowTreeClient::OnDragOver(Id window_id,
1108 uint32_t key_state,
1109 const gfx::Point& position,
1110 uint32_t effect_bitmask,
1111 const OnDragOverCallback& callback) {
1112 Window* window = GetWindowByServerId(window_id);
1113 if (!window || !window->drop_target()) {
1114 callback.Run(mojom::kDropEffectNone);
1115 return;
1116 }
1117
1118 uint32_t ret =
1119 window->drop_target()->OnDragOver(key_state, position, effect_bitmask);
1120 callback.Run(ret);
1121 }
1122
1123 void WindowTreeClient::OnDragLeave(Id window_id) {
1124 Window* window = GetWindowByServerId(window_id);
1125 if (!window || !window->drop_target())
1126 return;
1127
1128 window->drop_target()->OnDragLeave();
1129 }
1130
1131 void WindowTreeClient::OnDragFinish() {
1132 for (Id id : entered_windows_) {
1133 Window* window = GetWindowByServerId(id);
1134 if (!window || !window->drop_target())
1135 continue;
1136 window->drop_target()->OnDragFinish();
1137 }
1138 entered_windows_.clear();
1139 }
1140
1141 void WindowTreeClient::OnCompleteDrop(Id window_id,
1142 uint32_t key_state,
1143 const gfx::Point& position,
1144 uint32_t effect_bitmask,
1145 const OnCompleteDropCallback& callback) {
1146 Window* window = GetWindowByServerId(window_id);
1147 if (!window || !window->drop_target()) {
1148 callback.Run(mojom::kDropEffectNone);
1149 return;
1150 }
1151
1152 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position,
1153 effect_bitmask);
1154 callback.Run(ret);
1155 }
1156
1047 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { 1157 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
1048 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 1158 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
1049 in_flight_map_.erase(change_id); 1159 in_flight_map_.erase(change_id);
1050 if (!change) 1160 if (!change)
1051 return; 1161 return;
1052 1162
1053 if (!success) 1163 if (!success)
1054 change->ChangeFailed(); 1164 change->ChangeFailed();
1055 1165
1056 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1166 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1057 if (next_change) { 1167 if (next_change) {
1058 if (!success) 1168 if (!success)
1059 next_change->SetRevertValueFrom(*change); 1169 next_change->SetRevertValueFrom(*change);
1060 } else if (!success) { 1170 } else if (!success) {
1061 change->Revert(); 1171 change->Revert();
1062 } 1172 }
1063 1173
1064 if (change_id == current_move_loop_change_) { 1174 if (change_id == current_move_loop_change_) {
1065 current_move_loop_change_ = 0; 1175 current_move_loop_change_ = 0;
1066 on_current_move_finished_.Run(success); 1176 on_current_move_finished_.Run(success);
1067 on_current_move_finished_.Reset(); 1177 on_current_move_finished_.Reset();
1068 } 1178 }
1179
1180 if (change_id == current_drag_change_) {
1181 if (change->window() && change->window()->drop_target())
1182 change->window()->drop_target()->OnDragFinish();
1183
1184 current_drag_change_ = 0;
1185 on_current_drag_finished_.Run(success);
1186 on_current_drag_finished_.Reset();
1187 }
1069 } 1188 }
1070 1189
1071 void WindowTreeClient::GetWindowManager( 1190 void WindowTreeClient::GetWindowManager(
1072 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1191 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1073 window_manager_internal_.reset( 1192 window_manager_internal_.reset(
1074 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1193 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1075 std::move(internal))); 1194 std::move(internal)));
1076 } 1195 }
1077 1196
1078 void WindowTreeClient::RequestClose(uint32_t window_id) { 1197 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 Window* window, 1372 Window* window,
1254 const gfx::Vector2d& offset, 1373 const gfx::Vector2d& offset,
1255 const gfx::Insets& hit_area) { 1374 const gfx::Insets& hit_area) {
1256 if (window_manager_internal_client_) { 1375 if (window_manager_internal_client_) {
1257 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1376 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1258 server_id(window), offset.x(), offset.y(), hit_area); 1377 server_id(window), offset.x(), offset.y(), hit_area);
1259 } 1378 }
1260 } 1379 }
1261 1380
1262 } // namespace ui 1381 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698