Chromium Code Reviews| 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 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" | |
| 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" | 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" |
| 26 #include "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 "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/l10n/l10n_util_mac.h" | 38 #include "ui/base/l10n/l10n_util_mac.h" |
| 37 | 39 |
| 38 using ios::material::TimingFunction; | 40 using ios::material::TimingFunction; |
| 39 | 41 |
| 40 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; | |
| 41 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; | |
| 42 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; | |
| 43 NSString* const kToolsMenuCloseAllIncognitoTabsId = | |
| 44 @"kToolsMenuCloseAllIncognitoTabsId"; | |
| 45 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | |
| 46 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | |
| 47 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | |
| 48 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | |
| 49 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | |
| 50 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | |
| 51 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | |
| 52 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | |
| 53 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | |
| 54 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | |
| 55 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | |
| 56 | |
| 57 namespace { | 42 namespace { |
| 58 | 43 |
| 59 // Time for ink to fade into view. | 44 // Time for ink to fade into view. |
| 60 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 45 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 61 | 46 |
| 62 static const CGFloat kMenuItemHeight = 48; | 47 static const CGFloat kMenuItemHeight = 48; |
| 63 | 48 |
| 64 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; | 49 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; |
| 65 | 50 |
| 66 // Menu items can be marked as visible or not when Incognito is enabled. | |
| 67 // The following bits are used for |visibility| field in |MenuItemInfo|. | |
| 68 const NSInteger kVisibleIncognitoOnly = 1 << 0; | |
| 69 const NSInteger kVisibleNotIncognitoOnly = 1 << 1; | |
| 70 | |
| 71 // Initialization table for all possible commands to initialize the | |
| 72 // tools menu at run time. Data initialized into this structure is not mutable. | |
| 73 struct MenuItemInfo { | |
| 74 int title_id; | |
| 75 NSString* accessibility_id; | |
| 76 int command_id; | |
| 77 int toolbar_types; | |
| 78 // |visibility| is applied if a menu item is included for a given | |
| 79 // |toolbar_types|. A value of 0 means the menu item is always visible for | |
| 80 // the given |toolbar_types|. | |
| 81 int visibility; | |
| 82 // Custom class, if any, for the menu item, or |nil|. | |
| 83 Class item_class; | |
| 84 }; | |
| 85 | |
| 86 // Flags for different toolbar types | |
| 87 typedef NS_OPTIONS(NSUInteger, kToolbarType) { | |
| 88 // clang-format off | |
| 89 kToolbarTypeNone = 0, | |
| 90 kToolbarTypeWebiPhone = 1 << 0, | |
| 91 kToolbarTypeWebiPad = 1 << 1, | |
| 92 kToolbarTypeNoTabsiPad = 1 << 2, | |
| 93 kToolbarTypeSwitcheriPhone = 1 << 3, | |
| 94 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, | |
| 95 kToolbarTypeAll = kToolbarTypeWebAll | | |
| 96 kToolbarTypeSwitcheriPhone | | |
| 97 kToolbarTypeNoTabsiPad, | |
| 98 // clang-format on | |
| 99 }; | |
| 100 | |
| 101 // Declare all the possible items. | |
| 102 static MenuItemInfo itemInfoList[] = { | |
| 103 // clang-format off | |
| 104 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, | |
| 105 IDC_NEW_TAB, kToolbarTypeAll, | |
| 106 0, nil }, | |
| 107 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, | |
| 108 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, | |
| 109 0, nil }, | |
| 110 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, | |
| 111 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, | |
| 112 kVisibleNotIncognitoOnly, nil }, | |
| 113 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS, | |
| 114 kToolsMenuCloseAllIncognitoTabsId, | |
| 115 IDC_CLOSE_ALL_INCOGNITO_TABS, kToolbarTypeSwitcheriPhone, | |
| 116 kVisibleIncognitoOnly, nil }, | |
| 117 { IDS_IOS_TOOLS_MENU_BOOKMARKS, kToolsMenuBookmarksId, | |
| 118 IDC_SHOW_BOOKMARK_MANAGER, kToolbarTypeWebAll, | |
| 119 0, nil }, | |
| 120 { IDS_IOS_TOOLS_MENU_READING_LIST, kToolsMenuReadingListId, | |
| 121 IDC_SHOW_READING_LIST, kToolbarTypeWebAll, | |
| 122 0, [ReadingListMenuViewItem class] }, | |
| 123 { IDS_IOS_TOOLS_MENU_SUGGESTIONS, kToolsMenuSuggestionsId, | |
| 124 IDC_SHOW_SUGGESTIONS, kToolbarTypeWebAll, | |
| 125 0, nil }, | |
| 126 { IDS_IOS_TOOLS_MENU_RECENT_TABS, kToolsMenuOtherDevicesId, | |
| 127 IDC_SHOW_OTHER_DEVICES, kToolbarTypeWebAll, | |
| 128 kVisibleNotIncognitoOnly, nil }, | |
| 129 { IDS_HISTORY_SHOW_HISTORY, kToolsMenuHistoryId, | |
| 130 IDC_SHOW_HISTORY, kToolbarTypeWebAll, | |
| 131 0, nil }, | |
| 132 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | |
| 133 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | |
| 134 0, nil }, | |
| 135 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | |
| 136 IDC_FIND, kToolbarTypeWebAll, | |
| 137 0, nil }, | |
| 138 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | |
| 139 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | |
| 140 0, nil }, | |
| 141 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | |
| 142 IDC_READER_MODE, kToolbarTypeWebAll, | |
| 143 0, nil }, | |
| 144 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | |
| 145 IDC_OPTIONS, kToolbarTypeAll, | |
| 146 0, nil }, | |
| 147 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | |
| 148 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | |
| 149 0, nil }, | |
| 150 // clang-format on | |
| 151 }; | |
| 152 | |
| 153 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, | |
| 154 BOOL incognito, | |
| 155 kToolbarType toolbarType) { | |
| 156 if (!(item.toolbar_types & toolbarType)) | |
| 157 return NO; | |
| 158 | |
| 159 if (incognito && (item.visibility & kVisibleNotIncognitoOnly)) | |
| 160 return NO; | |
| 161 | |
| 162 if (!incognito && (item.visibility & kVisibleIncognitoOnly)) | |
| 163 return NO; | |
| 164 | |
| 165 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { | |
| 166 if (!IsIPadIdiom()) { | |
| 167 return NO; | |
| 168 } | |
| 169 } | |
| 170 | |
| 171 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { | |
| 172 if (!experimental_flags::IsReaderModeEnabled()) { | |
| 173 return NO; | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 if (item.title_id == IDS_IOS_TOOLS_MENU_READING_LIST) { | |
| 178 if (!reading_list::switches::IsReadingListEnabled()) { | |
| 179 return NO; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 if (item.title_id == IDS_IOS_TOOLS_MENU_SUGGESTIONS) { | |
| 184 if (!experimental_flags::IsSuggestionsUIEnabled()) { | |
| 185 return NO; | |
| 186 } | |
| 187 } | |
| 188 | |
| 189 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { | |
| 190 if (!ios::GetChromeBrowserProvider() | |
| 191 ->GetUserFeedbackProvider() | |
| 192 ->IsUserFeedbackEnabled()) { | |
| 193 return NO; | |
| 194 } | |
| 195 } | |
| 196 | |
| 197 return YES; | |
| 198 } | |
| 199 | |
| 200 NS_INLINE void AnimateInViews(NSArray* views, | 51 NS_INLINE void AnimateInViews(NSArray* views, |
| 201 CGFloat initialX, | 52 CGFloat initialX, |
| 202 CGFloat initialY) { | 53 CGFloat initialY) { |
| 203 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, | 54 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, |
| 204 BOOL* stop) { | 55 BOOL* stop) { |
| 205 CGFloat beginTime = index * .035; | 56 CGFloat beginTime = index * .035; |
| 206 CABasicAnimation* transformAnimation = | 57 CABasicAnimation* transformAnimation = |
| 207 [CABasicAnimation animationWithKeyPath:@"transform"]; | 58 [CABasicAnimation animationWithKeyPath:@"transform"]; |
| 208 [transformAnimation | 59 [transformAnimation |
| 209 setFromValue:[NSValue | 60 setFromValue:[NSValue |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 ReadingListMenuNotificationDelegate> { | 106 ReadingListMenuNotificationDelegate> { |
| 256 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 107 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
| 257 BOOL _waitForInk; | 108 BOOL _waitForInk; |
| 258 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 109 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 259 // for the reading list badge. | 110 // for the reading list badge. |
| 260 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 111 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 261 } | 112 } |
| 262 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 113 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 263 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 114 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 264 @property(nonatomic, retain) NSMutableArray* menuItems; | 115 @property(nonatomic, retain) NSMutableArray* menuItems; |
| 265 @property(nonatomic, assign) kToolbarType toolbarType; | 116 @property(nonatomic, assign) ToolbarType toolbarType; |
| 266 | 117 |
| 267 // Get the reading list cell. | 118 // Get the reading list cell. |
| 268 - (ReadingListMenuViewCell*)readingListCell; | 119 - (ReadingListMenuViewCell*)readingListCell; |
| 269 @end | 120 @end |
| 270 | 121 |
| 271 @implementation ToolsMenuViewController | 122 @implementation ToolsMenuViewController |
| 272 | 123 |
| 273 @synthesize menuView = _menuView; | 124 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 125 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 126 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 127 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 128 @synthesize toolbarType = _toolbarType; |
| 278 @synthesize menuItems = _menuItems; | 129 @synthesize menuItems = _menuItems; |
| 279 @synthesize delegate = _delegate; | 130 @synthesize delegate = _delegate; |
| 280 | 131 |
| 281 #pragma mark Public methods | 132 #pragma mark Public methods |
| 282 | 133 |
| 283 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 134 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 284 NSInteger numberOfItems = [self.menuItems count]; | 135 NSInteger numberOfItems = [self.menuItems count]; |
| 285 if (_toolbarType == kToolbarTypeWebiPhone) { | 136 if (_toolbarType == ToolbarTypeWebiPhone) { |
| 286 // Account for the height of the first row, not included in |menuItems|. | 137 // Account for the height of the first row, not included in |menuItems|. |
| 287 numberOfItems++; | 138 numberOfItems++; |
| 288 } | 139 } |
| 289 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 140 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
| 290 if (maxItems >= numberOfItems) { | 141 if (maxItems >= numberOfItems) { |
| 291 return numberOfItems * kMenuItemHeight; | 142 return numberOfItems * kMenuItemHeight; |
| 292 } else { | 143 } else { |
| 293 const CGFloat halfHeight = kMenuItemHeight / 2; | 144 const CGFloat halfHeight = kMenuItemHeight / 2; |
| 294 return round(maxItems) * kMenuItemHeight - halfHeight; | 145 return round(maxItems) * kMenuItemHeight - halfHeight; |
| 295 } | 146 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 [[toolsCell reloadButton] setHidden:isTabLoading]; | 212 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 362 } | 213 } |
| 363 | 214 |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 215 - (void)initializeMenu:(ToolsMenuContext*)context { |
| 365 if (context.readingListMenuNotifier) { | 216 if (context.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 217 _readingListMenuNotifier.reset(context.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 218 [context.readingListMenuNotifier setDelegate:self]; |
| 368 } | 219 } |
| 369 | 220 |
| 370 if (IsIPadIdiom()) { | 221 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 222 _toolbarType = |
| 372 ? kToolbarTypeNoTabsiPad | 223 context.hasNoOpenedTabs |
|
edchin
2017/02/27 23:02:41
It's odd that clang-format moved this line when no
sczs
2017/03/02 22:56:11
I think the previous patch might have been uploade
| |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 224 ? ToolbarTypeNoTabsiPad |
| 374 : kToolbarTypeWebiPhone); | 225 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); |
| 375 } else { | 226 } else { |
| 376 // kOptionInTabSwitcher option must be enabled on iPhone with | 227 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 377 // no opened tabs. | 228 // no opened tabs. |
| 378 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); | 229 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); |
| 379 _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone | 230 _toolbarType = context.isInTabSwitcher ? ToolbarTypeSwitcheriPhone |
| 380 : kToolbarTypeWebiPhone; | 231 : ToolbarTypeWebiPhone; |
| 381 } | 232 } |
| 382 | 233 |
| 383 // Build the menu, adding all relevant items. | 234 // Build the menu, adding all relevant items. |
| 384 NSMutableArray* menu = [NSMutableArray array]; | 235 NSMutableArray* menu = [NSMutableArray array]; |
| 385 | 236 |
| 386 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 237 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 387 const MenuItemInfo& item = itemInfoList[i]; | 238 const MenuItemInfo& item = itemInfoList[i]; |
| 388 if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType)) | 239 if (!ToolsMenuItemShouldBeVisible(item, context.isInIncognito, |
| 240 _toolbarType)) | |
| 389 continue; | 241 continue; |
| 390 | 242 |
| 391 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 243 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 392 Class itemClass = | 244 Class itemClass = |
| 393 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 245 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 394 // Sanity check that the class is a useful one. | 246 // Sanity check that the class is a useful one. |
| 395 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 247 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 396 accessibilityIdentifier: | 248 accessibilityIdentifier: |
| 397 command:)]); | 249 command:)]); |
| 398 [menu addObject:[itemClass menuItemWithTitle:title | 250 [menu addObject:[itemClass menuItemWithTitle:title |
| 399 accessibilityIdentifier:item.accessibility_id | 251 accessibilityIdentifier:item.accessibility_id |
| 400 command:item.command_id]]; | 252 command:item.command_id]]; |
| 401 } | 253 } |
| 402 | 254 |
| 403 #if !defined(NDEBUG) | 255 #if !defined(NDEBUG) |
| 404 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 256 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 405 if ((_toolbarType & kToolbarTypeWebAll) && | 257 if ((_toolbarType & ToolbarTypeWebAll) && |
| 406 [standardDefaults boolForKey:@"DevViewSource"]) { | 258 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 407 // 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. |
| 408 [menu addObject:[self createViewSourceItem]]; | 260 [menu addObject:[self createViewSourceItem]]; |
| 409 } | 261 } |
| 410 #endif // !defined(NDEBUG) | 262 #endif // !defined(NDEBUG) |
| 411 | 263 |
| 412 [self setMenuItems:menu]; | 264 [self setMenuItems:menu]; |
| 413 | 265 |
| 414 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. | 266 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. |
| 415 if (!IsIPadIdiom()) { | 267 if (!IsIPadIdiom()) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 441 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) | 293 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) |
| 442 return visibleCell; | 294 return visibleCell; |
| 443 } | 295 } |
| 444 | 296 |
| 445 return nil; | 297 return nil; |
| 446 } | 298 } |
| 447 | 299 |
| 448 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { | 300 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { |
| 449 NSInteger item = [path item]; | 301 NSInteger item = [path item]; |
| 450 | 302 |
| 451 if (_toolbarType == kToolbarTypeWebiPhone) | 303 if (_toolbarType == ToolbarTypeWebiPhone) |
| 452 --item; | 304 --item; |
| 453 | 305 |
| 454 return item; | 306 return item; |
| 455 } | 307 } |
| 456 | 308 |
| 457 #pragma mark - UIViewController Overrides | 309 #pragma mark - UIViewController Overrides |
| 458 | 310 |
| 459 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 311 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
| 460 bundle:(NSBundle*)nibBundleOrNil { | 312 bundle:(NSBundle*)nibBundleOrNil { |
| 461 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | 313 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 if (center1.y < center2.y) | 403 if (center1.y < center2.y) |
| 552 return NSOrderedAscending; | 404 return NSOrderedAscending; |
| 553 | 405 |
| 554 if (center1.y > center2.y) | 406 if (center1.y > center2.y) |
| 555 return NSOrderedDescending; | 407 return NSOrderedDescending; |
| 556 | 408 |
| 557 return NSOrderedSame; | 409 return NSOrderedSame; |
| 558 }]; | 410 }]; |
| 559 | 411 |
| 560 ToolsMenuViewToolsCell* toolsCell = nil; | 412 ToolsMenuViewToolsCell* toolsCell = nil; |
| 561 if (_toolbarType == kToolbarTypeWebiPhone) { | 413 if (_toolbarType == ToolbarTypeWebiPhone) { |
| 562 toolsCell = [visibleCells firstObject]; | 414 toolsCell = [visibleCells firstObject]; |
| 563 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { | 415 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { |
| 564 visibleCells = [visibleCells | 416 visibleCells = [visibleCells |
| 565 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; | 417 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; |
| 566 } else { | 418 } else { |
| 567 toolsCell = nil; | 419 toolsCell = nil; |
| 568 } | 420 } |
| 569 } | 421 } |
| 570 | 422 |
| 571 [CATransaction begin]; | 423 [CATransaction begin]; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 [_delegate commandWasSelected:[menuItem tag]]; | 543 [_delegate commandWasSelected:[menuItem tag]]; |
| 692 [self chromeExecuteCommand:menuItem]; | 544 [self chromeExecuteCommand:menuItem]; |
| 693 }); | 545 }); |
| 694 } | 546 } |
| 695 | 547 |
| 696 #pragma mark - UICollectionViewDataSource Implementation | 548 #pragma mark - UICollectionViewDataSource Implementation |
| 697 | 549 |
| 698 - (NSInteger)collectionView:(UICollectionView*)view | 550 - (NSInteger)collectionView:(UICollectionView*)view |
| 699 numberOfItemsInSection:(NSInteger)section { | 551 numberOfItemsInSection:(NSInteger)section { |
| 700 NSInteger numberOfItems = [_menuItems count]; | 552 NSInteger numberOfItems = [_menuItems count]; |
| 701 if (_toolbarType == kToolbarTypeWebiPhone) | 553 if (_toolbarType == ToolbarTypeWebiPhone) |
| 702 ++numberOfItems; | 554 ++numberOfItems; |
| 703 | 555 |
| 704 return numberOfItems; | 556 return numberOfItems; |
| 705 } | 557 } |
| 706 | 558 |
| 707 - (UICollectionViewCell*)collectionView:(UICollectionView*)view | 559 - (UICollectionViewCell*)collectionView:(UICollectionView*)view |
| 708 cellForItemAtIndexPath:(NSIndexPath*)path { | 560 cellForItemAtIndexPath:(NSIndexPath*)path { |
| 709 NSInteger item = [self dataIndexForIndexPath:path]; | 561 NSInteger item = [self dataIndexForIndexPath:path]; |
| 710 if (item < 0) { | 562 if (item < 0) { |
| 711 ToolsMenuViewToolsCell* cell = | 563 ToolsMenuViewToolsCell* cell = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 | 599 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 600 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 601 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 602 } |
| 751 | 603 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 604 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 605 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 606 } |
| 755 | 607 |
| 756 @end | 608 @end |
| OLD | NEW |