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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "mash/shelf/shelf_application.h"
6
7 #include <stdint.h>
8
9 #include "base/macros.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "components/mus/public/cpp/property_type_converters.h"
13 #include "components/mus/public/cpp/window.h"
14 #include "mash/wm/public/interfaces/container.mojom.h"
15 #include "mojo/shell/public/cpp/application_connection.h"
16 #include "mojo/shell/public/cpp/application_impl.h"
17 #include "ui/gfx/canvas.h"
18 #include "ui/views/controls/button/label_button.h"
19 #include "ui/views/layout/box_layout.h"
20 #include "ui/views/mus/aura_init.h"
21 #include "ui/views/mus/native_widget_mus.h"
22 #include "ui/views/mus/window_manager_connection.h"
23 #include "ui/views/widget/widget_delegate.h"
24
25 namespace mash {
26 namespace shelf {
27
28 enum ShelfButtonID {
29 SHELF_BUTTON_VIEWS_EXAMPLES,
30 SHELF_BUTTON_TASK_VIEWER,
31 };
32
33 // A rudimentary mash shelf, used to build up the required wm interfaces.
34 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
35 public views::ButtonListener,
36 public mus::mojom::UserWindowObserver {
37 public:
38 explicit ShelfView(mojo::ApplicationImpl* app) : app_(app), binding_(this) {
39 app->ConnectToService("mojo:desktop_wm", &user_window_controller_);
40
41 mus::mojom::UserWindowObserverPtr observer;
42 mojo::InterfaceRequest<mus::mojom::UserWindowObserver> request =
43 mojo::GetProxy(&observer);
44 user_window_controller_->AddUserWindowObserver(std::move(observer));
45 binding_.Bind(std::move(request));
46
47 SetLayoutManager(
48 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
49
50 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
51 new views::LabelButton(this, base::ASCIIToUTF16("Views Examples"));
52 views_examples->set_tag(SHELF_BUTTON_VIEWS_EXAMPLES);
53 AddChildView(views_examples);
54
55 views::LabelButton* task_viewer =
56 new views::LabelButton(this, base::ASCIIToUTF16("Task Viewer"));
57 task_viewer->set_tag(SHELF_BUTTON_TASK_VIEWER);
58 AddChildView(task_viewer);
59 }
60 ~ShelfView() override {}
61
62 private:
63 // Overridden from views::View:
64 void OnPaint(gfx::Canvas* canvas) override {
65 canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW);
66 views::View::OnPaint(canvas);
67 }
68 gfx::Size GetPreferredSize() const override { return gfx::Size(1, 48); }
69
70 // Overridden from views::WidgetDelegate:
71 views::View* GetContentsView() override { return this; }
72
73 // Overridden from views::ButtonListener:
74 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
75 if (sender->tag() == SHELF_BUTTON_VIEWS_EXAMPLES)
76 app_->ConnectToApplication("mojo:views_examples");
77 else if (sender->tag() == SHELF_BUTTON_TASK_VIEWER)
78 app_->ConnectToApplication("mojo:task_viewer");
79 else
80 user_window_controller_->FocusUserWindow(sender->tag());
81 }
82
83 // Overridden from mus::mojom::UserWindowObserver:
84 void OnUserWindowAdded(uint32_t window_id) override {
85 // TODO(msw): Get the actual window title and icon.
86 views::LabelButton* open_window_button = new views::LabelButton(
87 this, base::ASCIIToUTF16(base::StringPrintf("Window %d", window_id)));
88 open_window_button->set_tag(window_id);
89 open_window_buttons_.push_back(open_window_button);
90 AddChildView(open_window_button);
91 Layout();
92 SchedulePaint();
93 }
94 void OnUserWindowRemoved(uint32_t window_id) override {
95 for (size_t i = 0; i < open_window_buttons_.size(); ++i) {
96 if (static_cast<uint32_t>(open_window_buttons_[i]->tag()) == window_id) {
97 views::LabelButton* button = open_window_buttons_[i];
98 open_window_buttons_.erase(open_window_buttons_.begin() + i);
99 RemoveChildView(button);
100 delete button;
101 return;
102 }
103 }
104 }
105
106 mojo::ApplicationImpl* app_;
107 std::vector<views::LabelButton*> open_window_buttons_;
108 mus::mojom::UserWindowControllerPtr user_window_controller_;
109 mojo::Binding<mus::mojom::UserWindowObserver> binding_;
110
111 DISALLOW_COPY_AND_ASSIGN(ShelfView);
112 };
113
114 ShelfApplication::ShelfApplication() {}
115
116 ShelfApplication::~ShelfApplication() {}
117
118 void ShelfApplication::Initialize(mojo::ApplicationImpl* app) {
119 tracing_.Initialize(app);
120
121 aura_init_.reset(new views::AuraInit(app, "views_mus_resources.pak"));
122 views::WindowManagerConnection::Create(app);
123
124 views::Widget* widget = new views::Widget;
125 views::Widget::InitParams params(
126 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
127 params.delegate = new ShelfView(app);
128
129 std::map<std::string, std::vector<uint8_t>> properties;
130 properties[mash::wm::mojom::kWindowContainer_Property] =
131 mojo::TypeConverter<const std::vector<uint8_t>, int32_t>::Convert(
132 mash::wm::mojom::CONTAINER_USER_SHELF);
133 mus::Window* window =
134 views::WindowManagerConnection::Get()->NewWindow(properties);
135 params.native_widget = new views::NativeWidgetMus(
136 widget, app->shell(), window, mus::mojom::SURFACE_TYPE_DEFAULT);
137 widget->Init(params);
138 widget->Show();
139 }
140
141 bool ShelfApplication::ConfigureIncomingConnection(
142 mojo::ApplicationConnection* connection) {
143 return true;
144 }
145
146 } // namespace shelf
147 } // namespace mash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698