Commit 9eece05a authored by rohitrao's avatar rohitrao Committed by Commit bot

[ios] Adds GetStyledTextField() to ChromeBrowserProvider.

This will be used to provide custom-styled text fields for use in UI.

BUG=None

Review-Url: https://codereview.chromium.org/2372703002
Cr-Commit-Position: refs/heads/master@{#421186}
parent 766306f5
...@@ -25,6 +25,7 @@ source_set("browser") { ...@@ -25,6 +25,7 @@ source_set("browser") {
"ui/default_ios_web_view_factory.mm", "ui/default_ios_web_view_factory.mm",
"ui/infobar_view_delegate.h", "ui/infobar_view_delegate.h",
"ui/infobar_view_protocol.h", "ui/infobar_view_protocol.h",
"ui/text_field_styling.h",
"updatable_resource_provider.h", "updatable_resource_provider.h",
"updatable_resource_provider.mm", "updatable_resource_provider.mm",
] ]
......
...@@ -40,8 +40,10 @@ namespace user_prefs { ...@@ -40,8 +40,10 @@ namespace user_prefs {
class PrefRegistrySyncable; class PrefRegistrySyncable;
} }
@class UIView;
@protocol InfoBarViewProtocol; @protocol InfoBarViewProtocol;
@protocol TextFieldStyling;
@class UITextField;
@class UIView;
typedef UIView<InfoBarViewProtocol>* InfoBarViewPlaceholder; typedef UIView<InfoBarViewProtocol>* InfoBarViewPlaceholder;
namespace ios { namespace ios {
...@@ -109,6 +111,9 @@ class ChromeBrowserProvider { ...@@ -109,6 +111,9 @@ class ChromeBrowserProvider {
const GURL& page_url, const GURL& page_url,
const std::vector<int>& desired_sizes_in_pixel, const std::vector<int>& desired_sizes_in_pixel,
const favicon_base::FaviconResultsCallback& callback) const; const favicon_base::FaviconResultsCallback& callback) const;
// Creates and returns a new styled text field with the given |frame|.
virtual UITextField<TextFieldStyling>* CreateStyledTextField(
CGRect frame) const NS_RETURNS_RETAINED;
// Returns whether safe browsing is enabled. See the comment on // Returns whether safe browsing is enabled. See the comment on
// metrics_services_manager_client.h for details on |on_update_callback|. // metrics_services_manager_client.h for details on |on_update_callback|.
......
...@@ -97,6 +97,11 @@ void ChromeBrowserProvider::GetFaviconForURL( ...@@ -97,6 +97,11 @@ void ChromeBrowserProvider::GetFaviconForURL(
const std::vector<int>& desired_sizes_in_pixel, const std::vector<int>& desired_sizes_in_pixel,
const favicon_base::FaviconResultsCallback& callback) const {} const favicon_base::FaviconResultsCallback& callback) const {}
UITextField<TextFieldStyling>* ChromeBrowserProvider::CreateStyledTextField(
CGRect frame) const {
return nil;
}
bool ChromeBrowserProvider::IsSafeBrowsingEnabled( bool ChromeBrowserProvider::IsSafeBrowsingEnabled(
const base::Closure& on_update_callback) { const base::Closure& on_update_callback) {
return false; return false;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/public/provider/chrome/browser/ui/text_field_styling.h"
namespace ios { namespace ios {
...@@ -27,6 +28,8 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider { ...@@ -27,6 +28,8 @@ class TestChromeBrowserProvider : public ChromeBrowserProvider {
std::unique_ptr<ChromeIdentityService> service) override; std::unique_ptr<ChromeIdentityService> service) override;
ChromeIdentityService* GetChromeIdentityService() override; ChromeIdentityService* GetChromeIdentityService() override;
UpdatableResourceProvider* GetUpdatableResourceProvider() override; UpdatableResourceProvider* GetUpdatableResourceProvider() override;
UITextField<TextFieldStyling>* CreateStyledTextField(
CGRect frame) const override NS_RETURNS_RETAINED;
private: private:
std::unique_ptr<ChromeIdentityService> chrome_identity_service_; std::unique_ptr<ChromeIdentityService> chrome_identity_service_;
......
...@@ -4,11 +4,24 @@ ...@@ -4,11 +4,24 @@
#include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h"
#import <UIKit/UIKit.h>
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h" #include "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/public/provider/chrome/browser/test_updatable_resource_provider.h" #import "ios/public/provider/chrome/browser/test_updatable_resource_provider.h"
@interface TestStyledTextField : UITextField<TextFieldStyling>
@end
@implementation TestStyledTextField
@synthesize placeholderStyle = _placeholderStyle;
@synthesize textValidator = _textValidator;
- (void)setUseErrorStyling:(BOOL)error {
}
@end
namespace ios { namespace ios {
TestChromeBrowserProvider::TestChromeBrowserProvider() TestChromeBrowserProvider::TestChromeBrowserProvider()
...@@ -40,4 +53,9 @@ TestChromeBrowserProvider::GetUpdatableResourceProvider() { ...@@ -40,4 +53,9 @@ TestChromeBrowserProvider::GetUpdatableResourceProvider() {
return test_updatable_resource_provider_.get(); return test_updatable_resource_provider_.get();
} }
UITextField<TextFieldStyling>* TestChromeBrowserProvider::CreateStyledTextField(
CGRect frame) const {
return [[TestStyledTextField alloc] initWithFrame:frame];
}
} // namespace ios } // namespace ios
// Copyright 2016 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_PUBLIC_PROVIDER_CHROME_BROWSER_UI_TEXT_FIELD_STYLING_H_
#define IOS_PUBLIC_PROVIDER_CHROME_BROWSER_UI_TEXT_FIELD_STYLING_H_
#import <Foundation/Foundation.h>
@protocol TextFieldValidation;
// Types of styling controlling layout of the placeholder.
typedef NS_ENUM(NSInteger, TextFieldStylingPlaceholder) {
// Effectively the same placeholder as a UITextField.
TextFieldStylingPlaceholderDefault = 0,
// The placeholder text will float above the field when there is content or
// the field is being edited.
TextFieldStylingPlaceholderFloatingPlaceholder,
};
// The TextFieldStyling protocol works with UITextField to add methods related
// to styling and input validation.
@protocol TextFieldStyling
// The placement for the placeholder text (if there is any).
@property(nonatomic, assign) TextFieldStylingPlaceholder placeholderStyle;
// The object used to validate text in this text field. If nil, no validation
// is performed.
@property(nonatomic, assign) id<TextFieldValidation> textValidator; // weak
// If |error| is YES, display this field using error colors and styling.
- (void)setUseErrorStyling:(BOOL)error;
@end
// The TextFieldValidation protocol is used to validate the contents of a text
// field.
@protocol TextFieldValidation
// Returns an error string to display if the contents of the given |field| are
// invalid. If this method returns nil, the contents of the field are presumed
// to be valid and no error needs to displayed. This method is called whenever
// the field's text changes.
- (NSString*)validationErrorForTextField:(id<TextFieldStyling>)field;
@end
#endif // IOS_PUBLIC_PROVIDER_CHROME_BROWSER_UI_TEXT_FIELD_STYLING_H_
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