OLD | NEW |
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 Loading... |
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 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| 659 // we start showing an image representation of the drag under he cursor. |
| 660 |
| 661 if (window->drop_target()) { |
| 662 // To minimize the number of round trips, copy the drag drop data to our |
| 663 // handler here, instead of forcing mus to send this same data back. |
| 664 window->drop_target()->OnDragStart(drag_data); |
| 665 } |
| 666 |
| 667 current_drag_change_ = |
| 668 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window)); |
| 669 tree_->PerformDragDrop( |
| 670 current_drag_change_, window->server_id(), |
| 671 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
| 672 drag_operation); |
| 673 } |
| 674 |
647 void WindowTreeClient::PerformWindowMove( | 675 void WindowTreeClient::PerformWindowMove( |
648 Window* window, | 676 Window* window, |
649 ui::mojom::MoveLoopSource source, | 677 ui::mojom::MoveLoopSource source, |
650 const gfx::Point& cursor_location, | 678 const gfx::Point& cursor_location, |
651 const base::Callback<void(bool)>& callback) { | 679 const base::Callback<void(bool)>& callback) { |
652 DCHECK(on_current_move_finished_.is_null()); | 680 DCHECK(on_current_move_finished_.is_null()); |
653 on_current_move_finished_ = callback; | 681 on_current_move_finished_ = callback; |
654 | 682 |
655 current_move_loop_change_ = ScheduleInFlightChange( | 683 current_move_loop_change_ = |
656 base::MakeUnique<InFlightMoveLoopChange>(window)); | 684 ScheduleInFlightChange(base::MakeUnique<InFlightDragChange>(window)); |
657 // Tell the window manager to take over moving us. | 685 // Tell the window manager to take over moving us. |
658 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), | 686 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), |
659 source, cursor_location); | 687 source, cursor_location); |
660 } | 688 } |
661 | 689 |
662 void WindowTreeClient::CancelWindowMove(Window* window) { | 690 void WindowTreeClient::CancelWindowMove(Window* window) { |
663 tree_->CancelWindowMove(window->server_id()); | 691 tree_->CancelWindowMove(window->server_id()); |
664 } | 692 } |
665 | 693 |
666 Window* WindowTreeClient::NewWindow( | 694 Window* WindowTreeClient::NewWindow( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 // WindowTreeClient, WindowTreeClient implementation: | 732 // WindowTreeClient, WindowTreeClient implementation: |
705 | 733 |
706 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { | 734 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
707 observers_.AddObserver(observer); | 735 observers_.AddObserver(observer); |
708 } | 736 } |
709 | 737 |
710 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { | 738 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
711 observers_.RemoveObserver(observer); | 739 observers_.RemoveObserver(observer); |
712 } | 740 } |
713 | 741 |
| 742 void WindowTreeClient::SetCanAcceptDrags(Id window_id, bool can_accept_drags) { |
| 743 DCHECK(tree_); |
| 744 tree_->SetCanAcceptDrags(window_id, can_accept_drags); |
| 745 } |
| 746 |
714 void WindowTreeClient::SetCanAcceptEvents(Id window_id, | 747 void WindowTreeClient::SetCanAcceptEvents(Id window_id, |
715 bool can_accept_events) { | 748 bool can_accept_events) { |
716 DCHECK(tree_); | 749 DCHECK(tree_); |
717 tree_->SetCanAcceptEvents(window_id, can_accept_events); | 750 tree_->SetCanAcceptEvents(window_id, can_accept_events); |
718 } | 751 } |
719 | 752 |
720 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 753 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
721 mojom::WindowDataPtr root_data, | 754 mojom::WindowDataPtr root_data, |
722 mojom::WindowTreePtr tree, | 755 mojom::WindowTreePtr tree, |
723 int64_t display_id, | 756 int64_t display_id, |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 if (!window) | 1083 if (!window) |
1051 return; | 1084 return; |
1052 | 1085 |
1053 InFlightPredefinedCursorChange new_change(window, cursor); | 1086 InFlightPredefinedCursorChange new_change(window, cursor); |
1054 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1087 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
1055 return; | 1088 return; |
1056 | 1089 |
1057 WindowPrivate(window).LocalSetPredefinedCursor(cursor); | 1090 WindowPrivate(window).LocalSetPredefinedCursor(cursor); |
1058 } | 1091 } |
1059 | 1092 |
| 1093 void WindowTreeClient::OnDragStart( |
| 1094 Id window_id, |
| 1095 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { |
| 1096 Window* window = GetWindowByServerId(window_id); |
| 1097 if (!window) |
| 1098 return; |
| 1099 |
| 1100 WindowDropTarget* target = window->drop_target(); |
| 1101 if (!target) |
| 1102 return; |
| 1103 |
| 1104 target->OnDragStart( |
| 1105 mime_data.To<std::map<std::string, std::vector<uint8_t>>>()); |
| 1106 } |
| 1107 |
| 1108 void WindowTreeClient::OnDragEnter(Id window_id, |
| 1109 uint32_t key_state, |
| 1110 const gfx::Point& position, |
| 1111 uint32_t effect_bitmask, |
| 1112 const OnDragEnterCallback& callback) { |
| 1113 Window* window = GetWindowByServerId(window_id); |
| 1114 if (!window) { |
| 1115 callback.Run(mojom::kDropEffectNone); |
| 1116 return; |
| 1117 } |
| 1118 |
| 1119 WindowDropTarget* target = window->drop_target(); |
| 1120 if (!target) { |
| 1121 callback.Run(mojom::kDropEffectNone); |
| 1122 return; |
| 1123 } |
| 1124 |
| 1125 uint32_t ret = target->OnDragEnter(key_state, position, effect_bitmask); |
| 1126 callback.Run(ret); |
| 1127 } |
| 1128 |
| 1129 void WindowTreeClient::OnDragOver(Id window_id, |
| 1130 uint32_t key_state, |
| 1131 const gfx::Point& position, |
| 1132 uint32_t effect_bitmask, |
| 1133 const OnDragOverCallback& callback) { |
| 1134 Window* window = GetWindowByServerId(window_id); |
| 1135 if (!window) { |
| 1136 callback.Run(mojom::kDropEffectNone); |
| 1137 return; |
| 1138 } |
| 1139 |
| 1140 WindowDropTarget* target = window->drop_target(); |
| 1141 if (!target) { |
| 1142 callback.Run(mojom::kDropEffectNone); |
| 1143 return; |
| 1144 } |
| 1145 |
| 1146 uint32_t ret = target->OnDragOver(key_state, position, effect_bitmask); |
| 1147 callback.Run(ret); |
| 1148 } |
| 1149 |
| 1150 void WindowTreeClient::OnDragLeave(Id window_id) { |
| 1151 Window* window = GetWindowByServerId(window_id); |
| 1152 if (!window) |
| 1153 return; |
| 1154 |
| 1155 WindowDropTarget* target = window->drop_target(); |
| 1156 if (!target) |
| 1157 return; |
| 1158 |
| 1159 target->OnDragLeave(); |
| 1160 } |
| 1161 |
| 1162 void WindowTreeClient::OnDragFinish(Id window_id) { |
| 1163 Window* window = GetWindowByServerId(window_id); |
| 1164 if (!window) |
| 1165 return; |
| 1166 |
| 1167 WindowDropTarget* target = window->drop_target(); |
| 1168 if (!target) |
| 1169 return; |
| 1170 |
| 1171 target->OnDragFinish(); |
| 1172 } |
| 1173 |
| 1174 void WindowTreeClient::OnDragDrop(Id window_id, |
| 1175 uint32_t key_state, |
| 1176 const gfx::Point& position, |
| 1177 uint32_t effect_bitmask, |
| 1178 const OnDragDropCallback& callback) { |
| 1179 Window* window = GetWindowByServerId(window_id); |
| 1180 if (!window) { |
| 1181 callback.Run(mojom::kDropEffectNone); |
| 1182 return; |
| 1183 } |
| 1184 |
| 1185 WindowDropTarget* target = window->drop_target(); |
| 1186 if (!target) { |
| 1187 callback.Run(mojom::kDropEffectNone); |
| 1188 return; |
| 1189 } |
| 1190 |
| 1191 uint32_t ret = target->OnDragDrop(key_state, position, effect_bitmask); |
| 1192 callback.Run(ret); |
| 1193 } |
| 1194 |
1060 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { | 1195 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
1061 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1196 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
1062 in_flight_map_.erase(change_id); | 1197 in_flight_map_.erase(change_id); |
1063 if (!change) | 1198 if (!change) |
1064 return; | 1199 return; |
1065 | 1200 |
1066 if (!success) | 1201 if (!success) |
1067 change->ChangeFailed(); | 1202 change->ChangeFailed(); |
1068 | 1203 |
1069 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); | 1204 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); |
1070 if (next_change) { | 1205 if (next_change) { |
1071 if (!success) | 1206 if (!success) |
1072 next_change->SetRevertValueFrom(*change); | 1207 next_change->SetRevertValueFrom(*change); |
1073 } else if (!success) { | 1208 } else if (!success) { |
1074 change->Revert(); | 1209 change->Revert(); |
1075 } | 1210 } |
1076 | 1211 |
1077 if (change_id == current_move_loop_change_) { | 1212 if (change_id == current_move_loop_change_) { |
1078 current_move_loop_change_ = 0; | 1213 current_move_loop_change_ = 0; |
1079 on_current_move_finished_.Run(success); | 1214 on_current_move_finished_.Run(success); |
1080 on_current_move_finished_.Reset(); | 1215 on_current_move_finished_.Reset(); |
1081 } | 1216 } |
| 1217 |
| 1218 if (change_id == current_drag_change_) { |
| 1219 if (change->window() && change->window()->drop_target()) |
| 1220 change->window()->drop_target()->OnDragFinish(); |
| 1221 |
| 1222 current_drag_change_ = 0; |
| 1223 on_current_drag_finished_.Run(success); |
| 1224 on_current_drag_finished_.Reset(); |
| 1225 } |
1082 } | 1226 } |
1083 | 1227 |
1084 void WindowTreeClient::GetWindowManager( | 1228 void WindowTreeClient::GetWindowManager( |
1085 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1229 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
1086 window_manager_internal_.reset( | 1230 window_manager_internal_.reset( |
1087 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1231 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
1088 std::move(internal))); | 1232 std::move(internal))); |
1089 } | 1233 } |
1090 | 1234 |
1091 void WindowTreeClient::RequestClose(uint32_t window_id) { | 1235 void WindowTreeClient::RequestClose(uint32_t window_id) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1266 Window* window, | 1410 Window* window, |
1267 const gfx::Vector2d& offset, | 1411 const gfx::Vector2d& offset, |
1268 const gfx::Insets& hit_area) { | 1412 const gfx::Insets& hit_area) { |
1269 if (window_manager_internal_client_) { | 1413 if (window_manager_internal_client_) { |
1270 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1414 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1271 server_id(window), offset.x(), offset.y(), hit_area); | 1415 server_id(window), offset.x(), offset.y(), hit_area); |
1272 } | 1416 } |
1273 } | 1417 } |
1274 | 1418 |
1275 } // namespace ui | 1419 } // namespace ui |
OLD | NEW |