OLD | NEW |
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 "ash/sysui/sysui_application.h" | 5 #include "ash/sysui/sysui_application.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/display/display_manager.h" |
13 #include "ash/host/ash_window_tree_host_init_params.h" | 13 #include "ash/host/ash_window_tree_host_init_params.h" |
14 #include "ash/host/ash_window_tree_host_platform.h" | 14 #include "ash/host/ash_window_tree_host_platform.h" |
15 #include "ash/material_design/material_design_controller.h" | 15 #include "ash/material_design/material_design_controller.h" |
16 #include "ash/public/interfaces/ash_window_type.mojom.h" | 16 #include "ash/public/interfaces/ash_window_type.mojom.h" |
17 #include "ash/public/interfaces/container.mojom.h" | 17 #include "ash/public/interfaces/container.mojom.h" |
18 #include "ash/root_window_settings.h" | 18 #include "ash/root_window_settings.h" |
19 #include "ash/shell.h" | 19 #include "ash/shell.h" |
20 #include "ash/shell_init_params.h" | 20 #include "ash/shell_init_params.h" |
21 #include "ash/shell_window_ids.h" | 21 #include "ash/shell_window_ids.h" |
22 #include "ash/sysui/app_list_presenter_mus.h" | 22 #include "ash/sysui/app_list_presenter_mus.h" |
23 #include "ash/sysui/keyboard_ui_mus.h" | 23 #include "ash/sysui/keyboard_ui_mus.h" |
24 #include "ash/sysui/shelf_delegate_mus.h" | 24 #include "ash/sysui/shelf_delegate_mus.h" |
25 #include "ash/sysui/shell_delegate_mus.h" | 25 #include "ash/sysui/shell_delegate_mus.h" |
26 #include "ash/sysui/stub_context_factory.h" | 26 #include "ash/sysui/stub_context_factory.h" |
| 27 #include "ash/sysui/user_wallpaper_delegate_mus.h" |
27 #include "base/bind.h" | 28 #include "base/bind.h" |
28 #include "base/files/file_path.h" | 29 #include "base/files/file_path.h" |
29 #include "base/path_service.h" | 30 #include "base/path_service.h" |
30 #include "base/threading/sequenced_worker_pool.h" | 31 #include "base/threading/sequenced_worker_pool.h" |
31 #include "components/mus/public/cpp/property_type_converters.h" | 32 #include "components/mus/public/cpp/property_type_converters.h" |
32 #include "services/catalog/public/cpp/resource_loader.h" | 33 #include "services/catalog/public/cpp/resource_loader.h" |
33 #include "services/shell/public/cpp/connector.h" | 34 #include "services/shell/public/cpp/connector.h" |
34 #include "ui/aura/env.h" | 35 #include "ui/aura/env.h" |
35 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
36 #include "ui/base/ui_base_paths.h" | 37 #include "ui/base/ui_base_paths.h" |
| 38 #include "ui/display/display.h" |
| 39 #include "ui/display/screen.h" |
37 #include "ui/message_center/message_center.h" | 40 #include "ui/message_center/message_center.h" |
38 #include "ui/platform_window/stub/stub_window.h" | 41 #include "ui/platform_window/stub/stub_window.h" |
39 #include "ui/views/mus/aura_init.h" | 42 #include "ui/views/mus/aura_init.h" |
40 #include "ui/views/mus/native_widget_mus.h" | 43 #include "ui/views/mus/native_widget_mus.h" |
41 #include "ui/views/mus/window_manager_connection.h" | 44 #include "ui/views/mus/window_manager_connection.h" |
42 #include "ui/views/views_delegate.h" | 45 #include "ui/views/views_delegate.h" |
43 | 46 |
44 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
45 #include "chromeos/audio/cras_audio_handler.h" | 48 #include "chromeos/audio/cras_audio_handler.h" |
46 #include "chromeos/dbus/dbus_thread_manager.h" | 49 #include "chromeos/dbus/dbus_thread_manager.h" |
47 #include "device/bluetooth/dbus/bluez_dbus_manager.h" | 50 #include "device/bluetooth/dbus/bluez_dbus_manager.h" |
48 #include "ui/events/devices/device_data_manager.h" | 51 #include "ui/events/devices/device_data_manager.h" |
49 #endif | 52 #endif |
50 | 53 |
51 using views::ViewsDelegate; | 54 using views::ViewsDelegate; |
52 | 55 |
53 namespace ash { | 56 namespace ash { |
54 namespace sysui { | 57 namespace sysui { |
55 | 58 |
56 namespace { | 59 namespace { |
57 | 60 |
58 const char kResourceFileStrings[] = "ash_resources_strings.pak"; | 61 const char kResourceFileStrings[] = "ash_resources_strings.pak"; |
59 const char kResourceFile100[] = "ash_resources_100_percent.pak"; | 62 const char kResourceFile100[] = "ash_resources_100_percent.pak"; |
60 const char kResourceFile200[] = "ash_resources_200_percent.pak"; | 63 const char kResourceFile200[] = "ash_resources_200_percent.pak"; |
61 | 64 |
62 // Tries to determine the corresponding mash container from widget init params. | 65 // Tries to determine the corresponding mash container from widget init params. |
63 mojom::Container GetContainerId(const views::Widget::InitParams& params) { | 66 ash::mojom::Container GetContainerId(const views::Widget::InitParams& params) { |
64 const int id = params.parent->id(); | 67 const int id = params.parent->id(); |
65 if (id == kShellWindowId_DesktopBackgroundContainer) | 68 if (id == kShellWindowId_DesktopBackgroundContainer) |
66 return mojom::Container::USER_BACKGROUND; | 69 return ash::mojom::Container::USER_BACKGROUND; |
67 if (id == kShellWindowId_ShelfContainer) | 70 if (id == kShellWindowId_ShelfContainer) |
68 return mojom::Container::USER_PRIVATE_SHELF; | 71 return ash::mojom::Container::USER_PRIVATE_SHELF; |
69 if (id == kShellWindowId_StatusContainer) | 72 if (id == kShellWindowId_StatusContainer) |
70 return mojom::Container::STATUS; | 73 return ash::mojom::Container::STATUS; |
71 | 74 |
72 // Determine the container based on Widget type. | 75 // Determine the container based on Widget type. |
73 switch (params.type) { | 76 switch (params.type) { |
74 case views::Widget::InitParams::Type::TYPE_BUBBLE: | 77 case views::Widget::InitParams::Type::TYPE_BUBBLE: |
75 return mojom::Container::BUBBLES; | 78 return ash::mojom::Container::BUBBLES; |
76 case views::Widget::InitParams::Type::TYPE_MENU: | 79 case views::Widget::InitParams::Type::TYPE_MENU: |
77 return mojom::Container::MENUS; | 80 return ash::mojom::Container::MENUS; |
78 case views::Widget::InitParams::Type::TYPE_TOOLTIP: | 81 case views::Widget::InitParams::Type::TYPE_TOOLTIP: |
79 return mojom::Container::DRAG_AND_TOOLTIPS; | 82 return ash::mojom::Container::DRAG_AND_TOOLTIPS; |
80 default: | 83 default: |
81 return mojom::Container::COUNT; | 84 return ash::mojom::Container::COUNT; |
82 } | 85 } |
83 } | 86 } |
84 | 87 |
85 // Tries to determine the corresponding ash window type from the ash container | 88 // Tries to determine the corresponding ash window type from the ash container |
86 // for the widget. | 89 // for the widget. |
87 mojom::AshWindowType GetAshWindowType(aura::Window* container) { | 90 ash::mojom::AshWindowType GetAshWindowType(aura::Window* container) { |
88 DCHECK(container); | 91 DCHECK(container); |
89 int id = container->id(); | 92 int id = container->id(); |
90 if (id == kShellWindowId_ShelfContainer) | 93 if (id == kShellWindowId_ShelfContainer) |
91 return mojom::AshWindowType::SHELF; | 94 return ash::mojom::AshWindowType::SHELF; |
92 if (id == kShellWindowId_StatusContainer) | 95 if (id == kShellWindowId_StatusContainer) |
93 return mojom::AshWindowType::STATUS_AREA; | 96 return ash::mojom::AshWindowType::STATUS_AREA; |
94 return mojom::AshWindowType::COUNT; | 97 return ash::mojom::AshWindowType::COUNT; |
95 } | 98 } |
96 | 99 |
97 // Creates a StubWindow, which means this window never receives any input event, | 100 // Creates a StubWindow, which means this window never receives any input event, |
98 // or displays anything to the user. | 101 // or displays anything to the user. |
99 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { | 102 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { |
100 public: | 103 public: |
101 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) | 104 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) |
102 : AshWindowTreeHostPlatform() { | 105 : AshWindowTreeHostPlatform() { |
103 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); | 106 std::unique_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); |
104 window->SetBounds(initial_bounds); | 107 window->SetBounds(initial_bounds); |
(...skipping 28 matching lines...) Expand all Loading... |
133 ViewsDelegate::GetInstance()->set_native_widget_factory( | 136 ViewsDelegate::GetInstance()->set_native_widget_factory( |
134 ViewsDelegate::NativeWidgetFactory()); | 137 ViewsDelegate::NativeWidgetFactory()); |
135 } | 138 } |
136 | 139 |
137 private: | 140 private: |
138 views::NativeWidget* InitNativeWidget( | 141 views::NativeWidget* InitNativeWidget( |
139 const views::Widget::InitParams& params, | 142 const views::Widget::InitParams& params, |
140 views::internal::NativeWidgetDelegate* delegate) { | 143 views::internal::NativeWidgetDelegate* delegate) { |
141 std::map<std::string, std::vector<uint8_t>> properties; | 144 std::map<std::string, std::vector<uint8_t>> properties; |
142 if (params.parent) { | 145 if (params.parent) { |
143 mojom::Container container = GetContainerId(params); | 146 ash::mojom::Container container = GetContainerId(params); |
144 if (container != mojom::Container::COUNT) { | 147 if (container != ash::mojom::Container::COUNT) { |
145 properties[mojom::kWindowContainer_Property] = | 148 properties[ash::mojom::kWindowContainer_Property] = |
146 mojo::ConvertTo<std::vector<uint8_t>>( | 149 mojo::ConvertTo<std::vector<uint8_t>>( |
147 static_cast<int32_t>(container)); | 150 static_cast<int32_t>(container)); |
148 } | 151 } |
149 mojom::AshWindowType type = GetAshWindowType(params.parent); | 152 ash::mojom::AshWindowType type = GetAshWindowType(params.parent); |
150 if (type != mojom::AshWindowType::COUNT) { | 153 if (type != ash::mojom::AshWindowType::COUNT) { |
151 properties[mojom::kAshWindowType_Property] = | 154 properties[ash::mojom::kAshWindowType_Property] = |
152 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); | 155 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<int32_t>(type)); |
153 } | 156 } |
154 } | 157 } |
155 | 158 |
156 // AshInit installs a stub implementation of ui::ContextFactory, so that the | 159 // AshInit installs a stub implementation of ui::ContextFactory, so that the |
157 // AshWindowTreeHost instances created do not actually show anything to the | 160 // AshWindowTreeHost instances created do not actually show anything to the |
158 // user. However, when creating a views::Widget instance, the | 161 // user. However, when creating a views::Widget instance, the |
159 // WindowManagerConnection creates a WindowTreeHostMus instance, which | 162 // WindowManagerConnection creates a WindowTreeHostMus instance, which |
160 // creates a ui::Compositor, and it needs a real ui::ContextFactory | 163 // creates a ui::Compositor, and it needs a real ui::ContextFactory |
161 // implementation. So, unset the context-factory here temporarily when | 164 // implementation. So, unset the context-factory here temporarily when |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 init_params.context_factory = new StubContextFactory; | 231 init_params.context_factory = new StubContextFactory; |
229 init_params.blocking_pool = worker_pool_.get(); | 232 init_params.blocking_pool = worker_pool_.get(); |
230 init_params.in_mus = true; | 233 init_params.in_mus = true; |
231 init_params.keyboard_factory = | 234 init_params.keyboard_factory = |
232 base::Bind(&KeyboardUIMus::Create, connector); | 235 base::Bind(&KeyboardUIMus::Create, connector); |
233 Shell::CreateInstance(init_params); | 236 Shell::CreateInstance(init_params); |
234 Shell::GetInstance()->CreateShelf(); | 237 Shell::GetInstance()->CreateShelf(); |
235 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER); | 238 Shell::GetInstance()->UpdateAfterLoginStatusChange(user::LOGGED_IN_USER); |
236 | 239 |
237 Shell::GetPrimaryRootWindow()->GetHost()->Show(); | 240 Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
238 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); | |
239 } | 241 } |
240 | 242 |
241 void InitializeResourceBundle(::shell::Connector* connector) { | 243 void InitializeResourceBundle(::shell::Connector* connector) { |
242 if (ui::ResourceBundle::HasSharedInstance()) | 244 if (ui::ResourceBundle::HasSharedInstance()) |
243 return; | 245 return; |
244 | 246 |
245 std::set<std::string> resource_paths; | 247 std::set<std::string> resource_paths; |
246 resource_paths.insert(kResourceFileStrings); | 248 resource_paths.insert(kResourceFileStrings); |
247 resource_paths.insert(kResourceFile100); | 249 resource_paths.insert(kResourceFile100); |
248 resource_paths.insert(kResourceFile200); | 250 resource_paths.insert(kResourceFile200); |
249 | 251 |
250 catalog::ResourceLoader loader; | 252 catalog::ResourceLoader loader; |
251 filesystem::mojom::DirectoryPtr directory; | 253 filesystem::mojom::DirectoryPtr directory; |
252 connector->ConnectToInterface("mojo:catalog", &directory); | 254 connector->ConnectToInterface("mojo:catalog", &directory); |
253 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); | 255 CHECK(loader.OpenFiles(std::move(directory), resource_paths)); |
254 | 256 |
255 // Load ash resources and en-US strings; not 'common' (Chrome) resources. | 257 // Load ash resources and en-US strings; not 'common' (Chrome) resources. |
256 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. | 258 // TODO(msw): Check ResourceBundle::IsScaleFactorSupported; load 300% etc. |
257 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 259 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
258 loader.TakeFile(kResourceFileStrings), | 260 loader.TakeFile(kResourceFileStrings), |
259 base::MemoryMappedFile::Region::kWholeFile); | 261 base::MemoryMappedFile::Region::kWholeFile); |
260 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 262 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
261 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), | 263 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), |
262 ui::SCALE_FACTOR_100P); | 264 ui::SCALE_FACTOR_100P); |
263 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), | 265 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), |
264 ui::SCALE_FACTOR_200P); | 266 ui::SCALE_FACTOR_200P); |
265 } | 267 } |
266 | 268 |
267 void SetupWallpaper(SkColor color) { | |
268 SkBitmap bitmap; | |
269 bitmap.allocN32Pixels(16, 16); | |
270 bitmap.eraseColor(color); | |
271 #if !defined(NDEBUG) | |
272 // In debug builds we generate a simple pattern that allows visually | |
273 // notice if transparency is broken. | |
274 { | |
275 SkAutoLockPixels alp(bitmap); | |
276 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0); | |
277 } | |
278 #endif | |
279 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
280 Shell::GetInstance()->desktop_background_controller()->SetWallpaperImage( | |
281 wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE); | |
282 } | |
283 | |
284 void InitializeComponents() { | 269 void InitializeComponents() { |
285 message_center::MessageCenter::Initialize(); | 270 message_center::MessageCenter::Initialize(); |
286 | 271 |
287 #if defined(OS_CHROMEOS) | 272 #if defined(OS_CHROMEOS) |
288 ui::DeviceDataManager::CreateInstance(); | 273 ui::DeviceDataManager::CreateInstance(); |
289 chromeos::DBusThreadManager::Initialize(); | 274 chromeos::DBusThreadManager::Initialize(); |
290 bluez::BluezDBusManager::Initialize( | 275 bluez::BluezDBusManager::Initialize( |
291 chromeos::DBusThreadManager::Get()->GetSystemBus(), | 276 chromeos::DBusThreadManager::Get()->GetSystemBus(), |
292 chromeos::DBusThreadManager::Get()->IsUsingStub( | 277 chromeos::DBusThreadManager::Get()->IsUsingStub( |
293 chromeos::DBusClientBundle::BLUETOOTH)); | 278 chromeos::DBusClientBundle::BLUETOOTH)); |
(...skipping 16 matching lines...) Expand all Loading... |
310 | 295 |
311 void SysUIApplication::Initialize(::shell::Connector* connector, | 296 void SysUIApplication::Initialize(::shell::Connector* connector, |
312 const ::shell::Identity& identity, | 297 const ::shell::Identity& identity, |
313 uint32_t id) { | 298 uint32_t id) { |
314 ash_init_.reset(new AshInit()); | 299 ash_init_.reset(new AshInit()); |
315 ash_init_->Initialize(connector, identity); | 300 ash_init_->Initialize(connector, identity); |
316 } | 301 } |
317 | 302 |
318 bool SysUIApplication::AcceptConnection(::shell::Connection* connection) { | 303 bool SysUIApplication::AcceptConnection(::shell::Connection* connection) { |
319 connection->AddInterface<mash::shelf::mojom::ShelfController>(this); | 304 connection->AddInterface<mash::shelf::mojom::ShelfController>(this); |
| 305 connection->AddInterface<mojom::WallpaperController>(this); |
320 return true; | 306 return true; |
321 } | 307 } |
322 | 308 |
323 void SysUIApplication::Create( | 309 void SysUIApplication::Create( |
324 ::shell::Connection* connection, | 310 ::shell::Connection* connection, |
325 mojo::InterfaceRequest<mash::shelf::mojom::ShelfController> request) { | 311 mash::shelf::mojom::ShelfControllerRequest request) { |
326 mash::shelf::mojom::ShelfController* shelf_controller = | 312 mash::shelf::mojom::ShelfController* shelf_controller = |
327 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); | 313 static_cast<ShelfDelegateMus*>(Shell::GetInstance()->GetShelfDelegate()); |
328 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); | 314 shelf_controller_bindings_.AddBinding(shelf_controller, std::move(request)); |
329 } | 315 } |
330 | 316 |
| 317 void SysUIApplication::Create(::shell::Connection* connection, |
| 318 mojom::WallpaperControllerRequest request) { |
| 319 mojom::WallpaperController* wallpaper_controller = |
| 320 static_cast<UserWallpaperDelegateMus*>( |
| 321 Shell::GetInstance()->user_wallpaper_delegate()); |
| 322 wallpaper_controller_bindings_.AddBinding(wallpaper_controller, |
| 323 std::move(request)); |
| 324 } |
| 325 |
331 } // namespace sysui | 326 } // namespace sysui |
332 } // namespace ash | 327 } // namespace ash |
OLD | NEW |