Commit 7e943dac authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add standard action to toolbar buttons

This CL adds the standard actions (cancelling omnibox edit and
recording metrics) to all the toolbar buttons.

Bug: 806274
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ifbc108f852ae5f521343f3ea8065a8637c8afb68
Reviewed-on: https://chromium-review.googlesource.com/893266
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarLouis Romero <lpromero@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533245}
parent e945bb1f
...@@ -57,8 +57,6 @@ ...@@ -57,8 +57,6 @@
self.started = YES; self.started = YES;
self.viewController.dispatcher = self.dispatcher;
self.mediator = [[ToolbarMediator alloc] init]; self.mediator = [[ToolbarMediator alloc] init];
self.mediator.voiceSearchProvider = self.mediator.voiceSearchProvider =
ios::GetChromeBrowserProvider()->GetVoiceSearchProvider(); ios::GetChromeBrowserProvider()->GetVoiceSearchProvider();
......
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
@property(nonatomic, strong, readonly) ToolbarButton* bookmarkButton; @property(nonatomic, strong, readonly) ToolbarButton* bookmarkButton;
// Button to display the tools menu. // Button to display the tools menu.
@property(nonatomic, strong, readonly) ToolbarToolsMenuButton* toolsMenuButton; @property(nonatomic, strong, readonly) ToolbarToolsMenuButton* toolsMenuButton;
// Button to display the tools menu.
@property(nonatomic, strong, readonly) ToolbarButton* omniboxButton;
// The following 2 properties are for the two buttons to navigate forward that // The following 2 properties are for the two buttons to navigate forward that
// are visible in various mutually exclusive configurations of the toolbar. // are visible in various mutually exclusive configurations of the toolbar.
......
...@@ -5,12 +5,14 @@ ...@@ -5,12 +5,14 @@
#import "ios/chrome/browser/ui/toolbar/adaptive/adaptive_toolbar_view_controller.h" #import "ios/chrome/browser/ui/toolbar/adaptive/adaptive_toolbar_view_controller.h"
#import "base/logging.h" #import "base/logging.h"
#include "base/metrics/user_metrics.h"
#import "ios/chrome/browser/ui/toolbar/adaptive/adaptive_toolbar_view.h" #import "ios/chrome/browser/ui/toolbar/adaptive/adaptive_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_button.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_button.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_button_factory.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_button_factory.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_constants.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_tab_grid_button.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_tab_grid_button.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_tools_menu_button.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_tools_menu_button.h"
#import "ios/chrome/browser/ui/toolbar/public/omnibox_focuser.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h"
#import "ios/third_party/material_components_ios/src/components/ProgressView/src/MaterialProgressView.h" #import "ios/third_party/material_components_ios/src/components/ProgressView/src/MaterialProgressView.h"
#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" #import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
...@@ -54,6 +56,11 @@ ...@@ -54,6 +56,11 @@
[self updateAllButtonsVisibility]; [self updateAllButtonsVisibility];
} }
- (void)viewDidLoad {
[super viewDidLoad];
[self addStandardActionsForAllButtons];
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection]; [super traitCollectionDidChange:previousTraitCollection];
[self updateAllButtonsVisibility]; [self updateAllButtonsVisibility];
...@@ -139,4 +146,44 @@ ...@@ -139,4 +146,44 @@
} }
} }
// Registers the actions which will be triggered when tapping a button.
- (void)addStandardActionsForAllButtons {
for (ToolbarButton* button in self.view.allButtons) {
if (button != self.view.toolsMenuButton) {
[button addTarget:self.dispatcher
action:@selector(cancelOmniboxEdit)
forControlEvents:UIControlEventTouchUpInside];
}
[button addTarget:self
action:@selector(recordUserMetrics:)
forControlEvents:UIControlEventTouchUpInside];
}
}
// Records the use of a button.
- (IBAction)recordUserMetrics:(id)sender {
if (sender == self.view.backButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarBack"));
} else if (sender == self.view.forwardLeadingButton ||
sender == self.view.forwardTrailingButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarForward"));
} else if (sender == self.view.reloadButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarReload"));
} else if (sender == self.view.stopButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarStop"));
} else if (sender == self.view.bookmarkButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarToggleBookmark"));
} else if (sender == self.view.toolsMenuButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowMenu"));
} else if (sender == self.view.tabGridButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowStackView"));
} else if (sender == self.view.shareButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarShareMenu"));
} else if (sender == self.view.omniboxButton) {
base::RecordAction(base::UserMetricsAction("MobileToolbarOmniboxShortcut"));
} else {
NOTREACHED();
}
}
@end @end
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
- (void)start { - (void)start {
self.viewController = [[PrimaryToolbarViewController alloc] init]; self.viewController = [[PrimaryToolbarViewController alloc] init];
self.viewController.buttonFactory = [self buttonFactoryWithType:PRIMARY]; self.viewController.buttonFactory = [self buttonFactoryWithType:PRIMARY];
self.viewController.dispatcher = self.dispatcher;
[self setUpLocationBar]; [self setUpLocationBar];
self.viewController.locationBarView = self.locationBarCoordinator.view; self.viewController.locationBarView = self.locationBarCoordinator.view;
......
...@@ -264,4 +264,10 @@ ...@@ -264,4 +264,10 @@
return _allButtons; return _allButtons;
} }
#pragma mark - AdaptiveToolbarView
- (ToolbarButton*)omniboxButton {
return nil;
}
@end @end
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
- (void)start { - (void)start {
self.viewController = [[SecondaryToolbarViewController alloc] init]; self.viewController = [[SecondaryToolbarViewController alloc] init];
self.viewController.buttonFactory = [self buttonFactoryWithType:SECONDARY]; self.viewController.buttonFactory = [self buttonFactoryWithType:SECONDARY];
self.viewController.dispatcher = self.dispatcher;
[super start]; [super start];
} }
......
...@@ -12431,6 +12431,13 @@ should be able to be added at any place in this file. ...@@ -12431,6 +12431,13 @@ should be able to be added at any place in this file.
<description>Please enter the description of this user action.</description> <description>Please enter the description of this user action.</description>
</action> </action>
<action name="MobileToolbarOmniboxShortcut">
<owner>gambard@chromium.org</owner>
<description>
User pressed the omnibox shortcut on the toolbar. iOS only.
</description>
</action>
<action name="MobileToolbarReload"> <action name="MobileToolbarReload">
<owner>tedchoc@chromium.org</owner> <owner>tedchoc@chromium.org</owner>
<description> <description>
...@@ -12440,6 +12447,13 @@ should be able to be added at any place in this file. ...@@ -12440,6 +12447,13 @@ should be able to be added at any place in this file.
</description> </description>
</action> </action>
<action name="MobileToolbarShareMenu">
<owner>gambard@chromium.org</owner>
<description>
User pressed the toolbar's button to open the share menu. iOS only.
</description>
</action>
<action name="MobileToolbarShowMenu"> <action name="MobileToolbarShowMenu">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner> <owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<description>Please enter the description of this user action.</description> <description>Please enter the description of this user action.</description>
......
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