| 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> |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 root = window; | 80 root = window; |
| 81 last_window = window; | 81 last_window = window; |
| 82 } | 82 } |
| 83 return root; | 83 return root; |
| 84 } | 84 } |
| 85 | 85 |
| 86 struct WindowTreeClient::CurrentDragState { | 86 struct WindowTreeClient::CurrentDragState { |
| 87 // The current change id of the current drag an drop ipc. | 87 // The current change id of the current drag an drop ipc. |
| 88 uint32_t change_id; | 88 uint32_t change_id; |
| 89 | 89 |
| 90 // The effect to return when we send our finish signal. |
| 91 uint32_t completed_action; |
| 92 |
| 90 // Callback executed when a drag initiated by PerformDragDrop() is completed. | 93 // Callback executed when a drag initiated by PerformDragDrop() is completed. |
| 91 base::Callback<void(bool)> on_finished; | 94 base::Callback<void(bool, uint32_t)> on_finished; |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 WindowTreeClient::WindowTreeClient( | 97 WindowTreeClient::WindowTreeClient( |
| 95 WindowTreeClientDelegate* delegate, | 98 WindowTreeClientDelegate* delegate, |
| 96 WindowManagerDelegate* window_manager_delegate, | 99 WindowManagerDelegate* window_manager_delegate, |
| 97 mojo::InterfaceRequest<mojom::WindowTreeClient> request) | 100 mojo::InterfaceRequest<mojom::WindowTreeClient> request) |
| 98 : client_id_(0), | 101 : client_id_(0), |
| 99 next_window_id_(1), | 102 next_window_id_(1), |
| 100 next_change_id_(1), | 103 next_change_id_(1), |
| 101 delegate_(delegate), | 104 delegate_(delegate), |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 has_pointer_watcher_ = false; | 643 has_pointer_watcher_ = false; |
| 641 } | 644 } |
| 642 | 645 |
| 643 void WindowTreeClient::PerformDragDrop( | 646 void WindowTreeClient::PerformDragDrop( |
| 644 Window* window, | 647 Window* window, |
| 645 int drag_pointer, | 648 int drag_pointer, |
| 646 const std::map<std::string, std::vector<uint8_t>>& drag_data, | 649 const std::map<std::string, std::vector<uint8_t>>& drag_data, |
| 647 int drag_operation, | 650 int drag_operation, |
| 648 const gfx::Point& cursor_location, | 651 const gfx::Point& cursor_location, |
| 649 const SkBitmap& bitmap, | 652 const SkBitmap& bitmap, |
| 650 const base::Callback<void(bool)>& callback) { | 653 const base::Callback<void(bool, uint32_t)>& callback) { |
| 651 DCHECK(!current_drag_state_); | 654 DCHECK(!current_drag_state_); |
| 652 | 655 |
| 653 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when | 656 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| 654 // we start showing an image representation of the drag under he cursor. | 657 // we start showing an image representation of the drag under he cursor. |
| 655 | 658 |
| 656 if (window->drop_target()) { | 659 if (window->drop_target()) { |
| 657 // To minimize the number of round trips, copy the drag drop data to our | 660 // 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. | 661 // handler here, instead of forcing mus to send this same data back. |
| 659 OnDragDropStart( | 662 OnDragDropStart( |
| 660 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); | 663 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); |
| 661 } | 664 } |
| 662 | 665 |
| 663 uint32_t current_drag_change = ScheduleInFlightChange( | 666 uint32_t current_drag_change = ScheduleInFlightChange( |
| 664 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 667 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
| 665 current_drag_state_.reset( | 668 current_drag_state_.reset(new CurrentDragState{ |
| 666 new CurrentDragState{current_drag_change, callback}); | 669 current_drag_change, ui::mojom::kDropEffectNone, callback}); |
| 667 | 670 |
| 668 tree_->PerformDragDrop( | 671 tree_->PerformDragDrop( |
| 669 current_drag_change, window->server_id(), drag_pointer, | 672 current_drag_change, window->server_id(), drag_pointer, |
| 670 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), | 673 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
| 671 drag_operation); | 674 drag_operation); |
| 672 } | 675 } |
| 673 | 676 |
| 674 void WindowTreeClient::PerformWindowMove( | 677 void WindowTreeClient::PerformWindowMove( |
| 675 Window* window, | 678 Window* window, |
| 676 ui::mojom::MoveLoopSource source, | 679 ui::mojom::MoveLoopSource source, |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 if (!window || !window->drop_target()) { | 1162 if (!window || !window->drop_target()) { |
| 1160 callback.Run(mojom::kDropEffectNone); | 1163 callback.Run(mojom::kDropEffectNone); |
| 1161 return; | 1164 return; |
| 1162 } | 1165 } |
| 1163 | 1166 |
| 1164 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, | 1167 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, |
| 1165 effect_bitmask); | 1168 effect_bitmask); |
| 1166 callback.Run(ret); | 1169 callback.Run(ret); |
| 1167 } | 1170 } |
| 1168 | 1171 |
| 1172 void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, |
| 1173 bool success, |
| 1174 uint32_t action_taken) { |
| 1175 if (current_drag_state_ && change_id == current_drag_state_->change_id) { |
| 1176 current_drag_state_->completed_action = action_taken; |
| 1177 OnChangeCompleted(change_id, success); |
| 1178 } |
| 1179 } |
| 1180 |
| 1169 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { | 1181 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| 1170 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1182 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 1171 in_flight_map_.erase(change_id); | 1183 in_flight_map_.erase(change_id); |
| 1172 if (!change) | 1184 if (!change) |
| 1173 return; | 1185 return; |
| 1174 | 1186 |
| 1175 if (!success) | 1187 if (!success) |
| 1176 change->ChangeFailed(); | 1188 change->ChangeFailed(); |
| 1177 | 1189 |
| 1178 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); | 1190 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); |
| 1179 if (next_change) { | 1191 if (next_change) { |
| 1180 if (!success) | 1192 if (!success) |
| 1181 next_change->SetRevertValueFrom(*change); | 1193 next_change->SetRevertValueFrom(*change); |
| 1182 } else if (!success) { | 1194 } else if (!success) { |
| 1183 change->Revert(); | 1195 change->Revert(); |
| 1184 } | 1196 } |
| 1185 | 1197 |
| 1186 if (change_id == current_move_loop_change_) { | 1198 if (change_id == current_move_loop_change_) { |
| 1187 current_move_loop_change_ = 0; | 1199 current_move_loop_change_ = 0; |
| 1188 on_current_move_finished_.Run(success); | 1200 on_current_move_finished_.Run(success); |
| 1189 on_current_move_finished_.Reset(); | 1201 on_current_move_finished_.Reset(); |
| 1190 } | 1202 } |
| 1191 | 1203 |
| 1192 if (current_drag_state_ && change_id == current_drag_state_->change_id) { | 1204 if (current_drag_state_ && change_id == current_drag_state_->change_id) { |
| 1193 OnDragDropDone(); | 1205 OnDragDropDone(); |
| 1194 | 1206 |
| 1195 current_drag_state_->on_finished.Run(success); | 1207 current_drag_state_->on_finished.Run(success, |
| 1208 current_drag_state_->completed_action); |
| 1196 current_drag_state_.reset(); | 1209 current_drag_state_.reset(); |
| 1197 } | 1210 } |
| 1198 } | 1211 } |
| 1199 | 1212 |
| 1200 void WindowTreeClient::GetWindowManager( | 1213 void WindowTreeClient::GetWindowManager( |
| 1201 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1214 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| 1202 window_manager_internal_.reset( | 1215 window_manager_internal_.reset( |
| 1203 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1216 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
| 1204 std::move(internal))); | 1217 std::move(internal))); |
| 1205 } | 1218 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1393 Window* window, | 1406 Window* window, |
| 1394 const gfx::Vector2d& offset, | 1407 const gfx::Vector2d& offset, |
| 1395 const gfx::Insets& hit_area) { | 1408 const gfx::Insets& hit_area) { |
| 1396 if (window_manager_internal_client_) { | 1409 if (window_manager_internal_client_) { |
| 1397 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1410 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1398 server_id(window), offset.x(), offset.y(), hit_area); | 1411 server_id(window), offset.x(), offset.y(), hit_area); |
| 1399 } | 1412 } |
| 1400 } | 1413 } |
| 1401 | 1414 |
| 1402 } // namespace ui | 1415 } // namespace ui |
| OLD | NEW |