OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/shelf/shelf_controller.h" | 5 #include "ash/common/shelf/shelf_controller.h" |
6 | 6 |
7 #include "ash/common/shelf/shelf_item_delegate.h" | 7 #include "ash/common/shelf/shelf_item_delegate.h" |
8 #include "ash/common/shelf/shelf_menu_model.h" | 8 #include "ash/common/shelf/shelf_menu_model.h" |
9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
10 #include "ash/common/wm_lookup.h" | 10 #include "ash/common/wm_lookup.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 void set_title(const base::string16& title) { title_ = title; } | 53 void set_title(const base::string16& title) { title_ = title; } |
54 | 54 |
55 private: | 55 private: |
56 // This application menu model for ShelfItemDelegateMus lists open windows. | 56 // This application menu model for ShelfItemDelegateMus lists open windows. |
57 class ShelfMenuModelMus : public ShelfMenuModel, | 57 class ShelfMenuModelMus : public ShelfMenuModel, |
58 public ui::SimpleMenuModel::Delegate { | 58 public ui::SimpleMenuModel::Delegate { |
59 public: | 59 public: |
60 explicit ShelfMenuModelMus(ShelfItemDelegateMus* item_delegate) | 60 explicit ShelfMenuModelMus(ShelfItemDelegateMus* item_delegate) |
61 : ShelfMenuModel(this), item_delegate_(item_delegate) { | 61 : ShelfMenuModel(this), item_delegate_(item_delegate) { |
62 AddSeparator(ui::SPACING_SEPARATOR); | 62 AddSeparator(ui::SPACING_SEPARATOR); |
63 AddItem(0, item_delegate_->GetTitle()); | 63 AddItem(0, item_delegate_->title()); |
64 AddSeparator(ui::SPACING_SEPARATOR); | 64 AddSeparator(ui::SPACING_SEPARATOR); |
65 for (const auto& window : item_delegate_->window_id_to_title()) | 65 for (const auto& window : item_delegate_->window_id_to_title()) |
66 AddItem(window.first, window.second); | 66 AddItem(window.first, window.second); |
67 AddSeparator(ui::SPACING_SEPARATOR); | 67 AddSeparator(ui::SPACING_SEPARATOR); |
68 } | 68 } |
69 ~ShelfMenuModelMus() override {} | 69 ~ShelfMenuModelMus() override {} |
70 | 70 |
71 // ShelfMenuModel: | 71 // ShelfMenuModel: |
72 bool IsCommandActive(int command_id) const override { return false; } | 72 bool IsCommandActive(int command_id) const override { return false; } |
73 | 73 |
(...skipping 19 matching lines...) Expand all Loading... |
93 delegate_->LaunchItem(); | 93 delegate_->LaunchItem(); |
94 return kNewWindowCreated; | 94 return kNewWindowCreated; |
95 } | 95 } |
96 if (window_id_to_title_.size() == 1) { | 96 if (window_id_to_title_.size() == 1) { |
97 // TODO(mash): Activate the window and return kExistingWindowActivated. | 97 // TODO(mash): Activate the window and return kExistingWindowActivated. |
98 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
99 } | 99 } |
100 return kNoAction; | 100 return kNoAction; |
101 } | 101 } |
102 | 102 |
103 base::string16 GetTitle() override { | |
104 return window_id_to_title_.empty() ? title_ | |
105 : window_id_to_title_.begin()->second; | |
106 } | |
107 | |
108 ShelfMenuModel* CreateApplicationMenu(int event_flags) override { | 103 ShelfMenuModel* CreateApplicationMenu(int event_flags) override { |
109 return new ShelfMenuModelMus(this); | 104 return new ShelfMenuModelMus(this); |
110 } | 105 } |
111 | 106 |
112 void Close() override { NOTIMPLEMENTED(); } | 107 void Close() override { NOTIMPLEMENTED(); } |
113 | 108 |
114 mojom::ShelfItemDelegateAssociatedPtr delegate_; | 109 mojom::ShelfItemDelegateAssociatedPtr delegate_; |
115 bool pinned_ = false; | 110 bool pinned_ = false; |
116 std::map<uint32_t, base::string16> window_id_to_title_; | 111 std::map<uint32_t, base::string16> window_id_to_title_; |
117 base::string16 title_; | 112 base::string16 title_; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 220 } |
226 | 221 |
227 ShelfID shelf_id = model_.next_id(); | 222 ShelfID shelf_id = model_.next_id(); |
228 app_id_to_shelf_id_.insert(std::make_pair(item->app_id, shelf_id)); | 223 app_id_to_shelf_id_.insert(std::make_pair(item->app_id, shelf_id)); |
229 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, item->app_id)); | 224 shelf_id_to_app_id_.insert(std::make_pair(shelf_id, item->app_id)); |
230 | 225 |
231 ShelfItem shelf_item; | 226 ShelfItem shelf_item; |
232 shelf_item.type = TYPE_APP_SHORTCUT; | 227 shelf_item.type = TYPE_APP_SHORTCUT; |
233 shelf_item.status = STATUS_CLOSED; | 228 shelf_item.status = STATUS_CLOSED; |
234 shelf_item.image = GetShelfIconFromBitmap(item->image); | 229 shelf_item.image = GetShelfIconFromBitmap(item->image); |
| 230 shelf_item.title = base::UTF8ToUTF16(item->app_title); |
235 model_.Add(shelf_item); | 231 model_.Add(shelf_item); |
236 | 232 |
237 std::unique_ptr<ShelfItemDelegateMus> item_delegate( | 233 std::unique_ptr<ShelfItemDelegateMus> item_delegate = |
238 new ShelfItemDelegateMus()); | 234 base::MakeUnique<ShelfItemDelegateMus>(); |
239 item_delegate->SetDelegate(std::move(delegate)); | 235 item_delegate->SetDelegate(std::move(delegate)); |
240 item_delegate->set_pinned(true); | 236 item_delegate->set_pinned(true); |
241 item_delegate->set_title(base::UTF8ToUTF16(item->app_title)); | 237 item_delegate->set_title(shelf_item.title); |
242 model_.SetShelfItemDelegate(shelf_id, std::move(item_delegate)); | 238 model_.SetShelfItemDelegate(shelf_id, std::move(item_delegate)); |
243 } | 239 } |
244 | 240 |
245 void ShelfController::UnpinItem(const std::string& app_id) { | 241 void ShelfController::UnpinItem(const std::string& app_id) { |
246 if (!app_id_to_shelf_id_.count(app_id)) | 242 if (!app_id_to_shelf_id_.count(app_id)) |
247 return; | 243 return; |
248 | 244 |
249 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 245 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
250 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); | 246 ShelfItemDelegateMus* item_delegate = GetShelfItemDelegate(shelf_id); |
251 DCHECK(item_delegate->pinned()); | 247 DCHECK(item_delegate->pinned()); |
(...skipping 11 matching lines...) Expand all Loading... |
263 return; | 259 return; |
264 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 260 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
265 int index = model_.ItemIndexByID(shelf_id); | 261 int index = model_.ItemIndexByID(shelf_id); |
266 DCHECK_GE(index, 0); | 262 DCHECK_GE(index, 0); |
267 ShelfItem item = *model_.ItemByID(shelf_id); | 263 ShelfItem item = *model_.ItemByID(shelf_id); |
268 item.image = GetShelfIconFromBitmap(image); | 264 item.image = GetShelfIconFromBitmap(image); |
269 model_.Set(index, item); | 265 model_.Set(index, item); |
270 } | 266 } |
271 | 267 |
272 } // namespace ash | 268 } // namespace ash |
OLD | NEW |