Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: services/ui/test_wm/test_wm.cc

Issue 2500973002: Converts test_wm to use aura (Closed)
Patch Set: reference bug Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « services/ui/test_wm/manifest.json ('k') | ui/views/animation/ink_drop_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h"
9 #include "base/threading/thread_task_runner_handle.h"
8 #include "mojo/public/cpp/bindings/binding.h" 10 #include "mojo/public/cpp/bindings/binding.h"
9 #include "services/service_manager/public/c/main.h" 11 #include "services/service_manager/public/c/main.h"
10 #include "services/service_manager/public/cpp/connector.h" 12 #include "services/service_manager/public/cpp/connector.h"
11 #include "services/service_manager/public/cpp/service.h" 13 #include "services/service_manager/public/cpp/service.h"
12 #include "services/service_manager/public/cpp/service_context.h" 14 #include "services/service_manager/public/cpp/service_context.h"
13 #include "services/service_manager/public/cpp/service_runner.h" 15 #include "services/service_manager/public/cpp/service_runner.h"
14 #include "services/ui/public/cpp/window.h" 16 #include "services/ui/public/cpp/gpu/gpu_service.h"
15 #include "services/ui/public/cpp/window_manager_delegate.h" 17 #include "ui/aura/env.h"
16 #include "services/ui/public/cpp/window_tree_client.h" 18 #include "ui/aura/mus/mus_context_factory.h"
17 #include "services/ui/public/cpp/window_tree_client_delegate.h" 19 #include "ui/aura/mus/property_converter.h"
20 #include "ui/aura/mus/property_utils.h"
21 #include "ui/aura/mus/window_manager_delegate.h"
22 #include "ui/aura/mus/window_tree_client.h"
23 #include "ui/aura/mus/window_tree_client_delegate.h"
24 #include "ui/aura/mus/window_tree_host_mus.h"
25 #include "ui/aura/test/test_focus_client.h"
26 #include "ui/aura/window.h"
18 #include "ui/display/display.h" 27 #include "ui/display/display.h"
19 #include "ui/display/test/test_screen.h" 28 #include "ui/display/test/test_screen.h"
29 #include "ui/wm/core/capture_controller.h"
30 #include "ui/wm/core/wm_state.h"
20 31
21 namespace ui { 32 namespace ui {
22 namespace test { 33 namespace test {
23 34
24 class TestWM : public service_manager::Service, 35 class TestWM : public service_manager::Service,
25 public ui::WindowTreeClientDelegate, 36 public aura::WindowTreeClientDelegate,
26 public ui::WindowManagerDelegate { 37 public aura::WindowManagerDelegate {
27 public: 38 public:
28 TestWM() {} 39 TestWM() {}
29 ~TestWM() override { display::Screen::SetScreenInstance(nullptr); } 40
41 ~TestWM() override {
42 // WindowTreeHost uses state from WindowTreeClient, so destroy it first.
43 window_tree_host_.reset();
44
45 // WindowTreeClient destruction may callback to us.
46 window_tree_client_.reset();
47
48 gpu_service_.reset();
49
50 display::Screen::SetScreenInstance(nullptr);
51 }
30 52
31 private: 53 private:
32 // service_manager::Service: 54 // service_manager::Service:
33 void OnStart() override { 55 void OnStart() override {
56 CHECK(!started_);
57 started_ = true;
34 test_screen_ = base::MakeUnique<display::test::TestScreen>(); 58 test_screen_ = base::MakeUnique<display::test::TestScreen>();
35 display::Screen::SetScreenInstance(test_screen_.get()); 59 display::Screen::SetScreenInstance(test_screen_.get());
36 window_tree_client_.reset(new ui::WindowTreeClient(this, this)); 60 aura_env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
61 gpu_service_ = ui::GpuService::Create(context()->connector(), nullptr);
62 compositor_context_factory_ =
63 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
64 aura_env_->set_context_factory(compositor_context_factory_.get());
65 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>(this, this);
66 aura_env_->SetWindowTreeClient(window_tree_client_.get());
37 window_tree_client_->ConnectAsWindowManager(context()->connector()); 67 window_tree_client_->ConnectAsWindowManager(context()->connector());
38 } 68 }
39 69
40 bool OnConnect(const service_manager::ServiceInfo& remote_info, 70 bool OnConnect(const service_manager::ServiceInfo& remote_info,
41 service_manager::InterfaceRegistry* registry) override { 71 service_manager::InterfaceRegistry* registry) override {
42 return false; 72 return false;
43 } 73 }
44 74
45 // ui::WindowTreeClientDelegate: 75 // aura::WindowTreeClientDelegate:
46 void OnEmbed(ui::Window* root) override { 76 void OnEmbed(
77 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {
47 // WindowTreeClients configured as the window manager should never get 78 // WindowTreeClients configured as the window manager should never get
48 // OnEmbed(). 79 // OnEmbed().
49 NOTREACHED(); 80 NOTREACHED();
50 } 81 }
51 void OnLostConnection(WindowTreeClient* client) override { 82 void OnLostConnection(aura::WindowTreeClient* client) override {
83 window_tree_host_.reset();
52 window_tree_client_.reset(); 84 window_tree_client_.reset();
53 } 85 }
54 void OnEmbedRootDestroyed(ui::Window* root) override { 86 void OnEmbedRootDestroyed(aura::Window* root) override {
55 // WindowTreeClients configured as the window manager should never get 87 // WindowTreeClients configured as the window manager should never get
56 // OnEmbedRootDestroyed(). 88 // OnEmbedRootDestroyed().
57 NOTREACHED(); 89 NOTREACHED();
58 } 90 }
59 void OnPointerEventObserved(const ui::PointerEvent& event, 91 void OnPointerEventObserved(const ui::PointerEvent& event,
60 ui::Window* target) override { 92 aura::Window* target) override {
61 // Don't care. 93 // Don't care.
62 } 94 }
95 aura::client::CaptureClient* GetCaptureClient() override {
96 return wm_state_.capture_controller();
97 }
98 aura::PropertyConverter* GetPropertyConverter() override {
99 return &property_converter_;
100 }
63 101
64 // ui::WindowManagerDelegate: 102 // aura::WindowManagerDelegate:
65 void SetWindowManagerClient(ui::WindowManagerClient* client) override { 103 void SetWindowManagerClient(aura::WindowManagerClient* client) override {
66 window_manager_client_ = client; 104 window_manager_client_ = client;
67 } 105 }
68 bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override { 106 bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override {
69 return true; 107 return true;
70 } 108 }
71 bool OnWmSetProperty( 109 bool OnWmSetProperty(
72 ui::Window* window, 110 aura::Window* window,
73 const std::string& name, 111 const std::string& name,
74 std::unique_ptr<std::vector<uint8_t>>* new_data) override { 112 std::unique_ptr<std::vector<uint8_t>>* new_data) override {
75 return true; 113 return true;
76 } 114 }
77 ui::Window* OnWmCreateTopLevelWindow( 115 aura::Window* OnWmCreateTopLevelWindow(
116 ui::mojom::WindowType window_type,
78 std::map<std::string, std::vector<uint8_t>>* properties) override { 117 std::map<std::string, std::vector<uint8_t>>* properties) override {
79 ui::Window* window = root_->window_tree()->NewWindow(properties); 118 aura::Window* window = new aura::Window(nullptr);
119 SetWindowType(window, window_type);
120 window->Init(LAYER_NOT_DRAWN);
80 window->SetBounds(gfx::Rect(10, 10, 500, 500)); 121 window->SetBounds(gfx::Rect(10, 10, 500, 500));
81 root_->AddChild(window); 122 root_->AddChild(window);
82 return window; 123 return window;
83 } 124 }
84 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, 125 void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
85 bool janky) override { 126 bool janky) override {
86 // Don't care. 127 // Don't care.
87 } 128 }
88 void OnWmNewDisplay(Window* window, 129 void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
89 const display::Display& display) override { 130 const display::Display& display) override {
90 // Only handles a single root. 131 // Only handles a single root.
91 DCHECK(!root_); 132 DCHECK(!root_);
92 root_ = window; 133 window_tree_host_ = std::move(window_tree_host);
134 root_ = window_tree_host_->window();
93 DCHECK(window_manager_client_); 135 DCHECK(window_manager_client_);
94 window_manager_client_->AddActivationParent(root_); 136 window_manager_client_->AddActivationParent(root_);
95 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = 137 ui::mojom::FrameDecorationValuesPtr frame_decoration_values =
96 ui::mojom::FrameDecorationValues::New(); 138 ui::mojom::FrameDecorationValues::New();
97 frame_decoration_values->max_title_bar_button_width = 0; 139 frame_decoration_values->max_title_bar_button_width = 0;
98 window_manager_client_->SetFrameDecorationValues( 140 window_manager_client_->SetFrameDecorationValues(
99 std::move(frame_decoration_values)); 141 std::move(frame_decoration_values));
142 aura::client::SetFocusClient(root_, &focus_client_);
100 } 143 }
101 void OnWmDisplayRemoved(ui::Window* window) override { window->Destroy(); } 144 void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override {
145 DCHECK_EQ(window_tree_host, window_tree_host_.get());
146 root_ = nullptr;
147 window_tree_host_.reset();
148 }
102 void OnWmDisplayModified(const display::Display& display) override {} 149 void OnWmDisplayModified(const display::Display& display) override {}
103 void OnWmPerformMoveLoop(Window* window, 150 void OnWmPerformMoveLoop(aura::Window* window,
104 mojom::MoveLoopSource source, 151 mojom::MoveLoopSource source,
105 const gfx::Point& cursor_location, 152 const gfx::Point& cursor_location,
106 const base::Callback<void(bool)>& on_done) override { 153 const base::Callback<void(bool)>& on_done) override {
107 // Don't care. 154 // Don't care.
108 } 155 }
109 void OnWmCancelMoveLoop(Window* window) override {} 156 void OnWmCancelMoveLoop(aura::Window* window) override {}
110 157
111 // Dummy screen required to be the screen instance. 158 // Dummy screen required to be the screen instance.
112 std::unique_ptr<display::test::TestScreen> test_screen_; 159 std::unique_ptr<display::test::TestScreen> test_screen_;
113 160
114 ui::Window* root_ = nullptr; 161 std::unique_ptr<aura::Env> aura_env_;
115 ui::WindowManagerClient* window_manager_client_ = nullptr; 162 ::wm::WMState wm_state_;
116 std::unique_ptr<ui::WindowTreeClient> window_tree_client_; 163 aura::PropertyConverter property_converter_;
164 aura::test::TestFocusClient focus_client_;
165 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
166 aura::Window* root_ = nullptr;
167 aura::WindowManagerClient* window_manager_client_ = nullptr;
168 std::unique_ptr<aura::WindowTreeClient> window_tree_client_;
169 std::unique_ptr<ui::GpuService> gpu_service_;
170 std::unique_ptr<aura::MusContextFactory> compositor_context_factory_;
171
172 bool started_ = false;
117 173
118 DISALLOW_COPY_AND_ASSIGN(TestWM); 174 DISALLOW_COPY_AND_ASSIGN(TestWM);
119 }; 175 };
120 176
121 } // namespace test 177 } // namespace test
122 } // namespace ui 178 } // namespace ui
123 179
124 MojoResult ServiceMain(MojoHandle service_request_handle) { 180 MojoResult ServiceMain(MojoHandle service_request_handle) {
125 service_manager::ServiceRunner runner(new ui::test::TestWM); 181 service_manager::ServiceRunner runner(new ui::test::TestWM);
126 return runner.Run(service_request_handle); 182 return runner.Run(service_request_handle);
127 } 183 }
OLDNEW
« no previous file with comments | « services/ui/test_wm/manifest.json ('k') | ui/views/animation/ink_drop_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698