| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/demo/mus_demo.h" | 5 #include "services/ui/demo/mus_demo.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "services/service_manager/public/cpp/connector.h" | 8 #include "services/service_manager/public/cpp/connector.h" |
| 9 #include "services/service_manager/public/cpp/service_context.h" | |
| 10 #include "services/ui/demo/window_tree_data.h" | 9 #include "services/ui/demo/window_tree_data.h" |
| 11 #include "services/ui/public/cpp/gpu/gpu.h" | 10 #include "services/ui/public/cpp/gpu/gpu.h" |
| 12 #include "ui/aura/client/default_capture_client.h" | 11 #include "ui/aura/client/default_capture_client.h" |
| 13 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 14 #include "ui/aura/mus/property_converter.h" | 13 #include "ui/aura/mus/property_converter.h" |
| 15 #include "ui/aura/mus/window_tree_client.h" | 14 #include "ui/aura/mus/window_tree_client.h" |
| 16 #include "ui/aura/mus/window_tree_host_mus.h" | 15 #include "ui/aura/mus/window_tree_host_mus.h" |
| 17 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/wm/core/wm_state.h" | 18 #include "ui/wm/core/wm_state.h" |
| 20 | 19 |
| 21 namespace ui { | 20 namespace ui { |
| 22 namespace demo { | 21 namespace demo { |
| 23 | 22 |
| 24 namespace { | |
| 25 | |
| 26 // Size of square in pixels to draw. | |
| 27 const int kSquareSize = 300; | |
| 28 | |
| 29 } | |
| 30 | |
| 31 MusDemo::MusDemo() {} | 23 MusDemo::MusDemo() {} |
| 32 | 24 |
| 33 MusDemo::~MusDemo() { | 25 MusDemo::~MusDemo() { |
| 34 display::Screen::SetScreenInstance(nullptr); | 26 display::Screen::SetScreenInstance(nullptr); |
| 35 } | 27 } |
| 36 | 28 |
| 29 void MusDemo::AddPrimaryDisplay(const display::Display& display) { |
| 30 screen_->display_list().AddDisplay(display, |
| 31 display::DisplayList::Type::PRIMARY); |
| 32 } |
| 33 |
| 34 void MusDemo::InitWindowTreeData( |
| 35 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 36 DCHECK(window_tree_data_); |
| 37 DCHECK(!window_tree_data_->IsInitialized()); |
| 38 window_tree_data_->Init(std::move(window_tree_host)); |
| 39 } |
| 40 |
| 41 void MusDemo::CleanupWindowTreeData() { |
| 42 window_tree_data_.reset(); |
| 43 } |
| 44 |
| 37 void MusDemo::OnStart() { | 45 void MusDemo::OnStart() { |
| 38 screen_ = base::MakeUnique<display::ScreenBase>(); | 46 screen_ = base::MakeUnique<display::ScreenBase>(); |
| 39 display::Screen::SetScreenInstance(screen_.get()); | 47 display::Screen::SetScreenInstance(screen_.get()); |
| 40 | 48 |
| 41 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); | 49 env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS); |
| 42 capture_client_ = base::MakeUnique<aura::client::DefaultCaptureClient>(); | 50 capture_client_ = base::MakeUnique<aura::client::DefaultCaptureClient>(); |
| 43 property_converter_ = base::MakeUnique<aura::PropertyConverter>(); | 51 property_converter_ = base::MakeUnique<aura::PropertyConverter>(); |
| 44 wm_state_ = base::MakeUnique<::wm::WMState>(); | 52 wm_state_ = base::MakeUnique<::wm::WMState>(); |
| 45 | 53 |
| 46 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( | 54 OnStartImpl(window_tree_client_, window_tree_data_); |
| 47 context()->connector(), this, this); | |
| 48 window_tree_client_->ConnectAsWindowManager(); | |
| 49 | |
| 50 window_tree_data_ = base::MakeUnique<WindowTreeData>(kSquareSize); | |
| 51 | 55 |
| 52 env_->SetWindowTreeClient(window_tree_client_.get()); | 56 env_->SetWindowTreeClient(window_tree_client_.get()); |
| 53 } | 57 } |
| 54 | 58 |
| 55 bool MusDemo::OnConnect(const service_manager::ServiceInfo& remote_info, | 59 bool MusDemo::OnConnect(const service_manager::ServiceInfo& remote_info, |
| 56 service_manager::InterfaceRegistry* registry) { | 60 service_manager::InterfaceRegistry* registry) { |
| 57 return true; | 61 return true; |
| 58 } | 62 } |
| 59 | 63 |
| 60 void MusDemo::OnEmbed( | 64 void MusDemo::OnEmbed( |
| 61 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 65 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 62 // Not called for the WindowManager. | |
| 63 NOTREACHED(); | 66 NOTREACHED(); |
| 64 } | 67 } |
| 65 | 68 |
| 66 void MusDemo::OnUnembed(aura::Window* root) { | 69 void MusDemo::OnUnembed(aura::Window* root) { |
| 67 NOTREACHED(); | 70 NOTREACHED(); |
| 68 } | 71 } |
| 69 | 72 |
| 70 void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) { | 73 void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) { |
| 71 // Not called for the WindowManager. | |
| 72 NOTREACHED(); | 74 NOTREACHED(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void MusDemo::OnLostConnection(aura::WindowTreeClient* client) { | 77 void MusDemo::OnLostConnection(aura::WindowTreeClient* client) { |
| 76 window_tree_client_.reset(); | 78 window_tree_client_.reset(); |
| 77 window_tree_data_.reset(); | 79 CleanupWindowTreeData(); |
| 78 } | 80 } |
| 79 | 81 |
| 80 void MusDemo::OnPointerEventObserved(const PointerEvent& event, | 82 void MusDemo::OnPointerEventObserved(const PointerEvent& event, |
| 81 aura::Window* target) {} | 83 aura::Window* target) {} |
| 82 | 84 |
| 83 aura::PropertyConverter* MusDemo::GetPropertyConverter() { | 85 aura::PropertyConverter* MusDemo::GetPropertyConverter() { |
| 84 return property_converter_.get(); | 86 return property_converter_.get(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void MusDemo::SetWindowManagerClient(aura::WindowManagerClient* client) {} | |
| 88 | |
| 89 bool MusDemo::OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) { | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 bool MusDemo::OnWmSetProperty(aura::Window* window, | |
| 94 const std::string& name, | |
| 95 std::unique_ptr<std::vector<uint8_t>>* new_data) { | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 99 void MusDemo::OnWmSetCanFocus(aura::Window* window, bool can_focus) {} | |
| 100 | |
| 101 aura::Window* MusDemo::OnWmCreateTopLevelWindow( | |
| 102 mojom::WindowType window_type, | |
| 103 std::map<std::string, std::vector<uint8_t>>* properties) { | |
| 104 NOTREACHED(); | |
| 105 return nullptr; | |
| 106 } | |
| 107 | |
| 108 void MusDemo::OnWmClientJankinessChanged( | |
| 109 const std::set<aura::Window*>& client_windows, | |
| 110 bool janky) { | |
| 111 // Don't care | |
| 112 } | |
| 113 | |
| 114 void MusDemo::OnWmWillCreateDisplay(const display::Display& display) { | |
| 115 screen_->display_list().AddDisplay(display, | |
| 116 display::DisplayList::Type::PRIMARY); | |
| 117 } | |
| 118 | |
| 119 void MusDemo::OnWmNewDisplay( | |
| 120 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, | |
| 121 const display::Display& display) { | |
| 122 DCHECK(!window_tree_data_->IsInitialized()); // Only support one display. | |
| 123 window_tree_data_->Init(std::move(window_tree_host)); | |
| 124 } | |
| 125 | |
| 126 void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { | |
| 127 window_tree_data_.reset(); | |
| 128 } | |
| 129 | |
| 130 void MusDemo::OnWmDisplayModified(const display::Display& display) {} | |
| 131 | |
| 132 mojom::EventResult MusDemo::OnAccelerator(uint32_t id, const Event& event) { | |
| 133 return mojom::EventResult::UNHANDLED; | |
| 134 } | |
| 135 | |
| 136 void MusDemo::OnWmPerformMoveLoop(aura::Window* window, | |
| 137 mojom::MoveLoopSource source, | |
| 138 const gfx::Point& cursor_location, | |
| 139 const base::Callback<void(bool)>& on_done) { | |
| 140 // Don't care | |
| 141 } | |
| 142 | |
| 143 void MusDemo::OnWmCancelMoveLoop(aura::Window* window) {} | |
| 144 | |
| 145 void MusDemo::OnWmSetClientArea( | |
| 146 aura::Window* window, | |
| 147 const gfx::Insets& insets, | |
| 148 const std::vector<gfx::Rect>& additional_client_areas) {} | |
| 149 | |
| 150 bool MusDemo::IsWindowActive(aura::Window* window) { return false; } | |
| 151 | |
| 152 void MusDemo::OnWmDeactivateWindow(aura::Window* window) {} | |
| 153 | |
| 154 } // namespace demo | 89 } // namespace demo |
| 155 } // namespace aura | 90 } // namespace aura |
| OLD | NEW |