Chromium Code Reviews| 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 "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> |
| 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 "base/message_loop/message_loop.h" | |
| 16 #include "base/run_loop.h" | |
| 15 #include "components/mus/common/util.h" | 17 #include "components/mus/common/util.h" |
| 16 #include "components/mus/public/cpp/input_event_handler.h" | 18 #include "components/mus/public/cpp/input_event_handler.h" |
| 17 #include "components/mus/public/cpp/lib/in_flight_change.h" | 19 #include "components/mus/public/cpp/lib/in_flight_change.h" |
| 18 #include "components/mus/public/cpp/lib/window_private.h" | 20 #include "components/mus/public/cpp/lib/window_private.h" |
| 19 #include "components/mus/public/cpp/window_manager_delegate.h" | 21 #include "components/mus/public/cpp/window_manager_delegate.h" |
| 20 #include "components/mus/public/cpp/window_observer.h" | 22 #include "components/mus/public/cpp/window_observer.h" |
| 21 #include "components/mus/public/cpp/window_tracker.h" | 23 #include "components/mus/public/cpp/window_tracker.h" |
| 22 #include "components/mus/public/cpp/window_tree_client_delegate.h" | 24 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 23 #include "components/mus/public/cpp/window_tree_client_observer.h" | 25 #include "components/mus/public/cpp/window_tree_client_observer.h" |
| 24 #include "components/mus/public/interfaces/window_manager_window_tree_factory.mo jom.h" | 26 #include "components/mus/public/interfaces/window_manager_window_tree_factory.mo jom.h" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 } | 227 } |
| 226 | 228 |
| 227 bool WindowTreeClient::OwnsWindow(Window* window) const { | 229 bool WindowTreeClient::OwnsWindow(Window* window) const { |
| 228 // Windows created via CreateTopLevelWindow() are not owned by us, but have | 230 // Windows created via CreateTopLevelWindow() are not owned by us, but have |
| 229 // our client id. | 231 // our client id. |
| 230 return HiWord(server_id(window)) == client_id_ && | 232 return HiWord(server_id(window)) == client_id_ && |
| 231 roots_.count(window) == 0; | 233 roots_.count(window) == 0; |
| 232 } | 234 } |
| 233 | 235 |
| 234 void WindowTreeClient::SetBounds(Window* window, | 236 void WindowTreeClient::SetBounds(Window* window, |
| 235 const gfx::Rect& old_bounds, | 237 const gfx::Rect& old_bounds, |
| 236 const gfx::Rect& bounds) { | 238 const gfx::Rect& bounds) { |
| 237 DCHECK(tree_); | 239 DCHECK(tree_); |
| 238 const uint32_t change_id = ScheduleInFlightChange( | 240 const uint32_t change_id = ScheduleInFlightChange( |
| 239 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); | 241 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); |
| 240 tree_->SetWindowBounds(change_id, server_id(window), bounds); | 242 tree_->SetWindowBounds(change_id, server_id(window), bounds); |
| 241 } | 243 } |
| 242 | 244 |
| 243 void WindowTreeClient::SetCapture(Window* window) { | 245 void WindowTreeClient::SetCapture(Window* window) { |
| 244 // In order for us to get here we had to have exposed a window, which implies | 246 // In order for us to get here we had to have exposed a window, which implies |
| 245 // we got a client. | 247 // we got a client. |
| 246 DCHECK(tree_); | 248 DCHECK(tree_); |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 if (matcher.is_null()) { | 619 if (matcher.is_null()) { |
| 618 has_event_observer_ = false; | 620 has_event_observer_ = false; |
| 619 tree_->SetEventObserver(nullptr, 0u); | 621 tree_->SetEventObserver(nullptr, 0u); |
| 620 } else { | 622 } else { |
| 621 has_event_observer_ = true; | 623 has_event_observer_ = true; |
| 622 event_observer_id_++; | 624 event_observer_id_++; |
| 623 tree_->SetEventObserver(std::move(matcher), event_observer_id_); | 625 tree_->SetEventObserver(std::move(matcher), event_observer_id_); |
| 624 } | 626 } |
| 625 } | 627 } |
| 626 | 628 |
| 629 bool WindowTreeClient::PerformWindowMove(Window* window, | |
| 630 const gfx::Point& cursor_location) { | |
| 631 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); | |
| 632 base::MessageLoop::ScopedNestableTaskAllower allow_nested(loop); | |
|
sky
2016/06/22 23:47:56
mus::Window shouldn't run a nested message loop. C
| |
| 633 base::RunLoop run_loop; | |
| 634 | |
| 635 const uint32_t change_id = ScheduleInFlightChange( | |
| 636 base::WrapUnique(new InFlightMoveLoopChange(window, window->bounds()))); | |
| 637 | |
| 638 current_move_succeeded_ = false; | |
| 639 on_current_move_finished_ = run_loop.QuitClosure(); | |
| 640 | |
| 641 // Tell the window manager to take over moving us. | |
| 642 tree_->PerformWindowMove(change_id, window->server_id(), cursor_location); | |
| 643 | |
| 644 // PerformWindowMove is deliberately not a sync call. We want to process | |
| 645 // other messages while we're otherwise blocking on RunMoveLoop(); everything | |
| 646 // in views makes this assumption. | |
| 647 // | |
| 648 // TODO(erg): Once mus is the only target for views, go through the chrome | |
| 649 // code base and try making this properly asynchronous instead of building up | |
| 650 // a nested RunLoop, as we always have in this situation. | |
| 651 run_loop.Run(); | |
| 652 | |
| 653 return current_move_succeeded_; | |
| 654 } | |
| 655 | |
| 656 void WindowTreeClient::CancelWindowMove(Window* window) { | |
| 657 tree_->CancelWindowMove(window->server_id()); | |
| 658 } | |
| 659 | |
| 627 Window* WindowTreeClient::NewWindow( | 660 Window* WindowTreeClient::NewWindow( |
| 628 const Window::SharedProperties* properties) { | 661 const Window::SharedProperties* properties) { |
| 629 return NewWindowImpl(NewWindowType::CHILD, properties); | 662 return NewWindowImpl(NewWindowType::CHILD, properties); |
| 630 } | 663 } |
| 631 | 664 |
| 632 Window* WindowTreeClient::NewTopLevelWindow( | 665 Window* WindowTreeClient::NewTopLevelWindow( |
| 633 const Window::SharedProperties* properties) { | 666 const Window::SharedProperties* properties) { |
| 634 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | 667 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
| 635 // Assume newly created top level windows are drawn by default, otherwise | 668 // Assume newly created top level windows are drawn by default, otherwise |
| 636 // 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1014 | 1047 |
| 1015 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); | 1048 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); |
| 1016 if (next_change) { | 1049 if (next_change) { |
| 1017 if (!success) | 1050 if (!success) |
| 1018 next_change->SetRevertValueFrom(*change); | 1051 next_change->SetRevertValueFrom(*change); |
| 1019 } else if (!success) { | 1052 } else if (!success) { |
| 1020 change->Revert(); | 1053 change->Revert(); |
| 1021 } | 1054 } |
| 1022 } | 1055 } |
| 1023 | 1056 |
| 1057 void WindowTreeClient::OnMoveLoopCompleted(uint32_t change_id, bool success) { | |
| 1058 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | |
| 1059 in_flight_map_.erase(change_id); | |
| 1060 if (!change) | |
| 1061 return; | |
| 1062 | |
| 1063 current_move_succeeded_ = success; | |
| 1064 on_current_move_finished_.Run(); | |
| 1065 } | |
| 1066 | |
| 1024 void WindowTreeClient::GetWindowManager( | 1067 void WindowTreeClient::GetWindowManager( |
| 1025 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1068 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| 1026 window_manager_internal_.reset( | 1069 window_manager_internal_.reset( |
| 1027 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1070 new mojo::AssociatedBinding<mojom::WindowManager>(this, |
| 1028 std::move(internal))); | 1071 std::move(internal))); |
| 1029 } | 1072 } |
| 1030 | 1073 |
| 1031 void WindowTreeClient::RequestClose(uint32_t window_id) { | 1074 void WindowTreeClient::RequestClose(uint32_t window_id) { |
| 1032 Window* window = GetWindowByServerId(window_id); | 1075 Window* window = GetWindowByServerId(window_id); |
| 1033 if (!window || !IsRoot(window)) | 1076 if (!window || !IsRoot(window)) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1062 // the client applies the bounds we set below. | 1105 // the client applies the bounds we set below. |
| 1063 result = bounds == transit_bounds; | 1106 result = bounds == transit_bounds; |
| 1064 window->SetBounds(bounds); | 1107 window->SetBounds(bounds); |
| 1065 } | 1108 } |
| 1066 } | 1109 } |
| 1067 if (window_manager_internal_client_) | 1110 if (window_manager_internal_client_) |
| 1068 window_manager_internal_client_->WmResponse(change_id, result); | 1111 window_manager_internal_client_->WmResponse(change_id, result); |
| 1069 } | 1112 } |
| 1070 | 1113 |
| 1071 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1114 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1072 Id window_id, | 1115 Id window_id, |
| 1073 const mojo::String& name, | 1116 const mojo::String& name, |
| 1074 mojo::Array<uint8_t> transit_data) { | 1117 mojo::Array<uint8_t> transit_data) { |
| 1075 Window* window = GetWindowByServerId(window_id); | 1118 Window* window = GetWindowByServerId(window_id); |
| 1076 bool result = false; | 1119 bool result = false; |
| 1077 if (window) { | 1120 if (window) { |
| 1078 DCHECK(window_manager_delegate_); | 1121 DCHECK(window_manager_delegate_); |
| 1079 std::unique_ptr<std::vector<uint8_t>> data; | 1122 std::unique_ptr<std::vector<uint8_t>> data; |
| 1080 if (!transit_data.is_null()) { | 1123 if (!transit_data.is_null()) { |
| 1081 data.reset( | 1124 data.reset( |
| 1082 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); | 1125 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); |
| 1083 } | 1126 } |
| 1084 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); | 1127 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1101 Window* window = | 1144 Window* window = |
| 1102 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1145 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); |
| 1103 embedded_windows_[requesting_client_id].insert(window); | 1146 embedded_windows_[requesting_client_id].insert(window); |
| 1104 if (window_manager_internal_client_) { | 1147 if (window_manager_internal_client_) { |
| 1105 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1148 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1106 change_id, server_id(window)); | 1149 change_id, server_id(window)); |
| 1107 } | 1150 } |
| 1108 } | 1151 } |
| 1109 | 1152 |
| 1110 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1153 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1111 bool janky) { | 1154 bool janky) { |
| 1112 if (window_manager_delegate_) { | 1155 if (window_manager_delegate_) { |
| 1113 auto it = embedded_windows_.find(client_id); | 1156 auto it = embedded_windows_.find(client_id); |
| 1114 CHECK(it != embedded_windows_.end()); | 1157 CHECK(it != embedded_windows_.end()); |
| 1115 window_manager_delegate_->OnWmClientJankinessChanged( | 1158 window_manager_delegate_->OnWmClientJankinessChanged( |
| 1116 embedded_windows_[client_id], janky); | 1159 embedded_windows_[client_id], janky); |
| 1117 } | 1160 } |
| 1118 } | 1161 } |
| 1119 | 1162 |
| 1163 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, | |
| 1164 Id window_id, | |
| 1165 const gfx::Point& cursor_location) { | |
| 1166 if (window_manager_delegate_) | |
| 1167 window_manager_delegate_->OnWmPerformMoveLoop(change_id, window_id, | |
| 1168 cursor_location); | |
| 1169 } | |
| 1170 | |
| 1171 void WindowTreeClient::WmCancelMoveLoop(uint32_t window_id) { | |
| 1172 if (window_manager_delegate_) | |
| 1173 window_manager_delegate_->OnWmCancelMoveLoop(window_id); | |
| 1174 } | |
| 1175 | |
| 1120 void WindowTreeClient::OnAccelerator(uint32_t id, | 1176 void WindowTreeClient::OnAccelerator(uint32_t id, |
| 1121 std::unique_ptr<ui::Event> event) { | 1177 std::unique_ptr<ui::Event> event) { |
| 1122 DCHECK(event); | 1178 DCHECK(event); |
| 1123 window_manager_delegate_->OnAccelerator(id, *event.get()); | 1179 window_manager_delegate_->OnAccelerator(id, *event.get()); |
| 1124 } | 1180 } |
| 1125 | 1181 |
| 1126 void WindowTreeClient::SetFrameDecorationValues( | 1182 void WindowTreeClient::SetFrameDecorationValues( |
| 1127 mojom::FrameDecorationValuesPtr values) { | 1183 mojom::FrameDecorationValuesPtr values) { |
| 1128 if (window_manager_internal_client_) { | 1184 if (window_manager_internal_client_) { |
| 1129 window_manager_internal_client_->WmSetFrameDecorationValues( | 1185 window_manager_internal_client_->WmSetFrameDecorationValues( |
| 1130 std::move(values)); | 1186 std::move(values)); |
| 1131 } | 1187 } |
| 1132 } | 1188 } |
| 1133 | 1189 |
| 1134 void WindowTreeClient::SetNonClientCursor(Window* window, | 1190 void WindowTreeClient::SetNonClientCursor(Window* window, |
| 1135 mus::mojom::Cursor cursor_id) { | 1191 mus::mojom::Cursor cursor_id) { |
| 1136 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), | 1192 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), |
| 1137 cursor_id); | 1193 cursor_id); |
| 1138 } | 1194 } |
| 1139 | 1195 |
| 1140 void WindowTreeClient::AddAccelerator( | 1196 void WindowTreeClient::AddAccelerator( |
| 1141 uint32_t id, | 1197 uint32_t id, |
| 1142 mojom::EventMatcherPtr event_matcher, | 1198 mojom::EventMatcherPtr event_matcher, |
| 1143 const base::Callback<void(bool)>& callback) { | 1199 const base::Callback<void(bool)>& callback) { |
| 1144 if (window_manager_internal_client_) { | 1200 if (window_manager_internal_client_) { |
| 1145 window_manager_internal_client_->AddAccelerator( | 1201 window_manager_internal_client_->AddAccelerator( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1171 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1227 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1172 Window* window, | 1228 Window* window, |
| 1173 const gfx::Vector2d& offset, | 1229 const gfx::Vector2d& offset, |
| 1174 const gfx::Insets& hit_area) { | 1230 const gfx::Insets& hit_area) { |
| 1175 if (window_manager_internal_client_) { | 1231 if (window_manager_internal_client_) { |
| 1176 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1232 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1177 server_id(window), offset.x(), offset.y(), hit_area); | 1233 server_id(window), offset.x(), offset.y(), hit_area); |
| 1178 } | 1234 } |
| 1179 } | 1235 } |
| 1180 | 1236 |
| 1237 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, | |
| 1238 uint32_t window_id, | |
| 1239 bool completed) { | |
| 1240 if (window_manager_internal_client_) { | |
| 1241 window_manager_internal_client_->OnWmMoveLoopCompleted(change_id, window_id, | |
| 1242 completed); | |
| 1243 } | |
| 1244 } | |
| 1245 | |
| 1181 } // namespace mus | 1246 } // namespace mus |
| OLD | NEW |