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

Side by Side Diff: ash/common/shelf/shelf_controller.cc

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Add comments Created 3 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
OLDNEW
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/wm_shelf.h" 8 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/common/wm_lookup.h" 9 #include "ash/common/wm_lookup.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 window_id_to_title_[id] = title; 46 window_id_to_title_[id] = title;
47 } 47 }
48 const std::map<uint32_t, base::string16>& window_id_to_title() const { 48 const std::map<uint32_t, base::string16>& window_id_to_title() const {
49 return window_id_to_title_; 49 return window_id_to_title_;
50 } 50 }
51 51
52 const base::string16& title() { return title_; } 52 const base::string16& title() { return title_; }
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.
57 class ShelfMenuModelMus : public ui::SimpleMenuModel,
58 public ui::SimpleMenuModel::Delegate {
59 public:
60 explicit ShelfMenuModelMus(ShelfItemDelegateMus* item_delegate)
61 : ui::SimpleMenuModel(this), item_delegate_(item_delegate) {
62 AddSeparator(ui::SPACING_SEPARATOR);
63 AddItem(0, item_delegate_->title());
64 AddSeparator(ui::SPACING_SEPARATOR);
65 for (const auto& window : item_delegate_->window_id_to_title())
66 AddItem(window.first, window.second);
67 AddSeparator(ui::SPACING_SEPARATOR);
68 }
69 ~ShelfMenuModelMus() override {}
70
71 // ui::SimpleMenuModel::Delegate:
72 bool IsCommandIdChecked(int command_id) const override { return false; }
73 bool IsCommandIdEnabled(int command_id) const override {
74 return command_id > 0;
75 }
76 void ExecuteCommand(int command_id, int event_flags) override {
77 NOTIMPLEMENTED();
78 }
79
80 private:
81 ShelfItemDelegateMus* item_delegate_;
82
83 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelMus);
84 };
85
86 // ShelfItemDelegate: 56 // ShelfItemDelegate:
87 ShelfItemDelegate::PerformedAction ItemSelected( 57 ShelfItemDelegate::PerformedAction ItemSelected(
88 const ui::Event& event) override { 58 const ui::Event& event) override {
89 if (window_id_to_title_.empty()) { 59 if (window_id_to_title_.empty()) {
90 delegate_->LaunchItem(); 60 delegate_->LaunchItem();
91 return kNewWindowCreated; 61 return kNewWindowCreated;
92 } 62 }
93 if (window_id_to_title_.size() == 1) { 63 if (window_id_to_title_.size() == 1) {
94 // TODO(mash): Activate the window and return kExistingWindowActivated. 64 // TODO(mash): Activate the window and return kExistingWindowActivated.
95 NOTIMPLEMENTED(); 65 NOTIMPLEMENTED();
96 } 66 }
97 return kNoAction; 67 return kNoAction;
98 } 68 }
99 69
100 ui::SimpleMenuModel* CreateApplicationMenu(int event_flags) override { 70 ShelfAppMenuItemList GetAppMenuItems(int event_flags) override {
101 return new ShelfMenuModelMus(this); 71 ShelfAppMenuItemList items;
72 for (const auto& window : window_id_to_title_) {
73 items.push_back(
74 base::MakeUnique<ShelfApplicationMenuItem>(window.second));
75 }
76 return items;
102 } 77 }
103 78
104 void Close() override { NOTIMPLEMENTED(); } 79 void Close() override { NOTIMPLEMENTED(); }
105 80
106 mojom::ShelfItemDelegateAssociatedPtr delegate_; 81 mojom::ShelfItemDelegateAssociatedPtr delegate_;
107 bool pinned_ = false; 82 bool pinned_ = false;
108 std::map<uint32_t, base::string16> window_id_to_title_; 83 std::map<uint32_t, base::string16> window_id_to_title_;
109 base::string16 title_; 84 base::string16 title_;
110 85
111 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); 86 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus);
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 return; 231 return;
257 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; 232 ShelfID shelf_id = app_id_to_shelf_id_[app_id];
258 int index = model_.ItemIndexByID(shelf_id); 233 int index = model_.ItemIndexByID(shelf_id);
259 DCHECK_GE(index, 0); 234 DCHECK_GE(index, 0);
260 ShelfItem item = *model_.ItemByID(shelf_id); 235 ShelfItem item = *model_.ItemByID(shelf_id);
261 item.image = GetShelfIconFromBitmap(image); 236 item.image = GetShelfIconFromBitmap(image);
262 model_.Set(index, item); 237 model_.Set(index, item);
263 } 238 }
264 239
265 } // namespace ash 240 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_application_menu_model_unittest.cc ('k') | ash/common/shelf/shelf_item_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698