| Index: ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm
|
| diff --git a/ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm b/ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm
|
| index 34d8df65a90d2e59bf9aac0945716dfd414fa7d8..e6157e493bbd1ddc227f61e6b8c924c80f2fa7a0 100644
|
| --- a/ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm
|
| +++ b/ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm
|
| @@ -12,6 +12,9 @@
|
| #include "base/mac/objc_property_releaser.h"
|
| #include "base/mac/scoped_nsobject.h"
|
| #include "base/metrics/field_trial.h"
|
| +#include "components/reading_list/core/reading_list_switches.h"
|
| +#include "components/strings/grit/components_strings.h"
|
| +#include "ios/chrome/browser/experimental_flags.h"
|
| #import "ios/chrome/browser/ui/animation_util.h"
|
| #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
|
| #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
|
| @@ -19,19 +22,38 @@
|
| #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h"
|
| #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h"
|
| #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h"
|
| -#include "ios/chrome/browser/ui/tools_menu/tools_menu_model.h"
|
| #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h"
|
| #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h"
|
| #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
|
| +#include "ios/chrome/browser/ui/ui_util.h"
|
| #import "ios/chrome/browser/ui/uikit_ui_util.h"
|
| #import "ios/chrome/common/material_timing.h"
|
| #include "ios/chrome/grit/ios_strings.h"
|
| +#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
|
| +#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
|
| #import "ios/third_party/material_components_ios/src/components/Ink/src/MaterialInk.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/l10n/l10n_util_mac.h"
|
|
|
| using ios::material::TimingFunction;
|
|
|
| +NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId";
|
| +NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId";
|
| +NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId";
|
| +NSString* const kToolsMenuCloseAllIncognitoTabsId =
|
| + @"kToolsMenuCloseAllIncognitoTabsId";
|
| +NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId";
|
| +NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId";
|
| +NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId";
|
| +NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId";
|
| +NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId";
|
| +NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId";
|
| +NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode";
|
| +NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId";
|
| +NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId";
|
| +NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId";
|
| +NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId";
|
| +
|
| namespace {
|
|
|
| // Time for ink to fade into view.
|
| @@ -40,6 +62,140 @@
|
| static const CGFloat kMenuItemHeight = 48;
|
|
|
| static NSString* const kToolsItemCellID = @"ToolsItemCellID";
|
| +
|
| +// Menu items can be marked as visible or not when Incognito is enabled.
|
| +// The following bits are used for |visibility| field in |MenuItemInfo|.
|
| +const NSInteger kVisibleIncognitoOnly = 1 << 0;
|
| +const NSInteger kVisibleNotIncognitoOnly = 1 << 1;
|
| +
|
| +// Initialization table for all possible commands to initialize the
|
| +// tools menu at run time. Data initialized into this structure is not mutable.
|
| +struct MenuItemInfo {
|
| + int title_id;
|
| + NSString* accessibility_id;
|
| + int command_id;
|
| + int toolbar_types;
|
| + // |visibility| is applied if a menu item is included for a given
|
| + // |toolbar_types|. A value of 0 means the menu item is always visible for
|
| + // the given |toolbar_types|.
|
| + int visibility;
|
| + // Custom class, if any, for the menu item, or |nil|.
|
| + Class item_class;
|
| +};
|
| +
|
| +// Flags for different toolbar types
|
| +typedef NS_OPTIONS(NSUInteger, kToolbarType) {
|
| + // clang-format off
|
| + kToolbarTypeNone = 0,
|
| + kToolbarTypeWebiPhone = 1 << 0,
|
| + kToolbarTypeWebiPad = 1 << 1,
|
| + kToolbarTypeNoTabsiPad = 1 << 2,
|
| + kToolbarTypeSwitcheriPhone = 1 << 3,
|
| + kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad,
|
| + kToolbarTypeAll = kToolbarTypeWebAll |
|
| + kToolbarTypeSwitcheriPhone |
|
| + kToolbarTypeNoTabsiPad,
|
| + // clang-format on
|
| +};
|
| +
|
| +// Declare all the possible items.
|
| +static MenuItemInfo itemInfoList[] = {
|
| + // clang-format off
|
| + { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId,
|
| + IDC_NEW_TAB, kToolbarTypeAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId,
|
| + IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId,
|
| + IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone,
|
| + kVisibleNotIncognitoOnly, nil },
|
| + { IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS,
|
| + kToolsMenuCloseAllIncognitoTabsId,
|
| + IDC_CLOSE_ALL_INCOGNITO_TABS, kToolbarTypeSwitcheriPhone,
|
| + kVisibleIncognitoOnly, nil },
|
| + { IDS_IOS_TOOLS_MENU_BOOKMARKS, kToolsMenuBookmarksId,
|
| + IDC_SHOW_BOOKMARK_MANAGER, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_READING_LIST, kToolsMenuReadingListId,
|
| + IDC_SHOW_READING_LIST, kToolbarTypeWebAll,
|
| + 0, [ReadingListMenuViewItem class] },
|
| + { IDS_IOS_TOOLS_MENU_SUGGESTIONS, kToolsMenuSuggestionsId,
|
| + IDC_SHOW_SUGGESTIONS, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_RECENT_TABS, kToolsMenuOtherDevicesId,
|
| + IDC_SHOW_OTHER_DEVICES, kToolbarTypeWebAll,
|
| + kVisibleNotIncognitoOnly, nil },
|
| + { IDS_HISTORY_SHOW_HISTORY, kToolsMenuHistoryId,
|
| + IDC_SHOW_HISTORY, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId,
|
| + IDC_REPORT_AN_ISSUE, kToolbarTypeAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId,
|
| + IDC_FIND, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId,
|
| + IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode,
|
| + IDC_READER_MODE, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId,
|
| + IDC_OPTIONS, kToolbarTypeAll,
|
| + 0, nil },
|
| + { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId,
|
| + IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll,
|
| + 0, nil },
|
| + // clang-format on
|
| +};
|
| +
|
| +NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item,
|
| + BOOL incognito,
|
| + kToolbarType toolbarType) {
|
| + if (!(item.toolbar_types & toolbarType))
|
| + return NO;
|
| +
|
| + if (incognito && (item.visibility & kVisibleNotIncognitoOnly))
|
| + return NO;
|
| +
|
| + if (!incognito && (item.visibility & kVisibleIncognitoOnly))
|
| + return NO;
|
| +
|
| + if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) {
|
| + if (!IsIPadIdiom()) {
|
| + return NO;
|
| + }
|
| + }
|
| +
|
| + if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) {
|
| + if (!experimental_flags::IsReaderModeEnabled()) {
|
| + return NO;
|
| + }
|
| + }
|
| +
|
| + if (item.title_id == IDS_IOS_TOOLS_MENU_READING_LIST) {
|
| + if (!reading_list::switches::IsReadingListEnabled()) {
|
| + return NO;
|
| + }
|
| + }
|
| +
|
| + if (item.title_id == IDS_IOS_TOOLS_MENU_SUGGESTIONS) {
|
| + if (!experimental_flags::IsSuggestionsUIEnabled()) {
|
| + return NO;
|
| + }
|
| + }
|
| +
|
| + if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) {
|
| + if (!ios::GetChromeBrowserProvider()
|
| + ->GetUserFeedbackProvider()
|
| + ->IsUserFeedbackEnabled()) {
|
| + return NO;
|
| + }
|
| + }
|
| +
|
| + return YES;
|
| +}
|
|
|
| NS_INLINE void AnimateInViews(NSArray* views,
|
| CGFloat initialX,
|
| @@ -106,7 +262,7 @@
|
| @property(nonatomic, retain) ToolsMenuCollectionView* menuView;
|
| @property(nonatomic, retain) MDCInkView* touchFeedbackView;
|
| @property(nonatomic, retain) NSMutableArray* menuItems;
|
| -@property(nonatomic, assign) ToolbarType toolbarType;
|
| +@property(nonatomic, assign) kToolbarType toolbarType;
|
|
|
| // Get the reading list cell.
|
| - (ReadingListMenuViewCell*)readingListCell;
|
| @@ -126,7 +282,7 @@
|
|
|
| - (CGFloat)optimalHeight:(CGFloat)suggestedHeight {
|
| NSInteger numberOfItems = [self.menuItems count];
|
| - if (_toolbarType == ToolbarTypeWebiPhone) {
|
| + if (_toolbarType == kToolbarTypeWebiPhone) {
|
| // Account for the height of the first row, not included in |menuItems|.
|
| numberOfItems++;
|
| }
|
| @@ -212,16 +368,16 @@
|
| }
|
|
|
| if (IsIPadIdiom()) {
|
| - _toolbarType =
|
| - context.hasNoOpenedTabs
|
| - ? ToolbarTypeNoTabsiPad
|
| - : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone);
|
| + _toolbarType = context.hasNoOpenedTabs
|
| + ? kToolbarTypeNoTabsiPad
|
| + : (!IsCompactTablet() ? kToolbarTypeWebiPad
|
| + : kToolbarTypeWebiPhone);
|
| } else {
|
| // kOptionInTabSwitcher option must be enabled on iPhone with
|
| // no opened tabs.
|
| DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher);
|
| - _toolbarType = context.isInTabSwitcher ? ToolbarTypeSwitcheriPhone
|
| - : ToolbarTypeWebiPhone;
|
| + _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone
|
| + : kToolbarTypeWebiPhone;
|
| }
|
|
|
| // Build the menu, adding all relevant items.
|
| @@ -229,8 +385,7 @@
|
|
|
| for (size_t i = 0; i < arraysize(itemInfoList); ++i) {
|
| const MenuItemInfo& item = itemInfoList[i];
|
| - if (!ToolsMenuItemShouldBeVisible(item, context.isInIncognito,
|
| - _toolbarType))
|
| + if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType))
|
| continue;
|
|
|
| NSString* title = l10n_util::GetNSStringWithFixup(item.title_id);
|
| @@ -247,7 +402,7 @@
|
|
|
| #if !defined(NDEBUG)
|
| NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
|
| - if ((_toolbarType & ToolbarTypeWebAll) &&
|
| + if ((_toolbarType & kToolbarTypeWebAll) &&
|
| [standardDefaults boolForKey:@"DevViewSource"]) {
|
| // Debug menu, not localized, only visible if turned on by a default.
|
| [menu addObject:[self createViewSourceItem]];
|
| @@ -293,7 +448,7 @@
|
| - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path {
|
| NSInteger item = [path item];
|
|
|
| - if (_toolbarType == ToolbarTypeWebiPhone)
|
| + if (_toolbarType == kToolbarTypeWebiPhone)
|
| --item;
|
|
|
| return item;
|
| @@ -403,7 +558,7 @@
|
| }];
|
|
|
| ToolsMenuViewToolsCell* toolsCell = nil;
|
| - if (_toolbarType == ToolbarTypeWebiPhone) {
|
| + if (_toolbarType == kToolbarTypeWebiPhone) {
|
| toolsCell = [visibleCells firstObject];
|
| if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) {
|
| visibleCells = [visibleCells
|
| @@ -543,7 +698,7 @@
|
| - (NSInteger)collectionView:(UICollectionView*)view
|
| numberOfItemsInSection:(NSInteger)section {
|
| NSInteger numberOfItems = [_menuItems count];
|
| - if (_toolbarType == ToolbarTypeWebiPhone)
|
| + if (_toolbarType == kToolbarTypeWebiPhone)
|
| ++numberOfItems;
|
|
|
| return numberOfItems;
|
|
|