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 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 Loading... | |
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::OnDragStart( | |
1082 Id window_id, | |
1083 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { | |
1084 Window* window = GetWindowByServerId(window_id); | |
1085 if (!window) | |
1086 return; | |
1087 | |
1088 WindowDropTarget* target = window->drop_target(); | |
1089 if (!target) | |
1090 return; | |
1091 | |
1092 target->OnDragStart( | |
1093 mime_data.To<std::map<std::string, std::vector<uint8_t>>>()); | |
1094 } | |
1095 | |
1096 void WindowTreeClient::OnDragEnter(Id window_id, | |
1097 uint32_t key_state, | |
1098 const gfx::Point& position, | |
1099 uint32_t effect_bitmask, | |
1100 const OnDragEnterCallback& callback) { | |
1101 Window* window = GetWindowByServerId(window_id); | |
1102 if (!window) { | |
1103 callback.Run(mojom::kDropEffectNone); | |
1104 return; | |
1105 } | |
1106 | |
1107 WindowDropTarget* target = window->drop_target(); | |
1108 if (!target) { | |
sky
2016/09/08 23:37:20
combine with if on 1102?
| |
1109 callback.Run(mojom::kDropEffectNone); | |
1110 return; | |
1111 } | |
1112 | |
1113 uint32_t ret = target->OnDragEnter(key_state, position, effect_bitmask); | |
1114 callback.Run(ret); | |
1115 } | |
1116 | |
1117 void WindowTreeClient::OnDragOver(Id window_id, | |
1118 uint32_t key_state, | |
1119 const gfx::Point& position, | |
1120 uint32_t effect_bitmask, | |
1121 const OnDragOverCallback& callback) { | |
1122 Window* window = GetWindowByServerId(window_id); | |
1123 if (!window) { | |
1124 callback.Run(mojom::kDropEffectNone); | |
1125 return; | |
1126 } | |
1127 | |
1128 WindowDropTarget* target = window->drop_target(); | |
1129 if (!target) { | |
sky
2016/09/08 23:37:20
Combine with if on 1123?
| |
1130 callback.Run(mojom::kDropEffectNone); | |
1131 return; | |
1132 } | |
1133 | |
1134 uint32_t ret = target->OnDragOver(key_state, position, effect_bitmask); | |
1135 callback.Run(ret); | |
1136 } | |
1137 | |
1138 void WindowTreeClient::OnDragLeave(Id window_id) { | |
1139 Window* window = GetWindowByServerId(window_id); | |
1140 if (!window) | |
1141 return; | |
1142 | |
1143 WindowDropTarget* target = window->drop_target(); | |
1144 if (!target) | |
1145 return; | |
1146 | |
1147 target->OnDragLeave(); | |
1148 } | |
1149 | |
1150 void WindowTreeClient::OnDragFinish(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->OnDragFinish(); | |
1160 } | |
1161 | |
1162 void WindowTreeClient::OnDragDrop(Id window_id, | |
1163 uint32_t key_state, | |
1164 const gfx::Point& position, | |
1165 uint32_t effect_bitmask, | |
1166 const OnDragDropCallback& callback) { | |
1167 Window* window = GetWindowByServerId(window_id); | |
1168 if (!window) { | |
1169 callback.Run(mojom::kDropEffectNone); | |
1170 return; | |
1171 } | |
1172 | |
1173 WindowDropTarget* target = window->drop_target(); | |
1174 if (!target) { | |
1175 callback.Run(mojom::kDropEffectNone); | |
1176 return; | |
1177 } | |
1178 | |
1179 uint32_t ret = target->OnDragDrop(key_state, position, effect_bitmask); | |
1180 callback.Run(ret); | |
1181 } | |
1182 | |
1047 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { | 1183 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
1048 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1184 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
1049 in_flight_map_.erase(change_id); | 1185 in_flight_map_.erase(change_id); |
1050 if (!change) | 1186 if (!change) |
1051 return; | 1187 return; |
1052 | 1188 |
1053 if (!success) | 1189 if (!success) |
1054 change->ChangeFailed(); | 1190 change->ChangeFailed(); |
1055 | 1191 |
1056 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); | 1192 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); |
1057 if (next_change) { | 1193 if (next_change) { |
1058 if (!success) | 1194 if (!success) |
1059 next_change->SetRevertValueFrom(*change); | 1195 next_change->SetRevertValueFrom(*change); |
1060 } else if (!success) { | 1196 } else if (!success) { |
1061 change->Revert(); | 1197 change->Revert(); |
1062 } | 1198 } |
1063 | 1199 |
1064 if (change_id == current_move_loop_change_) { | 1200 if (change_id == current_move_loop_change_) { |
1065 current_move_loop_change_ = 0; | 1201 current_move_loop_change_ = 0; |
1066 on_current_move_finished_.Run(success); | 1202 on_current_move_finished_.Run(success); |
1067 on_current_move_finished_.Reset(); | 1203 on_current_move_finished_.Reset(); |
1068 } | 1204 } |
1205 | |
1206 if (change_id == current_drag_change_) { | |
1207 if (change->window() && change->window()->drop_target()) | |
1208 change->window()->drop_target()->OnDragFinish(); | |
1209 | |
1210 current_drag_change_ = 0; | |
1211 on_current_drag_finished_.Run(success); | |
1212 on_current_drag_finished_.Reset(); | |
1213 } | |
1069 } | 1214 } |
1070 | 1215 |
1071 void WindowTreeClient::GetWindowManager( | 1216 void WindowTreeClient::GetWindowManager( |
1072 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1217 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
1073 window_manager_internal_.reset( | 1218 window_manager_internal_.reset( |
1074 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1219 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
1075 std::move(internal))); | 1220 std::move(internal))); |
1076 } | 1221 } |
1077 | 1222 |
1078 void WindowTreeClient::RequestClose(uint32_t window_id) { | 1223 void WindowTreeClient::RequestClose(uint32_t window_id) { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 Window* window, | 1398 Window* window, |
1254 const gfx::Vector2d& offset, | 1399 const gfx::Vector2d& offset, |
1255 const gfx::Insets& hit_area) { | 1400 const gfx::Insets& hit_area) { |
1256 if (window_manager_internal_client_) { | 1401 if (window_manager_internal_client_) { |
1257 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1402 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1258 server_id(window), offset.x(), offset.y(), hit_area); | 1403 server_id(window), offset.x(), offset.y(), hit_area); |
1259 } | 1404 } |
1260 } | 1405 } |
1261 | 1406 |
1262 } // namespace ui | 1407 } // namespace ui |
OLD | NEW |