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

Side by Side Diff: ash/mus/sysui/sysui_application.cc

Issue 1645503004: [exp] ash: sysui for mash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ash-in-mus
Patch Set: . Created 4 years, 10 months 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/mus/sysui/sysui_application.h"
6
7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/host/ash_window_tree_host.h"
9 #include "ash/root_window_settings.h"
10 #include "ash/shell.h"
11 #include "ash/shell/shell_delegate_impl.h"
12 #include "ash/shell_init_params.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "components/mus/public/cpp/property_type_converters.h"
15 #include "mash/wm/public/interfaces/container.mojom.h"
16 #include "mojo/shell/public/cpp/application_impl.h"
17 #include "ui/aura/env.h"
18 #include "ui/aura/env_observer.h"
19 #include "ui/base/resource/resource_bundle.h"
20 #include "ui/base/ui_base_paths.h"
21 #include "ui/message_center/message_center.h"
22 #include "ui/views/mus/aura_init.h"
23 #include "ui/views/mus/platform_window_mus.h"
24 #include "ui/views/mus/surface_context_factory.h"
25 #include "ui/views/mus/window_manager_connection.h"
26 #include "ui/views/test/test_views_delegate.h"
27
28 #include "ash/host/ash_window_tree_host_ozone.cc" // puke
29
30 namespace ash {
31 namespace sysui {
32
33 namespace {
34
35 class AshWindowTreeHostMus : public AshWindowTreeHostOzone {
sky 2016/02/03 22:43:48 Why do we need this? I thought the model we were g
sadrul 2016/02/04 00:03:42 Yeah. We don't actually need to create a mus::Wind
36 public:
37 AshWindowTreeHostMus(mojo::Shell* shell,
38 mus::Window* window,
39 const gfx::Rect& initial_bounds)
40 : AshWindowTreeHostOzone(initial_bounds) {
41 SetPlatformWindow(
42 make_scoped_ptr(new views::PlatformWindowMus(this, shell, window)));
43 }
44
45 ~AshWindowTreeHostMus() override {}
46 };
47
48 AshWindowTreeHost* CreateWindowTreeHostMus(
49 mojo::Shell* shell,
50 mus::Window* window,
51 const AshWindowTreeHostInitParams& init_params) {
52 return new AshWindowTreeHostMus(shell, window, init_params.initial_bounds);
53 }
54
55 class ScopedObserver {
sky 2016/02/03 22:43:48 Nit: name this better, maybe ScopedAshEnvObserver
sadrul 2016/02/04 00:03:42 Acknowledged.
56 public:
57 explicit ScopedObserver(aura::EnvObserver* observer) : observer_(observer) {
58 aura::Env::GetInstance()->AddObserver(observer_);
59 }
60 ~ScopedObserver() {
61 aura::Env::GetInstance()->RemoveObserver(observer_);
62 }
63 private:
64 aura::EnvObserver* observer_;
65 DISALLOW_COPY_AND_ASSIGN(ScopedObserver);
66 };
67
68 // Responsible for setting up a RootWindowSettings object for the root-window
69 // created for the views::Widget objects.
70 class NativeWidgetFactory : public aura::EnvObserver {
71 public:
72 NativeWidgetFactory() : root_window_(nullptr) {
73 views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance();
74 DCHECK(views_delegate);
75 factory_ = views_delegate->native_widget_factory();
76 DCHECK(!factory_.is_null());
77 views_delegate->set_native_widget_factory(
78 base::Bind(&NativeWidgetFactory::InitNativeWidget,
79 base::Unretained(this)));
80 }
81
82 private:
83 views::NativeWidget* InitNativeWidget(
84 const views::Widget::InitParams& params,
85 views::internal::NativeWidgetDelegate* delegate) {
86 ScopedObserver obs(this);
sky 2016/02/03 22:43:48 Instead of digging out the factory and all that, c
sadrul 2016/02/04 00:03:42 That would be simpler, yeah. We can avoid this Sco
87 DCHECK(!root_window_);
88 views::NativeWidget* native_widget = factory_.Run(params, delegate);
89 DCHECK(root_window_);
90 // TODO: Set the correct display id here.
91 InitRootWindowSettings(root_window_)->display_id =
92 Shell::GetInstance()->display_manager()->
93 GetPrimaryDisplayCandidate().id();
94 root_window_ = nullptr;
95 return native_widget;
96 }
97
98 // aura::EnvObserver:
99 void OnWindowInitialized(aura::Window* window) override {}
100 void OnHostInitialized(aura::WindowTreeHost* host) override {
101 DCHECK(!root_window_);
102 root_window_ = host->window();
103 }
104
105 aura::Window* root_window_;
106 views::ViewsDelegate::NativeWidgetFactory factory_;
107 DISALLOW_COPY_AND_ASSIGN(NativeWidgetFactory);
108 };
109
110 } // namespace
111
112 class AshInit : public mus::WindowObserver {
113 public:
114 AshInit() {
115 ui::RegisterPathProvider();
116 ui::ResourceBundle::InitSharedInstanceWithLocale(
117 "en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
118 }
119
120 ~AshInit() override {}
121
122 aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); }
123
124 void Initialize(mojo::ApplicationImpl* app) {
125 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
126 views::WindowManagerConnection::Create(app);
127
128 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash
129 // installs and uses the ScreenAsh. This can be removed once ash learns to
130 // talk to mus for managing displays.
131 gfx::Screen::SetScreenInstance(nullptr);
132
133 // Install some hook so that the WindowTreeHostMus created for widgets can
134 // be hooked up correctly.
135 native_widget_factory_.reset(new NativeWidgetFactory());
136
137 std::map<std::string, std::vector<uint8_t>> properties;
138 properties[mash::wm::mojom::kWindowContainer_Property] =
139 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
140 static_cast<int32_t>(mash::wm::mojom::Container::USER_WORKSPACE));
141 mus::Window* window =
142 views::WindowManagerConnection::Get()->NewWindow(properties);
143
144 ash_delegate_ = new ash::shell::ShellDelegateImpl;
145 message_center::MessageCenter::Initialize();
146 ash::AshWindowTreeHost::SetFactory(
147 base::Bind(&CreateWindowTreeHostMus, app->shell(), window));
148
149 ash::ShellInitParams init_params;
150 init_params.delegate = ash_delegate_;
151 init_params.context_factory = new views::SurfaceContextFactory(
152 app->shell(), window, mus::mojom::SurfaceType::DEFAULT);
153 init_params.blocking_pool = nullptr; // XXX(sad):
154 ash::Shell::CreateInstance(init_params);
155 ash::Shell::GetInstance()->CreateShelf();
156 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
157 ash::user::LOGGED_IN_USER);
158
159 ash::Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(window->bounds());
160 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
161 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0));
162 window->AddObserver(this);
163
164 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE,
165 base::Bind(&AshInit::SetupWallpaper, base::Unretained(this),
166 SkColorSetARGB(255, 0, 0, 255)),
167 base::TimeDelta::FromSeconds(5));
168 }
169
170 void SetupWallpaper(SkColor color) {
171 SkBitmap bitmap;
172 bitmap.allocN32Pixels(16, 16);
173 bitmap.eraseColor(color);
174 #if !defined(NDEBUG)
175 // In debug builds we generate a simple pattern that allows visually
176 // notice if transparency is broken.
177 {
178 SkAutoLockPixels alp(bitmap);
179 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0);
180 }
181 #endif
182 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
183 ash::Shell::GetInstance()
184 ->desktop_background_controller()
185 ->SetWallpaperImage(wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE);
186 }
187
188 private:
189 // mus::WindowObserver:
190 void OnWindowBoundsChanged(mus::Window* window,
191 const gfx::Rect& old_bounds,
192 const gfx::Rect& new_bounds) override {
193 ash::Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(new_bounds);
194 }
195
196 views::Widget* widget_;
197 scoped_ptr<views::AuraInit> aura_init_;
198 ash::shell::ShellDelegateImpl* ash_delegate_ = nullptr;
199 scoped_ptr<NativeWidgetFactory> native_widget_factory_;
200
201 DISALLOW_COPY_AND_ASSIGN(AshInit);
202 };
203
204 SysUIApplication::SysUIApplication() {}
205
206 SysUIApplication::~SysUIApplication() {}
207
208 void SysUIApplication::Initialize(mojo::ApplicationImpl* app) {
209 ash_init_.reset(new AshInit());
210 ash_init_->Initialize(app);
211 }
212
213 bool SysUIApplication::ConfigureIncomingConnection(
214 mojo::ApplicationConnection* connection) {
215 return true;
216 }
217
218 } // namespace sysui
219 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698