| 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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/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/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
| 17 #include "services/ui/public/cpp/property_type_converters.h" |
| 17 #include "services/ui/public/interfaces/constants.mojom.h" | 18 #include "services/ui/public/interfaces/constants.mojom.h" |
| 19 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 18 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" | 20 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 21 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/client/drag_drop_client.h" | 22 #include "ui/aura/client/drag_drop_client.h" |
| 21 #include "ui/aura/client/transient_window_client.h" | 23 #include "ui/aura/client/transient_window_client.h" |
| 22 #include "ui/aura/mus/capture_synchronizer.h" | 24 #include "ui/aura/mus/capture_synchronizer.h" |
| 23 #include "ui/aura/mus/drag_drop_controller_mus.h" | 25 #include "ui/aura/mus/drag_drop_controller_mus.h" |
| 24 #include "ui/aura/mus/focus_synchronizer.h" | 26 #include "ui/aura/mus/focus_synchronizer.h" |
| 25 #include "ui/aura/mus/in_flight_change.h" | 27 #include "ui/aura/mus/in_flight_change.h" |
| 26 #include "ui/aura/mus/input_method_mus.h" | 28 #include "ui/aura/mus/input_method_mus.h" |
| 27 #include "ui/aura/mus/property_converter.h" | 29 #include "ui/aura/mus/property_converter.h" |
| 30 #include "ui/aura/mus/property_utils.h" |
| 28 #include "ui/aura/mus/surface_id_handler.h" | 31 #include "ui/aura/mus/surface_id_handler.h" |
| 29 #include "ui/aura/mus/window_manager_delegate.h" | 32 #include "ui/aura/mus/window_manager_delegate.h" |
| 30 #include "ui/aura/mus/window_mus.h" | 33 #include "ui/aura/mus/window_mus.h" |
| 31 #include "ui/aura/mus/window_port_mus.h" | 34 #include "ui/aura/mus/window_port_mus.h" |
| 32 #include "ui/aura/mus/window_tree_client_delegate.h" | 35 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 33 #include "ui/aura/mus/window_tree_client_observer.h" | 36 #include "ui/aura/mus/window_tree_client_observer.h" |
| 34 #include "ui/aura/mus/window_tree_host_mus.h" | 37 #include "ui/aura/mus/window_tree_host_mus.h" |
| 35 #include "ui/aura/window.h" | 38 #include "ui/aura/window.h" |
| 36 #include "ui/aura/window_delegate.h" | 39 #include "ui/aura/window_delegate.h" |
| 37 #include "ui/aura/window_tracker.h" | 40 #include "ui/aura/window_tracker.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 115 } |
| 113 | 116 |
| 114 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { | 117 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { |
| 115 return GetWindowTreeHostMus(window->GetWindow()); | 118 return GetWindowTreeHostMus(window->GetWindow()); |
| 116 } | 119 } |
| 117 | 120 |
| 118 bool IsInternalProperty(const void* key) { | 121 bool IsInternalProperty(const void* key) { |
| 119 return key == client::kModalKey; | 122 return key == client::kModalKey; |
| 120 } | 123 } |
| 121 | 124 |
| 125 void SetWindowTypeFromProperties( |
| 126 Window* window, |
| 127 const std::unordered_map<std::string, std::vector<uint8_t>>& properties) { |
| 128 auto type_iter = |
| 129 properties.find(ui::mojom::WindowManager::kWindowType_Property); |
| 130 if (type_iter == properties.end()) |
| 131 return; |
| 132 |
| 133 // TODO: need to validate type! http://crbug.com/654924. |
| 134 ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>( |
| 135 mojo::ConvertTo<int32_t>(type_iter->second)); |
| 136 SetWindowType(window, window_type); |
| 137 } |
| 138 |
| 122 // Helper function to get the device_scale_factor() of the display::Display | 139 // Helper function to get the device_scale_factor() of the display::Display |
| 123 // with |display_id|. | 140 // with |display_id|. |
| 124 float ScaleFactorForDisplay(Window* window) { | 141 float ScaleFactorForDisplay(Window* window) { |
| 125 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after | 142 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after |
| 126 // https://codereview.chromium.org/2361283002/ is landed. | 143 // https://codereview.chromium.org/2361283002/ is landed. |
| 127 return display::Screen::GetScreen() | 144 return display::Screen::GetScreen() |
| 128 ->GetDisplayNearestWindow(window) | 145 ->GetDisplayNearestWindow(window) |
| 129 .device_scale_factor(); | 146 .device_scale_factor(); |
| 130 } | 147 } |
| 131 | 148 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 410 |
| 394 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 411 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| 395 WindowMus* parent, | 412 WindowMus* parent, |
| 396 const ui::mojom::WindowDataPtr& window_data) { | 413 const ui::mojom::WindowDataPtr& window_data) { |
| 397 // This function is only called for windows coming from other clients. | 414 // This function is only called for windows coming from other clients. |
| 398 std::unique_ptr<WindowPortMus> window_port_mus( | 415 std::unique_ptr<WindowPortMus> window_port_mus( |
| 399 CreateWindowPortMus(window_data, WindowMusType::OTHER)); | 416 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
| 400 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 417 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| 401 Window* window = new Window(nullptr, std::move(window_port_mus)); | 418 Window* window = new Window(nullptr, std::move(window_port_mus)); |
| 402 WindowMus* window_mus = window_port_mus_ptr; | 419 WindowMus* window_mus = window_port_mus_ptr; |
| 420 SetWindowTypeFromProperties(window, window_data->properties); |
| 403 window->Init(ui::LAYER_NOT_DRAWN); | 421 window->Init(ui::LAYER_NOT_DRAWN); |
| 404 SetLocalPropertiesFromServerProperties(window_mus, window_data); | 422 SetLocalPropertiesFromServerProperties(window_mus, window_data); |
| 405 window_mus->SetBoundsFromServer(window_data->bounds); | 423 window_mus->SetBoundsFromServer(window_data->bounds); |
| 406 if (parent) | 424 if (parent) |
| 407 parent->AddChildFromServer(window_port_mus_ptr); | 425 parent->AddChildFromServer(window_port_mus_ptr); |
| 408 if (window_data->visible) | 426 if (window_data->visible) |
| 409 window_mus->SetVisibleFromServer(true); | 427 window_mus->SetVisibleFromServer(true); |
| 410 return window_port_mus_ptr; | 428 return window_port_mus_ptr; |
| 411 } | 429 } |
| 412 | 430 |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 bool completed) { | 748 bool completed) { |
| 731 if (window_manager_internal_client_) | 749 if (window_manager_internal_client_) |
| 732 window_manager_internal_client_->WmResponse(change_id, completed); | 750 window_manager_internal_client_->WmResponse(change_id, completed); |
| 733 | 751 |
| 734 if (change_id == current_wm_move_loop_change_) { | 752 if (change_id == current_wm_move_loop_change_) { |
| 735 current_wm_move_loop_change_ = 0; | 753 current_wm_move_loop_change_ = 0; |
| 736 current_wm_move_loop_window_id_ = 0; | 754 current_wm_move_loop_window_id_ = 0; |
| 737 } | 755 } |
| 738 } | 756 } |
| 739 | 757 |
| 740 //////////////////////////////////////////////////////////////////////////////// | |
| 741 // WindowTreeClient, WindowTreeClient implementation: | |
| 742 | |
| 743 std::set<Window*> WindowTreeClient::GetRoots() { | 758 std::set<Window*> WindowTreeClient::GetRoots() { |
| 744 std::set<Window*> roots; | 759 std::set<Window*> roots; |
| 745 for (WindowMus* window : roots_) | 760 for (WindowMus* window : roots_) |
| 746 roots.insert(window->GetWindow()); | 761 roots.insert(window->GetWindow()); |
| 747 return roots; | 762 return roots; |
| 748 } | 763 } |
| 749 | 764 |
| 750 gfx::Point WindowTreeClient::GetCursorScreenPoint() { | 765 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| 751 // We raced initialization. Return (0, 0). | 766 // We raced initialization. Return (0, 0). |
| 752 if (!cursor_location_memory()) | 767 if (!cursor_location_memory()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); | 799 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); |
| 785 // Tell the window manager to take over moving us. | 800 // Tell the window manager to take over moving us. |
| 786 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), | 801 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), |
| 787 source, cursor_location); | 802 source, cursor_location); |
| 788 } | 803 } |
| 789 | 804 |
| 790 void WindowTreeClient::CancelWindowMove(Window* window) { | 805 void WindowTreeClient::CancelWindowMove(Window* window) { |
| 791 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); | 806 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); |
| 792 } | 807 } |
| 793 | 808 |
| 794 //////////////////////////////////////////////////////////////////////////////// | |
| 795 // WindowTreeClient, WindowTreeClient implementation: | |
| 796 | |
| 797 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { | 809 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
| 798 observers_.AddObserver(observer); | 810 observers_.AddObserver(observer); |
| 799 } | 811 } |
| 800 | 812 |
| 801 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { | 813 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
| 802 observers_.RemoveObserver(observer); | 814 observers_.RemoveObserver(observer); |
| 803 } | 815 } |
| 804 | 816 |
| 805 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { | 817 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { |
| 806 DCHECK(tree_); | 818 DCHECK(tree_); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 window_manager_internal_client_->WmResponse(change_id, result); | 1362 window_manager_internal_client_->WmResponse(change_id, result); |
| 1351 } | 1363 } |
| 1352 | 1364 |
| 1353 void WindowTreeClient::WmCreateTopLevelWindow( | 1365 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1354 uint32_t change_id, | 1366 uint32_t change_id, |
| 1355 ClientSpecificId requesting_client_id, | 1367 ClientSpecificId requesting_client_id, |
| 1356 const std::unordered_map<std::string, std::vector<uint8_t>>& | 1368 const std::unordered_map<std::string, std::vector<uint8_t>>& |
| 1357 transport_properties) { | 1369 transport_properties) { |
| 1358 std::map<std::string, std::vector<uint8_t>> properties = | 1370 std::map<std::string, std::vector<uint8_t>> properties = |
| 1359 mojo::UnorderedMapToMap(transport_properties); | 1371 mojo::UnorderedMapToMap(transport_properties); |
| 1360 Window* window = | 1372 ui::mojom::WindowType window_type = ui::mojom::WindowType::UNKNOWN; |
| 1361 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1373 auto type_iter = |
| 1374 properties.find(ui::mojom::WindowManager::kWindowType_Property); |
| 1375 if (type_iter != properties.end()) { |
| 1376 // TODO: validation! http://crbug.com/654924. |
| 1377 window_type = static_cast<ui::mojom::WindowType>( |
| 1378 mojo::ConvertTo<int32_t>(type_iter->second)); |
| 1379 } |
| 1380 Window* window = window_manager_delegate_->OnWmCreateTopLevelWindow( |
| 1381 window_type, &properties); |
| 1362 embedded_windows_[requesting_client_id].insert(window); | 1382 embedded_windows_[requesting_client_id].insert(window); |
| 1363 if (window_manager_internal_client_) { | 1383 if (window_manager_internal_client_) { |
| 1364 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1384 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1365 change_id, WindowMus::Get(window)->server_id()); | 1385 change_id, WindowMus::Get(window)->server_id()); |
| 1366 } | 1386 } |
| 1367 } | 1387 } |
| 1368 | 1388 |
| 1369 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1389 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1370 bool janky) { | 1390 bool janky) { |
| 1371 if (window_manager_delegate_) { | 1391 if (window_manager_delegate_) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1579 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1560 this, capture_synchronizer_.get(), window)); | 1580 this, capture_synchronizer_.get(), window)); |
| 1561 } | 1581 } |
| 1562 | 1582 |
| 1563 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1583 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1564 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1584 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1565 this, focus_synchronizer_.get(), window)); | 1585 this, focus_synchronizer_.get(), window)); |
| 1566 } | 1586 } |
| 1567 | 1587 |
| 1568 } // namespace aura | 1588 } // namespace aura |
| OLD | NEW |