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

Side by Side Diff: components/mus/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: OnWmMoveLoopComplete() -> WmResponse() and use change_id instead of window_id in cancel. 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
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 "components/mus/public/cpp/window_tree_client.h" 5 #include "components/mus/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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 bool WindowTreeClient::OwnsWindow(Window* window) const { 227 bool WindowTreeClient::OwnsWindow(Window* window) const {
228 // Windows created via CreateTopLevelWindow() are not owned by us, but have 228 // Windows created via CreateTopLevelWindow() are not owned by us, but have
229 // our client id. 229 // our client id.
230 return HiWord(server_id(window)) == client_id_ && 230 return HiWord(server_id(window)) == client_id_ &&
231 roots_.count(window) == 0; 231 roots_.count(window) == 0;
232 } 232 }
233 233
234 void WindowTreeClient::SetBounds(Window* window, 234 void WindowTreeClient::SetBounds(Window* window,
235 const gfx::Rect& old_bounds, 235 const gfx::Rect& old_bounds,
236 const gfx::Rect& bounds) { 236 const gfx::Rect& bounds) {
237 DCHECK(tree_); 237 DCHECK(tree_);
238 const uint32_t change_id = ScheduleInFlightChange( 238 const uint32_t change_id = ScheduleInFlightChange(
239 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 239 base::WrapUnique(new InFlightBoundsChange(window, old_bounds)));
240 tree_->SetWindowBounds(change_id, server_id(window), bounds); 240 tree_->SetWindowBounds(change_id, server_id(window), bounds);
241 } 241 }
242 242
243 void WindowTreeClient::SetCapture(Window* window) { 243 void WindowTreeClient::SetCapture(Window* window) {
244 // In order for us to get here we had to have exposed a window, which implies 244 // In order for us to get here we had to have exposed a window, which implies
245 // we got a client. 245 // we got a client.
246 DCHECK(tree_); 246 DCHECK(tree_);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 window_manager_delegate_->OnWmNewDisplay(root, display); 574 window_manager_delegate_->OnWmNewDisplay(root, display);
575 } 575 }
576 576
577 void WindowTreeClient::OnReceivedCursorLocationMemory( 577 void WindowTreeClient::OnReceivedCursorLocationMemory(
578 mojo::ScopedSharedBufferHandle handle) { 578 mojo::ScopedSharedBufferHandle handle) {
579 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); 579 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32));
580 DCHECK(cursor_location_mapping_); 580 DCHECK(cursor_location_mapping_);
581 } 581 }
582 582
583 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id,
584 bool completed) {
585 if (window_manager_internal_client_)
586 window_manager_internal_client_->WmResponse(change_id, completed);
587
588 if (change_id == current_wm_move_loop_change_) {
589 current_wm_move_loop_change_ = 0;
590 current_wm_move_loop_window_id_ = 0;
591 }
592 }
593
583 //////////////////////////////////////////////////////////////////////////////// 594 ////////////////////////////////////////////////////////////////////////////////
584 // WindowTreeClient, WindowTreeClient implementation: 595 // WindowTreeClient, WindowTreeClient implementation:
585 596
586 void WindowTreeClient::SetDeleteOnNoRoots(bool value) { 597 void WindowTreeClient::SetDeleteOnNoRoots(bool value) {
587 delete_on_no_roots_ = value; 598 delete_on_no_roots_ = value;
588 } 599 }
589 600
590 const std::set<Window*>& WindowTreeClient::GetRoots() { 601 const std::set<Window*>& WindowTreeClient::GetRoots() {
591 return roots_; 602 return roots_;
592 } 603 }
(...skipping 24 matching lines...) Expand all
617 if (matcher.is_null()) { 628 if (matcher.is_null()) {
618 has_event_observer_ = false; 629 has_event_observer_ = false;
619 tree_->SetEventObserver(nullptr, 0u); 630 tree_->SetEventObserver(nullptr, 0u);
620 } else { 631 } else {
621 has_event_observer_ = true; 632 has_event_observer_ = true;
622 event_observer_id_++; 633 event_observer_id_++;
623 tree_->SetEventObserver(std::move(matcher), event_observer_id_); 634 tree_->SetEventObserver(std::move(matcher), event_observer_id_);
624 } 635 }
625 } 636 }
626 637
638 void WindowTreeClient::PerformWindowMove(
639 Window* window,
640 ::mus::mojom::MoveLoopSource source,
641 const gfx::Point& cursor_location,
642 const base::Callback<void(bool)>& callback) {
643 DCHECK(on_current_move_finished_.is_null());
644 on_current_move_finished_ = callback;
645
646 current_move_loop_change_ = ScheduleInFlightChange(
647 base::WrapUnique(new InFlightMoveLoopChange(window)));
dcheng 2016/07/06 09:27:53 Nit: I'd suggest writing base::MakeUnique<InFlight
648 // Tell the window manager to take over moving us.
649 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
650 source, cursor_location);
651 }
652
653 void WindowTreeClient::CancelWindowMove(Window* window) {
654 tree_->CancelWindowMove(window->server_id());
655 }
656
627 Window* WindowTreeClient::NewWindow( 657 Window* WindowTreeClient::NewWindow(
628 const Window::SharedProperties* properties) { 658 const Window::SharedProperties* properties) {
629 return NewWindowImpl(NewWindowType::CHILD, properties); 659 return NewWindowImpl(NewWindowType::CHILD, properties);
630 } 660 }
631 661
632 Window* WindowTreeClient::NewTopLevelWindow( 662 Window* WindowTreeClient::NewTopLevelWindow(
633 const Window::SharedProperties* properties) { 663 const Window::SharedProperties* properties) {
634 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); 664 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties);
635 // Assume newly created top level windows are drawn by default, otherwise 665 // Assume newly created top level windows are drawn by default, otherwise
636 // requests to focus will fail. We will get the real value in 666 // requests to focus will fail. We will get the real value in
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 if (!success) 1042 if (!success)
1013 change->ChangeFailed(); 1043 change->ChangeFailed();
1014 1044
1015 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1045 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1016 if (next_change) { 1046 if (next_change) {
1017 if (!success) 1047 if (!success)
1018 next_change->SetRevertValueFrom(*change); 1048 next_change->SetRevertValueFrom(*change);
1019 } else if (!success) { 1049 } else if (!success) {
1020 change->Revert(); 1050 change->Revert();
1021 } 1051 }
1052
1053 if (change_id == current_move_loop_change_) {
1054 current_move_loop_change_ = 0;
1055 on_current_move_finished_.Run(success);
1056 on_current_move_finished_.Reset();
1057 }
1022 } 1058 }
1023 1059
1024 void WindowTreeClient::GetWindowManager( 1060 void WindowTreeClient::GetWindowManager(
1025 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1061 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1026 window_manager_internal_.reset( 1062 window_manager_internal_.reset(
1027 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1063 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1028 std::move(internal))); 1064 std::move(internal)));
1029 } 1065 }
1030 1066
1031 void WindowTreeClient::RequestClose(uint32_t window_id) { 1067 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 30 matching lines...) Expand all
1062 // the client applies the bounds we set below. 1098 // the client applies the bounds we set below.
1063 result = bounds == transit_bounds; 1099 result = bounds == transit_bounds;
1064 window->SetBounds(bounds); 1100 window->SetBounds(bounds);
1065 } 1101 }
1066 } 1102 }
1067 if (window_manager_internal_client_) 1103 if (window_manager_internal_client_)
1068 window_manager_internal_client_->WmResponse(change_id, result); 1104 window_manager_internal_client_->WmResponse(change_id, result);
1069 } 1105 }
1070 1106
1071 void WindowTreeClient::WmSetProperty(uint32_t change_id, 1107 void WindowTreeClient::WmSetProperty(uint32_t change_id,
1072 Id window_id, 1108 Id window_id,
1073 const mojo::String& name, 1109 const mojo::String& name,
1074 mojo::Array<uint8_t> transit_data) { 1110 mojo::Array<uint8_t> transit_data) {
1075 Window* window = GetWindowByServerId(window_id); 1111 Window* window = GetWindowByServerId(window_id);
1076 bool result = false; 1112 bool result = false;
1077 if (window) { 1113 if (window) {
1078 DCHECK(window_manager_delegate_); 1114 DCHECK(window_manager_delegate_);
1079 std::unique_ptr<std::vector<uint8_t>> data; 1115 std::unique_ptr<std::vector<uint8_t>> data;
1080 if (!transit_data.is_null()) { 1116 if (!transit_data.is_null()) {
1081 data.reset( 1117 data.reset(
1082 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); 1118 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>()));
1083 } 1119 }
1084 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); 1120 result = window_manager_delegate_->OnWmSetProperty(window, name, &data);
(...skipping 16 matching lines...) Expand all
1101 Window* window = 1137 Window* window =
1102 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); 1138 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties);
1103 embedded_windows_[requesting_client_id].insert(window); 1139 embedded_windows_[requesting_client_id].insert(window);
1104 if (window_manager_internal_client_) { 1140 if (window_manager_internal_client_) {
1105 window_manager_internal_client_->OnWmCreatedTopLevelWindow( 1141 window_manager_internal_client_->OnWmCreatedTopLevelWindow(
1106 change_id, server_id(window)); 1142 change_id, server_id(window));
1107 } 1143 }
1108 } 1144 }
1109 1145
1110 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, 1146 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id,
1111 bool janky) { 1147 bool janky) {
1112 if (window_manager_delegate_) { 1148 if (window_manager_delegate_) {
1113 auto it = embedded_windows_.find(client_id); 1149 auto it = embedded_windows_.find(client_id);
1114 CHECK(it != embedded_windows_.end()); 1150 CHECK(it != embedded_windows_.end());
1115 window_manager_delegate_->OnWmClientJankinessChanged( 1151 window_manager_delegate_->OnWmClientJankinessChanged(
1116 embedded_windows_[client_id], janky); 1152 embedded_windows_[client_id], janky);
1117 } 1153 }
1118 } 1154 }
1119 1155
1156 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id,
1157 Id window_id,
1158 ::mus::mojom::MoveLoopSource source,
1159 const gfx::Point& cursor_location) {
1160 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) {
1161 OnWmMoveLoopCompleted(change_id, false);
1162 return;
1163 }
1164
1165 current_wm_move_loop_change_ = change_id;
1166 current_wm_move_loop_window_id_ = window_id;
1167 Window* window = GetWindowByServerId(window_id);
1168 if (window) {
1169 window_manager_delegate_->OnWmPerformMoveLoop(
1170 window, source, cursor_location,
1171 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted,
1172 weak_factory_.GetWeakPtr(), change_id));
1173 } else {
1174 OnWmMoveLoopCompleted(change_id, false);
1175 }
1176 }
1177
1178 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) {
1179 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_)
1180 return;
1181
1182 Window* window = GetWindowByServerId(current_wm_move_loop_window_id_);
1183 if (window)
1184 window_manager_delegate_->OnWmCancelMoveLoop(window);
1185 }
1186
1120 void WindowTreeClient::OnAccelerator(uint32_t id, 1187 void WindowTreeClient::OnAccelerator(uint32_t id,
1121 std::unique_ptr<ui::Event> event) { 1188 std::unique_ptr<ui::Event> event) {
1122 DCHECK(event); 1189 DCHECK(event);
1123 window_manager_delegate_->OnAccelerator(id, *event.get()); 1190 window_manager_delegate_->OnAccelerator(id, *event.get());
1124 } 1191 }
1125 1192
1126 void WindowTreeClient::SetFrameDecorationValues( 1193 void WindowTreeClient::SetFrameDecorationValues(
1127 mojom::FrameDecorationValuesPtr values) { 1194 mojom::FrameDecorationValuesPtr values) {
1128 if (window_manager_internal_client_) { 1195 if (window_manager_internal_client_) {
1129 window_manager_internal_client_->WmSetFrameDecorationValues( 1196 window_manager_internal_client_->WmSetFrameDecorationValues(
1130 std::move(values)); 1197 std::move(values));
1131 } 1198 }
1132 } 1199 }
1133 1200
1134 void WindowTreeClient::SetNonClientCursor(Window* window, 1201 void WindowTreeClient::SetNonClientCursor(Window* window,
1135 mus::mojom::Cursor cursor_id) { 1202 mus::mojom::Cursor cursor_id) {
1136 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), 1203 window_manager_internal_client_->WmSetNonClientCursor(server_id(window),
1137 cursor_id); 1204 cursor_id);
1138 } 1205 }
1139 1206
1140 void WindowTreeClient::AddAccelerator( 1207 void WindowTreeClient::AddAccelerator(
1141 uint32_t id, 1208 uint32_t id,
1142 mojom::EventMatcherPtr event_matcher, 1209 mojom::EventMatcherPtr event_matcher,
1143 const base::Callback<void(bool)>& callback) { 1210 const base::Callback<void(bool)>& callback) {
1144 if (window_manager_internal_client_) { 1211 if (window_manager_internal_client_) {
1145 window_manager_internal_client_->AddAccelerator( 1212 window_manager_internal_client_->AddAccelerator(
(...skipping 26 matching lines...) Expand all
1172 Window* window, 1239 Window* window,
1173 const gfx::Vector2d& offset, 1240 const gfx::Vector2d& offset,
1174 const gfx::Insets& hit_area) { 1241 const gfx::Insets& hit_area) {
1175 if (window_manager_internal_client_) { 1242 if (window_manager_internal_client_) {
1176 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1243 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1177 server_id(window), offset.x(), offset.y(), hit_area); 1244 server_id(window), offset.x(), offset.y(), hit_area);
1178 } 1245 }
1179 } 1246 }
1180 1247
1181 } // namespace mus 1248 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698