Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: ios/chrome/browser/ui/history/history_search_view_controller.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/history/history_search_view_controller.mm
diff --git a/ios/chrome/browser/ui/history/history_search_view_controller.mm b/ios/chrome/browser/ui/history/history_search_view_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..5d30562461508011877ee3f429d31d25d5f0d12b
--- /dev/null
+++ b/ios/chrome/browser/ui/history/history_search_view_controller.mm
@@ -0,0 +1,79 @@
+// 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.
+
+#import "ios/chrome/browser/ui/history/history_search_view_controller.h"
+
+#include "base/ios/weak_nsobject.h"
+#include "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/ui/history/history_search_view.h"
+
+@interface HistorySearchViewController ()<UITextFieldDelegate> {
+ // Delegate for forwarding interactions with the search view.
+ base::WeakNSProtocol<id<HistorySearchViewControllerDelegate>> _delegate;
+ // View displayed by the HistorySearchViewController
+ base::scoped_nsobject<HistorySearchView> _searchView;
+}
+
+// Action for the cancel button.
+- (void)cancelButtonClicked:(id)sender;
+
+@end
+
+@implementation HistorySearchViewController
+
+@synthesize enabled = _enabled;
+
+- (void)loadView {
+ _searchView.reset([[HistorySearchView alloc] init]);
+ [_searchView setSearchBarDelegate:self];
+ [_searchView setCancelTarget:self action:@selector(cancelButtonClicked:)];
+ self.view = _searchView;
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+ [_searchView becomeFirstResponder];
+}
+
+- (void)setDelegate:(id<HistorySearchViewControllerDelegate>)delegate {
+ _delegate.reset(delegate);
+}
+
+- (id<HistorySearchViewControllerDelegate>)delegate {
+ return _delegate;
+}
+
+- (void)setEnabled:(BOOL)enabled {
+ _enabled = enabled;
+ [_searchView setEnabled:enabled];
+}
+
+- (void)cancelButtonClicked:(id)sender {
+ [_searchView clearText];
+ [_searchView endEditing:YES];
+ [self.delegate historySearchViewControllerDidCancel:self];
+}
+
+#pragma mark - UITextFieldDelegate
+
+- (BOOL)textField:(UITextField*)textField
+ shouldChangeCharactersInRange:(NSRange)range
+ replacementString:(NSString*)string {
+ NSMutableString* text = [NSMutableString stringWithString:[textField text]];
+ [text replaceCharactersInRange:range withString:string];
+ [self.delegate historySearchViewController:self didRequestSearchForTerm:text];
+ return YES;
+}
+
+- (BOOL)textFieldShouldClear:(UITextField*)textField {
+ [self.delegate historySearchViewController:self didRequestSearchForTerm:@""];
+ return YES;
+}
+
+- (BOOL)textFieldShouldReturn:(UITextField*)textField {
+ [textField resignFirstResponder];
+ return YES;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698