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

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: Uploaded for a few 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 has_pointer_watcher_ = true; 638 has_pointer_watcher_ = true;
638 tree_->StartPointerWatcher(want_moves); 639 tree_->StartPointerWatcher(want_moves);
639 } 640 }
640 641
641 void WindowTreeClient::StopPointerWatcher() { 642 void WindowTreeClient::StopPointerWatcher() {
642 DCHECK(has_pointer_watcher_); 643 DCHECK(has_pointer_watcher_);
643 tree_->StopPointerWatcher(); 644 tree_->StopPointerWatcher();
644 has_pointer_watcher_ = false; 645 has_pointer_watcher_ = false;
645 } 646 }
646 647
648 void WindowTreeClient::PerformDragDrop(
649 Window* window,
650 const std::map<std::string, std::vector<uint8_t>>& drag_data,
651 int drag_operation,
652 const gfx::Point& cursor_location,
653 const SkBitmap& bitmap,
654 const base::Callback<void(bool)>& callback) {
655 DCHECK(on_current_drag_finished_.is_null());
656 on_current_drag_finished_ = callback;
657
658 current_drag_change_ =
659 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window));
660 tree_->PerformDragDrop(
661 current_drag_change_, window->server_id(),
662 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data),
663 drag_operation, cursor_location, bitmap);
664 }
665
647 void WindowTreeClient::PerformWindowMove( 666 void WindowTreeClient::PerformWindowMove(
648 Window* window, 667 Window* window,
649 ui::mojom::MoveLoopSource source, 668 ui::mojom::MoveLoopSource source,
650 const gfx::Point& cursor_location, 669 const gfx::Point& cursor_location,
651 const base::Callback<void(bool)>& callback) { 670 const base::Callback<void(bool)>& callback) {
652 DCHECK(on_current_move_finished_.is_null()); 671 DCHECK(on_current_move_finished_.is_null());
653 on_current_move_finished_ = callback; 672 on_current_move_finished_ = callback;
654 673
655 current_move_loop_change_ = ScheduleInFlightChange( 674 current_move_loop_change_ =
656 base::MakeUnique<InFlightMoveLoopChange>(window)); 675 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window));
657 // Tell the window manager to take over moving us. 676 // Tell the window manager to take over moving us.
658 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), 677 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
659 source, cursor_location); 678 source, cursor_location);
660 } 679 }
661 680
662 void WindowTreeClient::CancelWindowMove(Window* window) { 681 void WindowTreeClient::CancelWindowMove(Window* window) {
663 tree_->CancelWindowMove(window->server_id()); 682 tree_->CancelWindowMove(window->server_id());
664 } 683 }
665 684
666 Window* WindowTreeClient::NewWindow( 685 Window* WindowTreeClient::NewWindow(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 // WindowTreeClient, WindowTreeClient implementation: 723 // WindowTreeClient, WindowTreeClient implementation:
705 724
706 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { 725 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) {
707 observers_.AddObserver(observer); 726 observers_.AddObserver(observer);
708 } 727 }
709 728
710 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { 729 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) {
711 observers_.RemoveObserver(observer); 730 observers_.RemoveObserver(observer);
712 } 731 }
713 732
733 void WindowTreeClient::SetCanAcceptDrags(Id window_id, bool can_accept_drags) {
734 DCHECK(tree_);
735 tree_->SetCanAcceptDrags(window_id, can_accept_drags);
736 }
737
714 void WindowTreeClient::SetCanAcceptEvents(Id window_id, 738 void WindowTreeClient::SetCanAcceptEvents(Id window_id,
715 bool can_accept_events) { 739 bool can_accept_events) {
716 DCHECK(tree_); 740 DCHECK(tree_);
717 tree_->SetCanAcceptEvents(window_id, can_accept_events); 741 tree_->SetCanAcceptEvents(window_id, can_accept_events);
718 } 742 }
719 743
720 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, 744 void WindowTreeClient::OnEmbed(ClientSpecificId client_id,
721 mojom::WindowDataPtr root_data, 745 mojom::WindowDataPtr root_data,
722 mojom::WindowTreePtr tree, 746 mojom::WindowTreePtr tree,
723 int64_t display_id, 747 int64_t display_id,
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 if (!window) 1069 if (!window)
1046 return; 1070 return;
1047 1071
1048 InFlightPredefinedCursorChange new_change(window, cursor); 1072 InFlightPredefinedCursorChange new_change(window, cursor);
1049 if (ApplyServerChangeToExistingInFlightChange(new_change)) 1073 if (ApplyServerChangeToExistingInFlightChange(new_change))
1050 return; 1074 return;
1051 1075
1052 WindowPrivate(window).LocalSetPredefinedCursor(cursor); 1076 WindowPrivate(window).LocalSetPredefinedCursor(cursor);
1053 } 1077 }
1054 1078
1079 void WindowTreeClient::OnDragEnter(
1080 Id window_id,
1081 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data,
1082 uint32_t key_state,
1083 const gfx::Point& position,
1084 uint32_t effect_bitmask,
1085 const OnDragEnterCallback& callback) {
1086 Window* window = GetWindowByServerId(window_id);
1087 if (!window) {
1088 callback.Run(mojom::kDropEffectNone);
1089 return;
1090 }
1091
1092 WindowDropTarget* target = window->drop_target();
1093 if (!target) {
1094 callback.Run(mojom::kDropEffectNone);
1095 return;
1096 }
1097
1098 uint32_t ret = target->OnDragEnter(
1099 mime_data.To<std::map<std::string, std::vector<uint8_t>>>(), key_state,
1100 position, effect_bitmask);
1101 callback.Run(ret);
1102 }
1103
1104 void WindowTreeClient::OnDragOver(Id window_id,
1105 uint32_t key_state,
1106 const gfx::Point& position,
1107 uint32_t effect_bitmask,
1108 const OnDragOverCallback& callback) {
1109 Window* window = GetWindowByServerId(window_id);
1110 if (!window) {
1111 callback.Run(mojom::kDropEffectNone);
1112 return;
1113 }
1114
1115 WindowDropTarget* target = window->drop_target();
1116 if (!target) {
1117 callback.Run(mojom::kDropEffectNone);
1118 return;
1119 }
1120
1121 uint32_t ret = target->OnDragOver(key_state, position, effect_bitmask);
1122 callback.Run(ret);
1123 }
1124
1125 void WindowTreeClient::OnDragLeave(Id window_id) {
1126 Window* window = GetWindowByServerId(window_id);
1127 if (!window)
1128 return;
1129
1130 WindowDropTarget* target = window->drop_target();
1131 if (!target)
1132 return;
1133
1134 target->OnDragLeave();
1135 }
1136
1137 void WindowTreeClient::OnDragDrop(Id window_id,
1138 uint32_t key_state,
1139 const gfx::Point& position,
1140 uint32_t effect_bitmask,
1141 const OnDragDropCallback& callback) {
1142 Window* window = GetWindowByServerId(window_id);
1143 if (!window) {
1144 callback.Run(mojom::kDropEffectNone);
1145 return;
1146 }
1147
1148 WindowDropTarget* target = window->drop_target();
1149 if (!target) {
1150 callback.Run(mojom::kDropEffectNone);
1151 return;
1152 }
1153
1154 uint32_t ret = target->OnDragDrop(key_state, position, effect_bitmask);
1155 callback.Run(ret);
1156 }
1157
1055 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { 1158 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
1056 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 1159 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
1057 in_flight_map_.erase(change_id); 1160 in_flight_map_.erase(change_id);
1058 if (!change) 1161 if (!change)
1059 return; 1162 return;
1060 1163
1061 if (!success) 1164 if (!success)
1062 change->ChangeFailed(); 1165 change->ChangeFailed();
1063 1166
1064 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1167 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1065 if (next_change) { 1168 if (next_change) {
1066 if (!success) 1169 if (!success)
1067 next_change->SetRevertValueFrom(*change); 1170 next_change->SetRevertValueFrom(*change);
1068 } else if (!success) { 1171 } else if (!success) {
1069 change->Revert(); 1172 change->Revert();
1070 } 1173 }
1071 1174
1072 if (change_id == current_move_loop_change_) { 1175 if (change_id == current_move_loop_change_) {
1073 current_move_loop_change_ = 0; 1176 current_move_loop_change_ = 0;
1074 on_current_move_finished_.Run(success); 1177 on_current_move_finished_.Run(success);
1075 on_current_move_finished_.Reset(); 1178 on_current_move_finished_.Reset();
1076 } 1179 }
1180
1181 if (change_id == current_drag_change_) {
1182 current_drag_change_ = 0;
1183 on_current_drag_finished_.Run(success);
1184 on_current_drag_finished_.Reset();
1185 }
1077 } 1186 }
1078 1187
1079 void WindowTreeClient::GetWindowManager( 1188 void WindowTreeClient::GetWindowManager(
1080 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1189 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1081 window_manager_internal_.reset( 1190 window_manager_internal_.reset(
1082 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1191 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1083 std::move(internal))); 1192 std::move(internal)));
1084 } 1193 }
1085 1194
1086 void WindowTreeClient::RequestClose(uint32_t window_id) { 1195 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 Window* window, 1370 Window* window,
1262 const gfx::Vector2d& offset, 1371 const gfx::Vector2d& offset,
1263 const gfx::Insets& hit_area) { 1372 const gfx::Insets& hit_area) {
1264 if (window_manager_internal_client_) { 1373 if (window_manager_internal_client_) {
1265 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1374 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1266 server_id(window), offset.x(), offset.y(), hit_area); 1375 server_id(window), offset.x(), offset.y(), hit_area);
1267 } 1376 }
1268 } 1377 }
1269 1378
1270 } // namespace ui 1379 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698