Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: ios/chrome/browser/ui/tools_menu/tools_menu_view_controller.mm

Issue 2965963002: [ios] Remove IDC_STOP and IDC_RELOAD
Patch Set: Rebased. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "components/strings/grit/components_strings.h" 13 #include "components/strings/grit/components_strings.h"
14 #include "ios/chrome/browser/experimental_flags.h" 14 #include "ios/chrome/browser/experimental_flags.h"
15 #import "ios/chrome/browser/ui/animation_util.h" 15 #import "ios/chrome/browser/ui/animation_util.h"
16 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" 16 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h"
17 #import "ios/chrome/browser/ui/commands/browser_commands.h"
17 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 18 #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" 19 #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" 20 #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" 21 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h"
21 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" 22 #import "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h"
22 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h" 23 #import "ios/chrome/browser/ui/tools_menu/tools_menu_model.h"
23 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" 24 #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" 25 #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" 26 #import "ios/chrome/browser/ui/tools_menu/tools_popup_controller.h"
26 #include "ios/chrome/browser/ui/ui_util.h" 27 #include "ios/chrome/browser/ui/ui_util.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 127
127 @implementation ToolsMenuViewController 128 @implementation ToolsMenuViewController
128 129
129 @synthesize menuView = _menuView; 130 @synthesize menuView = _menuView;
130 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked; 131 @synthesize isCurrentPageBookmarked = _isCurrentPageBookmarked;
131 @synthesize touchFeedbackView = _touchFeedbackView; 132 @synthesize touchFeedbackView = _touchFeedbackView;
132 @synthesize isTabLoading = _isTabLoading; 133 @synthesize isTabLoading = _isTabLoading;
133 @synthesize toolbarType = _toolbarType; 134 @synthesize toolbarType = _toolbarType;
134 @synthesize menuItems = _menuItems; 135 @synthesize menuItems = _menuItems;
135 @synthesize delegate = _delegate; 136 @synthesize delegate = _delegate;
137 @synthesize dispatcher = _dispatcher;
136 @synthesize requestStartTime = _requestStartTime; 138 @synthesize requestStartTime = _requestStartTime;
137 139
138 #pragma mark Public methods 140 #pragma mark Public methods
139 141
140 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { 142 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight {
141 NSInteger numberOfItems = [self.menuItems count]; 143 NSInteger numberOfItems = [self.menuItems count];
142 if (_toolbarType == ToolbarTypeWebiPhone) { 144 if (_toolbarType == ToolbarTypeWebiPhone) {
143 // Account for the height of the first row, not included in |menuItems|. 145 // Account for the height of the first row, not included in |menuItems|.
144 numberOfItems++; 146 numberOfItems++;
145 } 147 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 - (void)hideContent { 454 - (void)hideContent {
453 _menuView.alpha = 0; 455 _menuView.alpha = 0;
454 456
455 // Remove the target/action for touching the buttons. VoiceOver may hold on 457 // Remove the target/action for touching the buttons. VoiceOver may hold on
456 // to these buttons after |self| has been released, causing a crash if a 458 // to these buttons after |self| has been released, causing a crash if a
457 // button is activated (see http://crbug.com/480974 ). 459 // button is activated (see http://crbug.com/480974 ).
458 UIButton* toolsButton = [[self toolsCell] toolsButton]; 460 UIButton* toolsButton = [[self toolsCell] toolsButton];
459 [toolsButton removeTarget:self 461 [toolsButton removeTarget:self
460 action:@selector(buttonPressed:) 462 action:@selector(buttonPressed:)
461 forControlEvents:UIControlEventTouchUpInside]; 463 forControlEvents:UIControlEventTouchUpInside];
462 for (UIButton* button in [[self toolsCell] allButtons]) { 464 ToolsMenuViewToolsCell* toolsCell = [self toolsCell];
465 for (UIButton* button in [toolsCell allButtons]) {
463 [button removeTarget:self 466 [button removeTarget:self
464 action:@selector(buttonPressed:) 467 action:@selector(buttonPressed:)
465 forControlEvents:UIControlEventTouchUpInside]; 468 forControlEvents:UIControlEventTouchUpInside];
466 } 469 }
470 [toolsCell.stopButton removeTarget:self.dispatcher
471 action:@selector(stopLoading)
472 forControlEvents:UIControlEventTouchUpInside];
473 [toolsCell.reloadButton removeTarget:self.dispatcher
474 action:@selector(reload)
475 forControlEvents:UIControlEventTouchUpInside];
467 } 476 }
468 477
469 #pragma mark - Button event handling 478 #pragma mark - Button event handling
470 479
471 - (IBAction)buttonPressed:(id)sender { 480 - (void)buttonPressed:(id)sender {
472 int commandId = [sender tag]; 481 int commandId = [sender tag];
473 DCHECK(commandId); 482 DCHECK(commandId);
474 // The bookmark command workaround is only needed for metrics; remap it 483 // The bookmark command workaround is only needed for metrics; remap it
475 // to the real command for the dispatch. This is very hacky, but it will go 484 // to the real command for the dispatch. This is very hacky, but it will go
476 // away soon. See crbug/228521 485 // away soon. See crbug/228521
477 DCHECK([sender respondsToSelector:@selector(setTag:)]); 486 DCHECK([sender respondsToSelector:@selector(setTag:)]);
478 if (commandId == IDC_TEMP_EDIT_BOOKMARK) 487 if (commandId == IDC_TEMP_EDIT_BOOKMARK)
479 [sender setTag:IDC_BOOKMARK_PAGE]; 488 [sender setTag:IDC_BOOKMARK_PAGE];
480 // Do nothing when tapping the tools menu a second time. 489 // Do nothing when tapping the tools menu a second time.
481 if (commandId != IDC_SHOW_TOOLS_MENU) { 490 // Do not use -chromeExecuteCommand: for tags < 0 -- that is, items that have
491 // been refactored to use the dispatcher.
492 if (commandId != IDC_SHOW_TOOLS_MENU && commandId > 0) {
482 [self chromeExecuteCommand:sender]; 493 [self chromeExecuteCommand:sender];
483 } 494 }
484 if (commandId == IDC_TEMP_EDIT_BOOKMARK) 495 if (commandId == IDC_TEMP_EDIT_BOOKMARK)
485 [sender setTag:IDC_TEMP_EDIT_BOOKMARK]; 496 [sender setTag:IDC_TEMP_EDIT_BOOKMARK];
486 497
498 // Do any metrics logging for the command, and then close the menu.
487 [_delegate commandWasSelected:commandId]; 499 [_delegate commandWasSelected:commandId];
488 } 500 }
489 501
490 #pragma mark - UICollectionViewDelegate Implementation 502 #pragma mark - UICollectionViewDelegate Implementation
491 503
492 - (BOOL)collectionView:(ToolsMenuCollectionView*)view 504 - (BOOL)collectionView:(ToolsMenuCollectionView*)view
493 shouldHighlightItemAtIndexPath:(NSIndexPath*)path { 505 shouldHighlightItemAtIndexPath:(NSIndexPath*)path {
494 if (view.tracking) 506 if (view.tracking)
495 return NO; 507 return NO;
496 NSInteger item = [self dataIndexForIndexPath:path]; 508 NSInteger item = [self dataIndexForIndexPath:path];
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 return numberOfItems; 581 return numberOfItems;
570 } 582 }
571 583
572 - (UICollectionViewCell*)collectionView:(UICollectionView*)view 584 - (UICollectionViewCell*)collectionView:(UICollectionView*)view
573 cellForItemAtIndexPath:(NSIndexPath*)path { 585 cellForItemAtIndexPath:(NSIndexPath*)path {
574 NSInteger item = [self dataIndexForIndexPath:path]; 586 NSInteger item = [self dataIndexForIndexPath:path];
575 if (item < 0) { 587 if (item < 0) {
576 ToolsMenuViewToolsCell* cell = 588 ToolsMenuViewToolsCell* cell =
577 [view dequeueReusableCellWithReuseIdentifier:kToolsItemCellID 589 [view dequeueReusableCellWithReuseIdentifier:kToolsItemCellID
578 forIndexPath:path]; 590 forIndexPath:path];
591 // Add specific target/action dispatch for buttons refactored away from
592 // ChromeExecuteCommand. These need to be added *before* -buttonPressed:,
593 // because -buttonPressed: closes the popup menu, which will usually
594 // destroy the buttons before any other actions can be called.
595 [cell.stopButton addTarget:self.dispatcher
596 action:@selector(stopLoading)
597 forControlEvents:UIControlEventTouchUpInside];
598 [cell.reloadButton addTarget:self.dispatcher
599 action:@selector(reload)
600 forControlEvents:UIControlEventTouchUpInside];
579 for (UIButton* button in [cell allButtons]) { 601 for (UIButton* button in [cell allButtons]) {
580 [button addTarget:self 602 [button addTarget:self
581 action:@selector(buttonPressed:) 603 action:@selector(buttonPressed:)
582 forControlEvents:UIControlEventTouchUpInside]; 604 forControlEvents:UIControlEventTouchUpInside];
583 } 605 }
606
584 return cell; 607 return cell;
585 } 608 }
586 609
587 ToolsMenuViewItem* menuItem = [_menuItems objectAtIndex:item]; 610 ToolsMenuViewItem* menuItem = [_menuItems objectAtIndex:item];
588 ToolsMenuViewCell* menuItemCell = 611 ToolsMenuViewCell* menuItemCell =
589 [view dequeueReusableCellWithReuseIdentifier:[[menuItem class] cellID] 612 [view dequeueReusableCellWithReuseIdentifier:[[menuItem class] cellID]
590 forIndexPath:path]; 613 forIndexPath:path];
591 [menuItemCell configureForMenuItem:menuItem]; 614 [menuItemCell configureForMenuItem:menuItem];
592 615
593 return menuItemCell; 616 return menuItemCell;
(...skipping 18 matching lines...) Expand all
612 635
613 - (void)unreadCountChanged:(NSInteger)unreadCount { 636 - (void)unreadCountChanged:(NSInteger)unreadCount {
614 [[self readingListCell] updateBadgeCount:unreadCount animated:YES]; 637 [[self readingListCell] updateBadgeCount:unreadCount animated:YES];
615 } 638 }
616 639
617 - (void)unseenStateChanged:(BOOL)unseenItemsExist { 640 - (void)unseenStateChanged:(BOOL)unseenItemsExist {
618 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES]; 641 [[self readingListCell] updateSeenState:unseenItemsExist animated:YES];
619 } 642 }
620 643
621 @end 644 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698