Commit 7a6c1aee authored by stkhapugin@chromium.org's avatar stkhapugin@chromium.org Committed by Commit Bot

[UI Refresh] Support special cases for the incognito NTP location bar.

Adds a special treatment for the Incognito NTP: the share button is now
hidden, and there is a fake "placeholder" in the steady view.

Bug: 845956
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I761ff6d418b49527afb04ce890ca09a481e39778
Reviewed-on: https://chromium-review.googlesource.com/1095111
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566833}
parent 4fd11d48
......@@ -16,6 +16,10 @@
// Notifies consumer to defocus the omnibox (for example on tab change).
- (void)defocusOmnibox;
// Notifies the consumer to update after a navigation to NTP. Will be called
// after -updateLocationText. Used for triggering NTP-specific location bar UI.
- (void)updateAfterNavigatingToNTP;
@end
#endif // IOS_CHROME_BROWSER_UI_LOCATION_BAR_LOCATION_BAR_CONSUMER_H_
......@@ -273,6 +273,7 @@ const int kLocationAuthorizationStatusCount = 4;
- (void)updateLocationText:(NSString*)text {
[self.omniboxCoordinator updateOmniboxState];
[self.viewController updateLocationText:text];
[self.viewController updateForIncognitoNTP:NO];
}
- (void)defocusOmnibox {
......@@ -283,6 +284,13 @@ const int kLocationAuthorizationStatusCount = 4;
[self.viewController updateLocationIcon:icon];
}
- (void)updateAfterNavigatingToNTP {
BOOL isIncognito = self.browserState->IsOffTheRecord();
if (isIncognito) {
[self.viewController updateForIncognitoNTP:YES];
}
}
#pragma mark - private
// Returns a dictionary with variation headers for qualified URLs. Can be empty.
......
......@@ -78,20 +78,20 @@
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
DCHECK_EQ(_webState, webState);
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
}
- (void)webState:(web::WebState*)webState
didStartNavigation:(web::NavigationContext*)navigation {
DCHECK_EQ(_webState, webState);
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
- (void)webState:(web::WebState*)webState
didFinishNavigation:(web::NavigationContext*)navigation {
DCHECK_EQ(_webState, webState);
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
......@@ -102,13 +102,13 @@
- (void)webStateDidStartLoading:(web::WebState*)webState {
DCHECK_EQ(_webState, webState);
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
- (void)webStateDidStopLoading:(web::WebState*)webState {
DCHECK_EQ(_webState, webState);
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
......@@ -148,7 +148,7 @@
_webState->AddObserver(_webStateObserver.get());
if (self.consumer) {
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
}
......@@ -157,7 +157,7 @@
- (void)setConsumer:(id<LocationBarConsumer>)consumer {
_consumer = consumer;
if (self.webState) {
[self.consumer updateLocationText:[self currentLocationString]];
[self notifyConsumerOfChangedLocation];
[self notifyConsumerOfChangedSecurityIcon];
}
}
......@@ -174,6 +174,15 @@
#pragma mark - private
- (void)notifyConsumerOfChangedLocation {
[self.consumer updateLocationText:[self currentLocationString]];
GURL URL = self.webState->GetVisibleURL();
BOOL isNTP = URL.GetOrigin() == kChromeUINewTabURL;
if (isNTP) {
[self.consumer updateAfterNavigatingToNTP];
}
}
- (void)notifyConsumerOfChangedSecurityIcon {
[self.consumer updateLocationIcon:[self currentLocationIcon]];
}
......
......@@ -56,6 +56,10 @@
- (void)updateLocationIcon:(UIImage*)icon;
// Updates the location text in the non-editing mode.
- (void)updateLocationText:(NSString*)text;
// Updates the location view to show a fake placeholder in the steady location
// view and hides the trailing button if |isIncognitoNTP|. Otherwise, shows the
// location text and the button as normal.
- (void)updateForIncognitoNTP:(BOOL)isIncognitoNTP;
// Displays the voice search button instead of the share button in steady state,
// and adds the voice search button to the empty textfield.
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/location_bar/location_bar_view_controller.h"
#include "components/strings/grit/components_strings.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/browser_commands.h"
......@@ -11,6 +12,7 @@
#include "ios/chrome/browser/ui/location_bar/location_bar_steady_view.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#import "ios/chrome/browser/ui/util/named_guide.h"
#include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -35,6 +37,11 @@ typedef NS_ENUM(int, TrailingButtonState) {
@property(nonatomic, assign) TrailingButtonState trailingButtonState;
// When this flag is YES, the share button will not be displayed in situations
// when it normally is shown. Setting it triggers a refresh of the button
// visibility.
@property(nonatomic, assign) BOOL hideShareButtonWhileOnIncognitoNTP;
// Starts voice search, updating the NamedGuide to be constrained to the
// trailing button.
- (void)startVoiceSearch;
......@@ -49,6 +56,8 @@ typedef NS_ENUM(int, TrailingButtonState) {
@synthesize dispatcher = _dispatcher;
@synthesize voiceSearchEnabled = _voiceSearchEnabled;
@synthesize trailingButtonState = _trailingButtonState;
@synthesize hideShareButtonWhileOnIncognitoNTP =
_hideShareButtonWhileOnIncognitoNTP;
#pragma mark - public
......@@ -95,10 +104,18 @@ typedef NS_ENUM(int, TrailingButtonState) {
return;
}
_voiceSearchEnabled = enabled;
[self updateTrailingButtonState];
}
- (void)setHideShareButtonWhileOnIncognitoNTP:(BOOL)hide {
if (_hideShareButtonWhileOnIncognitoNTP == hide) {
return;
}
_hideShareButtonWhileOnIncognitoNTP = hide;
[self updateTrailingButton];
}
- (void)updateTrailingButton {
- (void)updateTrailingButtonState {
BOOL shouldShowVoiceSearch =
self.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassRegular ||
......@@ -134,7 +151,7 @@ typedef NS_ENUM(int, TrailingButtonState) {
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[self updateTrailingButton];
[self updateTrailingButtonState];
[super traitCollectionDidChange:previousTraitCollection];
}
......@@ -183,17 +200,28 @@ typedef NS_ENUM(int, TrailingButtonState) {
[icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
- (void)updateForIncognitoNTP:(BOOL)isIncognitoNTP {
if (isIncognitoNTP) {
// Display a fake "placeholder".
NSString* placeholderString =
l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT);
UIColor* placeholderColor =
[LocationBarSteadyViewColorScheme incognitoScheme].placeholderColor;
self.locationBarSteadyView.locationLabel.attributedText = [
[NSAttributedString alloc]
initWithString:placeholderString
attributes:@{NSForegroundColorAttributeName : placeholderColor}];
}
self.hideShareButtonWhileOnIncognitoNTP = isIncognitoNTP;
}
#pragma mark - private
- (void)locationBarSteadyViewTapped {
[self.delegate locationBarSteadyViewTapped];
}
- (void)setTrailingButtonState:(TrailingButtonState)state {
if (_trailingButtonState == state) {
return;
}
- (void)updateTrailingButton {
// Stop constraining the voice guide to the trailing button if transitioning
// from kVoiceSearchButton.
NamedGuide* voiceGuide =
......@@ -202,7 +230,6 @@ typedef NS_ENUM(int, TrailingButtonState) {
if (voiceGuide.constrainedView == self.locationBarSteadyView.trailingButton)
voiceGuide.constrainedView = nil;
_trailingButtonState = state;
// Cancel previous possible state.
[self.locationBarSteadyView.trailingButton
......@@ -211,6 +238,11 @@ typedef NS_ENUM(int, TrailingButtonState) {
forControlEvents:UIControlEventAllEvents];
self.locationBarSteadyView.trailingButton.hidden = NO;
TrailingButtonState state = self.trailingButtonState;
if (state == kShareButton && self.hideShareButtonWhileOnIncognitoNTP) {
state = kNoButton;
}
switch (state) {
case kNoButton: {
self.locationBarSteadyView.trailingButton.hidden = YES;
......@@ -247,6 +279,15 @@ typedef NS_ENUM(int, TrailingButtonState) {
}
}
- (void)setTrailingButtonState:(TrailingButtonState)state {
if (_trailingButtonState == state) {
return;
}
_trailingButtonState = state;
[self updateTrailingButton];
}
- (void)startVoiceSearch {
[NamedGuide guideWithName:kVoiceSearchButtonGuide view:self.view]
.constrainedView = self.locationBarSteadyView.trailingButton;
......
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