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

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

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

Powered by Google App Engine
This is Rietveld 408576698