| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" | 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/objc_property_releaser.h" | 12 #include "base/mac/objc_property_releaser.h" |
| 13 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
| 15 #include "components/reading_list/core/reading_list_switches.h" | 15 #include "components/reading_list/core/reading_list_switches.h" |
| 16 #include "components/strings/grit/components_strings.h" | 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "ios/chrome/browser/experimental_flags.h" | 17 #include "ios/chrome/browser/experimental_flags.h" |
| 18 #import "ios/chrome/browser/ui/animation_util.h" | 18 #import "ios/chrome/browser/ui/animation_util.h" |
| 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 21 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg
ate.h" | 21 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_deleg
ate.h" |
| 22 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" | 22 #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notifier.h" |
| 23 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" | 23 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h" |
| 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
| 26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" |
| 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 27 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
| 26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" | 28 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" |
| 27 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 29 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 28 #include "ios/chrome/browser/ui/ui_util.h" | 30 #include "ios/chrome/browser/ui/ui_util.h" |
| 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 31 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 30 #import "ios/chrome/common/material_timing.h" | 32 #import "ios/chrome/common/material_timing.h" |
| 31 #include "ios/chrome/grit/ios_strings.h" | 33 #include "ios/chrome/grit/ios_strings.h" |
| 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 34 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 33 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 35 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
| 34 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 36 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 35 #include "ios/web/public/user_agent.h" | 37 #include "ios/web/public/user_agent.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/l10n/l10n_util_mac.h" | 39 #include "ui/base/l10n/l10n_util_mac.h" |
| 38 | 40 |
| 39 // TODO(crbug.com/678047) Remove this switch when request mobile site | 41 // TODO(crbug.com/678047) Remove this switch when request mobile site |
| 40 // functionality is implemented. | 42 // functionality is implemented. |
| 41 #define HIDE_REQUEST_MOBILE_SITE_CELL | 43 #define HIDE_REQUEST_MOBILE_SITE_CELL |
| 42 | 44 |
| 43 using ios::material::TimingFunction; | 45 using ios::material::TimingFunction; |
| 44 | 46 |
| 45 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; | |
| 46 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; | |
| 47 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; | |
| 48 NSString* const kToolsMenuCloseAllIncognitoTabsId = | |
| 49 @"kToolsMenuCloseAllIncognitoTabsId"; | |
| 50 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | |
| 51 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | |
| 52 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | |
| 53 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | |
| 54 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | |
| 55 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | |
| 56 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | |
| 57 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | |
| 58 NSString* const kToolsMenuRequestMobileId = @"kToolsMenuRequestMobileId"; | |
| 59 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | |
| 60 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | |
| 61 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | |
| 62 | |
| 63 namespace { | 47 namespace { |
| 64 | 48 |
| 65 // Time for ink to fade into view. | 49 // Time for ink to fade into view. |
| 66 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 50 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 67 | 51 |
| 68 static const CGFloat kMenuItemHeight = 48; | 52 static const CGFloat kMenuItemHeight = 48; |
| 69 | 53 |
| 70 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; | 54 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; |
| 71 | 55 |
| 72 // Menu items can be marked as visible or not when Incognito is enabled. | |
| 73 // The following bits are used for |visibility| field in |MenuItemInfo|. | |
| 74 const NSInteger kVisibleIncognitoOnly = 1 << 0; | |
| 75 const NSInteger kVisibleNotIncognitoOnly = 1 << 1; | |
| 76 | |
| 77 // Initialization table for all possible commands to initialize the | |
| 78 // tools menu at run time. Data initialized into this structure is not mutable. | |
| 79 struct MenuItemInfo { | |
| 80 int title_id; | |
| 81 NSString* accessibility_id; | |
| 82 int command_id; | |
| 83 int toolbar_types; | |
| 84 // |visibility| is applied if a menu item is included for a given | |
| 85 // |toolbar_types|. A value of 0 means the menu item is always visible for | |
| 86 // the given |toolbar_types|. | |
| 87 int visibility; | |
| 88 // Custom class, if any, for the menu item, or |nil|. | |
| 89 Class item_class; | |
| 90 }; | |
| 91 | |
| 92 // Flags for different toolbar types | |
| 93 typedef NS_OPTIONS(NSUInteger, kToolbarType) { | |
| 94 // clang-format off | |
| 95 kToolbarTypeNone = 0, | |
| 96 kToolbarTypeWebiPhone = 1 << 0, | |
| 97 kToolbarTypeWebiPad = 1 << 1, | |
| 98 kToolbarTypeNoTabsiPad = 1 << 2, | |
| 99 kToolbarTypeSwitcheriPhone = 1 << 3, | |
| 100 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, | |
| 101 kToolbarTypeAll = kToolbarTypeWebAll | | |
| 102 kToolbarTypeSwitcheriPhone | | |
| 103 kToolbarTypeNoTabsiPad, | |
| 104 // clang-format on | |
| 105 }; | |
| 106 | |
| 107 // Declares all the possible items. | |
| 108 static MenuItemInfo itemInfoList[] = { | |
| 109 // clang-format off | |
| 110 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, | |
| 111 IDC_NEW_TAB, kToolbarTypeAll, | |
| 112 0, nil }, | |
| 113 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, | |
| 114 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, | |
| 115 0, nil }, | |
| 116 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, | |
| 117 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, | |
| 118 kVisibleNotIncognitoOnly, nil }, | |
| 119 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS, | |
| 120 kToolsMenuCloseAllIncognitoTabsId, | |
| 121 IDC_CLOSE_ALL_INCOGNITO_TABS, kToolbarTypeSwitcheriPhone, | |
| 122 kVisibleIncognitoOnly, nil }, | |
| 123 { IDS_IOS_TOOLS_MENU_BOOKMARKS, kToolsMenuBookmarksId, | |
| 124 IDC_SHOW_BOOKMARK_MANAGER, kToolbarTypeWebAll, | |
| 125 0, nil }, | |
| 126 { IDS_IOS_TOOLS_MENU_READING_LIST, kToolsMenuReadingListId, | |
| 127 IDC_SHOW_READING_LIST, kToolbarTypeWebAll, | |
| 128 0, [ReadingListMenuViewItem class] }, | |
| 129 { IDS_IOS_TOOLS_MENU_SUGGESTIONS, kToolsMenuSuggestionsId, | |
| 130 IDC_SHOW_SUGGESTIONS, kToolbarTypeWebAll, | |
| 131 0, nil }, | |
| 132 { IDS_IOS_TOOLS_MENU_RECENT_TABS, kToolsMenuOtherDevicesId, | |
| 133 IDC_SHOW_OTHER_DEVICES, kToolbarTypeWebAll, | |
| 134 kVisibleNotIncognitoOnly, nil }, | |
| 135 { IDS_HISTORY_SHOW_HISTORY, kToolsMenuHistoryId, | |
| 136 IDC_SHOW_HISTORY, kToolbarTypeWebAll, | |
| 137 0, nil }, | |
| 138 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | |
| 139 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | |
| 140 0, nil }, | |
| 141 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | |
| 142 IDC_FIND, kToolbarTypeWebAll, | |
| 143 0, nil }, | |
| 144 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | |
| 145 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | |
| 146 0, nil }, | |
| 147 { IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE, kToolsMenuRequestMobileId, | |
| 148 IDC_REQUEST_MOBILE_SITE, kToolbarTypeWebAll, | |
| 149 0, nil }, | |
| 150 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | |
| 151 IDC_READER_MODE, kToolbarTypeWebAll, | |
| 152 0, nil }, | |
| 153 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | |
| 154 IDC_OPTIONS, kToolbarTypeAll, | |
| 155 0, nil }, | |
| 156 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | |
| 157 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | |
| 158 0, nil }, | |
| 159 // clang-format on | |
| 160 }; | |
| 161 | |
| 162 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, | |
| 163 kToolbarType toolbarType, | |
| 164 ToolsMenuConfiguration* configuration) { | |
| 165 if (!(item.toolbar_types & toolbarType)) | |
| 166 return NO; | |
| 167 | |
| 168 if (configuration.inIncognito && (item.visibility & kVisibleNotIncognitoOnly)) | |
| 169 return NO; | |
| 170 | |
| 171 if (!configuration.inIncognito && (item.visibility & kVisibleIncognitoOnly)) | |
| 172 return NO; | |
| 173 | |
| 174 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { | |
| 175 if (!IsIPadIdiom()) { | |
| 176 return NO; | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { | |
| 181 if (!experimental_flags::IsReaderModeEnabled()) { | |
| 182 return NO; | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 if (item.title_id == IDS_IOS_TOOLS_MENU_READING_LIST) { | |
| 187 if (!reading_list::switches::IsReadingListEnabled()) { | |
| 188 return NO; | |
| 189 } | |
| 190 } | |
| 191 | |
| 192 if (item.title_id == IDS_IOS_TOOLS_MENU_SUGGESTIONS) { | |
| 193 if (!experimental_flags::IsSuggestionsUIEnabled()) { | |
| 194 return NO; | |
| 195 } | |
| 196 } | |
| 197 | |
| 198 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { | |
| 199 if (!ios::GetChromeBrowserProvider() | |
| 200 ->GetUserFeedbackProvider() | |
| 201 ->IsUserFeedbackEnabled()) { | |
| 202 return NO; | |
| 203 } | |
| 204 } | |
| 205 | |
| 206 // TODO(crbug.com/696676): Talk to UI/UX people to decide the correct behavior | |
| 207 // of "Requestion Desktop/Mobile Site" (e.g. Whether user agent flag should | |
| 208 // stick when going backward and which cell should be visible when navigating | |
| 209 // to native pages). | |
| 210 if (item.title_id == IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE) { | |
| 211 // TODO(crbug.com/678047) Remove this switch when request mobile site | |
| 212 // functionality is implemented. | |
| 213 #ifdef HIDE_REQUEST_MOBILE_SITE_CELL | |
| 214 return YES; | |
| 215 #else | |
| 216 if (configuration.userAgentType == web::UserAgentType::DESKTOP) | |
| 217 return NO; | |
| 218 #endif | |
| 219 } | |
| 220 | |
| 221 if (item.title_id == IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE) { | |
| 222 // TODO(crbug.com/678047) Remove this switch when request mobile site | |
| 223 // functionality is implemented. | |
| 224 #ifdef HIDE_REQUEST_MOBILE_SITE_CELL | |
| 225 return NO; | |
| 226 #else | |
| 227 if (configuration.userAgentType != web::UserAgentType::DESKTOP) | |
| 228 return NO; | |
| 229 #endif | |
| 230 } | |
| 231 | |
| 232 return YES; | |
| 233 } | |
| 234 | 56 |
| 235 NS_INLINE void AnimateInViews(NSArray* views, | 57 NS_INLINE void AnimateInViews(NSArray* views, |
| 236 CGFloat initialX, | 58 CGFloat initialX, |
| 237 CGFloat initialY) { | 59 CGFloat initialY) { |
| 238 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, | 60 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, |
| 239 BOOL* stop) { | 61 BOOL* stop) { |
| 240 CGFloat beginTime = index * .035; | 62 CGFloat beginTime = index * .035; |
| 241 CABasicAnimation* transformAnimation = | 63 CABasicAnimation* transformAnimation = |
| 242 [CABasicAnimation animationWithKeyPath:@"transform"]; | 64 [CABasicAnimation animationWithKeyPath:@"transform"]; |
| 243 [transformAnimation | 65 [transformAnimation |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 UICollectionViewDataSource, | 111 UICollectionViewDataSource, |
| 290 ReadingListMenuNotificationDelegate> { | 112 ReadingListMenuNotificationDelegate> { |
| 291 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 113 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
| 292 BOOL _waitForInk; | 114 BOOL _waitForInk; |
| 293 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 115 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 294 // for the reading list badge. | 116 // for the reading list badge. |
| 295 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 117 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 296 } | 118 } |
| 297 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 119 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 298 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 120 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 299 @property(nonatomic, assign) kToolbarType toolbarType; | 121 @property(nonatomic, assign) ToolbarType toolbarType; |
| 300 | 122 |
| 301 // Returns the reading list cell. | 123 // Returns the reading list cell. |
| 302 - (ReadingListMenuViewCell*)readingListCell; | 124 - (ReadingListMenuViewCell*)readingListCell; |
| 303 @end | 125 @end |
| 304 | 126 |
| 305 @implementation ToolsMenuViewController | 127 @implementation ToolsMenuViewController |
| 306 | 128 |
| 307 @synthesize menuView = _menuView; | 129 @synthesize menuView = _menuView; |
| 308 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 130 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 309 @synthesize touchFeedbackView = _touchFeedbackView; | 131 @synthesize touchFeedbackView = _touchFeedbackView; |
| 310 @synthesize isTabLoading = _isTabLoading; | 132 @synthesize isTabLoading = _isTabLoading; |
| 311 @synthesize toolbarType = _toolbarType; | 133 @synthesize toolbarType = _toolbarType; |
| 312 @synthesize menuItems = _menuItems; | 134 @synthesize menuItems = _menuItems; |
| 313 @synthesize delegate = _delegate; | 135 @synthesize delegate = _delegate; |
| 314 | 136 |
| 315 #pragma mark Public methods | 137 #pragma mark Public methods |
| 316 | 138 |
| 317 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 139 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 318 NSInteger numberOfItems = [self.menuItems count]; | 140 NSInteger numberOfItems = [self.menuItems count]; |
| 319 if (_toolbarType == kToolbarTypeWebiPhone) { | 141 if (_toolbarType == ToolbarTypeWebiPhone) { |
| 320 // Account for the height of the first row, not included in |menuItems|. | 142 // Account for the height of the first row, not included in |menuItems|. |
| 321 numberOfItems++; | 143 numberOfItems++; |
| 322 } | 144 } |
| 323 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 145 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
| 324 if (maxItems >= numberOfItems) { | 146 if (maxItems >= numberOfItems) { |
| 325 return numberOfItems * kMenuItemHeight; | 147 return numberOfItems * kMenuItemHeight; |
| 326 } else { | 148 } else { |
| 327 const CGFloat halfHeight = kMenuItemHeight / 2; | 149 const CGFloat halfHeight = kMenuItemHeight / 2; |
| 328 return round(maxItems) * kMenuItemHeight - halfHeight; | 150 return round(maxItems) * kMenuItemHeight - halfHeight; |
| 329 } | 151 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 [[toolsCell reloadButton] setHidden:isTabLoading]; | 213 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 392 } | 214 } |
| 393 | 215 |
| 394 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { | 216 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 395 if (configuration.readingListMenuNotifier) { | 217 if (configuration.readingListMenuNotifier) { |
| 396 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); | 218 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); |
| 397 [configuration.readingListMenuNotifier setDelegate:self]; | 219 [configuration.readingListMenuNotifier setDelegate:self]; |
| 398 } | 220 } |
| 399 | 221 |
| 400 if (IsIPadIdiom()) { | 222 if (IsIPadIdiom()) { |
| 401 _toolbarType = configuration.hasNoOpenedTabs | 223 _toolbarType = |
| 402 ? kToolbarTypeNoTabsiPad | 224 configuration.hasNoOpenedTabs |
| 403 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 225 ? ToolbarTypeNoTabsiPad |
| 404 : kToolbarTypeWebiPhone); | 226 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); |
| 405 } else { | 227 } else { |
| 406 // kOptionInTabSwitcher option must be enabled on iPhone with | 228 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 407 // no opened tabs. | 229 // no opened tabs. |
| 408 DCHECK(!configuration.hasNoOpenedTabs || configuration.isInTabSwitcher); | 230 DCHECK(!configuration.hasNoOpenedTabs || configuration.isInTabSwitcher); |
| 409 _toolbarType = configuration.isInTabSwitcher ? kToolbarTypeSwitcheriPhone | 231 _toolbarType = configuration.isInTabSwitcher ? ToolbarTypeSwitcheriPhone |
| 410 : kToolbarTypeWebiPhone; | 232 : ToolbarTypeWebiPhone; |
| 411 } | 233 } |
| 412 | 234 |
| 413 // Build the menu, adding all relevant items. | 235 // Build the menu, adding all relevant items. |
| 414 NSMutableArray* menu = [NSMutableArray array]; | 236 NSMutableArray* menu = [NSMutableArray array]; |
| 415 | 237 |
| 416 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 238 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 417 const MenuItemInfo& item = itemInfoList[i]; | 239 const MenuItemInfo& item = itemInfoList[i]; |
| 418 if (!ItemShouldBeVisible(item, _toolbarType, configuration)) | 240 if (!ToolsMenuItemShouldBeVisible(item, _toolbarType, configuration)) |
| 419 continue; | 241 continue; |
| 420 | 242 |
| 421 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 243 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 422 Class itemClass = | 244 Class itemClass = |
| 423 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 245 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 424 // Sanity check that the class is a useful one. | 246 // Sanity check that the class is a useful one. |
| 425 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 247 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 426 accessibilityIdentifier: | 248 accessibilityIdentifier: |
| 427 command:)]); | 249 command:)]); |
| 428 [menu addObject:[itemClass menuItemWithTitle:title | 250 [menu addObject:[itemClass menuItemWithTitle:title |
| 429 accessibilityIdentifier:item.accessibility_id | 251 accessibilityIdentifier:item.accessibility_id |
| 430 command:item.command_id]]; | 252 command:item.command_id]]; |
| 431 } | 253 } |
| 432 | 254 |
| 433 #if !defined(NDEBUG) | 255 #if !defined(NDEBUG) |
| 434 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 256 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 435 if ((_toolbarType & kToolbarTypeWebAll) && | 257 if ((_toolbarType & ToolbarTypeWebAll) && |
| 436 [standardDefaults boolForKey:@"DevViewSource"]) { | 258 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 437 // Debug menu, not localized, only visible if turned on by a default. | 259 // Debug menu, not localized, only visible if turned on by a default. |
| 438 [menu addObject:[self createViewSourceItem]]; | 260 [menu addObject:[self createViewSourceItem]]; |
| 439 } | 261 } |
| 440 #endif // !defined(NDEBUG) | 262 #endif // !defined(NDEBUG) |
| 441 | 263 |
| 442 [self setMenuItems:menu]; | 264 [self setMenuItems:menu]; |
| 443 | 265 |
| 444 // Decide the enabled state of the currently visible item between | 266 // Decide the enabled state of the currently visible item between |
| 445 // "Request Desktop Site" and "Request Mobile Site". | 267 // "Request Desktop Site" and "Request Mobile Site". |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) | 314 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) |
| 493 return visibleCell; | 315 return visibleCell; |
| 494 } | 316 } |
| 495 | 317 |
| 496 return nil; | 318 return nil; |
| 497 } | 319 } |
| 498 | 320 |
| 499 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { | 321 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { |
| 500 NSInteger item = [path item]; | 322 NSInteger item = [path item]; |
| 501 | 323 |
| 502 if (_toolbarType == kToolbarTypeWebiPhone) | 324 if (_toolbarType == ToolbarTypeWebiPhone) |
| 503 --item; | 325 --item; |
| 504 | 326 |
| 505 return item; | 327 return item; |
| 506 } | 328 } |
| 507 | 329 |
| 508 #pragma mark - UIViewController Overrides | 330 #pragma mark - UIViewController Overrides |
| 509 | 331 |
| 510 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 332 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
| 511 bundle:(NSBundle*)nibBundleOrNil { | 333 bundle:(NSBundle*)nibBundleOrNil { |
| 512 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | 334 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 if (center1.y < center2.y) | 424 if (center1.y < center2.y) |
| 603 return NSOrderedAscending; | 425 return NSOrderedAscending; |
| 604 | 426 |
| 605 if (center1.y > center2.y) | 427 if (center1.y > center2.y) |
| 606 return NSOrderedDescending; | 428 return NSOrderedDescending; |
| 607 | 429 |
| 608 return NSOrderedSame; | 430 return NSOrderedSame; |
| 609 }]; | 431 }]; |
| 610 | 432 |
| 611 ToolsMenuViewToolsCell* toolsCell = nil; | 433 ToolsMenuViewToolsCell* toolsCell = nil; |
| 612 if (_toolbarType == kToolbarTypeWebiPhone) { | 434 if (_toolbarType == ToolbarTypeWebiPhone) { |
| 613 toolsCell = [visibleCells firstObject]; | 435 toolsCell = [visibleCells firstObject]; |
| 614 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { | 436 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { |
| 615 visibleCells = [visibleCells | 437 visibleCells = [visibleCells |
| 616 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; | 438 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; |
| 617 } else { | 439 } else { |
| 618 toolsCell = nil; | 440 toolsCell = nil; |
| 619 } | 441 } |
| 620 } | 442 } |
| 621 | 443 |
| 622 [CATransaction begin]; | 444 [CATransaction begin]; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 [_delegate commandWasSelected:[menuItem tag]]; | 564 [_delegate commandWasSelected:[menuItem tag]]; |
| 743 [self chromeExecuteCommand:menuItem]; | 565 [self chromeExecuteCommand:menuItem]; |
| 744 }); | 566 }); |
| 745 } | 567 } |
| 746 | 568 |
| 747 #pragma mark - UICollectionViewDataSource Implementation | 569 #pragma mark - UICollectionViewDataSource Implementation |
| 748 | 570 |
| 749 - (NSInteger)collectionView:(UICollectionView*)view | 571 - (NSInteger)collectionView:(UICollectionView*)view |
| 750 numberOfItemsInSection:(NSInteger)section { | 572 numberOfItemsInSection:(NSInteger)section { |
| 751 NSInteger numberOfItems = [_menuItems count]; | 573 NSInteger numberOfItems = [_menuItems count]; |
| 752 if (_toolbarType == kToolbarTypeWebiPhone) | 574 if (_toolbarType == ToolbarTypeWebiPhone) |
| 753 ++numberOfItems; | 575 ++numberOfItems; |
| 754 | 576 |
| 755 return numberOfItems; | 577 return numberOfItems; |
| 756 } | 578 } |
| 757 | 579 |
| 758 - (UICollectionViewCell*)collectionView:(UICollectionView*)view | 580 - (UICollectionViewCell*)collectionView:(UICollectionView*)view |
| 759 cellForItemAtIndexPath:(NSIndexPath*)path { | 581 cellForItemAtIndexPath:(NSIndexPath*)path { |
| 760 NSInteger item = [self dataIndexForIndexPath:path]; | 582 NSInteger item = [self dataIndexForIndexPath:path]; |
| 761 if (item < 0) { | 583 if (item < 0) { |
| 762 ToolsMenuViewToolsCell* cell = | 584 ToolsMenuViewToolsCell* cell = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 | 620 |
| 799 - (void)unreadCountChanged:(NSInteger)unreadCount { | 621 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 800 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 622 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 801 } | 623 } |
| 802 | 624 |
| 803 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 625 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 804 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 626 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 805 } | 627 } |
| 806 | 628 |
| 807 @end | 629 @end |
| OLD | NEW |