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

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

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

Powered by Google App Engine
This is Rietveld 408576698