| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; | 299 @property(nonatomic, retain) NSMutableArray* menuItems; |
| 265 @property(nonatomic, assign) kToolbarType toolbarType; | 300 @property(nonatomic, assign) kToolbarType toolbarType; |
| 266 | 301 |
| 267 // Get the reading list cell. | 302 // Returns the reading list cell. |
| 268 - (ReadingListMenuViewCell*)readingListCell; | 303 - (ReadingListMenuViewCell*)readingListCell; |
| 269 @end | 304 @end |
| 270 | 305 |
| 271 @implementation ToolsMenuViewController | 306 @implementation ToolsMenuViewController |
| 272 | 307 |
| 273 @synthesize menuView = _menuView; | 308 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 309 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 310 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 311 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 312 @synthesize toolbarType = _toolbarType; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 356 |
| 322 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 357 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 323 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; | 358 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; |
| 324 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; | 359 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; |
| 325 } | 360 } |
| 326 | 361 |
| 327 - (void)setCanUseReaderMode:(BOOL)enabled { | 362 - (void)setCanUseReaderMode:(BOOL)enabled { |
| 328 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; | 363 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; |
| 329 } | 364 } |
| 330 | 365 |
| 331 - (void)setCanUseDesktopUserAgent:(BOOL)enabled { | |
| 332 [self setItemEnabled:enabled withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 333 } | |
| 334 | |
| 335 - (void)setCanShowFindBar:(BOOL)enabled { | 366 - (void)setCanShowFindBar:(BOOL)enabled { |
| 336 [self setItemEnabled:enabled withTag:IDC_FIND]; | 367 [self setItemEnabled:enabled withTag:IDC_FIND]; |
| 337 } | 368 } |
| 338 | 369 |
| 339 - (void)setCanShowShareMenu:(BOOL)enabled { | 370 - (void)setCanShowShareMenu:(BOOL)enabled { |
| 340 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 371 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 341 [[toolsCell shareButton] setEnabled:enabled]; | 372 [[toolsCell shareButton] setEnabled:enabled]; |
| 342 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; | 373 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; |
| 343 } | 374 } |
| 344 | 375 |
| 345 - (UIButton*)toolsButton { | 376 - (UIButton*)toolsButton { |
| 346 UIButton* toolsButton = [[self toolsCell] toolsButton]; | 377 UIButton* toolsButton = [[self toolsCell] toolsButton]; |
| 347 [toolsButton addTarget:self | 378 [toolsButton addTarget:self |
| 348 action:@selector(buttonPressed:) | 379 action:@selector(buttonPressed:) |
| 349 forControlEvents:UIControlEventTouchUpInside]; | 380 forControlEvents:UIControlEventTouchUpInside]; |
| 350 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; | 381 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; |
| 351 [toolsButton setOpaque:NO]; | 382 [toolsButton setOpaque:NO]; |
| 352 [toolsButton setBackgroundColor:[UIColor clearColor]]; | 383 [toolsButton setBackgroundColor:[UIColor clearColor]]; |
| 353 return toolsButton; | 384 return toolsButton; |
| 354 } | 385 } |
| 355 | 386 |
| 356 - (void)setIsTabLoading:(BOOL)isTabLoading { | 387 - (void)setIsTabLoading:(BOOL)isTabLoading { |
| 357 _isTabLoading = isTabLoading; | 388 _isTabLoading = isTabLoading; |
| 358 | 389 |
| 359 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 390 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 360 [[toolsCell stopButton] setHidden:!isTabLoading]; | 391 [[toolsCell stopButton] setHidden:!isTabLoading]; |
| 361 [[toolsCell reloadButton] setHidden:isTabLoading]; | 392 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 362 } | 393 } |
| 363 | 394 |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 395 - (void)initializeMenuWithConfiguration:(ToolsMenuConfiguration*)configuration { |
| 365 if (context.readingListMenuNotifier) { | 396 if (configuration.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 397 _readingListMenuNotifier.reset(configuration.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 398 [configuration.readingListMenuNotifier setDelegate:self]; |
| 368 } | 399 } |
| 369 | 400 |
| 370 if (IsIPadIdiom()) { | 401 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 402 _toolbarType = configuration.hasNoOpenedTabs |
| 372 ? kToolbarTypeNoTabsiPad | 403 ? kToolbarTypeNoTabsiPad |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 404 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| 374 : kToolbarTypeWebiPhone); | 405 : kToolbarTypeWebiPhone); |
| 375 } else { | 406 } else { |
| 376 // kOptionInTabSwitcher option must be enabled on iPhone with | 407 // kOptionInTabSwitcher option must be enabled on iPhone with |
| 377 // no opened tabs. | 408 // no opened tabs. |
| 378 DCHECK(!context.hasNoOpenedTabs || context.isInTabSwitcher); | 409 DCHECK(!configuration.hasNoOpenedTabs || configuration.isInTabSwitcher); |
| 379 _toolbarType = context.isInTabSwitcher ? kToolbarTypeSwitcheriPhone | 410 _toolbarType = configuration.isInTabSwitcher ? kToolbarTypeSwitcheriPhone |
| 380 : kToolbarTypeWebiPhone; | 411 : kToolbarTypeWebiPhone; |
| 381 } | 412 } |
| 382 | 413 |
| 383 // Build the menu, adding all relevant items. | 414 // Build the menu, adding all relevant items. |
| 384 NSMutableArray* menu = [NSMutableArray array]; | 415 NSMutableArray* menu = [NSMutableArray array]; |
| 385 | 416 |
| 386 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { | 417 for (size_t i = 0; i < arraysize(itemInfoList); ++i) { |
| 387 const MenuItemInfo& item = itemInfoList[i]; | 418 const MenuItemInfo& item = itemInfoList[i]; |
| 388 if (!ItemShouldBeVisible(item, context.isInIncognito, _toolbarType)) | 419 if (!ItemShouldBeVisible(item, _toolbarType, configuration)) |
| 389 continue; | 420 continue; |
| 390 | 421 |
| 391 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); | 422 NSString* title = l10n_util::GetNSStringWithFixup(item.title_id); |
| 392 Class itemClass = | 423 Class itemClass = |
| 393 item.item_class ? item.item_class : [ToolsMenuViewItem class]; | 424 item.item_class ? item.item_class : [ToolsMenuViewItem class]; |
| 394 // Sanity check that the class is a useful one. | 425 // Sanity check that the class is a useful one. |
| 395 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: | 426 DCHECK([itemClass respondsToSelector:@selector(menuItemWithTitle: |
| 396 accessibilityIdentifier: | 427 accessibilityIdentifier: |
| 397 command:)]); | 428 command:)]); |
| 398 [menu addObject:[itemClass menuItemWithTitle:title | 429 [menu addObject:[itemClass menuItemWithTitle:title |
| 399 accessibilityIdentifier:item.accessibility_id | 430 accessibilityIdentifier:item.accessibility_id |
| 400 command:item.command_id]]; | 431 command:item.command_id]]; |
| 401 } | 432 } |
| 402 | 433 |
| 403 #if !defined(NDEBUG) | 434 #if !defined(NDEBUG) |
| 404 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; | 435 NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults]; |
| 405 if ((_toolbarType & kToolbarTypeWebAll) && | 436 if ((_toolbarType & kToolbarTypeWebAll) && |
| 406 [standardDefaults boolForKey:@"DevViewSource"]) { | 437 [standardDefaults boolForKey:@"DevViewSource"]) { |
| 407 // Debug menu, not localized, only visible if turned on by a default. | 438 // Debug menu, not localized, only visible if turned on by a default. |
| 408 [menu addObject:[self createViewSourceItem]]; | 439 [menu addObject:[self createViewSourceItem]]; |
| 409 } | 440 } |
| 410 #endif // !defined(NDEBUG) | 441 #endif // !defined(NDEBUG) |
| 411 | 442 |
| 412 [self setMenuItems:menu]; | 443 [self setMenuItems:menu]; |
| 413 | 444 |
| 445 // Decide the enabled state of the currently visible item between |
| 446 // "Request Desktop Site" and "Request Mobile Site". |
| 447 switch (configuration.userAgentType) { |
| 448 case web::UserAgentType::NONE: |
| 449 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 450 break; |
| 451 case web::UserAgentType::MOBILE: |
| 452 [self setItemEnabled:YES withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 453 break; |
| 454 case web::UserAgentType::DESKTOP: |
| 455 [self setItemEnabled:YES withTag:IDC_REQUEST_MOBILE_SITE]; |
| 456 |
| 457 // TODO(crbug.com/678047) Remove this switch when request mobile site |
| 458 // functionality is implemented. |
| 459 #ifdef HIDE_REQUEST_MOBILE_SITE_CELL |
| 460 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; |
| 461 #endif |
| 462 break; |
| 463 } |
| 464 |
| 414 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. | 465 // Disable IDC_CLOSE_ALL_TABS menu item if on phone with no tabs. |
| 415 if (!IsIPadIdiom()) { | 466 if (!IsIPadIdiom()) { |
| 416 [self setItemEnabled:!context.hasNoOpenedTabs withTag:IDC_CLOSE_ALL_TABS]; | 467 [self setItemEnabled:!configuration.hasNoOpenedTabs |
| 468 withTag:IDC_CLOSE_ALL_TABS]; |
| 417 } | 469 } |
| 418 } | 470 } |
| 419 | 471 |
| 420 #if !defined(NDEBUG) | 472 #if !defined(NDEBUG) |
| 421 - (ToolsMenuViewItem*)createViewSourceItem { | 473 - (ToolsMenuViewItem*)createViewSourceItem { |
| 422 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" | 474 return [ToolsMenuViewItem menuItemWithTitle:@"View Source" |
| 423 accessibilityIdentifier:@"View Source" | 475 accessibilityIdentifier:@"View Source" |
| 424 command:IDC_VIEW_SOURCE]; | 476 command:IDC_VIEW_SOURCE]; |
| 425 } | 477 } |
| 426 #endif // !defined(NDEBUG) | 478 #endif // !defined(NDEBUG) |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 799 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 800 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 801 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 802 } |
| 751 | 803 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 804 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 805 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 806 } |
| 755 | 807 |
| 756 @end | 808 @end |
| OLD | NEW |