Commit 5832ab59 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates InfobarCommands protocol.

- InfobarCommands will be used by the LocationBar badge button to
communicate with the InfobarContainer and display the InfobarModal
whenever the button is tapped.

Bug: 911864
Change-Id: Ib0126ce8d8de9378d91606f9a76855ff882cbc9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1500605
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638188}
parent ecf62378
...@@ -2018,7 +2018,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2018,7 +2018,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
initWithBaseViewController:self initWithBaseViewController:self
browserState:_browserState browserState:_browserState
tabModel:self.tabModel]; tabModel:self.tabModel];
self.infobarContainerCoordinator.dispatcher = self.dispatcher; self.infobarContainerCoordinator.commandDispatcher = self.dispatcher;
self.infobarContainerCoordinator.positioner = self; self.infobarContainerCoordinator.positioner = self;
self.infobarContainerCoordinator.syncPresenter = self; self.infobarContainerCoordinator.syncPresenter = self;
[self.infobarContainerCoordinator start]; [self.infobarContainerCoordinator start];
......
...@@ -12,6 +12,7 @@ source_set("commands") { ...@@ -12,6 +12,7 @@ source_set("commands") {
"browsing_data_commands.h", "browsing_data_commands.h",
"command_dispatcher.h", "command_dispatcher.h",
"command_dispatcher.mm", "command_dispatcher.mm",
"infobar_commands.h",
"load_query_commands.h", "load_query_commands.h",
"omnibox_suggestion_commands.h", "omnibox_suggestion_commands.h",
"open_new_tab_command.h", "open_new_tab_command.h",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/commands/activity_service_commands.h" #import "ios/chrome/browser/ui/commands/activity_service_commands.h"
#import "ios/chrome/browser/ui/commands/browser_coordinator_commands.h" #import "ios/chrome/browser/ui/commands/browser_coordinator_commands.h"
#import "ios/chrome/browser/ui/commands/infobar_commands.h"
#import "ios/chrome/browser/ui/commands/page_info_commands.h" #import "ios/chrome/browser/ui/commands/page_info_commands.h"
#import "ios/chrome/browser/ui/commands/popup_menu_commands.h" #import "ios/chrome/browser/ui/commands/popup_menu_commands.h"
#import "ios/chrome/browser/ui/commands/qr_scanner_commands.h" #import "ios/chrome/browser/ui/commands/qr_scanner_commands.h"
...@@ -23,13 +24,14 @@ class GURL; ...@@ -23,13 +24,14 @@ class GURL;
// which in practice is the BrowserViewController instance displaying the tab. // which in practice is the BrowserViewController instance displaying the tab.
// TODO(crbug.com/906662) : Extract BrowserCoordinatorCommands from // TODO(crbug.com/906662) : Extract BrowserCoordinatorCommands from
// BrowserCommands. // BrowserCommands.
@protocol BrowserCommands<NSObject, @protocol BrowserCommands <NSObject,
ActivityServiceCommands, ActivityServiceCommands,
BrowserCoordinatorCommands, BrowserCoordinatorCommands,
PageInfoCommands, InfobarCommands,
PopupMenuCommands, PageInfoCommands,
QRScannerCommands, PopupMenuCommands,
SnackbarCommands> QRScannerCommands,
SnackbarCommands>
// Closes the current tab. // Closes the current tab.
- (void)closeCurrentTab; - (void)closeCurrentTab;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_COMMANDS_INFOBAR_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_COMMANDS_INFOBAR_COMMANDS_H_
// TODO(crbug.com/935804): This protocol is currently only being used in the
// Infobar redesign.
@protocol InfobarCommands <NSObject>
// Displays the InfobarModal for the InfobarBadge.
- (void)displayModalInfobar;
@end
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_INFOBAR_COMMANDS_H_
...@@ -11,8 +11,8 @@ namespace web { ...@@ -11,8 +11,8 @@ namespace web {
class WebState; class WebState;
} }
@class CommandDispatcher;
@class TabModel; @class TabModel;
@protocol ApplicationCommands;
@protocol InfobarPositioner; @protocol InfobarPositioner;
@protocol SyncPresenter; @protocol SyncPresenter;
...@@ -49,8 +49,8 @@ class WebState; ...@@ -49,8 +49,8 @@ class WebState;
// YES if an Infobar is being presented for |webState|. // YES if an Infobar is being presented for |webState|.
- (BOOL)isInfobarPresentingForWebState:(web::WebState*)webState; - (BOOL)isInfobarPresentingForWebState:(web::WebState*)webState;
// The dispatcher for this Coordinator. // The CommandDispatcher for this Coordinator.
@property(nonatomic, weak) id<ApplicationCommands> dispatcher; @property(nonatomic, weak) CommandDispatcher* commandDispatcher;
// The delegate used to position the InfobarContainer in the view. // The delegate used to position the InfobarContainer in the view.
@property(nonatomic, weak) id<InfobarPositioner> positioner; @property(nonatomic, weak) id<InfobarPositioner> positioner;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h" #include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinating.h" #import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinating.h"
#import "ios/chrome/browser/ui/infobars/infobar_container_consumer.h" #import "ios/chrome/browser/ui/infobars/infobar_container_consumer.h"
...@@ -39,6 +40,8 @@ ...@@ -39,6 +40,8 @@
LegacyInfobarContainerViewController* legacyContainerViewController; LegacyInfobarContainerViewController* legacyContainerViewController;
// The mediator for this Coordinator. // The mediator for this Coordinator.
@property(nonatomic, strong) InfobarContainerMediator* mediator; @property(nonatomic, strong) InfobarContainerMediator* mediator;
// The dispatcher for this Coordinator.
@property(nonatomic, weak) id<ApplicationCommands> dispatcher;
@end @end
...@@ -120,6 +123,23 @@ ...@@ -120,6 +123,23 @@
return NO; return NO;
} }
#pragma mark - Accessors
- (void)setCommandDispatcher:(CommandDispatcher*)commandDispatcher {
if (commandDispatcher == self.commandDispatcher) {
return;
}
if (self.commandDispatcher) {
[self.commandDispatcher stopDispatchingToTarget:self];
}
[commandDispatcher startDispatchingToTarget:self
forSelector:@selector(displayModalInfobar)];
_commandDispatcher = commandDispatcher;
self.dispatcher = static_cast<id<ApplicationCommands>>(_commandDispatcher);
}
#pragma mark - InfobarConsumer #pragma mark - InfobarConsumer
- (void)addInfoBarWithDelegate:(id<InfobarUIDelegate>)infoBarDelegate - (void)addInfoBarWithDelegate:(id<InfobarUIDelegate>)infoBarDelegate
...@@ -150,6 +170,12 @@ ...@@ -150,6 +170,12 @@
// since we use autolayout for the contained Infobars. // since we use autolayout for the contained Infobars.
} }
#pragma mark - InfobarCommands
- (void)displayModalInfobar {
// TODO(crbug.com/911864): To be implemented.
}
#pragma mark - UIViewControllerTransitioningDelegate #pragma mark - UIViewControllerTransitioningDelegate
- (UIPresentationController*) - (UIPresentationController*)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
@protocol ActivityServiceCommands; @protocol ActivityServiceCommands;
@protocol ApplicationCommands; @protocol ApplicationCommands;
@protocol BrowserCommands; @protocol BrowserCommands;
@protocol InfobarCommands;
@protocol LocationBarOffsetProvider; @protocol LocationBarOffsetProvider;
@protocol LoadQueryCommands; @protocol LoadQueryCommands;
...@@ -43,8 +44,9 @@ ...@@ -43,8 +44,9 @@
// The dispatcher for the share button, voice search, and long press actions. // The dispatcher for the share button, voice search, and long press actions.
@property(nonatomic, weak) id<ActivityServiceCommands, @property(nonatomic, weak) id<ActivityServiceCommands,
BrowserCommands,
ApplicationCommands, ApplicationCommands,
BrowserCommands,
InfobarCommands,
LoadQueryCommands> LoadQueryCommands>
dispatcher; dispatcher;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#import "ios/chrome/browser/ui/commands/activity_service_commands.h" #import "ios/chrome/browser/ui/commands/activity_service_commands.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h" #import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/infobar_commands.h"
#import "ios/chrome/browser/ui/commands/load_query_commands.h" #import "ios/chrome/browser/ui/commands/load_query_commands.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_animator.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_animator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
...@@ -437,6 +438,10 @@ typedef NS_ENUM(int, TrailingButtonState) { ...@@ -437,6 +438,10 @@ typedef NS_ENUM(int, TrailingButtonState) {
setImage:[[UIImage imageNamed:@"infobar_passwords_icon"] setImage:[[UIImage imageNamed:@"infobar_passwords_icon"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
forState:UIControlStateNormal]; forState:UIControlStateNormal];
[self.locationBarSteadyView.leadingButton
addTarget:self.dispatcher
action:@selector(displayModalInfobar)
forControlEvents:UIControlEventTouchUpInside];
self.locationBarSteadyView.leadingButton.tintColor = [UIColor lightGrayColor]; self.locationBarSteadyView.leadingButton.tintColor = [UIColor lightGrayColor];
// Set as hidden as it should only be shown by |displayInfobarButton:| // Set as hidden as it should only be shown by |displayInfobarButton:|
self.locationBarSteadyView.leadingButton.hidden = YES; self.locationBarSteadyView.leadingButton.hidden = YES;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment