| 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 e6157e493bbd1ddc227f61e6b8c924c80f2fa7a0..34d8df65a90d2e59bf9aac0945716dfd414fa7d8 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,9 +12,6 @@
|
| #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"
|
| @@ -22,38 +19,19 @@
|
| #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.
|
| @@ -63,140 +41,6 @@ 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,
|
| CGFloat initialY) {
|
| @@ -262,7 +106,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
| @property(nonatomic, retain) ToolsMenuCollectionView* menuView;
|
| @property(nonatomic, retain) MDCInkView* touchFeedbackView;
|
| @property(nonatomic, retain) NSMutableArray* menuItems;
|
| -@property(nonatomic, assign) kToolbarType toolbarType;
|
| +@property(nonatomic, assign) ToolbarType toolbarType;
|
|
|
| // Get the reading list cell.
|
| - (ReadingListMenuViewCell*)readingListCell;
|
| @@ -282,7 +126,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
|
|
| - (CGFloat)optimalHeight:(CGFloat)suggestedHeight {
|
| NSInteger numberOfItems = [self.menuItems count];
|
| - if (_toolbarType == kToolbarTypeWebiPhone) {
|
| + if (_toolbarType == ToolbarTypeWebiPhone) {
|
| // Account for the height of the first row, not included in |menuItems|.
|
| numberOfItems++;
|
| }
|
| @@ -368,16 +212,16 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
| }
|
|
|
| if (IsIPadIdiom()) {
|
| - _toolbarType = context.hasNoOpenedTabs
|
| - ? kToolbarTypeNoTabsiPad
|
| - : (!IsCompactTablet() ? kToolbarTypeWebiPad
|
| - : kToolbarTypeWebiPhone);
|
| + _toolbarType =
|
| + context.hasNoOpenedTabs
|
| + ? ToolbarTypeNoTabsiPad
|
| + : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone);
|
| } else {
|
| // kOptionInTabSwitcher option must be enabled on iPhone with
|
| // no opened tabs.
|
| DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher);
|
| - _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone
|
| - : kToolbarTypeWebiPhone;
|
| + _toolbarType = context.isInTabSwitcher ? ToolbarTypeSwitcheriPhone
|
| + : ToolbarTypeWebiPhone;
|
| }
|
|
|
| // Build the menu, adding all relevant items.
|
| @@ -385,7 +229,8 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
|
|
| for (size_t i = 0; i < arraysize(itemInfoList); ++i) {
|
| const MenuItemInfo& item = itemInfoList[i];
|
| - if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType))
|
| + if (!ToolsMenuItemShouldBeVisible(item, context.isInIncognito,
|
| + _toolbarType))
|
| continue;
|
|
|
| NSString* title = l10n_util::GetNSStringWithFixup(item.title_id);
|
| @@ -402,7 +247,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
|
|
| #if !defined(NDEBUG)
|
| NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
|
| - if ((_toolbarType & kToolbarTypeWebAll) &&
|
| + if ((_toolbarType & ToolbarTypeWebAll) &&
|
| [standardDefaults boolForKey:@"DevViewSource"]) {
|
| // Debug menu, not localized, only visible if turned on by a default.
|
| [menu addObject:[self createViewSourceItem]];
|
| @@ -448,7 +293,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
| - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path {
|
| NSInteger item = [path item];
|
|
|
| - if (_toolbarType == kToolbarTypeWebiPhone)
|
| + if (_toolbarType == ToolbarTypeWebiPhone)
|
| --item;
|
|
|
| return item;
|
| @@ -558,7 +403,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
| }];
|
|
|
| ToolsMenuViewToolsCell* toolsCell = nil;
|
| - if (_toolbarType == kToolbarTypeWebiPhone) {
|
| + if (_toolbarType == ToolbarTypeWebiPhone) {
|
| toolsCell = [visibleCells firstObject];
|
| if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) {
|
| visibleCells = [visibleCells
|
| @@ -698,7 +543,7 @@ NS_INLINE void AnimateInViews(NSArray* views,
|
| - (NSInteger)collectionView:(UICollectionView*)view
|
| numberOfItemsInSection:(NSInteger)section {
|
| NSInteger numberOfItems = [_menuItems count];
|
| - if (_toolbarType == kToolbarTypeWebiPhone)
|
| + if (_toolbarType == ToolbarTypeWebiPhone)
|
| ++numberOfItems;
|
|
|
| return numberOfItems;
|
|
|