| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/history/history_search_view_controller.h" |
| 6 |
| 7 #include "base/ios/weak_nsobject.h" |
| 8 #include "base/mac/scoped_nsobject.h" |
| 9 #import "ios/chrome/browser/ui/history/history_search_view.h" |
| 10 |
| 11 @interface HistorySearchViewController ()<UITextFieldDelegate> { |
| 12 // Delegate for forwarding interactions with the search view. |
| 13 base::WeakNSProtocol<id<HistorySearchViewControllerDelegate>> _delegate; |
| 14 // View displayed by the HistorySearchViewController |
| 15 base::scoped_nsobject<HistorySearchView> _searchView; |
| 16 } |
| 17 |
| 18 // Action for the cancel button. |
| 19 - (void)cancelButtonClicked:(id)sender; |
| 20 |
| 21 @end |
| 22 |
| 23 @implementation HistorySearchViewController |
| 24 |
| 25 @synthesize enabled = _enabled; |
| 26 |
| 27 - (void)loadView { |
| 28 _searchView.reset([[HistorySearchView alloc] init]); |
| 29 [_searchView setSearchBarDelegate:self]; |
| 30 [_searchView setCancelTarget:self action:@selector(cancelButtonClicked:)]; |
| 31 self.view = _searchView; |
| 32 } |
| 33 |
| 34 - (void)viewDidAppear:(BOOL)animated { |
| 35 [super viewDidAppear:animated]; |
| 36 [_searchView becomeFirstResponder]; |
| 37 } |
| 38 |
| 39 - (void)setDelegate:(id<HistorySearchViewControllerDelegate>)delegate { |
| 40 _delegate.reset(delegate); |
| 41 } |
| 42 |
| 43 - (id<HistorySearchViewControllerDelegate>)delegate { |
| 44 return _delegate; |
| 45 } |
| 46 |
| 47 - (void)setEnabled:(BOOL)enabled { |
| 48 _enabled = enabled; |
| 49 [_searchView setEnabled:enabled]; |
| 50 } |
| 51 |
| 52 - (void)cancelButtonClicked:(id)sender { |
| 53 [_searchView clearText]; |
| 54 [_searchView endEditing:YES]; |
| 55 [self.delegate historySearchViewControllerDidCancel:self]; |
| 56 } |
| 57 |
| 58 #pragma mark - UITextFieldDelegate |
| 59 |
| 60 - (BOOL)textField:(UITextField*)textField |
| 61 shouldChangeCharactersInRange:(NSRange)range |
| 62 replacementString:(NSString*)string { |
| 63 NSMutableString* text = [NSMutableString stringWithString:[textField text]]; |
| 64 [text replaceCharactersInRange:range withString:string]; |
| 65 [self.delegate historySearchViewController:self didRequestSearchForTerm:text]; |
| 66 return YES; |
| 67 } |
| 68 |
| 69 - (BOOL)textFieldShouldClear:(UITextField*)textField { |
| 70 [self.delegate historySearchViewController:self didRequestSearchForTerm:@""]; |
| 71 return YES; |
| 72 } |
| 73 |
| 74 - (BOOL)textFieldShouldReturn:(UITextField*)textField { |
| 75 [textField resignFirstResponder]; |
| 76 return YES; |
| 77 } |
| 78 |
| 79 @end |
| OLD | NEW |