Chromium Code Reviews| 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/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 Loading... | |
| 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 ShelfApplicationMenuItems GetAppMenuItems(int event_flags) override { |
| 101 return new ShelfMenuModelMus(this); | 71 ShelfApplicationMenuItems items; |
| 72 for (const auto& window : window_id_to_title_) | |
|
James Cook
2017/02/06 17:30:21
nit: {}
msw
2017/02/07 09:12:01
Done.
| |
| 73 items.push_back( | |
| 74 base::MakeUnique<ShelfApplicationMenuItem>(window.second, nullptr)); | |
| 75 return items; | |
| 102 } | 76 } |
| 103 | 77 |
| 104 void Close() override { NOTIMPLEMENTED(); } | 78 void Close() override { NOTIMPLEMENTED(); } |
| 105 | 79 |
| 106 mojom::ShelfItemDelegateAssociatedPtr delegate_; | 80 mojom::ShelfItemDelegateAssociatedPtr delegate_; |
| 107 bool pinned_ = false; | 81 bool pinned_ = false; |
| 108 std::map<uint32_t, base::string16> window_id_to_title_; | 82 std::map<uint32_t, base::string16> window_id_to_title_; |
| 109 base::string16 title_; | 83 base::string16 title_; |
| 110 | 84 |
| 111 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); | 85 DISALLOW_COPY_AND_ASSIGN(ShelfItemDelegateMus); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 return; | 230 return; |
| 257 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 231 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
| 258 int index = model_.ItemIndexByID(shelf_id); | 232 int index = model_.ItemIndexByID(shelf_id); |
| 259 DCHECK_GE(index, 0); | 233 DCHECK_GE(index, 0); |
| 260 ShelfItem item = *model_.ItemByID(shelf_id); | 234 ShelfItem item = *model_.ItemByID(shelf_id); |
| 261 item.image = GetShelfIconFromBitmap(image); | 235 item.image = GetShelfIconFromBitmap(image); |
| 262 model_.Set(index, item); | 236 model_.Set(index, item); |
| 263 } | 237 } |
| 264 | 238 |
| 265 } // namespace ash | 239 } // namespace ash |
| OLD | NEW |