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

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: Thread move loop source through api. 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_->OnWmMoveLoopCompleted(change_id,
587 completed);
588 }
589 }
590
583 //////////////////////////////////////////////////////////////////////////////// 591 ////////////////////////////////////////////////////////////////////////////////
584 // WindowTreeClient, WindowTreeClient implementation: 592 // WindowTreeClient, WindowTreeClient implementation:
585 593
586 void WindowTreeClient::SetDeleteOnNoRoots(bool value) { 594 void WindowTreeClient::SetDeleteOnNoRoots(bool value) {
587 delete_on_no_roots_ = value; 595 delete_on_no_roots_ = value;
588 } 596 }
589 597
590 const std::set<Window*>& WindowTreeClient::GetRoots() { 598 const std::set<Window*>& WindowTreeClient::GetRoots() {
591 return roots_; 599 return roots_;
592 } 600 }
(...skipping 24 matching lines...) Expand all
617 if (matcher.is_null()) { 625 if (matcher.is_null()) {
618 has_event_observer_ = false; 626 has_event_observer_ = false;
619 tree_->SetEventObserver(nullptr, 0u); 627 tree_->SetEventObserver(nullptr, 0u);
620 } else { 628 } else {
621 has_event_observer_ = true; 629 has_event_observer_ = true;
622 event_observer_id_++; 630 event_observer_id_++;
623 tree_->SetEventObserver(std::move(matcher), event_observer_id_); 631 tree_->SetEventObserver(std::move(matcher), event_observer_id_);
624 } 632 }
625 } 633 }
626 634
635 void WindowTreeClient::PerformWindowMove(
636 Window* window,
637 ::mus::mojom::MoveLoopSource source,
638 const gfx::Point& cursor_location,
639 const base::Callback<void(bool)>& callback) {
640 DCHECK(on_current_move_finished_.is_null());
641 on_current_move_finished_ = callback;
642
643 current_move_loop_change_ = ScheduleInFlightChange(
644 base::WrapUnique(new InFlightMoveLoopChange(window)));
645 // Tell the window manager to take over moving us.
646 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(),
647 source, cursor_location);
648 }
649
650 void WindowTreeClient::CancelWindowMove(Window* window) {
651 tree_->CancelWindowMove(window->server_id());
652 }
653
627 Window* WindowTreeClient::NewWindow( 654 Window* WindowTreeClient::NewWindow(
628 const Window::SharedProperties* properties) { 655 const Window::SharedProperties* properties) {
629 return NewWindowImpl(NewWindowType::CHILD, properties); 656 return NewWindowImpl(NewWindowType::CHILD, properties);
630 } 657 }
631 658
632 Window* WindowTreeClient::NewTopLevelWindow( 659 Window* WindowTreeClient::NewTopLevelWindow(
633 const Window::SharedProperties* properties) { 660 const Window::SharedProperties* properties) {
634 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); 661 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties);
635 // Assume newly created top level windows are drawn by default, otherwise 662 // Assume newly created top level windows are drawn by default, otherwise
636 // requests to focus will fail. We will get the real value in 663 // 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) 1039 if (!success)
1013 change->ChangeFailed(); 1040 change->ChangeFailed();
1014 1041
1015 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 1042 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
1016 if (next_change) { 1043 if (next_change) {
1017 if (!success) 1044 if (!success)
1018 next_change->SetRevertValueFrom(*change); 1045 next_change->SetRevertValueFrom(*change);
1019 } else if (!success) { 1046 } else if (!success) {
1020 change->Revert(); 1047 change->Revert();
1021 } 1048 }
1049
1050 if (change_id == current_move_loop_change_) {
1051 on_current_move_finished_.Run(success);
1052 on_current_move_finished_.Reset();
1053 current_move_loop_change_ = 0;
sky 2016/06/29 00:04:08 Please move current_move_loop_change_ = 0 before t
1054 }
1022 } 1055 }
1023 1056
1024 void WindowTreeClient::GetWindowManager( 1057 void WindowTreeClient::GetWindowManager(
1025 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 1058 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
1026 window_manager_internal_.reset( 1059 window_manager_internal_.reset(
1027 new mojo::AssociatedBinding<mojom::WindowManager>(this, 1060 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1028 std::move(internal))); 1061 std::move(internal)));
1029 } 1062 }
1030 1063
1031 void WindowTreeClient::RequestClose(uint32_t window_id) { 1064 void WindowTreeClient::RequestClose(uint32_t window_id) {
(...skipping 30 matching lines...) Expand all
1062 // the client applies the bounds we set below. 1095 // the client applies the bounds we set below.
1063 result = bounds == transit_bounds; 1096 result = bounds == transit_bounds;
1064 window->SetBounds(bounds); 1097 window->SetBounds(bounds);
1065 } 1098 }
1066 } 1099 }
1067 if (window_manager_internal_client_) 1100 if (window_manager_internal_client_)
1068 window_manager_internal_client_->WmResponse(change_id, result); 1101 window_manager_internal_client_->WmResponse(change_id, result);
1069 } 1102 }
1070 1103
1071 void WindowTreeClient::WmSetProperty(uint32_t change_id, 1104 void WindowTreeClient::WmSetProperty(uint32_t change_id,
1072 Id window_id, 1105 Id window_id,
1073 const mojo::String& name, 1106 const mojo::String& name,
1074 mojo::Array<uint8_t> transit_data) { 1107 mojo::Array<uint8_t> transit_data) {
1075 Window* window = GetWindowByServerId(window_id); 1108 Window* window = GetWindowByServerId(window_id);
1076 bool result = false; 1109 bool result = false;
1077 if (window) { 1110 if (window) {
1078 DCHECK(window_manager_delegate_); 1111 DCHECK(window_manager_delegate_);
1079 std::unique_ptr<std::vector<uint8_t>> data; 1112 std::unique_ptr<std::vector<uint8_t>> data;
1080 if (!transit_data.is_null()) { 1113 if (!transit_data.is_null()) {
1081 data.reset( 1114 data.reset(
1082 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); 1115 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>()));
1083 } 1116 }
1084 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); 1117 result = window_manager_delegate_->OnWmSetProperty(window, name, &data);
(...skipping 16 matching lines...) Expand all
1101 Window* window = 1134 Window* window =
1102 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); 1135 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties);
1103 embedded_windows_[requesting_client_id].insert(window); 1136 embedded_windows_[requesting_client_id].insert(window);
1104 if (window_manager_internal_client_) { 1137 if (window_manager_internal_client_) {
1105 window_manager_internal_client_->OnWmCreatedTopLevelWindow( 1138 window_manager_internal_client_->OnWmCreatedTopLevelWindow(
1106 change_id, server_id(window)); 1139 change_id, server_id(window));
1107 } 1140 }
1108 } 1141 }
1109 1142
1110 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, 1143 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id,
1111 bool janky) { 1144 bool janky) {
1112 if (window_manager_delegate_) { 1145 if (window_manager_delegate_) {
1113 auto it = embedded_windows_.find(client_id); 1146 auto it = embedded_windows_.find(client_id);
1114 CHECK(it != embedded_windows_.end()); 1147 CHECK(it != embedded_windows_.end());
1115 window_manager_delegate_->OnWmClientJankinessChanged( 1148 window_manager_delegate_->OnWmClientJankinessChanged(
1116 embedded_windows_[client_id], janky); 1149 embedded_windows_[client_id], janky);
1117 } 1150 }
1118 } 1151 }
1119 1152
1153 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id,
1154 Id window_id,
1155 ::mus::mojom::MoveLoopSource source,
1156 const gfx::Point& cursor_location) {
1157 if (window_manager_delegate_) {
sky 2016/06/29 00:04:08 If there is no window for id, immediately call OnW
1158 window_manager_delegate_->OnWmPerformMoveLoop(
1159 GetWindowByServerId(window_id), source, cursor_location,
1160 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted,
1161 weak_factory_.GetWeakPtr(), change_id));
1162 }
1163 }
1164
1165 void WindowTreeClient::WmCancelMoveLoop(uint32_t window_id) {
1166 if (window_manager_delegate_)
sky 2016/06/29 00:04:08 As WmCancelMoveLoop is async, it's entirely possib
1167 window_manager_delegate_->OnWmCancelMoveLoop(
1168 GetWindowByServerId(window_id));
1169 }
1170
1120 void WindowTreeClient::OnAccelerator(uint32_t id, 1171 void WindowTreeClient::OnAccelerator(uint32_t id,
1121 std::unique_ptr<ui::Event> event) { 1172 std::unique_ptr<ui::Event> event) {
1122 DCHECK(event); 1173 DCHECK(event);
1123 window_manager_delegate_->OnAccelerator(id, *event.get()); 1174 window_manager_delegate_->OnAccelerator(id, *event.get());
1124 } 1175 }
1125 1176
1126 void WindowTreeClient::SetFrameDecorationValues( 1177 void WindowTreeClient::SetFrameDecorationValues(
1127 mojom::FrameDecorationValuesPtr values) { 1178 mojom::FrameDecorationValuesPtr values) {
1128 if (window_manager_internal_client_) { 1179 if (window_manager_internal_client_) {
1129 window_manager_internal_client_->WmSetFrameDecorationValues( 1180 window_manager_internal_client_->WmSetFrameDecorationValues(
1130 std::move(values)); 1181 std::move(values));
1131 } 1182 }
1132 } 1183 }
1133 1184
1134 void WindowTreeClient::SetNonClientCursor(Window* window, 1185 void WindowTreeClient::SetNonClientCursor(Window* window,
1135 mus::mojom::Cursor cursor_id) { 1186 mus::mojom::Cursor cursor_id) {
1136 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), 1187 window_manager_internal_client_->WmSetNonClientCursor(server_id(window),
1137 cursor_id); 1188 cursor_id);
1138 } 1189 }
1139 1190
1140 void WindowTreeClient::AddAccelerator( 1191 void WindowTreeClient::AddAccelerator(
1141 uint32_t id, 1192 uint32_t id,
1142 mojom::EventMatcherPtr event_matcher, 1193 mojom::EventMatcherPtr event_matcher,
1143 const base::Callback<void(bool)>& callback) { 1194 const base::Callback<void(bool)>& callback) {
1144 if (window_manager_internal_client_) { 1195 if (window_manager_internal_client_) {
1145 window_manager_internal_client_->AddAccelerator( 1196 window_manager_internal_client_->AddAccelerator(
(...skipping 26 matching lines...) Expand all
1172 Window* window, 1223 Window* window,
1173 const gfx::Vector2d& offset, 1224 const gfx::Vector2d& offset,
1174 const gfx::Insets& hit_area) { 1225 const gfx::Insets& hit_area) {
1175 if (window_manager_internal_client_) { 1226 if (window_manager_internal_client_) {
1176 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1227 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1177 server_id(window), offset.x(), offset.y(), hit_area); 1228 server_id(window), offset.x(), offset.y(), hit_area);
1178 } 1229 }
1179 } 1230 }
1180 1231
1181 } // namespace mus 1232 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698