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

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

Issue 2500973002: Converts test_wm to use aura (Closed)
Patch Set: feedback Created 4 years, 1 month 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
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 "ui/aura/env.h"
15 #include "services/ui/public/cpp/window_manager_delegate.h" 18 #include "ui/aura/mus/gpu_service.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/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"
27 #include "ui/compositor/test/context_factories_for_test.h"
18 #include "ui/display/display.h" 28 #include "ui/display/display.h"
29 #include "ui/gl/test/gl_surface_test_support.h"
30 #include "ui/wm/core/capture_controller.h"
31 #include "ui/wm/core/wm_state.h"
19 32
20 namespace ui { 33 namespace ui {
21 namespace test { 34 namespace test {
22 35
23 class TestWM : public service_manager::Service, 36 class TestWM : public service_manager::Service,
24 public ui::WindowTreeClientDelegate, 37 public aura::WindowTreeClientDelegate,
25 public ui::WindowManagerDelegate { 38 public aura::WindowManagerDelegate {
26 public: 39 public:
27 TestWM() {} 40 TestWM() { gl::GLSurfaceTestSupport::InitializeOneOff(); }
28 ~TestWM() override {} 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 }
29 50
30 private: 51 private:
31 // service_manager::Service: 52 // service_manager::Service:
32 void OnStart() override { 53 void OnStart() override {
33 window_tree_client_.reset(new ui::WindowTreeClient(this, this)); 54 aura_env_ = aura::Env::CreateInstance(aura::Env::Mode::MUS);
55 gpu_service_ = aura::GpuService::Create(context()->connector(), nullptr);
56 compositor_context_factory_ =
57 base::MakeUnique<aura::MusContextFactory>(gpu_service_.get());
58 aura_env_->set_context_factory(compositor_context_factory_.get());
59 window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>(this, this);
60 aura_env_->SetWindowTreeClient(window_tree_client_.get());
34 window_tree_client_->ConnectAsWindowManager(context()->connector()); 61 window_tree_client_->ConnectAsWindowManager(context()->connector());
35 } 62 }
36 63
37 bool OnConnect(const service_manager::ServiceInfo& remote_info, 64 bool OnConnect(const service_manager::ServiceInfo& remote_info,
38 service_manager::InterfaceRegistry* registry) override { 65 service_manager::InterfaceRegistry* registry) override {
39 return false; 66 return false;
40 } 67 }
41 68
42 // ui::WindowTreeClientDelegate: 69 // aura::WindowTreeClientDelegate:
43 void OnEmbed(ui::Window* root) override { 70 void OnEmbed(
71 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override {
44 // WindowTreeClients configured as the window manager should never get 72 // WindowTreeClients configured as the window manager should never get
45 // OnEmbed(). 73 // OnEmbed().
46 NOTREACHED(); 74 NOTREACHED();
47 } 75 }
48 void OnLostConnection(WindowTreeClient* client) override { 76 void OnLostConnection(aura::WindowTreeClient* client) override {
77 window_tree_host_.reset();
49 window_tree_client_.reset(); 78 window_tree_client_.reset();
50 } 79 }
51 void OnEmbedRootDestroyed(ui::Window* root) override { 80 void OnEmbedRootDestroyed(aura::Window* root) override {
52 // WindowTreeClients configured as the window manager should never get 81 // WindowTreeClients configured as the window manager should never get
53 // OnEmbedRootDestroyed(). 82 // OnEmbedRootDestroyed().
54 NOTREACHED(); 83 NOTREACHED();
55 } 84 }
56 void OnPointerEventObserved(const ui::PointerEvent& event, 85 void OnPointerEventObserved(const ui::PointerEvent& event,
57 ui::Window* target) override { 86 aura::Window* target) override {
58 // Don't care. 87 // Don't care.
59 } 88 }
89 aura::client::CaptureClient* GetCaptureClient() override {
90 return wm_state_.capture_controller();
91 }
92 aura::PropertyConverter* GetPropertyConverter() override {
93 return &property_converter_;
94 }
60 95
61 // ui::WindowManagerDelegate: 96 // aura::WindowManagerDelegate:
62 void SetWindowManagerClient(ui::WindowManagerClient* client) override { 97 void SetWindowManagerClient(aura::WindowManagerClient* client) override {
63 window_manager_client_ = client; 98 window_manager_client_ = client;
64 } 99 }
65 bool OnWmSetBounds(ui::Window* window, gfx::Rect* bounds) override { 100 bool OnWmSetBounds(aura::Window* window, gfx::Rect* bounds) override {
66 return true; 101 return true;
67 } 102 }
68 bool OnWmSetProperty( 103 bool OnWmSetProperty(
69 ui::Window* window, 104 aura::Window* window,
70 const std::string& name, 105 const std::string& name,
71 std::unique_ptr<std::vector<uint8_t>>* new_data) override { 106 std::unique_ptr<std::vector<uint8_t>>* new_data) override {
72 return true; 107 return true;
73 } 108 }
74 ui::Window* OnWmCreateTopLevelWindow( 109 aura::Window* OnWmCreateTopLevelWindow(
75 std::map<std::string, std::vector<uint8_t>>* properties) override { 110 std::map<std::string, std::vector<uint8_t>>* properties) override {
76 ui::Window* window = root_->window_tree()->NewWindow(properties); 111 aura::Window* window = new aura::Window(nullptr);
112 window->Init(LAYER_NOT_DRAWN);
77 window->SetBounds(gfx::Rect(10, 10, 500, 500)); 113 window->SetBounds(gfx::Rect(10, 10, 500, 500));
78 root_->AddChild(window); 114 root_->AddChild(window);
79 return window; 115 return window;
80 } 116 }
81 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, 117 void OnWmClientJankinessChanged(const std::set<aura::Window*>& client_windows,
82 bool janky) override { 118 bool janky) override {
83 // Don't care. 119 // Don't care.
84 } 120 }
85 void OnWmNewDisplay(Window* window, 121 void OnWmNewDisplay(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host,
86 const display::Display& display) override { 122 const display::Display& display) override {
87 // Only handles a single root. 123 // Only handles a single root.
88 DCHECK(!root_); 124 DCHECK(!root_);
89 root_ = window; 125 window_tree_host_ = std::move(window_tree_host);
126 root_ = window_tree_host_->window();
90 DCHECK(window_manager_client_); 127 DCHECK(window_manager_client_);
91 window_manager_client_->AddActivationParent(root_); 128 window_manager_client_->AddActivationParent(root_);
92 ui::mojom::FrameDecorationValuesPtr frame_decoration_values = 129 ui::mojom::FrameDecorationValuesPtr frame_decoration_values =
93 ui::mojom::FrameDecorationValues::New(); 130 ui::mojom::FrameDecorationValues::New();
94 frame_decoration_values->max_title_bar_button_width = 0; 131 frame_decoration_values->max_title_bar_button_width = 0;
95 window_manager_client_->SetFrameDecorationValues( 132 window_manager_client_->SetFrameDecorationValues(
96 std::move(frame_decoration_values)); 133 std::move(frame_decoration_values));
134 aura::client::SetFocusClient(root_, &focus_client_);
97 } 135 }
98 void OnWmDisplayRemoved(ui::Window* window) override { window->Destroy(); } 136 void OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) override {
137 DCHECK_EQ(window_tree_host, window_tree_host_.get());
138 window_tree_host_.reset();
139 }
99 void OnWmDisplayModified(const display::Display& display) override {} 140 void OnWmDisplayModified(const display::Display& display) override {}
100 void OnWmPerformMoveLoop(Window* window, 141 void OnWmPerformMoveLoop(aura::Window* window,
101 mojom::MoveLoopSource source, 142 mojom::MoveLoopSource source,
102 const gfx::Point& cursor_location, 143 const gfx::Point& cursor_location,
103 const base::Callback<void(bool)>& on_done) override { 144 const base::Callback<void(bool)>& on_done) override {
104 // Don't care. 145 // Don't care.
105 } 146 }
106 void OnWmCancelMoveLoop(Window* window) override {} 147 void OnWmCancelMoveLoop(aura::Window* window) override {}
107 148
108 ui::Window* root_ = nullptr; 149 std::unique_ptr<aura::Env> aura_env_;
109 ui::WindowManagerClient* window_manager_client_ = nullptr; 150 ::wm::WMState wm_state_;
110 std::unique_ptr<ui::WindowTreeClient> window_tree_client_; 151 aura::PropertyConverter property_converter_;
152 aura::test::TestFocusClient focus_client_;
153 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_;
154 aura::Window* root_ = nullptr;
155 aura::WindowManagerClient* window_manager_client_ = nullptr;
156 std::unique_ptr<aura::WindowTreeClient> window_tree_client_;
157 std::unique_ptr<aura::GpuService> gpu_service_;
158 std::unique_ptr<aura::MusContextFactory> compositor_context_factory_;
111 159
112 DISALLOW_COPY_AND_ASSIGN(TestWM); 160 DISALLOW_COPY_AND_ASSIGN(TestWM);
113 }; 161 };
114 162
115 } // namespace test 163 } // namespace test
116 } // namespace ui 164 } // namespace ui
117 165
118 MojoResult ServiceMain(MojoHandle service_request_handle) { 166 MojoResult ServiceMain(MojoHandle service_request_handle) {
119 service_manager::ServiceRunner runner(new ui::test::TestWM); 167 service_manager::ServiceRunner runner(new ui::test::TestWM);
120 return runner.Run(service_request_handle); 168 return runner.Run(service_request_handle);
121 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698