Commit dbc09d0d authored by nancy's avatar nancy Committed by Commit Bot

Reorder the functions of AppContextMenu.

This is the follow up for CL:2010449. The order of the AppContextMenu's
functions is reordered to align with the definition.

BUG=1038487

Change-Id: I2a979a32fe1b9ac2a18d1fda26097312027f7037
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016684Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734953}
parent d4d2174e
...@@ -32,16 +32,6 @@ void AppContextMenu::GetMenuModel(GetMenuModelCallback callback) { ...@@ -32,16 +32,6 @@ void AppContextMenu::GetMenuModel(GetMenuModelCallback callback) {
std::move(callback).Run(std::move(menu_model)); std::move(callback).Run(std::move(menu_model));
} }
void AppContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
// Show Pin/Unpin option if shelf is available.
if (controller_->GetPinnable(app_id()) != AppListControllerDelegate::NO_PIN) {
AddContextMenuOption(menu_model, ash::TOGGLE_PIN,
controller_->IsAppPinned(app_id_)
? IDS_APP_LIST_CONTEXT_MENU_UNPIN
: IDS_APP_LIST_CONTEXT_MENU_PIN);
}
}
bool AppContextMenu::IsItemForCommandIdDynamic(int command_id) const { bool AppContextMenu::IsItemForCommandIdDynamic(int command_id) const {
return command_id == ash::TOGGLE_PIN; return command_id == ash::TOGGLE_PIN;
} }
...@@ -68,43 +58,22 @@ bool AppContextMenu::IsCommandIdEnabled(int command_id) const { ...@@ -68,43 +58,22 @@ bool AppContextMenu::IsCommandIdEnabled(int command_id) const {
return true; return true;
} }
void AppContextMenu::TogglePin(const std::string& shelf_app_id) { void AppContextMenu::ExecuteCommand(int command_id, int event_flags) {
DCHECK_EQ(AppListControllerDelegate::PIN_EDITABLE, switch (command_id) {
controller_->GetPinnable(shelf_app_id)); case ash::TOGGLE_PIN:
ash::ShelfModel::ScopedUserTriggeredMutation user_triggered( TogglePin(app_id_);
ash::ShelfModel::Get()); break;
if (controller_->IsAppPinned(shelf_app_id)) }
controller_->UnpinApp(shelf_app_id);
else
controller_->PinApp(shelf_app_id);
} }
void AppContextMenu::AddContextMenuOption(ui::SimpleMenuModel* menu_model, const gfx::VectorIcon* AppContextMenu::GetVectorIconForCommandId(
ash::CommandId command_id, int command_id) const {
int string_id) { DCHECK_EQ(command_id, ash::TOGGLE_PIN);
// Do not include disabled items. const gfx::VectorIcon& icon =
if (!IsCommandIdEnabled(command_id)) GetMenuItemVectorIcon(command_id, controller_->IsAppPinned(app_id_)
return; ? IDS_APP_LIST_CONTEXT_MENU_UNPIN
: IDS_APP_LIST_CONTEXT_MENU_PIN);
const gfx::VectorIcon& icon = GetMenuItemVectorIcon(command_id, string_id); return &icon;
if (!icon.is_empty()) {
menu_model->AddItemWithStringIdAndIcon(command_id, string_id, icon);
return;
}
// Check items use default icons.
if (command_id == ash::USE_LAUNCH_TYPE_PINNED ||
command_id == ash::USE_LAUNCH_TYPE_REGULAR ||
command_id == ash::USE_LAUNCH_TYPE_FULLSCREEN ||
command_id == ash::USE_LAUNCH_TYPE_WINDOW) {
menu_model->AddCheckItemWithStringId(command_id, string_id);
return;
}
if (command_id == ash::NOTIFICATION_CONTAINER) {
NOTREACHED()
<< "NOTIFICATION_CONTAINER is added by NotificationMenuController.";
return;
}
menu_model->AddItemWithStringId(command_id, string_id);
} }
const gfx::VectorIcon& AppContextMenu::GetMenuItemVectorIcon( const gfx::VectorIcon& AppContextMenu::GetMenuItemVectorIcon(
...@@ -154,22 +123,53 @@ const gfx::VectorIcon& AppContextMenu::GetMenuItemVectorIcon( ...@@ -154,22 +123,53 @@ const gfx::VectorIcon& AppContextMenu::GetMenuItemVectorIcon(
} }
} }
void AppContextMenu::ExecuteCommand(int command_id, int event_flags) { void AppContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
switch (command_id) { // Show Pin/Unpin option if shelf is available.
case ash::TOGGLE_PIN: if (controller_->GetPinnable(app_id()) != AppListControllerDelegate::NO_PIN) {
TogglePin(app_id_); AddContextMenuOption(menu_model, ash::TOGGLE_PIN,
break; controller_->IsAppPinned(app_id_)
? IDS_APP_LIST_CONTEXT_MENU_UNPIN
: IDS_APP_LIST_CONTEXT_MENU_PIN);
} }
} }
const gfx::VectorIcon* AppContextMenu::GetVectorIconForCommandId( void AppContextMenu::TogglePin(const std::string& shelf_app_id) {
int command_id) const { DCHECK_EQ(AppListControllerDelegate::PIN_EDITABLE,
DCHECK_EQ(command_id, ash::TOGGLE_PIN); controller_->GetPinnable(shelf_app_id));
const gfx::VectorIcon& icon = ash::ShelfModel::ScopedUserTriggeredMutation user_triggered(
GetMenuItemVectorIcon(command_id, controller_->IsAppPinned(app_id_) ash::ShelfModel::Get());
? IDS_APP_LIST_CONTEXT_MENU_UNPIN if (controller_->IsAppPinned(shelf_app_id))
: IDS_APP_LIST_CONTEXT_MENU_PIN); controller_->UnpinApp(shelf_app_id);
return &icon; else
controller_->PinApp(shelf_app_id);
}
void AppContextMenu::AddContextMenuOption(ui::SimpleMenuModel* menu_model,
ash::CommandId command_id,
int string_id) {
// Do not include disabled items.
if (!IsCommandIdEnabled(command_id))
return;
const gfx::VectorIcon& icon = GetMenuItemVectorIcon(command_id, string_id);
if (!icon.is_empty()) {
menu_model->AddItemWithStringIdAndIcon(command_id, string_id, icon);
return;
}
// Check items use default icons.
if (command_id == ash::USE_LAUNCH_TYPE_PINNED ||
command_id == ash::USE_LAUNCH_TYPE_REGULAR ||
command_id == ash::USE_LAUNCH_TYPE_FULLSCREEN ||
command_id == ash::USE_LAUNCH_TYPE_WINDOW) {
menu_model->AddCheckItemWithStringId(command_id, string_id);
return;
}
if (command_id == ash::NOTIFICATION_CONTAINER) {
NOTREACHED()
<< "NOTIFICATION_CONTAINER is added by NotificationMenuController.";
return;
}
menu_model->AddItemWithStringId(command_id, string_id);
} }
} // namespace app_list } // namespace app_list
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment