summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw <msw@chromium.org>2016-01-13 21:05:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-14 05:06:32 +0000
commit85273d0c56790d470d9d002990da25ae6fb9c950 (patch)
treefbfe488f0719d5e5a4c32aa1daf60db6f0b3695f
parent592c59e49f7a1c1ce7fb469dd1f7ef0d98482ad8 (diff)
downloadchromium_src-85273d0c56790d470d9d002990da25ae6fb9c950.zip
chromium_src-85273d0c56790d470d9d002990da25ae6fb9c950.tar.gz
chromium_src-85273d0c56790d470d9d002990da25ae6fb9c950.tar.bz2
Add rudimentary mash shelf functionality.
Add UserWindow[Controller|Observer] interfaces and impls. Move shelf code from mojo:system_ui to mojo:shelf. Add views_examples and task_viewer buttons to the shelf. Show buttons for open user windows; they focus on press. Cleanup mash deps tree (move data_deps from all to shell). BUG=557406 TEST=mojo:mash_shell shelf has rudimentary functionality. R=sky@chromium.org Review URL: https://codereview.chromium.org/1576683002 Cr-Commit-Position: refs/heads/master@{#369330}
-rw-r--r--mash/BUILD.gn3
-rw-r--r--mash/shelf/BUILD.gn (renamed from mash/system_ui/BUILD.gn)8
-rw-r--r--mash/shelf/main.cc (renamed from mash/system_ui/main.cc)4
-rw-r--r--mash/shelf/shelf_application.cc53
-rw-r--r--mash/shelf/shelf_application.h (renamed from mash/system_ui/system_ui.h)18
-rw-r--r--mash/shelf/shelf_view.cc98
-rw-r--r--mash/shelf/shelf_view.h62
-rw-r--r--mash/shell/BUILD.gn4
-rw-r--r--mash/shell/shell_application_delegate.cc8
-rw-r--r--mash/shell/shell_application_delegate.h2
-rw-r--r--mash/system_ui/system_ui.cc82
-rw-r--r--mash/wm/BUILD.gn2
-rw-r--r--mash/wm/public/interfaces/BUILD.gn1
-rw-r--r--mash/wm/public/interfaces/user_window_controller.mojom22
-rw-r--r--mash/wm/user_window_controller_impl.cc63
-rw-r--r--mash/wm/user_window_controller_impl.h49
-rw-r--r--mash/wm/window_manager_application.cc34
-rw-r--r--mash/wm/window_manager_application.h21
18 files changed, 422 insertions, 112 deletions
diff --git a/mash/BUILD.gn b/mash/BUILD.gn
index 8550b7c..37db36d 100644
--- a/mash/BUILD.gn
+++ b/mash/BUILD.gn
@@ -11,11 +11,8 @@ group("all") {
deps = [
":tests",
"//mash/example",
- "//mash/quick_launch",
"//mash/shell",
"//mash/task_viewer",
- "//mash/wallpaper",
- "//mash/wm",
]
}
diff --git a/mash/system_ui/BUILD.gn b/mash/shelf/BUILD.gn
index 6252901..8c316a7 100644
--- a/mash/system_ui/BUILD.gn
+++ b/mash/shelf/BUILD.gn
@@ -6,11 +6,13 @@ import("//build/config/ui.gni")
import("//mojo/public/mojo_application.gni")
import("//mojo/public/tools/bindings/mojom.gni")
-mojo_native_application("system_ui") {
+mojo_native_application("shelf") {
sources = [
"main.cc",
- "system_ui.cc",
- "system_ui.h",
+ "shelf_application.cc",
+ "shelf_application.h",
+ "shelf_view.cc",
+ "shelf_view.h",
]
deps = [
diff --git a/mash/system_ui/main.cc b/mash/shelf/main.cc
index 0c5832b..636e0e0 100644
--- a/mash/system_ui/main.cc
+++ b/mash/shelf/main.cc
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mash/system_ui/system_ui.h"
+#include "mash/shelf/shelf_application.h"
#include "mojo/public/c/system/main.h"
#include "mojo/shell/public/cpp/application_runner.h"
MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunner runner(new mash::system_ui::SystemUI);
+ mojo::ApplicationRunner runner(new mash::shelf::ShelfApplication);
return runner.Run(shell_handle);
}
diff --git a/mash/shelf/shelf_application.cc b/mash/shelf/shelf_application.cc
new file mode 100644
index 0000000..4656978
--- /dev/null
+++ b/mash/shelf/shelf_application.cc
@@ -0,0 +1,53 @@
+// Copyright 2015 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 "mash/shelf/shelf_application.h"
+
+#include <stdint.h>
+
+#include "components/mus/public/cpp/property_type_converters.h"
+#include "mash/shelf/shelf_view.h"
+#include "mash/wm/public/interfaces/container.mojom.h"
+#include "mojo/shell/public/cpp/application_impl.h"
+#include "ui/views/mus/aura_init.h"
+#include "ui/views/mus/native_widget_mus.h"
+#include "ui/views/mus/window_manager_connection.h"
+
+namespace mash {
+namespace shelf {
+
+ShelfApplication::ShelfApplication() {}
+
+ShelfApplication::~ShelfApplication() {}
+
+void ShelfApplication::Initialize(mojo::ApplicationImpl* app) {
+ tracing_.Initialize(app);
+
+ aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
+ views::WindowManagerConnection::Create(app);
+
+ views::Widget* widget = new views::Widget;
+ views::Widget::InitParams params(
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
+ params.delegate = new ShelfView(app);
+
+ 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(
+ mash::wm::mojom::CONTAINER_USER_SHELF);
+ mus::Window* window =
+ views::WindowManagerConnection::Get()->NewWindow(properties);
+ params.native_widget = new views::NativeWidgetMus(
+ widget, app->shell(), window, mus::mojom::SURFACE_TYPE_DEFAULT);
+ widget->Init(params);
+ widget->Show();
+}
+
+bool ShelfApplication::ConfigureIncomingConnection(
+ mojo::ApplicationConnection* connection) {
+ return true;
+}
+
+} // namespace shelf
+} // namespace mash
diff --git a/mash/system_ui/system_ui.h b/mash/shelf/shelf_application.h
index 86bfb22..901bdfa 100644
--- a/mash/system_ui/system_ui.h
+++ b/mash/shelf/shelf_application.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MASH_SYSTEM_UI_SYSTEM_UI_H_
-#define MASH_SYSTEM_UI_SYSTEM_UI_H_
+#ifndef MASH_SHELF_SHELF_APPLICATION_H_
+#define MASH_SHELF_SHELF_APPLICATION_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
@@ -15,12 +15,12 @@ class AuraInit;
}
namespace mash {
-namespace system_ui {
+namespace shelf {
-class SystemUI : public mojo::ApplicationDelegate {
+class ShelfApplication : public mojo::ApplicationDelegate {
public:
- SystemUI();
- ~SystemUI() override;
+ ShelfApplication();
+ ~ShelfApplication() override;
private:
// mojo::ApplicationDelegate:
@@ -32,10 +32,10 @@ class SystemUI : public mojo::ApplicationDelegate {
scoped_ptr<views::AuraInit> aura_init_;
- DISALLOW_COPY_AND_ASSIGN(SystemUI);
+ DISALLOW_COPY_AND_ASSIGN(ShelfApplication);
};
-} // namespace system_ui
+} // namespace shelf
} // namespace mash
-#endif // MASH_SYSTEM_UI_SYSTEM_UI_H_
+#endif // MASH_SHELF_SHELF_APPLICATION_H_
diff --git a/mash/shelf/shelf_view.cc b/mash/shelf/shelf_view.cc
new file mode 100644
index 0000000..6af2a5a
--- /dev/null
+++ b/mash/shelf/shelf_view.cc
@@ -0,0 +1,98 @@
+// Copyright 2015 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 "mash/shelf/shelf_view.h"
+
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "mojo/shell/public/cpp/application_impl.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/controls/button/label_button.h"
+#include "ui/views/layout/box_layout.h"
+
+namespace mash {
+namespace shelf {
+
+enum ShelfButtonID {
+ SHELF_BUTTON_VIEWS_EXAMPLES,
+ SHELF_BUTTON_TASK_VIEWER,
+};
+
+ShelfView::ShelfView(mojo::ApplicationImpl* app) : app_(app), binding_(this) {
+ app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
+
+ mash::wm::mojom::UserWindowObserverPtr observer;
+ mojo::InterfaceRequest<mash::wm::mojom::UserWindowObserver> request =
+ mojo::GetProxy(&observer);
+ user_window_controller_->AddUserWindowObserver(std::move(observer));
+ binding_.Bind(std::move(request));
+
+ SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
+
+ views::LabelButton* views_examples =
+ new views::LabelButton(this, base::ASCIIToUTF16("Views Examples"));
+ views_examples->set_tag(SHELF_BUTTON_VIEWS_EXAMPLES);
+ AddChildView(views_examples);
+
+ views::LabelButton* task_viewer =
+ new views::LabelButton(this, base::ASCIIToUTF16("Task Viewer"));
+ task_viewer->set_tag(SHELF_BUTTON_TASK_VIEWER);
+ AddChildView(task_viewer);
+}
+
+ShelfView::~ShelfView() {}
+
+void ShelfView::OnPaint(gfx::Canvas* canvas) {
+ canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
+ views::View::OnPaint(canvas);
+}
+
+gfx::Size ShelfView::GetPreferredSize() const {
+ return gfx::Size(1, 48);
+}
+
+views::View* ShelfView::GetContentsView() {
+ return this;
+}
+
+void ShelfView::ButtonPressed(views::Button* sender, const ui::Event& event) {
+ if (sender->tag() == SHELF_BUTTON_VIEWS_EXAMPLES)
+ app_->ConnectToApplication("mojo:views_examples");
+ else if (sender->tag() == SHELF_BUTTON_TASK_VIEWER)
+ app_->ConnectToApplication("mojo:task_viewer");
+ else
+ user_window_controller_->FocusUserWindow(sender->tag());
+}
+
+void ShelfView::OnUserWindowObserverAdded(mojo::Array<uint32_t> window_ids) {
+ for (size_t i = 0; i < window_ids.size(); ++i)
+ OnUserWindowAdded(window_ids[i]);
+}
+
+void ShelfView::OnUserWindowAdded(uint32_t window_id) {
+ // TODO(msw): Get the actual window title and icon.
+ views::LabelButton* open_window_button = new views::LabelButton(
+ this, base::ASCIIToUTF16(base::StringPrintf("Window %d", window_id)));
+ open_window_button->set_tag(window_id);
+ open_window_buttons_.push_back(open_window_button);
+ AddChildView(open_window_button);
+ Layout();
+ SchedulePaint();
+}
+
+void ShelfView::OnUserWindowRemoved(uint32_t window_id) {
+ for (size_t i = 0; i < open_window_buttons_.size(); ++i) {
+ if (static_cast<uint32_t>(open_window_buttons_[i]->tag()) == window_id) {
+ views::LabelButton* button = open_window_buttons_[i];
+ open_window_buttons_.erase(open_window_buttons_.begin() + i);
+ RemoveChildView(button);
+ delete button;
+ return;
+ }
+ }
+}
+
+} // namespace shelf
+} // namespace mash
diff --git a/mash/shelf/shelf_view.h b/mash/shelf/shelf_view.h
new file mode 100644
index 0000000..f631dbd
--- /dev/null
+++ b/mash/shelf/shelf_view.h
@@ -0,0 +1,62 @@
+// Copyright 2015 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.
+
+#ifndef MASH_SHELF_SHELF_VIEW_H_
+#define MASH_SHELF_SHELF_VIEW_H_
+
+#include <stdint.h>
+
+#include "base/macros.h"
+#include "mash/wm/public/interfaces/user_window_controller.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "ui/views/controls/button/button.h"
+#include "ui/views/widget/widget_delegate.h"
+
+namespace mojo {
+class ApplicationImpl;
+}
+
+namespace views {
+class LabelButton;
+}
+
+namespace mash {
+namespace shelf {
+
+// A rudimentary mash shelf, used to build up the required wm interfaces.
+class ShelfView : public views::WidgetDelegateView,
+ public views::ButtonListener,
+ public mash::wm::mojom::UserWindowObserver {
+ public:
+ explicit ShelfView(mojo::ApplicationImpl* app);
+ ~ShelfView() override;
+
+ private:
+ // Overridden from views::View:
+ void OnPaint(gfx::Canvas* canvas) override;
+ gfx::Size GetPreferredSize() const override;
+
+ // Overridden from views::WidgetDelegate:
+ views::View* GetContentsView() override;
+
+ // Overridden from views::ButtonListener:
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+
+ // Overridden from mash::wm::mojom::UserWindowObserver:
+ void OnUserWindowObserverAdded(mojo::Array<uint32_t> window_ids) override;
+ void OnUserWindowAdded(uint32_t window_id) override;
+ void OnUserWindowRemoved(uint32_t window_id) override;
+
+ mojo::ApplicationImpl* app_;
+ std::vector<views::LabelButton*> open_window_buttons_;
+ mash::wm::mojom::UserWindowControllerPtr user_window_controller_;
+ mojo::Binding<mash::wm::mojom::UserWindowObserver> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfView);
+};
+
+} // namespace shelf
+} // namespace mash
+
+#endif // MASH_SHELF_SHELF_VIEW_H_
diff --git a/mash/shell/BUILD.gn b/mash/shell/BUILD.gn
index 2a4b763..25487bd 100644
--- a/mash/shell/BUILD.gn
+++ b/mash/shell/BUILD.gn
@@ -25,7 +25,9 @@ mojo_native_application("shell") {
data_deps = [
"//mash/browser_driver",
- "//mash/system_ui",
+ "//mash/quick_launch",
+ "//mash/shelf",
+ "//mash/wallpaper",
"//mash/wm",
]
}
diff --git a/mash/shell/shell_application_delegate.cc b/mash/shell/shell_application_delegate.cc
index 11f5cb7..6672295 100644
--- a/mash/shell/shell_application_delegate.cc
+++ b/mash/shell/shell_application_delegate.cc
@@ -20,7 +20,7 @@ void ShellApplicationDelegate::Initialize(mojo::ApplicationImpl* app) {
StartBrowserDriver();
StartWindowManager();
StartWallpaper();
- StartSystemUI();
+ StartShelf();
StartQuickLaunch();
}
@@ -42,9 +42,9 @@ void ShellApplicationDelegate::StartWallpaper() {
base::Unretained(this)));
}
-void ShellApplicationDelegate::StartSystemUI() {
- StartRestartableService("mojo:system_ui",
- base::Bind(&ShellApplicationDelegate::StartSystemUI,
+void ShellApplicationDelegate::StartShelf() {
+ StartRestartableService("mojo:shelf",
+ base::Bind(&ShellApplicationDelegate::StartShelf,
base::Unretained(this)));
}
diff --git a/mash/shell/shell_application_delegate.h b/mash/shell/shell_application_delegate.h
index cca181d..c2230dd 100644
--- a/mash/shell/shell_application_delegate.h
+++ b/mash/shell/shell_application_delegate.h
@@ -32,7 +32,7 @@ class ShellApplicationDelegate : public mojo::ApplicationDelegate {
void StartWindowManager();
void StartWallpaper();
- void StartSystemUI();
+ void StartShelf();
void StartBrowserDriver();
void StartQuickLaunch();
diff --git a/mash/system_ui/system_ui.cc b/mash/system_ui/system_ui.cc
deleted file mode 100644
index 6761365..0000000
--- a/mash/system_ui/system_ui.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2015 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 "mash/system_ui/system_ui.h"
-
-#include <stdint.h>
-
-#include "base/macros.h"
-#include "components/mus/public/cpp/property_type_converters.h"
-#include "mash/wm/public/interfaces/container.mojom.h"
-#include "mojo/shell/public/cpp/application_connection.h"
-#include "mojo/shell/public/cpp/application_impl.h"
-#include "ui/gfx/canvas.h"
-#include "ui/views/mus/aura_init.h"
-#include "ui/views/mus/native_widget_mus.h"
-#include "ui/views/mus/window_manager_connection.h"
-#include "ui/views/widget/widget_delegate.h"
-
-namespace mash {
-namespace system_ui {
-namespace {
-
-class Shelf : public views::WidgetDelegateView {
- public:
- static void Create(mojo::Shell* shell) {
- views::Widget* widget = new views::Widget;
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.delegate = new Shelf;
-
- 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(
- mash::wm::mojom::CONTAINER_USER_SHELF);
- mus::Window* window =
- views::WindowManagerConnection::Get()->NewWindow(properties);
- params.native_widget = new views::NativeWidgetMus(
- widget, shell, window, mus::mojom::SURFACE_TYPE_DEFAULT);
- widget->Init(params);
- widget->Show();
- }
-
- private:
- Shelf() {}
- ~Shelf() override {}
-
- // Overridden from views::View:
- void OnPaint(gfx::Canvas* canvas) override {
- canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
- }
- gfx::Size GetPreferredSize() const override { return gfx::Size(1, 48); }
-
- // Overridden from views::WidgetDelegate:
- views::View* GetContentsView() override { return this; }
-
- DISALLOW_COPY_AND_ASSIGN(Shelf);
-};
-
-} // namespace
-
-SystemUI::SystemUI() {}
-
-SystemUI::~SystemUI() {
-}
-
-void SystemUI::Initialize(mojo::ApplicationImpl* app) {
- tracing_.Initialize(app);
-
- aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
- views::WindowManagerConnection::Create(app);
-
- Shelf::Create(app->shell());
-}
-
-bool SystemUI::ConfigureIncomingConnection(
- mojo::ApplicationConnection* connection) {
- return true;
-}
-
-} // namespace system_ui
-} // namespace mash
diff --git a/mash/wm/BUILD.gn b/mash/wm/BUILD.gn
index 9beaa14e..e9d54ae 100644
--- a/mash/wm/BUILD.gn
+++ b/mash/wm/BUILD.gn
@@ -50,6 +50,8 @@ source_set("lib") {
"shadow_controller.h",
"shelf_layout.cc",
"shelf_layout.h",
+ "user_window_controller_impl.cc",
+ "user_window_controller_impl.h",
"window_layout.cc",
"window_layout.h",
"window_manager_application.cc",
diff --git a/mash/wm/public/interfaces/BUILD.gn b/mash/wm/public/interfaces/BUILD.gn
index e778f37..65b21b4 100644
--- a/mash/wm/public/interfaces/BUILD.gn
+++ b/mash/wm/public/interfaces/BUILD.gn
@@ -7,5 +7,6 @@ import("//mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"container.mojom",
+ "user_window_controller.mojom",
]
}
diff --git a/mash/wm/public/interfaces/user_window_controller.mojom b/mash/wm/public/interfaces/user_window_controller.mojom
new file mode 100644
index 0000000..9ec33ec
--- /dev/null
+++ b/mash/wm/public/interfaces/user_window_controller.mojom
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+module mash.wm.mojom;
+
+// An observer of user windows within mojom::CONTAINER_USER_WINDOWS.
+// TODO(msw): Observe focus changes, title/icon changes, etc.
+interface UserWindowObserver {
+ // Called when the observer is first added to supply the initial state.
+ OnUserWindowObserverAdded(array<uint32> window_ids);
+
+ OnUserWindowAdded(uint32 window_id);
+ OnUserWindowRemoved(uint32 window_id);
+};
+
+// An interface allowing system UIs to manage the set of user windows.
+// TODO(msw): Add minimization, restoration, opening a chooser view, etc.
+interface UserWindowController {
+ AddUserWindowObserver(UserWindowObserver observer);
+ FocusUserWindow(uint32 window_id);
+}; \ No newline at end of file
diff --git a/mash/wm/user_window_controller_impl.cc b/mash/wm/user_window_controller_impl.cc
new file mode 100644
index 0000000..d4181fb
--- /dev/null
+++ b/mash/wm/user_window_controller_impl.cc
@@ -0,0 +1,63 @@
+// Copyright 2015 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 "mash/wm/user_window_controller_impl.h"
+
+#include "components/mus/public/cpp/window.h"
+#include "mash/wm/public/interfaces/container.mojom.h"
+#include "mash/wm/window_manager_application.h"
+
+namespace mash {
+namespace wm {
+
+UserWindowControllerImpl::UserWindowControllerImpl() : state_(nullptr) {}
+
+UserWindowControllerImpl::~UserWindowControllerImpl() {
+ if (state_)
+ GetUserWindowContainer()->RemoveObserver(this);
+}
+
+void UserWindowControllerImpl::Initialize(WindowManagerApplication* state) {
+ DCHECK(state);
+ DCHECK(!state_);
+ state_ = state;
+ GetUserWindowContainer()->AddObserver(this);
+}
+
+mus::Window* UserWindowControllerImpl::GetUserWindowContainer() const {
+ return state_->GetWindowForContainer(mojom::CONTAINER_USER_WINDOWS);
+}
+
+void UserWindowControllerImpl::OnTreeChanging(const TreeChangeParams& params) {
+ DCHECK(state_);
+ if (user_window_observer_) {
+ mus::Window* user_window_container = GetUserWindowContainer();
+ if (params.new_parent == user_window_container)
+ user_window_observer_->OnUserWindowAdded(params.target->id());
+ else if (params.old_parent == user_window_container)
+ user_window_observer_->OnUserWindowRemoved(params.target->id());
+ }
+}
+
+void UserWindowControllerImpl::AddUserWindowObserver(
+ mash::wm::mojom::UserWindowObserverPtr observer) {
+ // TODO(msw): Support multiple observers.
+ user_window_observer_ = std::move(observer);
+
+ const mus::Window::Children& windows = GetUserWindowContainer()->children();
+ mojo::Array<uint32_t> user_windows =
+ mojo::Array<uint32_t>::New(windows.size());
+ for (size_t i = 0; i < windows.size(); ++i)
+ user_windows[i] = windows[i]->id();
+ user_window_observer_->OnUserWindowObserverAdded(std::move(user_windows));
+}
+
+void UserWindowControllerImpl::FocusUserWindow(uint32_t window_id) {
+ mus::Window* window = GetUserWindowContainer()->GetChildById(window_id);
+ if (window)
+ window->SetFocus();
+}
+
+} // namespace wm
+} // namespace mash
diff --git a/mash/wm/user_window_controller_impl.h b/mash/wm/user_window_controller_impl.h
new file mode 100644
index 0000000..1737b61
--- /dev/null
+++ b/mash/wm/user_window_controller_impl.h
@@ -0,0 +1,49 @@
+// Copyright 2015 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.
+
+#ifndef MASH_WM_USER_WINDOW_CONTROLLER_IMPL_H_
+#define MASH_WM_USER_WINDOW_CONTROLLER_IMPL_H_
+
+#include <stdint.h>
+
+#include "base/macros.h"
+#include "components/mus/common/types.h"
+#include "components/mus/public/cpp/window_observer.h"
+#include "mash/wm/public/interfaces/user_window_controller.mojom.h"
+
+namespace mash {
+namespace wm {
+
+class WindowManagerApplication;
+
+class UserWindowControllerImpl : public mash::wm::mojom::UserWindowController,
+ public mus::WindowObserver {
+ public:
+ UserWindowControllerImpl();
+ ~UserWindowControllerImpl() override;
+
+ void Initialize(WindowManagerApplication* state);
+
+ private:
+ // A helper to get the container for user windows.
+ mus::Window* GetUserWindowContainer() const;
+
+ // mus::WindowObserver:
+ void OnTreeChanging(const TreeChangeParams& params) override;
+
+ // mash::wm::mojom::UserWindowController:
+ void AddUserWindowObserver(
+ mash::wm::mojom::UserWindowObserverPtr observer) override;
+ void FocusUserWindow(uint32_t window_id) override;
+
+ WindowManagerApplication* state_;
+ mash::wm::mojom::UserWindowObserverPtr user_window_observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(UserWindowControllerImpl);
+};
+
+} // namespace wm
+} // namespace mash
+
+#endif // MASH_WM_USER_WINDOW_CONTROLLER_IMPL_H_
diff --git a/mash/wm/window_manager_application.cc b/mash/wm/window_manager_application.cc
index 748bc48..4436e2e 100644
--- a/mash/wm/window_manager_application.cc
+++ b/mash/wm/window_manager_application.cc
@@ -17,6 +17,7 @@
#include "mash/wm/background_layout.h"
#include "mash/wm/shadow_controller.h"
#include "mash/wm/shelf_layout.h"
+#include "mash/wm/user_window_controller_impl.h"
#include "mash/wm/window_layout.h"
#include "mash/wm/window_manager_impl.h"
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
@@ -79,8 +80,10 @@ void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) {
window_manager_.reset(new WindowManagerImpl());
// Don't bind to the WindowManager immediately. Wait for OnEmbed() first.
mus::mojom::WindowManagerPtr window_manager;
- requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>(
- mojo::GetProxy(&window_manager)));
+ requests_.push_back(
+ make_scoped_ptr(new mojo::InterfaceRequest<mus::mojom::WindowManager>(
+ mojo::GetProxy(&window_manager))));
+ user_window_controller_.reset(new UserWindowControllerImpl());
mus::mojom::WindowTreeHostClientPtr host_client;
host_client_binding_.Bind(GetProxy(&host_client));
mus::CreateSingleWindowTreeHost(app, std::move(host_client), this,
@@ -90,6 +93,7 @@ void WindowManagerApplication::Initialize(mojo::ApplicationImpl* app) {
bool WindowManagerApplication::ConfigureIncomingConnection(
mojo::ApplicationConnection* connection) {
+ connection->AddService<mash::wm::mojom::UserWindowController>(this);
connection->AddService<mus::mojom::AcceleratorRegistrar>(this);
connection->AddService<mus::mojom::WindowManager>(this);
return true;
@@ -132,11 +136,17 @@ void WindowManagerApplication::OnEmbed(mus::Window* root) {
aura_init_.reset(new views::AuraInit(app_, "mash_wm_resources.pak"));
window_manager_->Initialize(this);
- for (auto request : requests_)
+ for (auto& request : requests_)
window_manager_binding_.AddBinding(window_manager_.get(),
std::move(*request));
requests_.clear();
+ user_window_controller_->Initialize(this);
+ for (auto& request : user_window_controller_requests_)
+ user_window_controller_binding_.AddBinding(user_window_controller_.get(),
+ std::move(*request));
+ user_window_controller_requests_.clear();
+
shadow_controller_.reset(new ShadowController(root->connection()));
}
@@ -149,6 +159,19 @@ void WindowManagerApplication::OnConnectionLost(
void WindowManagerApplication::Create(
mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mash::wm::mojom::UserWindowController> request) {
+ if (root_) {
+ user_window_controller_binding_.AddBinding(user_window_controller_.get(),
+ std::move(request));
+ } else {
+ user_window_controller_requests_.push_back(make_scoped_ptr(
+ new mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>(
+ std::move(request))));
+ }
+}
+
+void WindowManagerApplication::Create(
+ mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request) {
static int accelerator_registrar_count = 0;
if (accelerator_registrar_count == std::numeric_limits<int>::max()) {
@@ -173,8 +196,9 @@ void WindowManagerApplication::Create(
window_manager_binding_.AddBinding(window_manager_.get(),
std::move(request));
} else {
- requests_.push_back(new mojo::InterfaceRequest<mus::mojom::WindowManager>(
- std::move(request)));
+ requests_.push_back(
+ make_scoped_ptr(new mojo::InterfaceRequest<mus::mojom::WindowManager>(
+ std::move(request))));
}
}
diff --git a/mash/wm/window_manager_application.h b/mash/wm/window_manager_application.h
index 20593df..cf0f26c0 100644
--- a/mash/wm/window_manager_application.h
+++ b/mash/wm/window_manager_application.h
@@ -11,7 +11,6 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
#include "components/mus/common/types.h"
#include "components/mus/public/cpp/window_observer.h"
#include "components/mus/public/cpp/window_tree_delegate.h"
@@ -19,6 +18,7 @@
#include "components/mus/public/interfaces/window_manager.mojom.h"
#include "components/mus/public/interfaces/window_tree_host.mojom.h"
#include "mash/wm/public/interfaces/container.mojom.h"
+#include "mash/wm/public/interfaces/user_window_controller.mojom.h"
#include "mojo/common/weak_binding_set.h"
#include "mojo/services/tracing/public/cpp/tracing_impl.h"
#include "mojo/shell/public/cpp/application_delegate.h"
@@ -41,6 +41,7 @@ class AcceleratorRegistrarImpl;
class BackgroundLayout;
class ShadowController;
class ShelfLayout;
+class UserWindowControllerImpl;
class WindowLayout;
class WindowManagerImpl;
@@ -49,6 +50,7 @@ class WindowManagerApplication
public mus::WindowObserver,
public mus::mojom::WindowTreeHostClient,
public mus::WindowTreeDelegate,
+ public mojo::InterfaceFactory<mash::wm::mojom::UserWindowController>,
public mojo::InterfaceFactory<mus::mojom::WindowManager>,
public mojo::InterfaceFactory<mus::mojom::AcceleratorRegistrar> {
public:
@@ -86,6 +88,11 @@ class WindowManagerApplication
void OnEmbed(mus::Window* root) override;
void OnConnectionLost(mus::WindowTreeConnection* connection) override;
+ // InterfaceFactory<mash::wm::mojom::UserWindowController>:
+ void Create(mojo::ApplicationConnection* connection,
+ mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>
+ request) override;
+
// InterfaceFactory<mus::mojom::AcceleratorRegistrar>:
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mus::mojom::AcceleratorRegistrar> request)
@@ -120,7 +127,17 @@ class WindowManagerApplication
// |requests_| stores any pending WindowManager interface requests.
scoped_ptr<WindowManagerImpl> window_manager_;
mojo::WeakBindingSet<mus::mojom::WindowManager> window_manager_binding_;
- ScopedVector<mojo::InterfaceRequest<mus::mojom::WindowManager>> requests_;
+ std::vector<scoped_ptr<mojo::InterfaceRequest<mus::mojom::WindowManager>>>
+ requests_;
+
+ // |user_window_controller_| is created once OnEmbed() is called. Until that
+ // time |user_window_controller_requests_| stores pending interface requests.
+ scoped_ptr<UserWindowControllerImpl> user_window_controller_;
+ mojo::WeakBindingSet<mash::wm::mojom::UserWindowController>
+ user_window_controller_binding_;
+ std::vector<
+ scoped_ptr<mojo::InterfaceRequest<mash::wm::mojom::UserWindowController>>>
+ user_window_controller_requests_;
scoped_ptr<BackgroundLayout> background_layout_;
scoped_ptr<ShelfLayout> shelf_layout_;