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