Commit 3bfa474b authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Create named guide for last tapped voice search button.

Bug: 805120
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I610f604d1f20695d028571166e443c12cd11cc20
Reviewed-on: https://chromium-review.googlesource.com/952766
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545585}
parent 13105d48
......@@ -2339,6 +2339,7 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
kToolsMenuGuide,
kTabSwitcherGuide,
kSecondaryToolbar,
kVoiceSearchButtonGuide,
];
AddNamedGuidesToView(guideNames, self.view);
}
......
......@@ -71,6 +71,7 @@ source_set("content_suggestions") {
"//ios/chrome/browser/ui/toolbar/buttons",
"//ios/chrome/browser/ui/toolbar/clean:toolbar",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/common/app_group",
"//ios/public/provider/chrome/browser",
......
......@@ -26,6 +26,7 @@
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/browser/ui/url_loader.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/ui/logo_vendor.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -362,9 +363,11 @@ const UIEdgeInsets kSearchBoxStretchInsets = {3, 3, 3, 3};
DCHECK(self.voiceSearchIsEnabled);
base::RecordAction(UserMetricsAction("MobileNTPMostVisitedVoiceSearch"));
UIView* view = base::mac::ObjCCastStrict<UIView>(sender);
UIView* voiceSearchButton = base::mac::ObjCCastStrict<UIView>(sender);
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:voiceSearchButton]
.constrainedView = voiceSearchButton;
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc] initWithOriginView:view];
[[StartVoiceSearchCommand alloc] initWithOriginView:voiceSearchButton];
[self.dispatcher startVoiceSearch:command];
}
......
......@@ -10,6 +10,7 @@
#include "ios/chrome/browser/ui/commands/start_voice_search_command.h"
#import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h"
#include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -198,6 +199,10 @@ keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer
modifierFlags:UIKeyModifierCommand | UIKeyModifierShift
title:voiceSearchTitle
action:^{
UIView* baseView = baseViewController.view;
[[NamedGuide guideWithName:kVoiceSearchButtonGuide
view:baseView]
resetConstraints];
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc]
initWithOriginView:nil];
......
......@@ -656,6 +656,8 @@ const CGFloat kScrollFadeDistance = 30;
// Target of the voice search button.
- (void)startVoiceSearch:(id)sender {
UIView* view = base::mac::ObjCCastStrict<UIView>(sender);
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:view].constrainedView =
view;
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc] initWithOriginView:view];
[self.dispatcher startVoiceSearch:command];
......
......@@ -31,6 +31,7 @@ source_set("keyboard_assist") {
"//ios/chrome/browser/ui/location_bar:constants",
"//ios/chrome/browser/ui/omnibox:omnibox_internal",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util/",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/external_search",
"//ios/public/provider/chrome/browser/voice",
......
......@@ -9,6 +9,7 @@
@protocol ApplicationCommands;
@protocol BrowserCommands;
@class NamedGuide;
@class OmniboxTextFieldIOS;
// Delegate protocol for the KeyboardAccessoryView.
......@@ -38,6 +39,7 @@
@property(nonatomic, weak) id<ApplicationCommands, BrowserCommands> dispatcher;
@property(nonatomic, weak) OmniboxTextFieldIOS* omniboxTextField;
@property(nonatomic, weak) NamedGuide* voiceSearchButtonGuide;
@end
......
......@@ -12,6 +12,7 @@
#import "ios/chrome/browser/ui/commands/start_voice_search_command.h"
#import "ios/chrome/browser/ui/location_bar/location_bar_constants.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
......@@ -23,6 +24,7 @@
@synthesize dispatcher = _dispatcher;
@synthesize omniboxTextField = _omniboxTextField;
@synthesize voiceSearchButtonGuide = _voiceSearchButtonGuide;
#pragma mark - Public
......@@ -39,6 +41,21 @@
->GetVoiceSearchProvider()
->IsVoiceSearchEnabled()) {
base::RecordAction(base::UserMetricsAction("MobileCustomRowVoiceSearch"));
// Since the keyboard accessory view is in a different window than the main
// UIViewController upon which Voice Search will be presented, the guide
// must be constrained to a frame instead of the view itself. The keyboard
// and its accessory view will be dismissed at the bottom of the screen
// before the presentation animation, so bottom-align the view's frame.
if (self.voiceSearchButtonGuide) {
self.voiceSearchButtonGuide.autoresizingMask =
(UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin);
CGRect frame = view.frame;
frame.origin.y =
CGRectGetMaxY(self.voiceSearchButtonGuide.owningView.bounds) -
CGRectGetHeight(frame);
self.voiceSearchButtonGuide.constrainedFrame = frame;
}
StartVoiceSearchCommand* command =
[[StartVoiceSearchCommand alloc] initWithOriginView:view];
[self.dispatcher startVoiceSearch:command];
......
......@@ -28,5 +28,8 @@ extern GuideName* const kForwardButtonGuide;
extern GuideName* const kTabSwitcherGuide;
// A guide that is constrained to match the frame of the ToolsMenu button.
extern GuideName* const kToolsMenuGuide;
// A guide that is constrained to match the frame of the last-tapped voice
// search button.
extern GuideName* const kVoiceSearchButtonGuide;
#endif // IOS_CHROME_BROWSER_UI_UTIL_LAYOUT_GUIDE_NAMES_H_
......@@ -16,3 +16,4 @@ GuideName* const kBackButtonGuide = @"kBackButtonGuide";
GuideName* const kForwardButtonGuide = @"kForwardButtonGuide";
GuideName* const kTabSwitcherGuide = @"kTabSwitcherGuide";
GuideName* const kToolsMenuGuide = @"kToolsMenuGuide";
GuideName* const kVoiceSearchButtonGuide = @"kVoiceSearchButtonGuide";
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