1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/commerce/product_specifications/product_specifications_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/commerce/compare_sub_menu_model.h"
#include "chrome/browser/ui/toolbar/reading_list_sub_menu_model.h"
#include "chrome/grit/generated_resources.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/commerce/core/commerce_feature_list.h"
#include "components/commerce/core/feature_utils.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/ui_base_features.h"
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(BookmarkSubMenuModel,
kShowBookmarkBarMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(BookmarkSubMenuModel,
kShowBookmarkSidePanelItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(BookmarkSubMenuModel,
kReadingListMenuItem);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(BookmarkSubMenuModel, kCompareMenuItem);
// For views and cocoa, we have complex delegate systems to handle
// injecting the bookmarks to the bookmark submenu. This is done to support
// advanced interactions with the menu contents, like right click context menus.
BookmarkSubMenuModel::BookmarkSubMenuModel(
ui::SimpleMenuModel::Delegate* delegate,
Browser* browser)
: SimpleMenuModel(delegate) {
Build(browser);
}
BookmarkSubMenuModel::~BookmarkSubMenuModel() = default;
void BookmarkSubMenuModel::Build(Browser* browser) {
if (delegate()->IsCommandIdVisible(IDC_BOOKMARK_THIS_TAB) ||
delegate()->IsCommandIdVisible(IDC_BOOKMARK_ALL_TABS)) {
AddItemWithStringId(IDC_BOOKMARK_THIS_TAB, IDS_BOOKMARK_THIS_TAB);
AddItemWithStringId(IDC_BOOKMARK_ALL_TABS, IDS_BOOKMARK_ALL_TABS);
AddSeparator(ui::NORMAL_SEPARATOR);
}
AddItemWithStringId(IDC_SHOW_BOOKMARK_BAR,
browser->profile()->GetPrefs()->GetBoolean(
bookmarks::prefs::kShowBookmarkBar)
? IDS_HIDE_BOOKMARK_BAR
: IDS_SHOW_BOOKMARK_BAR);
SetElementIdentifierAt(GetIndexOfCommandId(IDC_SHOW_BOOKMARK_BAR).value(),
kShowBookmarkBarMenuItem);
AddItemWithStringId(IDC_SHOW_BOOKMARK_SIDE_PANEL,
IDS_SHOW_BOOKMARK_SIDE_PANEL);
SetElementIdentifierAt(
GetIndexOfCommandId(IDC_SHOW_BOOKMARK_SIDE_PANEL).value(),
kShowBookmarkSidePanelItem);
AddItemWithStringId(IDC_SHOW_BOOKMARK_MANAGER, IDS_BOOKMARK_MANAGER);
#if !BUILDFLAG(IS_CHROMEOS)
AddItemWithStringId(IDC_IMPORT_SETTINGS, IDS_IMPORT_SETTINGS_MENU_LABEL);
#endif
AddSeparator(ui::NORMAL_SEPARATOR);
reading_list_sub_menu_model_ =
std::make_unique<ReadingListSubMenuModel>(delegate());
AddSubMenuWithStringIdAndIcon(
IDC_READING_LIST_MENU, IDS_READING_LIST_MENU,
reading_list_sub_menu_model_.get(),
ui::ImageModel::FromVectorIcon(kReadingListIcon));
SetElementIdentifierAt(GetIndexOfCommandId(IDC_READING_LIST_MENU).value(),
kReadingListMenuItem);
// Will be null if the product specifications service is unavailable.
auto* product_specs_service =
commerce::ProductSpecificationsServiceFactory::GetForBrowserContext(
browser->profile());
if (product_specs_service &&
base::FeatureList::IsEnabled(commerce::kProductSpecifications)) {
AddSeparator(ui::NORMAL_SEPARATOR);
compare_sub_menu_model_ = std::make_unique<commerce::CompareSubMenuModel>(
delegate(), browser, product_specs_service);
AddSubMenuWithStringIdAndIcon(
IDC_COMPARE_MENU, IDS_COMPARE_MENU_LABEL, compare_sub_menu_model_.get(),
ui::ImageModel::FromVectorIcon(kCompareIcon, ui::kColorMenuIcon, 16));
SetElementIdentifierAt(GetIndexOfCommandId(IDC_COMPARE_MENU).value(),
kCompareMenuItem);
}
auto set_icon = [this](int command_id, const gfx::VectorIcon& vector_icon) {
auto index = GetIndexOfCommandId(command_id);
if (index) {
SetIcon(index.value(), ui::ImageModel::FromVectorIcon(
vector_icon, ui::kColorMenuIcon, 16));
}
};
set_icon(IDC_BOOKMARK_THIS_TAB, kBookmarksListsMenuIcon);
set_icon(IDC_BOOKMARK_ALL_TABS, kBookmarkAllTabsChromeRefreshIcon);
set_icon(IDC_SHOW_BOOKMARK_BAR, kToolbarChromeRefreshIcon);
set_icon(IDC_SHOW_BOOKMARK_MANAGER, kBookmarksManagerIcon);
set_icon(IDC_SHOW_BOOKMARK_SIDE_PANEL, kBookmarksSidePanelRefreshIcon);
set_icon(IDC_IMPORT_SETTINGS, kMenuBookChromeRefreshIcon);
}
|