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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 NSString* const kToolsMenuCloseAllIncognitoTabsId = | 43 NSString* const kToolsMenuCloseAllIncognitoTabsId = |
| 44 @"kToolsMenuCloseAllIncognitoTabsId"; | 44 @"kToolsMenuCloseAllIncognitoTabsId"; |
| 45 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; | 45 NSString* const kToolsMenuBookmarksId = @"kToolsMenuBookmarksId"; |
| 46 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; | 46 NSString* const kToolsMenuReadingListId = @"kToolsMenuReadingListId"; |
| 47 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; | 47 NSString* const kToolsMenuOtherDevicesId = @"kToolsMenuOtherDevicesId"; |
| 48 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; | 48 NSString* const kToolsMenuHistoryId = @"kToolsMenuHistoryId"; |
| 49 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; | 49 NSString* const kToolsMenuReportAnIssueId = @"kToolsMenuReportAnIssueId"; |
| 50 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; | 50 NSString* const kToolsMenuFindInPageId = @"kToolsMenuFindInPageId"; |
| 51 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; | 51 NSString* const kToolsMenuReaderMode = @"kToolsMenuReaderMode"; |
| 52 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; | 52 NSString* const kToolsMenuRequestDesktopId = @"kToolsMenuRequestDesktopId"; |
| 53 NSString* const kToolsMenuRequestMobileId = @"kToolsMenuRequestMobileId"; | |
| 53 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; | 54 NSString* const kToolsMenuSettingsId = @"kToolsMenuSettingsId"; |
| 54 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; | 55 NSString* const kToolsMenuHelpId = @"kToolsMenuHelpId"; |
| 55 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; | 56 NSString* const kToolsMenuSuggestionsId = @"kToolsMenuSuggestionsId"; |
| 56 | 57 |
| 57 namespace { | 58 namespace { |
| 58 | 59 |
| 59 // Time for ink to fade into view. | 60 // Time for ink to fade into view. |
| 60 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; | 61 static const NSTimeInterval kMDCInkTouchDelayInterval = 0.15; |
| 61 | 62 |
| 62 static const CGFloat kMenuItemHeight = 48; | 63 static const CGFloat kMenuItemHeight = 48; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 0, nil }, | 132 0, nil }, |
| 132 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, | 133 { IDS_IOS_OPTIONS_REPORT_AN_ISSUE, kToolsMenuReportAnIssueId, |
| 133 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, | 134 IDC_REPORT_AN_ISSUE, kToolbarTypeAll, |
| 134 0, nil }, | 135 0, nil }, |
| 135 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, | 136 { IDS_IOS_TOOLS_MENU_FIND_IN_PAGE, kToolsMenuFindInPageId, |
| 136 IDC_FIND, kToolbarTypeWebAll, | 137 IDC_FIND, kToolbarTypeWebAll, |
| 137 0, nil }, | 138 0, nil }, |
| 138 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, | 139 { IDS_IOS_TOOLS_MENU_REQUEST_DESKTOP_SITE, kToolsMenuRequestDesktopId, |
| 139 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, | 140 IDC_REQUEST_DESKTOP_SITE, kToolbarTypeWebAll, |
| 140 0, nil }, | 141 0, nil }, |
| 142 { IDS_IOS_TOOLS_MENU_REQUEST_MOBILE_SITE, kToolsMenuRequestMobileId, | |
| 143 IDC_REQUEST_MOBILE_SITE, kToolbarTypeWebAll, | |
| 144 0, nil }, | |
| 141 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, | 145 { IDS_IOS_TOOLS_MENU_READER_MODE, kToolsMenuReaderMode, |
| 142 IDC_READER_MODE, kToolbarTypeWebAll, | 146 IDC_READER_MODE, kToolbarTypeWebAll, |
| 143 0, nil }, | 147 0, nil }, |
| 144 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, | 148 { IDS_IOS_TOOLS_MENU_SETTINGS, kToolsMenuSettingsId, |
| 145 IDC_OPTIONS, kToolbarTypeAll, | 149 IDC_OPTIONS, kToolbarTypeAll, |
| 146 0, nil }, | 150 0, nil }, |
| 147 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, | 151 { IDS_IOS_TOOLS_MENU_HELP_MOBILE, kToolsMenuHelpId, |
| 148 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, | 152 IDC_HELP_PAGE_VIA_MENU, kToolbarTypeWebAll, |
| 149 0, nil }, | 153 0, nil }, |
| 150 // clang-format on | 154 // clang-format on |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 // for the reading list badge. | 263 // for the reading list badge. |
| 260 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; | 264 base::WeakNSObject<ReadingListMenuNotifier> _readingListMenuNotifier; |
| 261 } | 265 } |
| 262 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; | 266 @property(nonatomic, retain) ToolsMenuCollectionView* menuView; |
| 263 @property(nonatomic, retain) MDCInkView* touchFeedbackView; | 267 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
| 264 @property(nonatomic, retain) NSMutableArray* menuItems; | 268 @property(nonatomic, retain) NSMutableArray* menuItems; |
| 265 @property(nonatomic, assign) kToolbarType toolbarType; | 269 @property(nonatomic, assign) kToolbarType toolbarType; |
| 266 | 270 |
| 267 // Get the reading list cell. | 271 // Get the reading list cell. |
| 268 - (ReadingListMenuViewCell*)readingListCell; | 272 - (ReadingListMenuViewCell*)readingListCell; |
| 273 | |
| 274 // Hide a menu item by IDC value. | |
| 275 - (void)hideItemWithTag:(NSInteger)tag; | |
| 269 @end | 276 @end |
| 270 | 277 |
| 271 @implementation ToolsMenuViewController | 278 @implementation ToolsMenuViewController |
| 272 | 279 |
| 273 @synthesize menuView = _menuView; | 280 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 281 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 282 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 283 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 284 @synthesize toolbarType = _toolbarType; |
| 278 @synthesize menuItems = _menuItems; | 285 @synthesize menuItems = _menuItems; |
| 279 @synthesize delegate = _delegate; | 286 @synthesize delegate = _delegate; |
| 287 @synthesize userAgentType = _userAgentType; | |
| 280 | 288 |
| 281 #pragma mark Public methods | 289 #pragma mark Public methods |
| 282 | 290 |
| 283 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 291 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 284 NSInteger numberOfItems = [self.menuItems count]; | 292 NSInteger numberOfItems = [self.menuItems count]; |
| 285 if (_toolbarType == kToolbarTypeWebiPhone) { | 293 if (_toolbarType == kToolbarTypeWebiPhone) { |
| 286 // Account for the height of the first row, not included in |menuItems|. | 294 // Account for the height of the first row, not included in |menuItems|. |
| 287 numberOfItems++; | 295 numberOfItems++; |
| 288 } | 296 } |
| 289 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 297 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
| 290 if (maxItems >= numberOfItems) { | 298 if (maxItems >= numberOfItems) { |
| 291 return numberOfItems * kMenuItemHeight; | 299 return numberOfItems * kMenuItemHeight; |
| 292 } else { | 300 } else { |
| 293 const CGFloat halfHeight = kMenuItemHeight / 2; | 301 const CGFloat halfHeight = kMenuItemHeight / 2; |
| 294 return round(maxItems) * kMenuItemHeight - halfHeight; | 302 return round(maxItems) * kMenuItemHeight - halfHeight; |
| 295 } | 303 } |
| 296 } | 304 } |
| 297 | 305 |
| 306 - (void)hideItemWithTag:(NSInteger)tag { | |
| 307 for (ToolsMenuViewItem* item in _menuItems) { | |
| 308 if ([item tag] == tag) { | |
| 309 [_menuItems removeObject:item]; | |
| 310 return; | |
| 311 } | |
| 312 } | |
| 313 NOTREACHED(); | |
| 314 } | |
| 315 | |
| 298 - (void)setItemEnabled:(BOOL)enabled withTag:(NSInteger)tag { | 316 - (void)setItemEnabled:(BOOL)enabled withTag:(NSInteger)tag { |
| 299 for (ToolsMenuViewItem* item in _menuItems) { | 317 for (ToolsMenuViewItem* item in _menuItems) { |
| 300 if ([item tag] == tag) { | 318 if ([item tag] == tag) { |
| 301 [item setActive:enabled]; | 319 [item setActive:enabled]; |
| 302 break; | 320 break; |
| 303 } | 321 } |
| 304 } | 322 } |
| 305 | 323 |
| 306 for (ToolsMenuViewCell* cell in [_menuView visibleCells]) { | 324 for (ToolsMenuViewCell* cell in [_menuView visibleCells]) { |
| 307 if (![cell isKindOfClass:[ToolsMenuViewCell class]]) | 325 if (![cell isKindOfClass:[ToolsMenuViewCell class]]) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 321 | 339 |
| 322 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 340 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 323 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; | 341 [[toolsCell starButton] setHidden:_isCurrentPageBookmarked]; |
| 324 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; | 342 [[toolsCell starredButton] setHidden:!_isCurrentPageBookmarked]; |
| 325 } | 343 } |
| 326 | 344 |
| 327 - (void)setCanUseReaderMode:(BOOL)enabled { | 345 - (void)setCanUseReaderMode:(BOOL)enabled { |
| 328 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; | 346 [self setItemEnabled:enabled withTag:IDC_READER_MODE]; |
| 329 } | 347 } |
| 330 | 348 |
| 331 - (void)setCanUseDesktopUserAgent:(BOOL)enabled { | |
| 332 [self setItemEnabled:enabled withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 333 } | |
| 334 | |
| 335 - (void)setCanShowFindBar:(BOOL)enabled { | 349 - (void)setCanShowFindBar:(BOOL)enabled { |
| 336 [self setItemEnabled:enabled withTag:IDC_FIND]; | 350 [self setItemEnabled:enabled withTag:IDC_FIND]; |
| 337 } | 351 } |
| 338 | 352 |
| 339 - (void)setCanShowShareMenu:(BOOL)enabled { | 353 - (void)setCanShowShareMenu:(BOOL)enabled { |
| 340 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 354 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 341 [[toolsCell shareButton] setEnabled:enabled]; | 355 [[toolsCell shareButton] setEnabled:enabled]; |
| 342 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; | 356 [self setItemEnabled:enabled withTag:IDC_SHARE_PAGE]; |
| 343 } | 357 } |
| 344 | 358 |
| 345 - (UIButton*)toolsButton { | 359 - (UIButton*)toolsButton { |
| 346 UIButton* toolsButton = [[self toolsCell] toolsButton]; | 360 UIButton* toolsButton = [[self toolsCell] toolsButton]; |
| 347 [toolsButton addTarget:self | 361 [toolsButton addTarget:self |
| 348 action:@selector(buttonPressed:) | 362 action:@selector(buttonPressed:) |
| 349 forControlEvents:UIControlEventTouchUpInside]; | 363 forControlEvents:UIControlEventTouchUpInside]; |
| 350 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; | 364 [toolsButton setTranslatesAutoresizingMaskIntoConstraints:YES]; |
| 351 [toolsButton setOpaque:NO]; | 365 [toolsButton setOpaque:NO]; |
| 352 [toolsButton setBackgroundColor:[UIColor clearColor]]; | 366 [toolsButton setBackgroundColor:[UIColor clearColor]]; |
| 353 return toolsButton; | 367 return toolsButton; |
| 354 } | 368 } |
| 355 | 369 |
| 356 - (void)setIsTabLoading:(BOOL)isTabLoading { | 370 - (void)setIsTabLoading:(BOOL)isTabLoading { |
| 357 _isTabLoading = isTabLoading; | 371 _isTabLoading = isTabLoading; |
| 358 | 372 |
| 359 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; | 373 ToolsMenuViewToolsCell* toolsCell = [self toolsCell]; |
| 360 [[toolsCell stopButton] setHidden:!isTabLoading]; | 374 [[toolsCell stopButton] setHidden:!isTabLoading]; |
| 361 [[toolsCell reloadButton] setHidden:isTabLoading]; | 375 [[toolsCell reloadButton] setHidden:isTabLoading]; |
| 362 } | 376 } |
| 363 | 377 |
| 378 - (void)setUserAgentType:(web::UserAgentType)type { | |
| 379 _userAgentType = type; | |
| 380 | |
| 381 // Hide exactly one of "Request Desktop Site" and "Request Mobile Site". | |
| 382 // TODO(crbug.com/696676): Talk to UI/UX people to decide the correct behavior | |
| 383 // of "Requestion Desktop/Mobile Site" (e.g. Whether user agent flag should | |
| 384 // stick when going backward and which cell should be visible when navigating | |
| 385 // to native pages). | |
| 386 if (type == web::UserAgentType::NONE || type == web::UserAgentType::MOBILE) | |
| 387 [self hideItemWithTag:IDC_REQUEST_MOBILE_SITE]; | |
| 388 else | |
| 389 [self hideItemWithTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 390 | |
| 391 // Decides the enability of "Request Desktop Site" and "Request Mobile Site". | |
| 392 [self setItemEnabled:NO withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 393 [self setItemEnabled:NO withTag:IDC_REQUEST_MOBILE_SITE]; | |
| 394 | |
| 395 if (type == web::UserAgentType::Mobile) | |
| 396 [self setItemEnabled:YES withTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 397 else if (type == web::UserAgentType::DESKTOP) | |
| 398 [self setItemEnabled:YES withTag:IDC_REQUEST_MOBILE_SITE]; | |
|
kkhorimoto
2017/02/27 23:44:24
Let's just combine these into a single condition,
liaoyuke
2017/02/28 02:01:00
The condition for hiding and enabling is actually
liaoyuke
2017/02/28 02:01:01
Also note that I will change this logic to always
kkhorimoto
2017/02/28 18:34:36
I just double checked, and it seems to me that the
kkhorimoto
2017/02/28 18:36:08
Also, you shouldn't make functional changes to a C
liaoyuke
2017/03/01 01:09:38
Sorry, I missed that you have "(type != web::UserA
| |
| 399 } | |
| 400 | |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 401 - (void)initializeMenu:(ToolsMenuContext*)context { |
| 365 if (context.readingListMenuNotifier) { | 402 if (context.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 403 _readingListMenuNotifier.reset(context.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 404 [context.readingListMenuNotifier setDelegate:self]; |
| 368 } | 405 } |
| 369 | 406 |
| 370 if (IsIPadIdiom()) { | 407 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 408 _toolbarType = context.hasNoOpenedTabs |
| 372 ? kToolbarTypeNoTabsiPad | 409 ? kToolbarTypeNoTabsiPad |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 410 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 | 784 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 785 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 786 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 787 } |
| 751 | 788 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 789 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 790 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 791 } |
| 755 | 792 |
| 756 @end | 793 @end |
| OLD | NEW |