Index: ios/chrome/browser/ui/stack_view/stack_view_controller.mm |
diff --git a/ios/chrome/browser/ui/stack_view/stack_view_controller.mm b/ios/chrome/browser/ui/stack_view/stack_view_controller.mm |
index 91ed3a17d58a22108a274be1bb36dd5878add2fd..336cf04edd31a2995edf57eaa87782f38e9ed43e 100644 |
--- a/ios/chrome/browser/ui/stack_view/stack_view_controller.mm |
+++ b/ios/chrome/browser/ui/stack_view/stack_view_controller.mm |
@@ -29,6 +29,7 @@ |
#import "ios/chrome/browser/ui/animation_util.h" |
#import "ios/chrome/browser/ui/background_generator.h" |
#import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
+#import "ios/chrome/browser/ui/commands/browser_commands.h" |
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
#include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
#import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" |
@@ -51,6 +52,7 @@ |
#import "ios/chrome/browser/ui/uikit_ui_util.h" |
#import "ios/chrome/common/material_timing.h" |
#include "ios/chrome/grit/ios_strings.h" |
+#import "ios/shared/chrome/browser/ui/commands/command_dispatcher.h" |
#import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
#include "ios/web/public/referrer.h" |
#import "net/base/mac/url_conversions.h" |
@@ -490,6 +492,8 @@ NSString* const kDummyToolbarBackgroundViewAnimationKey = |
// |YES| if there is card set animation being processed. For testing only. |
// Save last touch point used by new tab animation. |
CGPoint _lastTapPoint; |
+ // The dispacther instance used when this view controller is active. |
+ CommandDispatcher* _dispatcher; |
} |
@synthesize activeCardSet = _activeCardSet; |
@@ -530,6 +534,9 @@ NSString* const kDummyToolbarBackgroundViewAnimationKey = |
initWithTarget:self |
action:@selector(handleTapFrom:)]; |
[_modeSwitchRecognizer setDelegate:self]; |
+ _dispatcher = [[CommandDispatcher alloc] init]; |
+ [_dispatcher startDispatchingToTarget:self |
+ forProtocol:@protocol(BrowserCommands)]; |
} |
return self; |
} |
@@ -560,6 +567,10 @@ NSString* const kDummyToolbarBackgroundViewAnimationKey = |
return nil; |
} |
+- (id<BrowserCommands>)browserCommandsDispatcher { |
+ return static_cast<id<BrowserCommands>>(_dispatcher); |
+} |
+ |
- (void)setUpWithMainCardSet:(CardSet*)mainCardSet |
otrCardSet:(CardSet*)otrCardSet |
activeCardSet:(CardSet*)activeCardSet { |
@@ -2683,13 +2694,26 @@ NSString* const kDummyToolbarBackgroundViewAnimationKey = |
return nil; |
} |
+#pragma mark - BrowserCommands |
+ |
+- (void)showToolsMenu { |
+ ToolsMenuConfiguration* configuration = |
+ [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
+ [configuration setInTabSwitcher:YES]; |
+ // When checking for the existence of tabs, catch the case where the main set |
+ // is both active and empty, but the incognito set has some cards. |
+ if (([[_activeCardSet cards] count] == 0) && |
+ (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
+ [configuration setNoOpenedTabs:YES]; |
+ if (_activeCardSet == _otrCardSet) |
+ [configuration setInIncognito:YES]; |
+ [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
+} |
+ |
- (IBAction)chromeExecuteCommand:(id)sender { |
int command = [sender tag]; |
switch (command) { |
- case IDC_SHOW_TOOLS_MENU: |
- [self showToolsMenuPopup]; |
- break; |
// Closing all while the main set is active closes everything, but closing |
// all while incognito is active only closes incognito tabs. |
case IDC_CLOSE_ALL_TABS: |
@@ -2720,20 +2744,6 @@ NSString* const kDummyToolbarBackgroundViewAnimationKey = |
} |
} |
-- (void)showToolsMenuPopup { |
- ToolsMenuConfiguration* configuration = |
- [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
- [configuration setInTabSwitcher:YES]; |
- // When checking for the existence of tabs, catch the case where the main set |
- // is both active and empty, but the incognito set has some cards. |
- if (([[_activeCardSet cards] count] == 0) && |
- (_activeCardSet == _otrCardSet || [[_otrCardSet cards] count] == 0)) |
- [configuration setNoOpenedTabs:YES]; |
- if (_activeCardSet == _otrCardSet) |
- [configuration setInIncognito:YES]; |
- [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
-} |
- |
#pragma mark Notification Handlers |
- (void)allModelTabsHaveClosed:(NSNotification*)notify { |