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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: ash/mus/sysui/sysui_application.cc
diff --git a/ash/mus/sysui/sysui_application.cc b/ash/mus/sysui/sysui_application.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4afdadd8769a279d3e07a4718c19da0c79f645d8
--- /dev/null
+++ b/ash/mus/sysui/sysui_application.cc
@@ -0,0 +1,219 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/mus/sysui/sysui_application.h"
+
+#include "ash/desktop_background/desktop_background_controller.h"
+#include "ash/host/ash_window_tree_host.h"
+#include "ash/root_window_settings.h"
+#include "ash/shell.h"
+#include "ash/shell/shell_delegate_impl.h"
+#include "ash/shell_init_params.h"
+#include "base/thread_task_runner_handle.h"
+#include "components/mus/public/cpp/property_type_converters.h"
+#include "mash/wm/public/interfaces/container.mojom.h"
+#include "mojo/shell/public/cpp/application_impl.h"
+#include "ui/aura/env.h"
+#include "ui/aura/env_observer.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/ui_base_paths.h"
+#include "ui/message_center/message_center.h"
+#include "ui/views/mus/aura_init.h"
+#include "ui/views/mus/platform_window_mus.h"
+#include "ui/views/mus/surface_context_factory.h"
+#include "ui/views/mus/window_manager_connection.h"
+#include "ui/views/test/test_views_delegate.h"
+
+#include "ash/host/ash_window_tree_host_ozone.cc" // puke
+
+namespace ash {
+namespace sysui {
+
+namespace {
+
+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
+ public:
+ AshWindowTreeHostMus(mojo::Shell* shell,
+ mus::Window* window,
+ const gfx::Rect& initial_bounds)
+ : AshWindowTreeHostOzone(initial_bounds) {
+ SetPlatformWindow(
+ make_scoped_ptr(new views::PlatformWindowMus(this, shell, window)));
+ }
+
+ ~AshWindowTreeHostMus() override {}
+};
+
+AshWindowTreeHost* CreateWindowTreeHostMus(
+ mojo::Shell* shell,
+ mus::Window* window,
+ const AshWindowTreeHostInitParams& init_params) {
+ return new AshWindowTreeHostMus(shell, window, init_params.initial_bounds);
+}
+
+class ScopedObserver {
sky 2016/02/03 22:43:48 Nit: name this better, maybe ScopedAshEnvObserver
sadrul 2016/02/04 00:03:42 Acknowledged.
+ public:
+ explicit ScopedObserver(aura::EnvObserver* observer) : observer_(observer) {
+ aura::Env::GetInstance()->AddObserver(observer_);
+ }
+ ~ScopedObserver() {
+ aura::Env::GetInstance()->RemoveObserver(observer_);
+ }
+ private:
+ aura::EnvObserver* observer_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedObserver);
+};
+
+// Responsible for setting up a RootWindowSettings object for the root-window
+// created for the views::Widget objects.
+class NativeWidgetFactory : public aura::EnvObserver {
+ public:
+ NativeWidgetFactory() : root_window_(nullptr) {
+ views::ViewsDelegate* views_delegate = views::ViewsDelegate::GetInstance();
+ DCHECK(views_delegate);
+ factory_ = views_delegate->native_widget_factory();
+ DCHECK(!factory_.is_null());
+ views_delegate->set_native_widget_factory(
+ base::Bind(&NativeWidgetFactory::InitNativeWidget,
+ base::Unretained(this)));
+ }
+
+ private:
+ views::NativeWidget* InitNativeWidget(
+ const views::Widget::InitParams& params,
+ views::internal::NativeWidgetDelegate* delegate) {
+ 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
+ DCHECK(!root_window_);
+ views::NativeWidget* native_widget = factory_.Run(params, delegate);
+ DCHECK(root_window_);
+ // TODO: Set the correct display id here.
+ InitRootWindowSettings(root_window_)->display_id =
+ Shell::GetInstance()->display_manager()->
+ GetPrimaryDisplayCandidate().id();
+ root_window_ = nullptr;
+ return native_widget;
+ }
+
+ // aura::EnvObserver:
+ void OnWindowInitialized(aura::Window* window) override {}
+ void OnHostInitialized(aura::WindowTreeHost* host) override {
+ DCHECK(!root_window_);
+ root_window_ = host->window();
+ }
+
+ aura::Window* root_window_;
+ views::ViewsDelegate::NativeWidgetFactory factory_;
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetFactory);
+};
+
+} // namespace
+
+class AshInit : public mus::WindowObserver {
+ public:
+ AshInit() {
+ ui::RegisterPathProvider();
+ ui::ResourceBundle::InitSharedInstanceWithLocale(
+ "en-US", nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
+ }
+
+ ~AshInit() override {}
+
+ aura::Window* root() { return ash::Shell::GetPrimaryRootWindow(); }
+
+ void Initialize(mojo::ApplicationImpl* app) {
+ aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
+ views::WindowManagerConnection::Create(app);
+
+ // Uninstall the ScreenMus installed by WindowManagerConnection, so that ash
+ // installs and uses the ScreenAsh. This can be removed once ash learns to
+ // talk to mus for managing displays.
+ gfx::Screen::SetScreenInstance(nullptr);
+
+ // Install some hook so that the WindowTreeHostMus created for widgets can
+ // be hooked up correctly.
+ native_widget_factory_.reset(new NativeWidgetFactory());
+
+ std::map<std::string, std::vector<uint8_t>> properties;
+ properties[mash::wm::mojom::kWindowContainer_Property] =
+ mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
+ static_cast<int32_t>(mash::wm::mojom::Container::USER_WORKSPACE));
+ mus::Window* window =
+ views::WindowManagerConnection::Get()->NewWindow(properties);
+
+ ash_delegate_ = new ash::shell::ShellDelegateImpl;
+ message_center::MessageCenter::Initialize();
+ ash::AshWindowTreeHost::SetFactory(
+ base::Bind(&CreateWindowTreeHostMus, app->shell(), window));
+
+ ash::ShellInitParams init_params;
+ init_params.delegate = ash_delegate_;
+ init_params.context_factory = new views::SurfaceContextFactory(
+ app->shell(), window, mus::mojom::SurfaceType::DEFAULT);
+ init_params.blocking_pool = nullptr; // XXX(sad):
+ ash::Shell::CreateInstance(init_params);
+ ash::Shell::GetInstance()->CreateShelf();
+ ash::Shell::GetInstance()->UpdateAfterLoginStatusChange(
+ ash::user::LOGGED_IN_USER);
+
+ ash::Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(window->bounds());
+ ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
+ SetupWallpaper(SkColorSetARGB(255, 0, 255, 0));
+ window->AddObserver(this);
+
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE,
+ base::Bind(&AshInit::SetupWallpaper, base::Unretained(this),
+ SkColorSetARGB(255, 0, 0, 255)),
+ base::TimeDelta::FromSeconds(5));
+ }
+
+ void SetupWallpaper(SkColor color) {
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(16, 16);
+ bitmap.eraseColor(color);
+#if !defined(NDEBUG)
+ // In debug builds we generate a simple pattern that allows visually
+ // notice if transparency is broken.
+ {
+ SkAutoLockPixels alp(bitmap);
+ *bitmap.getAddr32(0, 0) = SkColorSetRGB(0, 0, 0);
+ }
+#endif
+ gfx::ImageSkia wallpaper = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
+ ash::Shell::GetInstance()
+ ->desktop_background_controller()
+ ->SetWallpaperImage(wallpaper, wallpaper::WALLPAPER_LAYOUT_TILE);
+ }
+
+ private:
+ // mus::WindowObserver:
+ void OnWindowBoundsChanged(mus::Window* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) override {
+ ash::Shell::GetPrimaryRootWindow()->GetHost()->SetBounds(new_bounds);
+ }
+
+ views::Widget* widget_;
+ scoped_ptr<views::AuraInit> aura_init_;
+ ash::shell::ShellDelegateImpl* ash_delegate_ = nullptr;
+ scoped_ptr<NativeWidgetFactory> native_widget_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(AshInit);
+};
+
+SysUIApplication::SysUIApplication() {}
+
+SysUIApplication::~SysUIApplication() {}
+
+void SysUIApplication::Initialize(mojo::ApplicationImpl* app) {
+ ash_init_.reset(new AshInit());
+ ash_init_->Initialize(app);
+}
+
+bool SysUIApplication::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ return true;
+}
+
+} // namespace sysui
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698