| 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" |
| 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "ios/chrome/browser/experimental_flags.h" |
| 15 #import "ios/chrome/browser/ui/animation_util.h" | 18 #import "ios/chrome/browser/ui/animation_util.h" |
| 16 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 19 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 20 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 18 #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" |
| 19 #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" |
| 20 #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" |
| 21 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_context.h" |
| 22 #include "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" | |
| 23 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 25 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
| 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" | 26 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" |
| 25 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" | 27 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h" |
| 28 #include "ios/chrome/browser/ui/ui_util.h" |
| 26 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 27 #import "ios/chrome/common/material_timing.h" | 30 #import "ios/chrome/common/material_timing.h" |
| 28 #include "ios/chrome/grit/ios_strings.h" | 31 #include "ios/chrome/grit/ios_strings.h" |
| 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 33 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" |
| 29 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 34 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 30 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| 31 #include "ui/base/l10n/l10n_util_mac.h" | 36 #include "ui/base/l10n/l10n_util_mac.h" |
| 32 | 37 |
| 33 using ios::material::TimingFunction; | 38 using ios::material::TimingFunction; |
| 34 | 39 |
| 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 |
| 35 namespace { | 57 namespace { |
| 36 | 58 |
| 37 // Time for ink to fade into view. | 59 // Time for ink to fade into view. |
| 38 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 60 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 39 | 61 |
| 40 static const CGFloat kMenuItemHeight = 48; | 62 static const CGFloat kMenuItemHeight = 48; |
| 41 | 63 |
| 42 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; | 64 static NSString* const kToolsItemCellID = @"ToolsItemCellID"; |
| 43 | 65 |
| 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 |
| 44 NS_INLINE void AnimateInViews(NSArray* views, | 200 NS_INLINE void AnimateInViews(NSArray* views, |
| 45 CGFloat initialX, | 201 CGFloat initialX, |
| 46 CGFloat initialY) { | 202 CGFloat initialY) { |
| 47 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, | 203 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, |
| 48 BOOL* stop) { | 204 BOOL* stop) { |
| 49 CGFloat beginTime = index * .035; | 205 CGFloat beginTime = index * .035; |
| 50 CABasicAnimation* transformAnimation = | 206 CABasicAnimation* transformAnimation = |
| 51 [CABasicAnimation animationWithKeyPath:@"transform"]; | 207 [CABasicAnimation animationWithKeyPath:@"transform"]; |
| 52 [transformAnimation | 208 [transformAnimation |
| 53 setFromValue:[NSValue | 209 setFromValue:[NSValue |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 ReadingListMenuNotificationDelegate> { | 255 ReadingListMenuNotificationDelegate> { |
| 100 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 256 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
| 101 BOOL _waitForInk; | 257 BOOL _waitForInk; |
| 102 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 258 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 103 // for the reading list badge. | 259 // for the reading list badge. |
| 104 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 260 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 105 } | 261 } |
| 106 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 262 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 107 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 263 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 108 @property(nonatomic, retain) NSMutableArray* menuItems; | 264 @property(nonatomic, retain) NSMutableArray* menuItems; |
| 109 @property(nonatomic, assign) ToolbarType toolbarType; | 265 @property(nonatomic, assign) kToolbarType toolbarType; |
| 110 | 266 |
| 111 // Get the reading list cell. | 267 // Get the reading list cell. |
| 112 - (ReadingListMenuViewCell*)readingListCell; | 268 - (ReadingListMenuViewCell*)readingListCell; |
| 113 @end | 269 @end |
| 114 | 270 |
| 115 @implementation ToolsMenuViewController | 271 @implementation ToolsMenuViewController |
| 116 | 272 |
| 117 @synthesize menuView = _menuView; | 273 @synthesize menuView = _menuView; |
| 118 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 119 @synthesize touchFeedbackView = _touchFeedbackView; | 275 @synthesize touchFeedbackView = _touchFeedbackView; |
| 120 @synthesize isTabLoading = _isTabLoading; | 276 @synthesize isTabLoading = _isTabLoading; |
| 121 @synthesize toolbarType = _toolbarType; | 277 @synthesize toolbarType = _toolbarType; |
| 122 @synthesize menuItems = _menuItems; | 278 @synthesize menuItems = _menuItems; |
| 123 @synthesize delegate = _delegate; | 279 @synthesize delegate = _delegate; |
| 124 | 280 |
| 125 #pragma mark Public methods | 281 #pragma mark Public methods |
| 126 | 282 |
| 127 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 283 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 128 NSInteger numberOfItems = [self.menuItems count]; | 284 NSInteger numberOfItems = [self.menuItems count]; |
| 129 if (_toolbarType == ToolbarTypeWebiPhone) { | 285 if (_toolbarType == kToolbarTypeWebiPhone) { |
| 130 // Account for the height of the first row, not included in |menuItems|. | 286 // Account for the height of the first row, not included in |menuItems|. |
| 131 numberOfItems++; | 287 numberOfItems++; |
| 132 } | 288 } |
| 133 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 289 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
| 134 if (maxItems >= numberOfItems) { | 290 if (maxItems >= numberOfItems) { |
| 135 return numberOfItems * kMenuItemHeight; | 291 return numberOfItems * kMenuItemHeight; |
| 136 } else { | 292 } else { |
| 137 const CGFloat halfHeight = kMenuItemHeight / 2; | 293 const CGFloat halfHeight = kMenuItemHeight / 2; |
| 138 return round(maxItems) * kMenuItemHeight - halfHeight; | 294 return round(maxItems) * kMenuItemHeight - halfHeight; |
| 139 } | 295 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 [[toolsCell reloadButton] setHidden:isTabLoading]; | 361 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 206 } | 362 } |
| 207 | 363 |
| 208 - (void)initializeMenu:(ToolsMenuContext*)context { | 364 - (void)initializeMenu:(ToolsMenuContext*)context { |
| 209 if (context.readingListMenuNotifier) { | 365 if (context.readingListMenuNotifier) { |
| 210 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); |
| 211 [context.readingListMenuNotifier setDelegate:self]; | 367 [context.readingListMenuNotifier setDelegate:self]; |
| 212 } | 368 } |
| 213 | 369 |
| 214 if (IsIPadIdiom()) { | 370 if (IsIPadIdiom()) { |
| 215 _toolbarType = | 371 _toolbarType = context.hasNoOpenedTabs |
| 216 context.hasNoOpenedTabs | 372 ? kToolbarTypeNoTabsiPad |
| 217 ? ToolbarTypeNoTabsiPad | 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| 218 : (!IsCompactTablet() ? ToolbarTypeWebiPad : ToolbarTypeWebiPhone); | 374 : kToolbarTypeWebiPhone); |
| 219 } else { | 375 } else { |
| 220 // kOptionInTabSwitcher option must be enabled on iPhone with | 376 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 221 // no opened tabs. | 377 // no opened tabs. |
| 222 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); | 378 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); |
| 223 _toolbarType = context.isInTabSwitcher ? ToolbarTypeSwitcheriPhone | 379 _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone |
| 224 : ToolbarTypeWebiPhone; | 380 : kToolbarTypeWebiPhone; |
| 225 } | 381 } |
| 226 | 382 |
| 227 // Build the menu, adding all relevant items. | 383 // Build the menu, adding all relevant items. |
| 228 NSMutableArray* menu = [NSMutableArray array]; | 384 NSMutableArray* menu = [NSMutableArray array]; |
| 229 | 385 |
| 230 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 386 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 231 const MenuItemInfo& item = itemInfoList[i]; | 387 const MenuItemInfo& item = itemInfoList[i]; |
| 232 if (!ToolsMenuItemShouldBeVisible(item, context.isInIncognito, | 388 if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType)) |
| 233 _toolbarType)) | |
| 234 continue; | 389 continue; |
| 235 | 390 |
| 236 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 391 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 237 Class itemClass = | 392 Class itemClass = |
| 238 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 393 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 239 // Sanity check that the class is a useful one. | 394 // Sanity check that the class is a useful one. |
| 240 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 395 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 241 accessibilityIdentifier: | 396 accessibilityIdentifier: |
| 242 command:)]); | 397 command:)]); |
| 243 [menu addObject:[itemClass menuItemWithTitle:title | 398 [menu addObject:[itemClass menuItemWithTitle:title |
| 244 accessibilityIdentifier:item.accessibility_id | 399 accessibilityIdentifier:item.accessibility_id |
| 245 command:item.command_id]]; | 400 command:item.command_id]]; |
| 246 } | 401 } |
| 247 | 402 |
| 248 #if !defined(NDEBUG) | 403 #if !defined(NDEBUG) |
| 249 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 404 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 250 if ((_toolbarType & ToolbarTypeWebAll) && | 405 if ((_toolbarType & kToolbarTypeWebAll) && |
| 251 [standardDefaults boolForKey:@"DevViewSource"]) { | 406 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 252 // Debug menu, not localized, only visible if turned on by a default. | 407 // Debug menu, not localized, only visible if turned on by a default. |
| 253 [menu addObject:[self createViewSourceItem]]; | 408 [menu addObject:[self createViewSourceItem]]; |
| 254 } | 409 } |
| 255 #endif // !defined(NDEBUG) | 410 #endif // !defined(NDEBUG) |
| 256 | 411 |
| 257 [self setMenuItems:menu]; | 412 [self setMenuItems:menu]; |
| 258 | 413 |
| 259 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. | 414 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. |
| 260 if (!IsIPadIdiom()) { | 415 if (!IsIPadIdiom()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 286 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) | 441 if ([visibleCell isKindOfClass:[ReadingListMenuViewCell class]]) |
| 287 return visibleCell; | 442 return visibleCell; |
| 288 } | 443 } |
| 289 | 444 |
| 290 return nil; | 445 return nil; |
| 291 } | 446 } |
| 292 | 447 |
| 293 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { | 448 - (NSInteger)dataIndexForIndexPath:(NSIndexPath*)path { |
| 294 NSInteger item = [path item]; | 449 NSInteger item = [path item]; |
| 295 | 450 |
| 296 if (_toolbarType == ToolbarTypeWebiPhone) | 451 if (_toolbarType == kToolbarTypeWebiPhone) |
| 297 --item; | 452 --item; |
| 298 | 453 |
| 299 return item; | 454 return item; |
| 300 } | 455 } |
| 301 | 456 |
| 302 #pragma mark - UIViewController Overrides | 457 #pragma mark - UIViewController Overrides |
| 303 | 458 |
| 304 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 459 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
| 305 bundle:(NSBundle*)nibBundleOrNil { | 460 bundle:(NSBundle*)nibBundleOrNil { |
| 306 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | 461 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 if (center1.y < center2.y) | 551 if (center1.y < center2.y) |
| 397 return NSOrderedAscending; | 552 return NSOrderedAscending; |
| 398 | 553 |
| 399 if (center1.y > center2.y) | 554 if (center1.y > center2.y) |
| 400 return NSOrderedDescending; | 555 return NSOrderedDescending; |
| 401 | 556 |
| 402 return NSOrderedSame; | 557 return NSOrderedSame; |
| 403 }]; | 558 }]; |
| 404 | 559 |
| 405 ToolsMenuViewToolsCell* toolsCell = nil; | 560 ToolsMenuViewToolsCell* toolsCell = nil; |
| 406 if (_toolbarType == ToolbarTypeWebiPhone) { | 561 if (_toolbarType == kToolbarTypeWebiPhone) { |
| 407 toolsCell = [visibleCells firstObject]; | 562 toolsCell = [visibleCells firstObject]; |
| 408 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { | 563 if ([toolsCell isKindOfClass:[ToolsMenuViewToolsCell class]]) { |
| 409 visibleCells = [visibleCells | 564 visibleCells = [visibleCells |
| 410 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; | 565 subarrayWithRange:NSMakeRange(1, [visibleCells count] - 1)]; |
| 411 } else { | 566 } else { |
| 412 toolsCell = nil; | 567 toolsCell = nil; |
| 413 } | 568 } |
| 414 } | 569 } |
| 415 | 570 |
| 416 [CATransaction begin]; | 571 [CATransaction begin]; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 [_delegate commandWasSelected:[menuItem tag]]; | 691 [_delegate commandWasSelected:[menuItem tag]]; |
| 537 [self chromeExecuteCommand:menuItem]; | 692 [self chromeExecuteCommand:menuItem]; |
| 538 }); | 693 }); |
| 539 } | 694 } |
| 540 | 695 |
| 541 #pragma mark - UICollectionViewDataSource Implementation | 696 #pragma mark - UICollectionViewDataSource Implementation |
| 542 | 697 |
| 543 - (NSInteger)collectionView:(UICollectionView*)view | 698 - (NSInteger)collectionView:(UICollectionView*)view |
| 544 numberOfItemsInSection:(NSInteger)section { | 699 numberOfItemsInSection:(NSInteger)section { |
| 545 NSInteger numberOfItems = [_menuItems count]; | 700 NSInteger numberOfItems = [_menuItems count]; |
| 546 if (_toolbarType == ToolbarTypeWebiPhone) | 701 if (_toolbarType == kToolbarTypeWebiPhone) |
| 547 ++numberOfItems; | 702 ++numberOfItems; |
| 548 | 703 |
| 549 return numberOfItems; | 704 return numberOfItems; |
| 550 } | 705 } |
| 551 | 706 |
| 552 - (UICollectionViewCell*)collectionView:(UICollectionView*)view | 707 - (UICollectionViewCell*)collectionView:(UICollectionView*)view |
| 553 cellForItemAtIndexPath:(NSIndexPath*)path { | 708 cellForItemAtIndexPath:(NSIndexPath*)path { |
| 554 NSInteger item = [self dataIndexForIndexPath:path]; | 709 NSInteger item = [self dataIndexForIndexPath:path]; |
| 555 if (item < 0) { | 710 if (item < 0) { |
| 556 ToolsMenuViewToolsCell* cell = | 711 ToolsMenuViewToolsCell* cell = |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 747 |
| 593 - (void)unreadCountChanged:(NSInteger)unreadCount { | 748 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 594 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 595 } | 750 } |
| 596 | 751 |
| 597 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 598 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 599 } | 754 } |
| 600 | 755 |
| 601 @end | 756 @end |
| OLD | NEW |