Commit 7e01d479 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev Committed by Commit Bot

cros: Add an icon to 'New window' menu item for Files app

There is no way to add an icon to a menu item provided by a platform
app via chrome.contextMenus API.

This CL detects that this particular item is being added (by checking
the app id and the menu item label) and adds an appropriate icon to
it.

This method can be applied to other apps if necessary, which will
require hard-coding app id, label and icon for each new case.

Bug: 943319
Test: manual
Change-Id: I9536e8dc7ab2d8623fca8b4d68cfb776e5053a26
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1632909
Commit-Queue: Vladislav Kaznacheev <kaznacheev@chromium.org>
Reviewed-by: default avatarYury Khmel <khmel@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663957}
parent 9d2e3f64
......@@ -12,6 +12,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_context_menu_delegate.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/extension_app_utils.h"
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/grit/chromium_strings.h"
......@@ -106,6 +107,12 @@ void ExtensionAppContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
base::string16(),
&index,
false); // is_action_menu
const int appended_count = index - ash::USE_LAUNCH_TYPE_COMMAND_END;
AddMenuItemIconsForSystemApps(app_id(), menu_model,
menu_model->GetItemCount() - appended_count,
appended_count);
if (!is_platform_app_)
AddContextMenuOption(menu_model, ash::OPTIONS, IDS_NEW_TAB_APP_OPTIONS);
......
......@@ -7,7 +7,14 @@
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/extensions/extension_ui_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/grit/generated_resources.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/vector_icons.h"
namespace app_list {
......@@ -34,4 +41,24 @@ bool HideInLauncherById(std::string extension_id) {
return false;
}
void AddMenuItemIconsForSystemApps(const std::string& app_id,
ui::SimpleMenuModel* menu_model,
int start_index,
int count) {
if (app_id != extension_misc::kFilesManagerAppId)
return;
for (int i = 0; i < count; ++i) {
const int index = start_index + i;
if (menu_model->GetLabelAt(index) ==
l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_NEW_WINDOW)) {
const views::MenuConfig& menu_config = views::MenuConfig::instance();
menu_model->SetIcon(
index, gfx::Image(gfx::CreateVectorIcon(
views::kNewWindowIcon, menu_config.touchable_icon_size,
menu_config.touchable_icon_color)));
}
}
}
} // namespace app_list
......@@ -15,12 +15,24 @@ namespace extensions {
class Extension;
}
namespace ui {
class SimpleMenuModel;
}
namespace app_list {
bool ShouldShowInLauncher(const extensions::Extension* extension,
content::BrowserContext* context);
bool HideInLauncherById(std::string extension_id);
// chrome.contextMenus API does not support menu item icons. This function
// compensates for that by adding icons to menus for prominent system apps
// (currently just Files app)
void AddMenuItemIconsForSystemApps(const std::string& app_id,
ui::SimpleMenuModel* menu_model,
int start_index,
int count);
} // namespace app_list
#endif // CHROME_BROWSER_UI_APP_LIST_EXTENSION_APP_UTILS_H_
......@@ -13,6 +13,7 @@
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/extension_app_utils.h"
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
......@@ -214,6 +215,9 @@ void ExtensionLauncherContextMenu::BuildMenu(ui::SimpleMenuModel* menu_model) {
int index = 0;
extension_items_->AppendExtensionItems(app_key, base::string16(), &index,
false); // is_action_menu
app_list::AddMenuItemIconsForSystemApps(
item().id.app_id, menu_model, menu_model->GetItemCount() - index,
index);
}
}
}
......
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