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

Side by Side Diff: ash/mus/shelf_delegate_mus.cc

Issue 1684633002: ash/mash: Introduce a ShelfDelegate implementation for mash. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ash-sysui-window-container
Patch Set: tot-merge Created 4 years, 10 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
« no previous file with comments | « ash/mus/shelf_delegate_mus.h ('k') | ash/mus/shell_delegate_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/shelf_delegate_mus.h"
6
7 #include "ash/shelf/shelf_item_delegate.h"
8 #include "ash/shelf/shelf_item_delegate_manager.h"
9 #include "ash/shelf/shelf_model.h"
10 #include "ash/shell.h"
11 #include "base/strings/string_util.h"
12 #include "mojo/common/common_type_converters.h"
13 #include "mojo/shell/public/cpp/shell.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/resources/grit/ui_resources.h"
16 #include "ui/views/mus/window_manager_connection.h"
17
18 using mash::wm::mojom::UserWindowController;
19
20 namespace ash {
21 namespace sysui {
22
23 namespace {
24
25 class ShelfItemDelegateMus : public ShelfItemDelegate {
26 public:
27 ShelfItemDelegateMus(uint32_t window_id,
28 const base::string16& title,
29 UserWindowController* user_window_controller)
30 : window_id_(window_id),
31 title_(title),
32 user_window_controller_(user_window_controller) {}
33 ~ShelfItemDelegateMus() override {}
34
35 void UpdateTitle(const base::string16& new_title) { title_ = new_title; }
36
37 private:
38 // ShelfItemDelegate:
39 ShelfItemDelegate::PerformedAction ItemSelected(
40 const ui::Event& event) override {
41 user_window_controller_->FocusUserWindow(window_id_);
42 return kExistingWindowActivated;
43 }
44
45 base::string16 GetTitle() override { return title_; }
46
47 ui::MenuModel* CreateContextMenu(aura::Window* root_window) override {
48 NOTIMPLEMENTED();
49 return nullptr;
50 }
51
52 bool CanPin() const override {
53 NOTIMPLEMENTED();
54 return false;
55 }
56
57 ShelfMenuModel* CreateApplicationMenu(int event_flags) override {
58 NOTIMPLEMENTED();
59 return nullptr;
60 }
61
62 bool IsDraggable() override {
63 NOTIMPLEMENTED();
64 return false;
65 }
66
67 bool ShouldShowTooltip() override {
68 // NOTIMPLEMENTED(); very noisy
69 return false;
70 }
71
72 void Close() override { NOTIMPLEMENTED(); }
73
74 // TODO(msw): Support multiple open windows per button.
75 uint32_t window_id_;
76 base::string16 title_;
77 UserWindowController* user_window_controller_;
78
79 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus);
80 };
81
82 } // namespace
83
84 ShelfDelegateMus::ShelfDelegateMus(ShelfModel* model)
85 : model_(model), binding_(this) {
86 mojo::Shell* shell = views::WindowManagerConnection::Get()->shell();
87 shell->ConnectToInterface("mojo:desktop_wm", &user_window_controller_);
88 user_window_controller_->AddUserWindowObserver(
89 binding_.CreateInterfacePtrAndBind());
90 }
91
92 ShelfDelegateMus::~ShelfDelegateMus() {}
93
94 void ShelfDelegateMus::OnShelfCreated(Shelf* shelf) {
95 NOTIMPLEMENTED();
96 }
97
98 void ShelfDelegateMus::OnShelfDestroyed(Shelf* shelf) {
99 NOTIMPLEMENTED();
100 }
101
102 ShelfID ShelfDelegateMus::GetShelfIDForAppID(const std::string& app_id) {
103 NOTIMPLEMENTED();
104 return 0;
105 }
106
107 bool ShelfDelegateMus::HasShelfIDToAppIDMapping(ShelfID id) const {
108 NOTIMPLEMENTED();
109 return false;
110 }
111
112 const std::string& ShelfDelegateMus::GetAppIDForShelfID(ShelfID id) {
113 NOTIMPLEMENTED();
114 return base::EmptyString();
115 }
116
117 void ShelfDelegateMus::PinAppWithID(const std::string& app_id) {
118 NOTIMPLEMENTED();
119 }
120
121 bool ShelfDelegateMus::IsAppPinned(const std::string& app_id) {
122 NOTIMPLEMENTED();
123 return false;
124 }
125
126 void ShelfDelegateMus::UnpinAppWithID(const std::string& app_id) {
127 NOTIMPLEMENTED();
128 }
129
130 void ShelfDelegateMus::OnUserWindowObserverAdded(
131 mojo::Array<mash::wm::mojom::UserWindowPtr> user_windows) {
132 for (size_t i = 0; i < user_windows.size(); ++i)
133 OnUserWindowAdded(std::move(user_windows[i]));
134 }
135
136 void ShelfDelegateMus::OnUserWindowAdded(
137 mash::wm::mojom::UserWindowPtr user_window) {
138 ShelfItem item;
139 item.type = TYPE_PLATFORM_APP;
140 item.status = user_window->window_has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
141 // TODO(msw): Support actual window icons.
142 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
143 item.image = *rb.GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
144
145 ShelfID shelf_id = model_->next_id();
146 window_id_to_shelf_id_.insert(
147 std::make_pair(user_window->window_id, shelf_id));
148 model_->Add(item);
149
150 ShelfItemDelegateManager* manager =
151 Shell::GetInstance()->shelf_item_delegate_manager();
152 scoped_ptr<ShelfItemDelegate> delegate(new ShelfItemDelegateMus(
153 user_window->window_id, user_window->window_title.To<base::string16>(),
154 user_window_controller_.get()));
155 manager->SetShelfItemDelegate(shelf_id, std::move(delegate));
156 }
157
158 void ShelfDelegateMus::OnUserWindowRemoved(uint32_t window_id) {
159 DCHECK(window_id_to_shelf_id_.count(window_id));
160 model_->RemoveItemAt(
161 model_->ItemIndexByID(window_id_to_shelf_id_[window_id]));
162 }
163
164 void ShelfDelegateMus::OnUserWindowTitleChanged(
165 uint32_t window_id,
166 const mojo::String& window_title) {
167 DCHECK(window_id_to_shelf_id_.count(window_id));
168 ShelfID shelf_id = window_id_to_shelf_id_[window_id];
169 ShelfItemDelegateManager* manager =
170 Shell::GetInstance()->shelf_item_delegate_manager();
171 ShelfItemDelegate* delegate = manager->GetShelfItemDelegate(shelf_id);
172 DCHECK(delegate);
173 static_cast<ShelfItemDelegateMus*>(delegate)->UpdateTitle(
174 window_title.To<base::string16>());
175
176 // There's nothing in the ShelfItem that needs to be updated. But we still
177 // need to update the ShelfModel so that the observers can pick up any
178 // changes.
179 int index = model_->ItemIndexByID(shelf_id);
180 DCHECK_GE(index, 0);
181 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id);
182 DCHECK(iter != model_->items().end());
183 model_->Set(index, *iter);
184 }
185
186 void ShelfDelegateMus::OnUserWindowFocusChanged(uint32_t window_id,
187 bool has_focus) {
188 DCHECK(window_id_to_shelf_id_.count(window_id));
189 ShelfID shelf_id = window_id_to_shelf_id_[window_id];
190 int index = model_->ItemIndexByID(shelf_id);
191 DCHECK_GE(index, 0);
192 ShelfItems::const_iterator iter = model_->ItemByID(shelf_id);
193 DCHECK(iter != model_->items().end());
194 ShelfItem item = *iter;
195 item.status = has_focus ? STATUS_ACTIVE : STATUS_RUNNING;
196 model_->Set(index, item);
197 }
198
199 } // namespace sysui
200 } // namespace ash
OLDNEW
« no previous file with comments | « ash/mus/shelf_delegate_mus.h ('k') | ash/mus/shell_delegate_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698