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

Side by Side Diff: services/ui/public/cpp/lib/window_tree_client.cc

Issue 2060513002: Tab dragging as implemented as a mus API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dcheng nits Created 4 years, 5 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
« no previous file with comments | « services/ui/public/cpp/lib/window.cc ('k') | services/ui/public/cpp/tests/test_window_tree.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 bool WindowTreeClient::OwnsWindow(Window* window) const { 230 bool WindowTreeClient::OwnsWindow(Window* window) const {
231 // Windows created via CreateTopLevelWindow() are not owned by us, but have 231 // Windows created via CreateTopLevelWindow() are not owned by us, but have
232 // our client id. 232 // our client id.
233 return HiWord(server_id(window)) == client_id_ && 233 return HiWord(server_id(window)) == client_id_ &&
234 roots_.count(window) == 0; 234 roots_.count(window) == 0;
235 } 235 }
236 236
237 void WindowTreeClient::SetBounds(Window* window, 237 void WindowTreeClient::SetBounds(Window* window,
238 const gfx::Rect& old_bounds, 238 const gfx::Rect& old_bounds,
239 const gfx::Rect& bounds) { 239 const gfx::Rect& bounds) {
240 DCHECK(tree_); 240 DCHECK(tree_);
241 const uint32_t change_id = ScheduleInFlightChange( 241 const uint32_t change_id = ScheduleInFlightChange(
242 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 242 base::WrapUnique(new InFlightBoundsChange(window, old_bounds)));
243 tree_->SetWindowBounds(change_id, server_id(window), bounds); 243 tree_->SetWindowBounds(change_id, server_id(window), bounds);
244 } 244 }
245 245
246 void WindowTreeClient::SetCapture(Window* window) { 246 void WindowTreeClient::SetCapture(Window* window) {
247 // In order for us to get here we had to have exposed a window, which implies 247 // In order for us to get here we had to have exposed a window, which implies
248 // we got a client. 248 // we got a client.
249 DCHECK(tree_); 249 DCHECK(tree_);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 576
577 window_manager_delegate_->OnWmNewDisplay(root, display); 577 window_manager_delegate_->OnWmNewDisplay(root, display);
578 } 578 }
579 579
580 void WindowTreeClient::OnReceivedCursorLocationMemory( 580 void WindowTreeClient::OnReceivedCursorLocationMemory(
581 mojo::ScopedSharedBufferHandle handle) { 581 mojo::ScopedSharedBufferHandle handle) {
582 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); 582 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32));
583 DCHECK(cursor_location_mapping_); 583 DCHECK(cursor_location_mapping_);
584 } 584 }
585 585
586 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id,
587 bool completed) {
588 if (window_manager_internal_client_)
589 window_manager_internal_client_->WmResponse(change_id, completed);
590
591 if (change_id == current_wm_move_loop_change_) {
592 current_wm_move_loop_change_ = 0;
593 current_wm_move_loop_window_id_ = 0;
594 }
595 }
596
586 //////////////////////////////////////////////////////////////////////////////// 597 ////////////////////////////////////////////////////////////////////////////////
587 // WindowTreeClient, WindowTreeClient implementation: 598 // WindowTreeClient, WindowTreeClient implementation:
588 599
589 void WindowTreeClient::SetDeleteOnNoRoots(bool value) { 600 void WindowTreeClient::SetDeleteOnNoRoots(bool value) {
590 delete_on_no_roots_ = value; 601 delete_on_no_roots_ = value;
591 } 602 }
592 603
593 const std::set<Window*>& WindowTreeClient::GetRoots() { 604 const std::set<Window*>& WindowTreeClient::GetRoots() {
594 return roots_; 605 return roots_;
595 } 606 }
(...skipping 24 matching lines...) Expand all
620 if (matcher.is_null()) { 631 if (matcher.is_null()) {
621 has_event_observer_ = false; 632 has_event_observer_ = false;
622 tree_->SetEventObserver(nullptr, 0u); 633 tree_->SetEventObserver(nullptr, 0u);
623 } else { 634 } else {
624 has_event_observer_ = true; 635 has_event_observer_ = true;
625 event_observer_id_++; 636 event_observer_id_++;
626 tree_->SetEventObserver(std::move(matcher), event_observer_id_); 637 tree_->SetEventObserver(std::move(matcher), event_observer_id_);
627 } 638 }
628 } 639 }
629 640
641 void WindowTreeClient::PerformWindowMove(
642 Window* window,
643 ui::mojom::MoveLoopSource source,
644 const gfx::Point& cursor_location,
645 const base::Callback<void(bool)>& callback) {
646 DCHECK(on_current_move_finished_.is_null());
647 on_current_move_finished_ = callback;
648
649 current_move_loop_change_ = ScheduleInFlightChange(
650 base::MakeUnique<InFlightMoveLoopChange>(window));
651 // Tell the window manager to take over moving us.
652 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
653 source, cursor_location);
654 }
655
656 void WindowTreeClient::CancelWindowMove(Window* window) {
657 tree_->CancelWindowMove(window->server_id());
658 }
659
630 Window* WindowTreeClient::NewWindow( 660 Window* WindowTreeClient::NewWindow(
631 const Window::SharedProperties* properties) { 661 const Window::SharedProperties* properties) {
632 return NewWindowImpl(NewWindowType::CHILD, properties); 662 return NewWindowImpl(NewWindowType::CHILD, properties);
633 } 663 }
634 664
635 Window* WindowTreeClient::NewTopLevelWindow( 665 Window* WindowTreeClient::NewTopLevelWindow(
636 const Window::SharedProperties* properties) { 666 const Window::SharedProperties* properties) {
637 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); 667 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties);
638 // Assume newly created top level windows are drawn by default, otherwise 668 // Assume newly created top level windows are drawn by default, otherwise
639 // requests to focus will fail. We will get the real value in 669 // requests to focus will fail. We will get the real value in
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 if (!success) 1045 if (!success)
1016 change->ChangeFailed(); 1046 change->ChangeFailed();
1017 1047
1018 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1048 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1019 if (next_change) { 1049 if (next_change) {
1020 if (!success) 1050 if (!success)
1021 next_change->SetRevertValueFrom(*change); 1051 next_change->SetRevertValueFrom(*change);
1022 } else if (!success) { 1052 } else if (!success) {
1023 change->Revert(); 1053 change->Revert();
1024 } 1054 }
1055
1056 if (change_id == current_move_loop_change_) {
1057 current_move_loop_change_ = 0;
1058 on_current_move_finished_.Run(success);
1059 on_current_move_finished_.Reset();
1060 }
1025 } 1061 }
1026 1062
1027 void WindowTreeClient::GetWindowManager( 1063 void WindowTreeClient::GetWindowManager(
1028 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1064 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1029 window_manager_internal_.reset( 1065 window_manager_internal_.reset(
1030 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1066 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1031 std::move(internal))); 1067 std::move(internal)));
1032 } 1068 }
1033 1069
1034 void WindowTreeClient::RequestClose(uint32_t window_id) { 1070 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 30 matching lines...) Expand all
1065 // the client applies the bounds we set below. 1101 // the client applies the bounds we set below.
1066 result = bounds == transit_bounds; 1102 result = bounds == transit_bounds;
1067 window->SetBounds(bounds); 1103 window->SetBounds(bounds);
1068 } 1104 }
1069 } 1105 }
1070 if (window_manager_internal_client_) 1106 if (window_manager_internal_client_)
1071 window_manager_internal_client_->WmResponse(change_id, result); 1107 window_manager_internal_client_->WmResponse(change_id, result);
1072 } 1108 }
1073 1109
1074 void WindowTreeClient::WmSetProperty(uint32_t change_id, 1110 void WindowTreeClient::WmSetProperty(uint32_t change_id,
1075 Id window_id, 1111 Id window_id,
1076 const mojo::String& name, 1112 const mojo::String& name,
1077 mojo::Array<uint8_t> transit_data) { 1113 mojo::Array<uint8_t> transit_data) {
1078 Window* window = GetWindowByServerId(window_id); 1114 Window* window = GetWindowByServerId(window_id);
1079 bool result = false; 1115 bool result = false;
1080 if (window) { 1116 if (window) {
1081 DCHECK(window_manager_delegate_); 1117 DCHECK(window_manager_delegate_);
1082 std::unique_ptr<std::vector<uint8_t>> data; 1118 std::unique_ptr<std::vector<uint8_t>> data;
1083 if (!transit_data.is_null()) { 1119 if (!transit_data.is_null()) {
1084 data.reset( 1120 data.reset(
1085 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); 1121 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>()));
1086 } 1122 }
1087 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); 1123 result = window_manager_delegate_->OnWmSetProperty(window, name, &data);
(...skipping 16 matching lines...) Expand all
1104 Window* window = 1140 Window* window =
1105 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); 1141 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties);
1106 embedded_windows_[requesting_client_id].insert(window); 1142 embedded_windows_[requesting_client_id].insert(window);
1107 if (window_manager_internal_client_) { 1143 if (window_manager_internal_client_) {
1108 window_manager_internal_client_->OnWmCreatedTopLevelWindow( 1144 window_manager_internal_client_->OnWmCreatedTopLevelWindow(
1109 change_id, server_id(window)); 1145 change_id, server_id(window));
1110 } 1146 }
1111 } 1147 }
1112 1148
1113 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, 1149 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id,
1114 bool janky) { 1150 bool janky) {
1115 if (window_manager_delegate_) { 1151 if (window_manager_delegate_) {
1116 auto it = embedded_windows_.find(client_id); 1152 auto it = embedded_windows_.find(client_id);
1117 CHECK(it != embedded_windows_.end()); 1153 CHECK(it != embedded_windows_.end());
1118 window_manager_delegate_->OnWmClientJankinessChanged( 1154 window_manager_delegate_->OnWmClientJankinessChanged(
1119 embedded_windows_[client_id], janky); 1155 embedded_windows_[client_id], janky);
1120 } 1156 }
1121 } 1157 }
1122 1158
1159 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id,
1160 Id window_id,
1161 mojom::MoveLoopSource source,
1162 const gfx::Point& cursor_location) {
1163 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) {
1164 OnWmMoveLoopCompleted(change_id, false);
1165 return;
1166 }
1167
1168 current_wm_move_loop_change_ = change_id;
1169 current_wm_move_loop_window_id_ = window_id;
1170 Window* window = GetWindowByServerId(window_id);
1171 if (window) {
1172 window_manager_delegate_->OnWmPerformMoveLoop(
1173 window, source, cursor_location,
1174 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted,
1175 weak_factory_.GetWeakPtr(), change_id));
1176 } else {
1177 OnWmMoveLoopCompleted(change_id, false);
1178 }
1179 }
1180
1181 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) {
1182 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_)
1183 return;
1184
1185 Window* window = GetWindowByServerId(current_wm_move_loop_window_id_);
1186 if (window)
1187 window_manager_delegate_->OnWmCancelMoveLoop(window);
1188 }
1189
1123 void WindowTreeClient::OnAccelerator(uint32_t id, 1190 void WindowTreeClient::OnAccelerator(uint32_t id,
1124 std::unique_ptr<ui::Event> event) { 1191 std::unique_ptr<ui::Event> event) {
1125 DCHECK(event); 1192 DCHECK(event);
1126 window_manager_delegate_->OnAccelerator(id, *event.get()); 1193 window_manager_delegate_->OnAccelerator(id, *event.get());
1127 } 1194 }
1128 1195
1129 void WindowTreeClient::SetFrameDecorationValues( 1196 void WindowTreeClient::SetFrameDecorationValues(
1130 mojom::FrameDecorationValuesPtr values) { 1197 mojom::FrameDecorationValuesPtr values) {
1131 if (window_manager_internal_client_) { 1198 if (window_manager_internal_client_) {
1132 window_manager_internal_client_->WmSetFrameDecorationValues( 1199 window_manager_internal_client_->WmSetFrameDecorationValues(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 Window* window, 1242 Window* window,
1176 const gfx::Vector2d& offset, 1243 const gfx::Vector2d& offset,
1177 const gfx::Insets& hit_area) { 1244 const gfx::Insets& hit_area) {
1178 if (window_manager_internal_client_) { 1245 if (window_manager_internal_client_) {
1179 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1246 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1180 server_id(window), offset.x(), offset.y(), hit_area); 1247 server_id(window), offset.x(), offset.y(), hit_area);
1181 } 1248 }
1182 } 1249 }
1183 1250
1184 } // namespace ui 1251 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/public/cpp/lib/window.cc ('k') | services/ui/public/cpp/tests/test_window_tree.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698