OLD | NEW |
(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_application.h" |
| 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/host/ash_window_tree_host_init_params.h" |
| 9 #include "ash/host/ash_window_tree_host_platform.h" |
| 10 #include "ash/mus/shell_delegate_mus.h" |
| 11 #include "ash/mus/stub_context_factory.h" |
| 12 #include "ash/root_window_settings.h" |
| 13 #include "ash/shell.h" |
| 14 #include "ash/shell_init_params.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "ui/aura/env.h" |
| 17 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/base/ui_base_paths.h" |
| 19 #include "ui/message_center/message_center.h" |
| 20 #include "ui/platform_window/stub/stub_window.h" |
| 21 #include "ui/views/mus/aura_init.h" |
| 22 #include "ui/views/mus/native_widget_mus.h" |
| 23 #include "ui/views/mus/window_manager_connection.h" |
| 24 #include "ui/views/views_delegate.h" |
| 25 |
| 26 using views::ViewsDelegate; |
| 27 |
| 28 namespace ash { |
| 29 namespace sysui { |
| 30 |
| 31 namespace { |
| 32 |
| 33 // Creates a StubWindow, which means this window never receives any input event, |
| 34 // or displays anything to the user. |
| 35 class AshWindowTreeHostMus : public AshWindowTreeHostPlatform { |
| 36 public: |
| 37 explicit AshWindowTreeHostMus(const gfx::Rect& initial_bounds) |
| 38 : AshWindowTreeHostPlatform() { |
| 39 scoped_ptr<ui::PlatformWindow> window(new ui::StubWindow(this)); |
| 40 window->SetBounds(initial_bounds); |
| 41 SetPlatformWindow(std::move(window)); |
| 42 } |
| 43 |
| 44 ~AshWindowTreeHostMus() override {} |
| 45 |
| 46 void OnBoundsChanged(const gfx::Rect& bounds) override { |
| 47 if (platform_window()) |
| 48 AshWindowTreeHostPlatform::OnBoundsChanged(bounds); |
| 49 } |
| 50 }; |
| 51 |
| 52 AshWindowTreeHost* CreateWindowTreeHostMus( |
| 53 const AshWindowTreeHostInitParams& init_params) { |
| 54 return new AshWindowTreeHostMus(init_params.initial_bounds); |
| 55 } |
| 56 |
| 57 // Responsible for setting up a RootWindowSettings object for the root-window |
| 58 // created for the views::Widget objects. |
| 59 class NativeWidgetFactory { |
| 60 public: |
| 61 NativeWidgetFactory() { |
| 62 ViewsDelegate* views_delegate = ViewsDelegate::GetInstance(); |
| 63 DCHECK(views_delegate); |
| 64 views_delegate->set_native_widget_factory(base::Bind( |
| 65 &NativeWidgetFactory::InitNativeWidget, base::Unretained(this))); |
| 66 } |
| 67 |
| 68 ~NativeWidgetFactory() { |
| 69 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 70 ViewsDelegate::NativeWidgetFactory()); |
| 71 } |
| 72 |
| 73 private: |
| 74 views::NativeWidget* InitNativeWidget( |
| 75 const views::Widget::InitParams& params, |
| 76 views::internal::NativeWidgetDelegate* delegate) { |
| 77 views::NativeWidgetMus* native_widget = |
| 78 static_cast<views::NativeWidgetMus*>( |
| 79 views::WindowManagerConnection::Get()->CreateNativeWidgetMus( |
| 80 params, delegate)); |
| 81 // TODO: Set the correct display id here. |
| 82 InitRootWindowSettings(native_widget->GetRootWindow())->display_id = |
| 83 Shell::GetInstance() |
| 84 ->display_manager() |
| 85 ->GetPrimaryDisplayCandidate() |
| 86 .id(); |
| 87 return native_widget; |
| 88 } |
| 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(NativeWidgetFactory); |
| 91 }; |
| 92 |
| 93 } // namespace |
| 94 |
| 95 class AshInit { |
| 96 public: |
| 97 AshInit() : worker_pool_(new base::SequencedWorkerPool(2, "AshWorkerPool")) { |
| 98 ui::RegisterPathProvider(); |
| 99 ui::ResourceBundle::InitSharedInstanceWithLocale( |
| 100 "en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES); |
| 101 } |
| 102 |
| 103 ~AshInit() { worker_pool_->Shutdown(); } |
| 104 |
| 105 aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); } |
| 106 |
| 107 void Initialize(mojo::Shell* shell) { |
| 108 aura_init_.reset(new views::AuraInit(shell, "views_mus_resources.pak")); |
| 109 views::WindowManagerConnection::Create(shell); |
| 110 |
| 111 gfx::Screen* screen = gfx::Screen::GetScreen(); |
| 112 DCHECK(screen); |
| 113 gfx::Size size = screen->GetPrimaryDisplay().bounds().size(); |
| 114 |
| 115 // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash |
| 116 // installs and uses the ScreenAsh. This can be removed once ash learns to |
| 117 // talk to mus for managing displays. |
| 118 gfx::Screen::SetScreenInstance(nullptr); |
| 119 |
| 120 // Install some hook so that the WindowTreeHostMus created for widgets can |
| 121 // be hooked up correctly. |
| 122 native_widget_factory_.reset(new NativeWidgetFactory()); |
| 123 |
| 124 ash::AshWindowTreeHost::SetFactory(base::Bind(&CreateWindowTreeHostMus)); |
| 125 ash_delegate_ = new ShellDelegateMus; |
| 126 message_center::MessageCenter::Initialize(); |
| 127 |
| 128 ash::ShellInitParams init_params; |
| 129 init_params.delegate = ash_delegate_; |
| 130 init_params.context_factory = new StubContextFactory; |
| 131 init_params.blocking_pool = worker_pool_.get(); |
| 132 ash::Shell::CreateInstance(init_params); |
| 133 ash::Shell::GetInstance()->CreateShelf(); |
| 134 ash::Shell::GetInstance()->UpdateAfterLoginStatusChange( |
| 135 ash::user::LOGGED_IN_USER); |
| 136 // Reset the context factory, so that NativeWidgetMus installs the context |
| 137 // factory for the views::Widgets correctly. |
| 138 aura::Env::GetInstance()->set_context_factory(nullptr); |
| 139 |
| 140 ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); |
| 141 SetupWallpaper(SkColorSetARGB(255, 0, 255, 0)); |
| 142 } |
| 143 |
| 144 void SetupWallpaper(SkColor color) { |
| 145 SkBitmap bitmap; |
| 146 bitmap.allocN32Pixels(16, 16); |
| 147 bitmap.eraseColor(color); |
| 148 #if !defined(NDEBUG) |
| 149 // In debug builds we generate a simple pattern that allows visually |
| 150 // notice if transparency is broken. |
| 151 { |
| 152 SkAutoLockPixels alp(bitmap); |
| 153 *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0); |
| 154 } |
| 155 #endif |
| 156 gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 157 ash::Shell::GetInstance() |
| 158 ->desktop_background_controller() |
| 159 ->SetWallpaperImage(wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE); |
| 160 } |
| 161 |
| 162 private: |
| 163 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 164 scoped_ptr<views::AuraInit> aura_init_; |
| 165 ShellDelegateMus* ash_delegate_ = nullptr; |
| 166 scoped_ptr<NativeWidgetFactory> native_widget_factory_; |
| 167 |
| 168 DISALLOW_COPY_AND_ASSIGN(AshInit); |
| 169 }; |
| 170 |
| 171 SysUIApplication::SysUIApplication() {} |
| 172 |
| 173 SysUIApplication::~SysUIApplication() {} |
| 174 |
| 175 void SysUIApplication::Initialize(mojo::Shell* shell, |
| 176 const std::string& url, |
| 177 uint32_t id) { |
| 178 ash_init_.reset(new AshInit()); |
| 179 ash_init_->Initialize(shell); |
| 180 } |
| 181 |
| 182 } // namespace sysui |
| 183 } // namespace ash |
OLD | NEW |