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

Implement default leading image behaviour in the omnibox.

Adds a default leading image to the omnibox to be used when
it's being focused (before the first update of the leading image).
There are two images: for the empty textfield (magnifying glass)
and the non-empty textfield (default favicon).

Bug: 865000
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib9869c3b87f81041ec8a13b0ac220a3b93aa521e
Reviewed-on: https://chromium-review.googlesource.com/1146926Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577877}
parent ca8690dc
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/omnibox/omnibox_coordinator.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
......@@ -12,6 +13,7 @@
#import "ios/chrome/browser/ui/location_bar/location_bar_constants.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_mediator.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_util.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_view_controller.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_view_ios.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.h"
......@@ -54,6 +56,19 @@
self.viewController =
[[OmniboxViewController alloc] initWithIncognito:isIncognito];
std::string defaultLeadingImageName = GetResourceNameForAutocompleteMatchType(
AutocompleteMatchType::URL_WHAT_YOU_TYPED, /* is_starred */ false);
UIImage* defaultLeadingImage =
[[UIImage imageNamed:base::SysUTF8ToNSString(defaultLeadingImageName)]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.viewController.defaultLeadingImage = defaultLeadingImage;
std::string defaultEmptyOmniboxLeadingImageName =
GetResourceNameForAutocompleteMatchType(
AutocompleteMatchType::SEARCH_SUGGEST, /* is_starred */ false);
UIImage* defaultEmptyOmniboxLeadingImage = [[UIImage
imageNamed:base::SysUTF8ToNSString(defaultEmptyOmniboxLeadingImageName)]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.viewController.emptyTextLeadingImage = defaultEmptyOmniboxLeadingImage;
self.viewController.dispatcher =
static_cast<id<LoadQueryCommands, OmniboxFocuser>>(self.dispatcher);
......
......@@ -21,6 +21,13 @@
// The textfield used by this view controller.
@property(nonatomic, readonly, strong) OmniboxTextFieldIOS* textField;
// The default leading image to be used on omnibox focus before this is updated
// via OmniboxConsumer protocol.
@property(nonatomic, strong) UIImage* defaultLeadingImage;
// The default leading image to be used whenever the omnibox text is empty.
@property(nonatomic, strong) UIImage* emptyTextLeadingImage;
// Designated initializer.
- (instancetype)initWithIncognito:(BOOL)isIncognito;
......
......@@ -37,6 +37,8 @@ const CGFloat kClearButtonSize = 28.0f;
@implementation OmniboxViewController
@synthesize incognito = _incognito;
@synthesize dispatcher = _dispatcher;
@synthesize defaultLeadingImage = _defaultLeadingImage;
@synthesize emptyTextLeadingImage = _emptyTextLeadingImage;
@dynamic view;
- (instancetype)initWithIncognito:(BOOL)isIncognito {
......@@ -92,6 +94,11 @@ const CGFloat kClearButtonSize = 28.0f;
selector:@selector(textFieldDidBeginEditing)
name:UITextFieldTextDidBeginEditingNotification
object:self.textField];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(textFieldDidChange)
name:UITextFieldTextDidChangeNotification
object:self.textField];
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
......@@ -135,6 +142,16 @@ const CGFloat kClearButtonSize = 28.0f;
- (void)textFieldDidBeginEditing {
// Update the clear button state.
[self updateClearButtonVisibility];
[self.view setLeadingImage:self.textField.text.length
? self.defaultLeadingImage
: self.emptyTextLeadingImage];
}
- (void)textFieldDidChange {
// If the text is empty, update the leading image.
if (self.textField.text.length == 0) {
[self.view setLeadingImage:self.emptyTextLeadingImage];
}
}
#pragma mark clear button
......@@ -185,6 +202,7 @@ const CGFloat kClearButtonSize = 28.0f;
// Calling setText: does not trigger UIControlEventEditingChanged, so update
// the clear button visibility manually.
[self updateClearButtonVisibility];
[self textFieldDidChange];
}
}
......
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