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

Unified Diff: mash/shelf/shelf_application.cc

Issue 1576683002: Add rudimentary mash shelf functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and rebase. 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: mash/shelf/shelf_application.cc
diff --git a/mash/shelf/shelf_application.cc b/mash/shelf/shelf_application.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d563961d52cefbd2573a83370cba6e290668295
--- /dev/null
+++ b/mash/shelf/shelf_application.cc
@@ -0,0 +1,147 @@
+// 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 "base/macros.h"
+#include "base/strings/stringprintf.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/mus/public/cpp/property_type_converters.h"
+#include "components/mus/public/cpp/window.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/controls/button/label_button.h"
+#include "ui/views/layout/box_layout.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 shelf {
+
+enum ShelfButtonID {
+ SHELF_BUTTON_VIEWS_EXAMPLES,
+ SHELF_BUTTON_TASK_VIEWER,
+};
+
+// A rudimentary mash shelf, used to build up the required wm interfaces.
+class ShelfView : public views::WidgetDelegateView,
sky 2016/01/13 21:17:17 This is fine for now, but no doubt this is going t
msw 2016/01/13 22:54:56 Yeah, this is just a POC to shape initial interfac
+ public views::ButtonListener,
+ public mus::mojom::UserWindowObserver {
+ public:
+ explicit ShelfView(mojo::ApplicationImpl* app) : app_(app), binding_(this) {
+ app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
+
+ mus::mojom::UserWindowObserverPtr observer;
+ mojo::InterfaceRequest<mus::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 =
sky 2016/01/13 21:17:17 If you click one of these buttons do you end up wi
msw 2016/01/13 22:54:56 Yes, these are just simple examples to launch appl
+ 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() override {}
+
+ private:
+ // Overridden from views::View:
+ void OnPaint(gfx::Canvas* canvas) override {
+ canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
+ views::View::OnPaint(canvas);
+ }
+ gfx::Size GetPreferredSize() const override { return gfx::Size(1, 48); }
+
+ // Overridden from views::WidgetDelegate:
+ views::View* GetContentsView() override { return this; }
+
+ // Overridden from views::ButtonListener:
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override {
+ 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());
+ }
+
+ // Overridden from mus::mojom::UserWindowObserver:
+ void OnUserWindowAdded(uint32_t window_id) override {
+ // 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 OnUserWindowRemoved(uint32_t window_id) override {
+ 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;
+ }
+ }
+ }
+
+ mojo::ApplicationImpl* app_;
+ std::vector<views::LabelButton*> open_window_buttons_;
+ mus::mojom::UserWindowControllerPtr user_window_controller_;
+ mojo::Binding<mus::mojom::UserWindowObserver> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(ShelfView);
+};
+
+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

Powered by Google App Engine
This is Rietveld 408576698