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 "services/ui/ws/window_tree.h" | 5 #include "services/ui/ws/window_tree.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "mojo/public/cpp/bindings/map.h" | 14 #include "mojo/public/cpp/bindings/map.h" |
| 15 #include "services/ui/ws/cursor_location_manager.h" | 15 #include "services/ui/ws/cursor_location_manager.h" |
| 16 #include "services/ui/ws/default_access_policy.h" | 16 #include "services/ui/ws/default_access_policy.h" |
| 17 #include "services/ui/ws/display.h" | 17 #include "services/ui/ws/display.h" |
| 18 #include "services/ui/ws/display_manager.h" | 18 #include "services/ui/ws/display_manager.h" |
| 19 #include "services/ui/ws/event_matcher.h" | 19 #include "services/ui/ws/event_matcher.h" |
| 20 #include "services/ui/ws/focus_controller.h" | 20 #include "services/ui/ws/focus_controller.h" |
| 21 #include "services/ui/ws/operation.h" | 21 #include "services/ui/ws/operation.h" |
| 22 #include "services/ui/ws/platform_display.h" | 22 #include "services/ui/ws/platform_display.h" |
| 23 #include "services/ui/ws/server_window.h" | 23 #include "services/ui/ws/server_window.h" |
| 24 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" | 24 #include "services/ui/ws/server_window_compositor_frame_sink_manager.h" |
| 25 #include "services/ui/ws/server_window_observer.h" | 25 #include "services/ui/ws/server_window_observer.h" |
| 26 #include "services/ui/ws/user_display_manager.h" | 26 #include "services/ui/ws/user_display_manager.h" |
| 27 #include "services/ui/ws/window_manager_display_root.h" | 27 #include "services/ui/ws/window_manager_display_root.h" |
| 28 #include "services/ui/ws/window_manager_state.h" | 28 #include "services/ui/ws/window_manager_state.h" |
| 29 #include "services/ui/ws/window_server.h" | 29 #include "services/ui/ws/window_server.h" |
| 30 #include "services/ui/ws/window_server_delegate.h" | |
| 30 #include "services/ui/ws/window_tree_binding.h" | 31 #include "services/ui/ws/window_tree_binding.h" |
| 31 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 33 #include "ui/display/display_list.h" | |
| 34 #include "ui/display/screen_base.h" | |
| 32 #include "ui/display/types/display_constants.h" | 35 #include "ui/display/types/display_constants.h" |
| 33 #include "ui/platform_window/mojo/ime_type_converters.h" | 36 #include "ui/platform_window/mojo/ime_type_converters.h" |
| 34 #include "ui/platform_window/text_input_state.h" | 37 #include "ui/platform_window/text_input_state.h" |
| 35 | 38 |
| 36 using mojo::InterfaceRequest; | 39 using mojo::InterfaceRequest; |
| 37 | 40 |
| 38 using EventProperties = std::unordered_map<std::string, std::vector<uint8_t>>; | 41 using EventProperties = std::unordered_map<std::string, std::vector<uint8_t>>; |
| 39 | 42 |
| 40 namespace ui { | 43 namespace ui { |
| 41 namespace ws { | 44 namespace ws { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 void WindowTree::OnWmMoveDragImageAck() { | 259 void WindowTree::OnWmMoveDragImageAck() { |
| 257 if (drag_move_state_->has_queued_drag_window_move) { | 260 if (drag_move_state_->has_queued_drag_window_move) { |
| 258 gfx::Point queued_location = drag_move_state_->queued_cursor_location; | 261 gfx::Point queued_location = drag_move_state_->queued_cursor_location; |
| 259 drag_move_state_.reset(); | 262 drag_move_state_.reset(); |
| 260 OnDragMoved(queued_location); | 263 OnDragMoved(queued_location); |
| 261 } else { | 264 } else { |
| 262 drag_move_state_.reset(); | 265 drag_move_state_.reset(); |
| 263 } | 266 } |
| 264 } | 267 } |
| 265 | 268 |
| 266 bool WindowTree::ProcessSetDisplayRoot(int64_t display_id, | 269 ServerWindow* WindowTree::ProcessSetDisplayRoot( |
| 267 const ClientWindowId& client_window_id) { | 270 const display::Display& display_to_create, |
| 271 const mojom::WmViewportMetrics& transport_viewport_metrics, | |
| 272 bool is_primary_display, | |
| 273 const ClientWindowId& client_window_id) { | |
| 268 DCHECK(window_manager_state_); // Only called for window manager. | 274 DCHECK(window_manager_state_); // Only called for window manager. |
| 275 DVLOG(3) << "SetDisplayRoot client=" << id_ | |
| 276 << " global window_id=" << client_window_id.id; | |
| 269 Display* display = | 277 Display* display = |
| 270 window_server_->display_manager()->GetDisplayById(display_id); | 278 window_server_->display_manager()->GetDisplayById(display_to_create.id()); |
| 271 if (!display) { | 279 if (display) { |
| 272 DVLOG(1) << "SetDisplayRoot called with unknown display " << display_id; | 280 DVLOG(1) << "SetDisplayRoot called with existing display " |
| 273 return false; | 281 << display_to_create.id(); |
| 282 return nullptr; | |
| 274 } | 283 } |
| 275 | 284 |
| 276 if (automatically_create_display_roots_) { | 285 if (automatically_create_display_roots_) { |
| 277 DVLOG(1) << "SetDisplayRoot is only applicable when " | 286 DVLOG(1) << "SetDisplayRoot is only applicable when " |
| 278 << "automatically_create_display_roots is false"; | 287 << "automatically_create_display_roots is false"; |
| 279 return false; | 288 return nullptr; |
| 280 } | 289 } |
| 281 | 290 |
| 282 ServerWindow* window = GetWindowByClientId(client_window_id); | 291 ServerWindow* window = GetWindowByClientId(client_window_id); |
| 283 // The window must not have a parent. | 292 // The window must not have a parent. |
| 284 if (!window || window->parent()) { | 293 if (!window || window->parent()) { |
| 285 DVLOG(1) << "SetDisplayRoot called with invalid window id " | 294 DVLOG(1) << "SetDisplayRoot called with invalid window id " |
| 286 << client_window_id.id; | 295 << client_window_id.id; |
| 287 return false; | 296 return nullptr; |
| 288 } | 297 } |
| 289 | 298 |
| 299 if (base::ContainsValue(roots_, window)) { | |
| 300 DVLOG(1) << "SetDisplayRoot called with existing root"; | |
| 301 return nullptr; | |
| 302 } | |
| 303 | |
| 304 const display::DisplayList::Type display_type = | |
| 305 is_primary_display ? display::DisplayList::Type::PRIMARY | |
| 306 : display::DisplayList::Type::NOT_PRIMARY; | |
| 307 window_server_->delegate()->GetScreen()->display_list().AddDisplay( | |
| 308 display_to_create, display_type); | |
| 309 display::ViewportMetrics viewport_metrics; | |
| 310 viewport_metrics.bounds_in_pixels = | |
| 311 transport_viewport_metrics.bounds_in_pixels; | |
| 312 viewport_metrics.device_scale_factor = | |
| 313 transport_viewport_metrics.device_scale_factor; | |
| 314 viewport_metrics.ui_scale_factor = transport_viewport_metrics.ui_scale_factor; | |
| 315 window_server_->display_manager()->AddDisplayForWindowManager( | |
| 316 display_to_create, viewport_metrics); | |
| 317 | |
| 318 // OnDisplayAdded() should trigger creation of the Display. | |
| 319 display = | |
| 320 window_server_->display_manager()->GetDisplayById(display_to_create.id()); | |
| 321 DCHECK(display); | |
| 290 WindowManagerDisplayRoot* display_root = | 322 WindowManagerDisplayRoot* display_root = |
| 291 display->GetWindowManagerDisplayRootForUser( | 323 display->GetWindowManagerDisplayRootForUser( |
| 292 window_manager_state_->user_id()); | 324 window_manager_state_->user_id()); |
| 293 DCHECK(display_root); | 325 DCHECK(display_root); |
| 294 if (!display_root->root()->children().empty()) { | 326 DCHECK(display_root->root()->children().empty()); |
| 295 DVLOG(1) << "SetDisplayRoot called more than once"; | |
| 296 return false; | |
| 297 } | |
| 298 | |
| 299 if (base::ContainsValue(roots_, window)) { | |
| 300 DVLOG(1) << "SetDisplayRoot called with existing root"; | |
| 301 return false; | |
| 302 } | |
| 303 | 327 |
| 304 // NOTE: this doesn't resize the window in anyway. We assume the client takes | 328 // NOTE: this doesn't resize the window in anyway. We assume the client takes |
| 305 // care of any modifications it needs to do. | 329 // care of any modifications it needs to do. |
| 306 roots_.insert(window); | 330 roots_.insert(window); |
| 307 Operation op(this, window_server_, OperationType::ADD_WINDOW); | 331 Operation op(this, window_server_, OperationType::ADD_WINDOW); |
| 308 display_root->root()->Add(window); | 332 display_root->root()->Add(window); |
| 309 return true; | 333 return window; |
| 310 } | 334 } |
| 311 | 335 |
| 312 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) { | 336 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) { |
| 313 ServerWindow* window = GetWindowByClientId(client_window_id); | 337 ServerWindow* window = GetWindowByClientId(client_window_id); |
| 314 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); | 338 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window); |
| 315 ServerWindow* current_capture_window = | 339 ServerWindow* current_capture_window = |
| 316 display_root ? display_root->window_manager_state()->capture_window() | 340 display_root ? display_root->window_manager_state()->capture_window() |
| 317 : nullptr; | 341 : nullptr; |
| 318 if (window && window->IsDrawn() && display_root && | 342 if (window && window->IsDrawn() && display_root && |
| 319 display_root->window_manager_state()->IsActive() && | 343 display_root->window_manager_state()->IsActive() && |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 340 return false; | 364 return false; |
| 341 } | 365 } |
| 342 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); | 366 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); |
| 343 return display_root->window_manager_state()->SetCapture(nullptr, | 367 return display_root->window_manager_state()->SetCapture(nullptr, |
| 344 kInvalidClientId); | 368 kInvalidClientId); |
| 345 } | 369 } |
| 346 | 370 |
| 347 bool WindowTree::NewWindow( | 371 bool WindowTree::NewWindow( |
| 348 const ClientWindowId& client_window_id, | 372 const ClientWindowId& client_window_id, |
| 349 const std::map<std::string, std::vector<uint8_t>>& properties) { | 373 const std::map<std::string, std::vector<uint8_t>>& properties) { |
| 350 if (!IsValidIdForNewWindow(client_window_id)) | 374 DVLOG(3) << "new window client=" << id_ |
| 375 << " window_id=" << client_window_id.id; | |
| 376 if (!IsValidIdForNewWindow(client_window_id)) { | |
| 377 DVLOG(1) << "new window failed, id is not valid for client"; | |
| 351 return false; | 378 return false; |
| 379 } | |
| 352 const WindowId window_id = GenerateNewWindowId(); | 380 const WindowId window_id = GenerateNewWindowId(); |
| 353 DCHECK(!GetWindow(window_id)); | 381 DCHECK(!GetWindow(window_id)); |
| 354 ServerWindow* window = | 382 ServerWindow* window = |
| 355 window_server_->CreateServerWindow(window_id, properties); | 383 window_server_->CreateServerWindow(window_id, properties); |
| 356 created_window_map_[window_id] = window; | 384 created_window_map_[window_id] = window; |
| 357 client_id_to_window_id_map_[client_window_id] = window_id; | 385 client_id_to_window_id_map_[client_window_id] = window_id; |
| 358 window_id_to_client_id_map_[window_id] = client_window_id; | 386 window_id_to_client_id_map_[window_id] = client_window_id; |
| 359 return true; | 387 return true; |
| 360 } | 388 } |
| 361 | 389 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 const ServerWindow* window = GetWindowByClientId(window_id); | 518 const ServerWindow* window = GetWindowByClientId(window_id); |
| 491 std::vector<const ServerWindow*> windows; | 519 std::vector<const ServerWindow*> windows; |
| 492 if (window) | 520 if (window) |
| 493 GetWindowTreeImpl(window, &windows); | 521 GetWindowTreeImpl(window, &windows); |
| 494 return windows; | 522 return windows; |
| 495 } | 523 } |
| 496 | 524 |
| 497 bool WindowTree::SetWindowVisibility(const ClientWindowId& window_id, | 525 bool WindowTree::SetWindowVisibility(const ClientWindowId& window_id, |
| 498 bool visible) { | 526 bool visible) { |
| 499 ServerWindow* window = GetWindowByClientId(window_id); | 527 ServerWindow* window = GetWindowByClientId(window_id); |
| 500 if (!window || !access_policy_->CanChangeWindowVisibility(window)) | 528 DVLOG(3) << "SetWindowVisibility client=" << id_ |
| 529 << " client window_id= " << window_id.id << " global window_id=" | |
| 530 << (window ? WindowIdToTransportId(window->id()) : 0); | |
| 531 if (!window) { | |
| 532 DVLOG(1) << "SetWindowVisibility failure, no window"; | |
| 501 return false; | 533 return false; |
| 534 } | |
| 535 if (!access_policy_->CanChangeWindowVisibility(window)) { | |
| 536 DVLOG(1) << "SetWindowVisibility failure, access policy denied change"; | |
| 537 return false; | |
| 538 } | |
| 502 if (window->visible() == visible) | 539 if (window->visible() == visible) |
| 503 return true; | 540 return true; |
| 504 Operation op(this, window_server_, OperationType::SET_WINDOW_VISIBILITY); | 541 Operation op(this, window_server_, OperationType::SET_WINDOW_VISIBILITY); |
| 505 window->SetVisible(visible); | 542 window->SetVisible(visible); |
| 506 return true; | 543 return true; |
| 507 } | 544 } |
| 508 | 545 |
| 509 bool WindowTree::SetWindowOpacity(const ClientWindowId& window_id, | 546 bool WindowTree::SetWindowOpacity(const ClientWindowId& window_id, |
| 510 float opacity) { | 547 float opacity) { |
| 511 ServerWindow* window = GetWindowByClientId(window_id); | 548 ServerWindow* window = GetWindowByClientId(window_id); |
| (...skipping 1586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2098 DVLOG(1) << "SetExtendedHitArea supplied unknown window"; | 2135 DVLOG(1) << "SetExtendedHitArea supplied unknown window"; |
| 2099 return; | 2136 return; |
| 2100 } | 2137 } |
| 2101 if (window->id().client_id != id_) { | 2138 if (window->id().client_id != id_) { |
| 2102 DVLOG(1) << "SetExtendedHitArea supplied window that client does not own"; | 2139 DVLOG(1) << "SetExtendedHitArea supplied window that client does not own"; |
| 2103 return; | 2140 return; |
| 2104 } | 2141 } |
| 2105 window->set_extended_hit_test_region(hit_area); | 2142 window->set_extended_hit_test_region(hit_area); |
| 2106 } | 2143 } |
| 2107 | 2144 |
| 2108 void WindowTree::SetDisplayRoot(int64_t display_id, | 2145 void WindowTree::SetDisplayRoot( |
| 2109 Id window_id, | 2146 const display::Display& display, |
| 2110 const SetDisplayRootCallback& callback) { | 2147 const mojom::WmViewportMetricsPtr viewport_metrics, |
| 2111 callback.Run(ProcessSetDisplayRoot(display_id, ClientWindowId(window_id))); | 2148 bool is_primary_display, |
| 2149 Id window_id, | |
| 2150 const SetDisplayRootCallback& callback) { | |
| 2151 ServerWindow* display_root = | |
| 2152 ProcessSetDisplayRoot(display, *(viewport_metrics.get()), | |
| 2153 is_primary_display, ClientWindowId(window_id)); | |
| 2154 if (!display_root) { | |
| 2155 base::Optional<cc::FrameSinkId> frame_sink_id; | |
| 2156 callback.Run(frame_sink_id); | |
|
kylechar
2017/04/19 18:06:08
Maybe named |empty_frame_sink_id| or just callback
sky
2017/04/19 19:30:03
Done.
| |
| 2157 return; | |
| 2158 } | |
| 2159 display_root->parent()->SetVisible(true); | |
| 2160 callback.Run(display_root->frame_sink_id()); | |
| 2112 } | 2161 } |
| 2113 | 2162 |
| 2114 void WindowTree::WmResponse(uint32_t change_id, bool response) { | 2163 void WindowTree::WmResponse(uint32_t change_id, bool response) { |
| 2115 if (window_server_->in_move_loop() && | 2164 if (window_server_->in_move_loop() && |
| 2116 window_server_->GetCurrentMoveLoopChangeId() == change_id) { | 2165 window_server_->GetCurrentMoveLoopChangeId() == change_id) { |
| 2117 ServerWindow* window = window_server_->GetCurrentMoveLoopWindow(); | 2166 ServerWindow* window = window_server_->GetCurrentMoveLoopWindow(); |
| 2118 | 2167 |
| 2119 if (window->id().client_id != id_) { | 2168 if (window->id().client_id != id_) { |
| 2120 window_server_->WindowManagerSentBogusMessage(); | 2169 window_server_->WindowManagerSentBogusMessage(); |
| 2121 window = nullptr; | 2170 window = nullptr; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2351 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset, | 2400 client()->OnCompleteDrop(client_window_id.id, event_flags, cursor_offset, |
| 2352 effect_bitmask, callback); | 2401 effect_bitmask, callback); |
| 2353 } | 2402 } |
| 2354 | 2403 |
| 2355 void WindowTree::PerformOnDragDropDone() { | 2404 void WindowTree::PerformOnDragDropDone() { |
| 2356 client()->OnDragDropDone(); | 2405 client()->OnDragDropDone(); |
| 2357 } | 2406 } |
| 2358 | 2407 |
| 2359 } // namespace ws | 2408 } // namespace ws |
| 2360 } // namespace ui | 2409 } // namespace ui |
| OLD | NEW |