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 "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 mojo::Map<mojo::String, mojo::Array<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.To<std::vector<uint8_t>>())); | |
| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 | 416 |
| 400 WindowMus* WindowTreeClient::NewWindowFromWindowData( | 417 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| 401 WindowMus* parent, | 418 WindowMus* parent, |
| 402 const ui::mojom::WindowDataPtr& window_data) { | 419 const ui::mojom::WindowDataPtr& window_data) { |
| 403 // This function is only called for windows coming from other clients. | 420 // This function is only called for windows coming from other clients. |
| 404 std::unique_ptr<WindowPortMus> window_port_mus( | 421 std::unique_ptr<WindowPortMus> window_port_mus( |
| 405 CreateWindowPortMus(window_data, WindowMusType::OTHER)); | 422 CreateWindowPortMus(window_data, WindowMusType::OTHER)); |
| 406 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | 423 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| 407 Window* window = new Window(nullptr, std::move(window_port_mus)); | 424 Window* window = new Window(nullptr, std::move(window_port_mus)); |
| 408 WindowMus* window_mus = window_port_mus_ptr; | 425 WindowMus* window_mus = window_port_mus_ptr; |
| 426 SetWindowTypeFromProperties(window, window_data->properties); | |
| 409 window->Init(ui::LAYER_NOT_DRAWN); | 427 window->Init(ui::LAYER_NOT_DRAWN); |
| 410 SetLocalPropertiesFromServerProperties(window_mus, window_data); | 428 SetLocalPropertiesFromServerProperties(window_mus, window_data); |
| 411 window_mus->SetBoundsFromServer(window_data->bounds); | 429 window_mus->SetBoundsFromServer(window_data->bounds); |
| 412 if (parent) | 430 if (parent) |
| 413 parent->AddChildFromServer(window_port_mus_ptr); | 431 parent->AddChildFromServer(window_port_mus_ptr); |
| 414 if (window_data->visible) | 432 if (window_data->visible) |
| 415 window_mus->SetVisibleFromServer(true); | 433 window_mus->SetVisibleFromServer(true); |
| 416 return window_port_mus_ptr; | 434 return window_port_mus_ptr; |
| 417 } | 435 } |
| 418 | 436 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 bool completed) { | 760 bool completed) { |
| 743 if (window_manager_internal_client_) | 761 if (window_manager_internal_client_) |
| 744 window_manager_internal_client_->WmResponse(change_id, completed); | 762 window_manager_internal_client_->WmResponse(change_id, completed); |
| 745 | 763 |
| 746 if (change_id == current_wm_move_loop_change_) { | 764 if (change_id == current_wm_move_loop_change_) { |
| 747 current_wm_move_loop_change_ = 0; | 765 current_wm_move_loop_change_ = 0; |
| 748 current_wm_move_loop_window_id_ = 0; | 766 current_wm_move_loop_window_id_ = 0; |
| 749 } | 767 } |
| 750 } | 768 } |
| 751 | 769 |
| 752 //////////////////////////////////////////////////////////////////////////////// | |
| 753 // WindowTreeClient, WindowTreeClient implementation: | |
| 754 | |
| 755 std::set<Window*> WindowTreeClient::GetRoots() { | 770 std::set<Window*> WindowTreeClient::GetRoots() { |
| 756 std::set<Window*> roots; | 771 std::set<Window*> roots; |
| 757 for (WindowMus* window : roots_) | 772 for (WindowMus* window : roots_) |
| 758 roots.insert(window->GetWindow()); | 773 roots.insert(window->GetWindow()); |
| 759 return roots; | 774 return roots; |
| 760 } | 775 } |
| 761 | 776 |
| 762 gfx::Point WindowTreeClient::GetCursorScreenPoint() { | 777 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| 763 // We raced initialization. Return (0, 0). | 778 // We raced initialization. Return (0, 0). |
| 764 if (!cursor_location_memory()) | 779 if (!cursor_location_memory()) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); | 811 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); |
| 797 // Tell the window manager to take over moving us. | 812 // Tell the window manager to take over moving us. |
| 798 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), | 813 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), |
| 799 source, cursor_location); | 814 source, cursor_location); |
| 800 } | 815 } |
| 801 | 816 |
| 802 void WindowTreeClient::CancelWindowMove(Window* window) { | 817 void WindowTreeClient::CancelWindowMove(Window* window) { |
| 803 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); | 818 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); |
| 804 } | 819 } |
| 805 | 820 |
| 806 //////////////////////////////////////////////////////////////////////////////// | |
| 807 // WindowTreeClient, WindowTreeClient implementation: | |
| 808 | |
| 809 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { | 821 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
| 810 observers_.AddObserver(observer); | 822 observers_.AddObserver(observer); |
| 811 } | 823 } |
| 812 | 824 |
| 813 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { | 825 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
| 814 observers_.RemoveObserver(observer); | 826 observers_.RemoveObserver(observer); |
| 815 } | 827 } |
| 816 | 828 |
| 817 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { | 829 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { |
| 818 DCHECK(tree_); | 830 DCHECK(tree_); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1368 if (window_manager_internal_client_) | 1380 if (window_manager_internal_client_) |
| 1369 window_manager_internal_client_->WmResponse(change_id, result); | 1381 window_manager_internal_client_->WmResponse(change_id, result); |
| 1370 } | 1382 } |
| 1371 | 1383 |
| 1372 void WindowTreeClient::WmCreateTopLevelWindow( | 1384 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1373 uint32_t change_id, | 1385 uint32_t change_id, |
| 1374 ClientSpecificId requesting_client_id, | 1386 ClientSpecificId requesting_client_id, |
| 1375 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1387 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 1376 std::map<std::string, std::vector<uint8_t>> properties = | 1388 std::map<std::string, std::vector<uint8_t>> properties = |
| 1377 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1389 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 1378 Window* window = | 1390 ui::mojom::WindowType window_type; |
|
msw
2016/11/21 19:26:47
nit: assign an explicit default value?
sky
2016/11/21 22:13:56
Done.
| |
| 1379 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1391 ui::mojom::WindowType* window_type_ptr = nullptr; |
| 1392 auto type_iter = | |
| 1393 properties.find(ui::mojom::WindowManager::kWindowType_Property); | |
| 1394 if (type_iter != properties.end()) { | |
| 1395 // TODO: validation! | |
|
msw
2016/11/21 19:26:47
nit: cite http://crbug.com/654924 like above?
sky
2016/11/21 22:13:56
Done.
| |
| 1396 window_type = static_cast<ui::mojom::WindowType>( | |
| 1397 mojo::ConvertTo<int32_t>(type_iter->second)); | |
| 1398 window_type_ptr = &window_type; | |
| 1399 } | |
| 1400 Window* window = window_manager_delegate_->OnWmCreateTopLevelWindow( | |
| 1401 window_type_ptr, &properties); | |
| 1380 embedded_windows_[requesting_client_id].insert(window); | 1402 embedded_windows_[requesting_client_id].insert(window); |
| 1381 if (window_manager_internal_client_) { | 1403 if (window_manager_internal_client_) { |
| 1382 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1404 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1383 change_id, WindowMus::Get(window)->server_id()); | 1405 change_id, WindowMus::Get(window)->server_id()); |
| 1384 } | 1406 } |
| 1385 } | 1407 } |
| 1386 | 1408 |
| 1387 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1409 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1388 bool janky) { | 1410 bool janky) { |
| 1389 if (window_manager_delegate_) { | 1411 if (window_manager_delegate_) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1559 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1581 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1560 this, capture_synchronizer_.get(), window)); | 1582 this, capture_synchronizer_.get(), window)); |
| 1561 } | 1583 } |
| 1562 | 1584 |
| 1563 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1585 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1564 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1586 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1565 this, focus_synchronizer_.get(), window)); | 1587 this, focus_synchronizer_.get(), window)); |
| 1566 } | 1588 } |
| 1567 | 1589 |
| 1568 } // namespace aura | 1590 } // namespace aura |
| OLD | NEW |