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. | |
|
Eugene But (OOO till 7-30)
2017/03/01 19:12:55
s/Hide/Hides
Same comment for other comments
liaoyuke
2017/03/03 01:04:06
Acknowledged.
| |
| 275 - (void)hideItemWithTag:(NSInteger)tag; | |
| 276 | |
| 277 // Show "Request Desktop Site" in tools menu and hide "Request Mobile Site". | |
| 278 // Note that only one of |showRequestDesktopSite| and |showRequestMobileSite| is | |
| 279 // expected to be called at any time. | |
| 280 - (void)showRequestDesktopSite; | |
| 281 | |
| 282 // Show "Request Mobile Site" in tools menu and hide "Request Desktop Site". | |
| 283 // Note that only one of |showRequestDesktopSite| and |showRequestMobileSite| is | |
| 284 // expected to be called at any time. | |
| 285 - (void)showRequestMobileSite; | |
| 269 @end | 286 @end |
| 270 | 287 |
| 271 @implementation ToolsMenuViewController | 288 @implementation ToolsMenuViewController |
| 272 | 289 |
| 273 @synthesize menuView = _menuView; | 290 @synthesize menuView = _menuView; |
| 274 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; | 291 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; |
| 275 @synthesize touchFeedbackView = _touchFeedbackView; | 292 @synthesize touchFeedbackView = _touchFeedbackView; |
| 276 @synthesize isTabLoading = _isTabLoading; | 293 @synthesize isTabLoading = _isTabLoading; |
| 277 @synthesize toolbarType = _toolbarType; | 294 @synthesize toolbarType = _toolbarType; |
| 278 @synthesize menuItems = _menuItems; | 295 @synthesize menuItems = _menuItems; |
| 279 @synthesize delegate = _delegate; | 296 @synthesize delegate = _delegate; |
| 297 @synthesize userAgentType = _userAgentType; | |
| 280 | 298 |
| 281 #pragma mark Public methods | 299 #pragma mark Public methods |
| 282 | 300 |
| 283 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 301 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 284 NSInteger numberOfItems = [self.menuItems count]; | 302 NSInteger numberOfItems = [self.menuItems count]; |
| 285 if (_toolbarType == kToolbarTypeWebiPhone) { | 303 if (_toolbarType == kToolbarTypeWebiPhone) { |
| 286 // Account for the height of the first row, not included in |menuItems|. | 304 // Account for the height of the first row, not included in |menuItems|. |
| 287 numberOfItems++; | 305 numberOfItems++; |
| 288 } | 306 } |
| 289 CGFloat maxItems = suggestedHeight / kMenuItemHeight; | 307 CGFloat maxItems = suggestedHeight / kMenuItemHeight; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 // Decides the visibility and enability of "Request Desktop Site" and | |
|
Eugene But (OOO till 7-30)
2017/03/01 19:12:55
s/enability/enabled state ?
liaoyuke
2017/03/03 01:04:06
Done.
| |
| 382 // "Request Mobile Site" in tools menu. | |
| 383 // | |
| 384 // TODO(crbug.com/696676): Talk to UI/UX people to decide the correct behavior | |
| 385 // of "Requestion Desktop/Mobile Site" (e.g. Whether user agent flag should | |
| 386 // stick when going backward and which cell should be visible when navigating | |
| 387 // to native pages). | |
| 388 NSInteger visibleItemTag; | |
| 389 if (type == web::UserAgentType::NONE || type == web::UserAgentType::MOBILE) { | |
| 390 [self showRequestDesktopSite]; | |
| 391 visibleItemTag = IDC_REQUEST_DESKTOP_SITE; | |
| 392 } else { | |
| 393 [self showRequestMobileSite]; | |
| 394 visibleItemTag = IDC_REQUEST_MOBILE_SITE; | |
| 395 } | |
| 396 | |
| 397 BOOL shouldItemBeEnabled = (type != web::UserAgentType::NONE); | |
| 398 [self setItemEnabled:shouldItemBeEnabled withTag:visibleItemTag]; | |
| 399 } | |
| 400 | |
| 401 - (void)showRequestDesktopSite { | |
| 402 // All items are visible by default, so hide the other one. | |
| 403 [self hideItemWithTag:IDC_REQUEST_MOBILE_SITE]; | |
| 404 } | |
| 405 | |
| 406 - (void)showRequestMobileSite { | |
| 407 // All items are visible by default, so hide the other one. | |
| 408 [self hideItemWithTag:IDC_REQUEST_DESKTOP_SITE]; | |
| 409 } | |
|
kkhorimoto
2017/03/01 18:52:52
These methods aren't exactly showing an option, bu
Eugene But (OOO till 7-30)
2017/03/01 19:12:55
+1 that method which hides something should start
liaoyuke
2017/03/03 01:04:06
Done.
liaoyuke
2017/03/03 01:04:06
Agreed. Though I would prefer positive over negati
| |
| 410 | |
| 411 - (void)hideItemWithTag:(NSInteger)tag { | |
|
Eugene But (OOO till 7-30)
2017/03/01 19:12:55
This code has the same lookup logic as setItemEnab
liaoyuke
2017/03/03 01:04:06
Acknowledged.
| |
| 412 for (ToolsMenuViewItem* item in _menuItems) { | |
| 413 if ([item tag] == tag) { | |
| 414 [_menuItems removeObject:item]; | |
| 415 return; | |
| 416 } | |
| 417 } | |
| 418 NOTREACHED(); | |
| 419 } | |
| 420 | |
| 364 - (void)initializeMenu:(ToolsMenuContext*)context { | 421 - (void)initializeMenu:(ToolsMenuContext*)context { |
| 365 if (context.readingListMenuNotifier) { | 422 if (context.readingListMenuNotifier) { |
| 366 _readingListMenuNotifier.reset(context.readingListMenuNotifier); | 423 _readingListMenuNotifier.reset(context.readingListMenuNotifier); |
| 367 [context.readingListMenuNotifier setDelegate:self]; | 424 [context.readingListMenuNotifier setDelegate:self]; |
| 368 } | 425 } |
| 369 | 426 |
| 370 if (IsIPadIdiom()) { | 427 if (IsIPadIdiom()) { |
| 371 _toolbarType = context.hasNoOpenedTabs | 428 _toolbarType = context.hasNoOpenedTabs |
| 372 ? kToolbarTypeNoTabsiPad | 429 ? kToolbarTypeNoTabsiPad |
| 373 : (!IsCompactTablet() ? kToolbarTypeWebiPad | 430 : (!IsCompactTablet() ? kToolbarTypeWebiPad |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 | 804 |
| 748 - (void)unreadCountChanged:(NSInteger)unreadCount { | 805 - (void)unreadCountChanged:(NSInteger)unreadCount { |
| 749 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; | 806 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; |
| 750 } | 807 } |
| 751 | 808 |
| 752 - (void)unseenStateChanged:(BOOL)unseenItemsExist { | 809 - (void)unseenStateChanged:(BOOL)unseenItemsExist { |
| 753 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; | 810 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; |
| 754 } | 811 } |
| 755 | 812 |
| 756 @end | 813 @end |
| OLD | NEW |