| 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_context.h" | 24 #import "ios/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| 25 #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" |
| 26 #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" |
| 27 #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" | 28 #include "ios/chrome/browser/ui/ui_util.h" |
| 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 30 #import "ios/chrome/common/material_timing.h" | 30 #import "ios/chrome/common/material_timing.h" |
| 31 #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" | 32 #include "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 33 #import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider
.h" | 33 #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" | 34 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 35 #include "ios/web/public/user_agent.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 36 #include "ui/base/l10n/l10n_util_mac.h" | 37 #include "ui/base/l10n/l10n_util_mac.h" |
| 37 | 38 |
| 39 // TODO(crbug.com/678047) Remove this switch when request mobile site |
| 40 // functionality is implemented. |
| 41 #define HIDE_REQUEST_MOBILE_SITE_CELL |
| 42 |
| 38 using ios::material::TimingFunction; | 43 using ios::material::TimingFunction; |
| 39 | 44 |
| 40 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; | 45 NSString* const kToolsMenuNewTabId = @"kToolsMenuNewTabId"; |
| 41 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; | 46 NSString* const kToolsMenuNewIncognitoTabId = @"kToolsMenuNewIncognitoTabId"; |
| 42 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; | 47 NSString* const kToolsMenuCloseAllTabsId = @"kToolsMenuCloseAllTabsId"; |
| 43 NSString* const kToolsMenuCloseAllIncognitoTabsId = | 48 NSString* const kToolsMenuCloseAllIncognitoTabsId = |
| 44 @"kToolsMenuCloseAllIncognitoTabsId"; | 49 @"kToolsMenuCloseAllIncognitoTabsId"; |
| 45 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | 50 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; |
| 46 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | 51 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; |
| 47 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | 52 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; |
| 48 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | 53 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; |
| 49 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | 54 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; |
| 50 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | 55 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; |
| 51 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | 56 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; |
| 52 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | 57 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; |
| 58 NSString* const kToolsMenuRequestMobileId = @"kToolsMenuRequestMobileId"; |
| 53 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | 59 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; |
| 54 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | 60 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; |
| 55 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | 61 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; |
| 56 | 62 |
| 57 namespace { | 63 namespace { |
| 58 | 64 |
| 59 // Time for ink to fade into view. | 65 // Time for ink to fade into view. |
| 60 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 66 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 61 | 67 |
| 62 static const CGFloat kMenuItemHeight = 48; | 68 static const CGFloat kMenuItemHeight = 48; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 91 kToolbarTypeWebiPad = 1 << 1, | 97 kToolbarTypeWebiPad = 1 << 1, |
| 92 kToolbarTypeNoTabsiPad = 1 << 2, | 98 kToolbarTypeNoTabsiPad = 1 << 2, |
| 93 kToolbarTypeSwitcheriPhone = 1 << 3, | 99 kToolbarTypeSwitcheriPhone = 1 << 3, |
| 94 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, | 100 kToolbarTypeWebAll = kToolbarTypeWebiPhone | kToolbarTypeWebiPad, |
| 95 kToolbarTypeAll = kToolbarTypeWebAll | | 101 kToolbarTypeAll = kToolbarTypeWebAll | |
| 96 kToolbarTypeSwitcheriPhone | | 102 kToolbarTypeSwitcheriPhone | |
| 97 kToolbarTypeNoTabsiPad, | 103 kToolbarTypeNoTabsiPad, |
| 98 // clang-format on | 104 // clang-format on |
| 99 }; | 105 }; |
| 100 | 106 |
| 101 // Declare all the possible items. | 107 // Declares all the possible items. |
| 102 static MenuItemInfo itemInfoList[] = { | 108 static MenuItemInfo itemInfoList[] = { |
| 103 // clang-format off | 109 // clang-format off |
| 104 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, | 110 { IDS_IOS_TOOLS_MENU_NEW_TAB, kToolsMenuNewTabId, |
| 105 IDC_NEW_TAB, kToolbarTypeAll, | 111 IDC_NEW_TAB, kToolbarTypeAll, |
| 106 0, nil }, | 112 0, nil }, |
| 107 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, | 113 { IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB, kToolsMenuNewIncognitoTabId, |
| 108 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, | 114 IDC_NEW_INCOGNITO_TAB, kToolbarTypeAll, |
| 109 0, nil }, | 115 0, nil }, |
| 110 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, | 116 { IDS_IOS_TOOLS_MENU_CLOSE_ALL_TABS, kToolsMenuCloseAllTabsId, |
| 111 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, | 117 IDC_CLOSE_ALL_TABS, kToolbarTypeSwitcheriPhone, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 131 0, nil }, | 137 0, nil }, |
| 132 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | 138 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, |
| 133 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | 139 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, |
| 134 0, nil }, | 140 0, nil }, |
| 135 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | 141 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, |
| 136 IDC_FIND, kToolbarTypeWebAll, | 142 IDC_FIND, kToolbarTypeWebAll, |
| 137 0, nil }, | 143 0, nil }, |
| 138 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | 144 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, |
| 139 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | 145 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, |
| 140 0, nil }, | 146 0, nil }, |
| 147 { IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE, kToolsMenuRequestMobileId, |
| 148 IDC_REQUEST_MOBILE_SITE, kToolbarTypeWebAll, |
| 149 0, nil }, |
| 141 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | 150 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, |
| 142 IDC_READER_MODE, kToolbarTypeWebAll, | 151 IDC_READER_MODE, kToolbarTypeWebAll, |
| 143 0, nil }, | 152 0, nil }, |
| 144 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | 153 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, |
| 145 IDC_OPTIONS, kToolbarTypeAll, | 154 IDC_OPTIONS, kToolbarTypeAll, |
| 146 0, nil }, | 155 0, nil }, |
| 147 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | 156 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, |
| 148 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | 157 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, |
| 149 0, nil }, | 158 0, nil }, |
| 150 // clang-format on | 159 // clang-format on |
| 151 }; | 160 }; |
| 152 | 161 |
| 153 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, | 162 NS_INLINE BOOL ItemShouldBeVisible(const MenuItemInfo& item, |
| 154 BOOL incognito, | 163 kToolbarType toolbarType, |
| 155 kToolbarType toolbarType) { | 164 ToolsMenuConfiguration* configuration) { |
| 156 if (!(item.toolbar_types & toolbarType)) | 165 if (!(item.toolbar_types & toolbarType)) |
| 157 return NO; | 166 return NO; |
| 158 | 167 |
| 159 if (incognito && (item.visibility & kVisibleNotIncognitoOnly)) | 168 if (configuration.inIncognito && (item.visibility & kVisibleNotIncognitoOnly)) |
| 160 return NO; | 169 return NO; |
| 161 | 170 |
| 162 if (!incognito && (item.visibility & kVisibleIncognitoOnly)) | 171 if (!configuration.inIncognito && (item.visibility & kVisibleIncognitoOnly)) |
| 163 return NO; | 172 return NO; |
| 164 | 173 |
| 165 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { | 174 if (item.title_id == IDS_IOS_TOOLBAR_SHOW_TABS) { |
| 166 if (!IsIPadIdiom()) { | 175 if (!IsIPadIdiom()) { |
| 167 return NO; | 176 return NO; |
| 168 } | 177 } |
| 169 } | 178 } |
| 170 | 179 |
| 171 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { | 180 if (item.title_id == IDS_IOS_TOOLS_MENU_READER_MODE) { |
| 172 if (!experimental_flags::IsReaderModeEnabled()) { | 181 if (!experimental_flags::IsReaderModeEnabled()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 187 } | 196 } |
| 188 | 197 |
| 189 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { | 198 if (item.title_id == IDS_IOS_OPTIONS_REPORT_AN_ISSUE) { |
| 190 if (!ios::GetChromeBrowserProvider() | 199 if (!ios::GetChromeBrowserProvider() |
| 191 ->GetUserFeedbackProvider() | 200 ->GetUserFeedbackProvider() |
| 192 ->IsUserFeedbackEnabled()) { | 201 ->IsUserFeedbackEnabled()) { |
| 193 return NO; | 202 return NO; |
| 194 } | 203 } |
| 195 } | 204 } |
| 196 | 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 |
| 197 return YES; | 232 return YES; |
| 198 } | 233 } |
| 199 | 234 |
| 200 NS_INLINE void AnimateInViews(NSArray* views, | 235 NS_INLINE void AnimateInViews(NSArray* views, |
| 201 CGFloat initialX, | 236 CGFloat initialX, |
| 202 CGFloat initialY) { | 237 CGFloat initialY) { |
| 203 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, | 238 [views enumerateObjectsUsingBlock:^(UIView* view, NSUInteger index, |
| 204 BOOL* stop) { | 239 BOOL* stop) { |
| 205 CGFloat beginTime = index * .035; | 240 CGFloat beginTime = index * .035; |
| 206 CABasicAnimation* transformAnimation = | 241 CABasicAnimation* transformAnimation = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 UICollectionViewDataSource, | 289 UICollectionViewDataSource, |
| 255 ReadingListMenuNotificationDelegate> { | 290 ReadingListMenuNotificationDelegate> { |
| 256 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; | 291 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewController; |
| 257 BOOL _waitForInk; | 292 BOOL _waitForInk; |
| 258 // Weak pointer to ReadingListMenuNotifier, used to set the starting values | 293 // Weak pointer to ReadingListMenuNotifier, used to set the starting values |
| 259 // for the reading list badge. | 294 // for the reading list badge. |
| 260 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 295 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 261 } | 296 } |
| 262 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 297 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 263 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 298 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 264 @property(nonatomic, retain) NSMutableArray* menuItems; | |
| 265 @property(nonatomic, assign) kToolbarType toolbarType; | 299 @property(nonatomic, assign) kToolbarType toolbarType; |
| 266 | 300 |
| 267 // Get the reading list cell. | 301 // Returns the reading list cell. |
| 268 - (ReadingListMenuViewCell*)readingListCell; | 302 - (ReadingListMenuViewCell*)readingListCell; |
| 269 @end | 303 @end |
| 270 | 304 |
| 271 @implementation ToolsMenuViewController | 305 @implementation ToolsMenuViewController |
| 272 | 306 |
| 273 @synthesize menuView = _menuView; | 307 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 308 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 309 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 310 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 311 @synthesize toolbarType = _toolbarType; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 355 |
| 322 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 356 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 323 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; | 357 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; |
| 324 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; | 358 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; |
| 325 } | 359 } |
| 326 | 360 |
| 327 - (void)setCanUseReaderMode:(BOOL)enabled { | 361 - (void)setCanUseReaderMode:(BOOL)enabled { |
| 328 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; | 362 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; |
| 329 } | 363 } |
| 330 | 364 |
| 331 - (void)setCanUseDesktopUserAgent:(BOOL)enabled { | |
| 332 [self setItemEnabled:enabled withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 333 } | |
| 334 | |
| 335 - (void)setCanShowFindBar:(BOOL)enabled { | 365 - (void)setCanShowFindBar:(BOOL)enabled { |
| 336 [self setItemEnabled:enabled withTag:IDC_FIND]; | 366 [self setItemEnabled:enabled withTag:IDC_FIND]; |
| 337 } | 367 } |
| 338 | 368 |
| 339 - (void)setCanShowShareMenu:(BOOL)enabled { | 369 - (void)setCanShowShareMenu:(BOOL)enabled { |
| 340 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 370 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 341 [[toolsCell shareButton] setEnabled:enabled]; | 371 [[toolsCell shareButton] setEnabled:enabled]; |
| 342 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; | 372 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; |
| 343 } | 373 } |
| 344 | 374 |
| 345 - (UIButton*)toolsButton { | 375 - (UIButton*)toolsButton { |
| 346 UIButton* toolsButton = [[self toolsCell] toolsButton]; | 376 UIButton* toolsButton = [[self toolsCell] toolsButton]; |
| 347 [toolsButton addTarget:self | 377 [toolsButton addTarget:self |
| 348 action:@selector(buttonPressed:) | 378 action:@selector(buttonPressed:) |
| 349 forControlEvents:UIControlEventTouchUpInside]; | 379 forControlEvents:UIControlEventTouchUpInside]; |
| 350 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; | 380 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; |
| 351 [toolsButton setOpaque:NO]; | 381 [toolsButton setOpaque:NO]; |
| 352 [toolsButton setBackgroundColor:[UIColor clearColor]]; | 382 [toolsButton setBackgroundColor:[UIColor clearColor]]; |
| 353 return toolsButton; | 383 return toolsButton; |
| 354 } | 384 } |
| 355 | 385 |
| 356 - (void)setIsTabLoading:(BOOL)isTabLoading { | 386 - (void)setIsTabLoading:(BOOL)isTabLoading { |
| 357 _isTabLoading = isTabLoading; | 387 _isTabLoading = isTabLoading; |
| 358 | 388 |
| 359 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 389 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 360 [[toolsCell stopButton] setHidden:!isTabLoading]; | 390 [[toolsCell stopButton] setHidden:!isTabLoading]; |
| 361 [[toolsCell reloadButton] setHidden:isTabLoading]; | 391 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 362 } | 392 } |
| 363 | 393 |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 394 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 365 if (context.readingListMenuNotifier) { | 395 if (configuration.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 396 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 397 [configuration.readingListMenuNotifier setDelegate:self]; |
| 368 } | 398 } |
| 369 | 399 |
| 370 if (IsIPadIdiom()) { | 400 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 401 _toolbarType = configuration.hasNoOpenedTabs |
| 372 ? kToolbarTypeNoTabsiPad | 402 ? kToolbarTypeNoTabsiPad |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 403 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| 374 : kToolbarTypeWebiPhone); | 404 : kToolbarTypeWebiPhone); |
| 375 } else { | 405 } else { |
| 376 // kOptionInTabSwitcher option must be enabled on iPhone with | 406 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 377 // no opened tabs. | 407 // no opened tabs. |
| 378 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); | 408 DCHECK(!configuration.hasNoOpenedTabs || configuration.isInTabSwitcher); |
| 379 _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone | 409 _toolbarType = configuration.isInTabSwitcher ? kToolbarTypeSwitcheriPhone |
| 380 : kToolbarTypeWebiPhone; | 410 : kToolbarTypeWebiPhone; |
| 381 } | 411 } |
| 382 | 412 |
| 383 // Build the menu, adding all relevant items. | 413 // Build the menu, adding all relevant items. |
| 384 NSMutableArray* menu = [NSMutableArray array]; | 414 NSMutableArray* menu = [NSMutableArray array]; |
| 385 | 415 |
| 386 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 416 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 387 const MenuItemInfo& item = itemInfoList[i]; | 417 const MenuItemInfo& item = itemInfoList[i]; |
| 388 if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType)) | 418 if (!ItemShouldBeVisible(item, _toolbarType, configuration)) |
| 389 continue; | 419 continue; |
| 390 | 420 |
| 391 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 421 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 392 Class itemClass = | 422 Class itemClass = |
| 393 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 423 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 394 // Sanity check that the class is a useful one. | 424 // Sanity check that the class is a useful one. |
| 395 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 425 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 396 accessibilityIdentifier: | 426 accessibilityIdentifier: |
| 397 command:)]); | 427 command:)]); |
| 398 [menu addObject:[itemClass menuItemWithTitle:title | 428 [menu addObject:[itemClass menuItemWithTitle:title |
| 399 accessibilityIdentifier:item.accessibility_id | 429 accessibilityIdentifier:item.accessibility_id |
| 400 command:item.command_id]]; | 430 command:item.command_id]]; |
| 401 } | 431 } |
| 402 | 432 |
| 403 #if !defined(NDEBUG) | 433 #if !defined(NDEBUG) |
| 404 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 434 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 405 if ((_toolbarType & kToolbarTypeWebAll) && | 435 if ((_toolbarType & kToolbarTypeWebAll) && |
| 406 [standardDefaults boolForKey:@"DevViewSource"]) { | 436 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 407 // Debug menu, not localized, only visible if turned on by a default. | 437 // Debug menu, not localized, only visible if turned on by a default. |
| 408 [menu addObject:[self createViewSourceItem]]; | 438 [menu addObject:[self createViewSourceItem]]; |
| 409 } | 439 } |
| 410 #endif // !defined(NDEBUG) | 440 #endif // !defined(NDEBUG) |
| 411 | 441 |
| 412 [self setMenuItems:menu]; | 442 [self setMenuItems:menu]; |
| 413 | 443 |
| 444 // Decide the enabled state of the currently visible item between |
| 445 // "Request Desktop Site" and "Request Mobile Site". |
| 446 switch (configuration.userAgentType) { |
| 447 case web::UserAgentType::NONE: |
| 448 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 449 break; |
| 450 case web::UserAgentType::MOBILE: |
| 451 [self setItemEnabled:YES withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 452 break; |
| 453 case web::UserAgentType::DESKTOP: |
| 454 [self setItemEnabled:YES withTag:IDC_REQUEST_MOBILE_SITE]; |
| 455 |
| 456 // TODO(crbug.com/678047) Remove this switch when request mobile site |
| 457 // functionality is implemented. |
| 458 #ifdef HIDE_REQUEST_MOBILE_SITE_CELL |
| 459 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 460 #endif |
| 461 break; |
| 462 } |
| 463 |
| 414 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. | 464 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. |
| 415 if (!IsIPadIdiom()) { | 465 if (!IsIPadIdiom()) { |
| 416 [self setItemEnabled:!context.hasNoOpenedTabs withTag:IDC_CLOSE_ALL_TABS]; | 466 [self setItemEnabled:!configuration.hasNoOpenedTabs |
| 467 withTag:IDC_CLOSE_ALL_TABS]; |
| 417 } | 468 } |
| 418 } | 469 } |
| 419 | 470 |
| 420 #if !defined(NDEBUG) | 471 #if !defined(NDEBUG) |
| 421 - (ToolsMenuViewItem*)createViewSourceItem { | 472 - (ToolsMenuViewItem*)createViewSourceItem { |
| 422 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" | 473 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" |
| 423 accessibilityIdentifier:@"View Source" | 474 accessibilityIdentifier:@"View Source" |
| 424 command:IDC_VIEW_SOURCE]; | 475 command:IDC_VIEW_SOURCE]; |
| 425 } | 476 } |
| 426 #endif // !defined(NDEBUG) | 477 #endif // !defined(NDEBUG) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 798 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 799 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 800 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 801 } |
| 751 | 802 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 803 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 804 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 805 } |
| 755 | 806 |
| 756 @end | 807 @end |
| OLD | NEW |