OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/ui/history/history_panel_view_controller.h" | 5 #import "ios/chrome/browser/ui/history/history_panel_view_controller.h" |
6 | 6 |
7 #include "base/ios/block_types.h" | 7 #include "base/ios/block_types.h" |
8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
9 #include "base/ios/weak_nsobject.h" | |
10 #include "base/mac/scoped_nsobject.h" | |
11 #include "base/metrics/user_metrics.h" | 9 #include "base/metrics/user_metrics.h" |
12 #include "base/metrics/user_metrics_action.h" | 10 #include "base/metrics/user_metrics_action.h" |
13 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
14 #import "ios/chrome/browser/ui/history/clear_browsing_bar.h" | 12 #import "ios/chrome/browser/ui/history/clear_browsing_bar.h" |
15 #import "ios/chrome/browser/ui/history/history_collection_view_controller.h" | 13 #import "ios/chrome/browser/ui/history/history_collection_view_controller.h" |
16 #import "ios/chrome/browser/ui/history/history_search_view_controller.h" | 14 #import "ios/chrome/browser/ui/history/history_search_view_controller.h" |
17 #import "ios/chrome/browser/ui/icons/chrome_icon.h" | 15 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
18 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" | 16 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" |
19 #import "ios/chrome/browser/ui/material_components/utils.h" | 17 #import "ios/chrome/browser/ui/material_components/utils.h" |
20 #import "ios/chrome/browser/ui/ntp/recent_tabs/views/panel_bar_view.h" | 18 #import "ios/chrome/browser/ui/ntp/recent_tabs/views/panel_bar_view.h" |
21 #import "ios/chrome/browser/ui/show_privacy_settings_util.h" | 19 #import "ios/chrome/browser/ui/show_privacy_settings_util.h" |
22 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 20 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
23 #import "ios/chrome/browser/ui/url_loader.h" | 21 #import "ios/chrome/browser/ui/url_loader.h" |
24 #include "ios/chrome/grit/ios_strings.h" | 22 #include "ios/chrome/grit/ios_strings.h" |
25 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" | 23 #import "ios/third_party/material_components_ios/src/components/AppBar/src/Mater
ialAppBar.h" |
26 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr
c/MaterialNavigationBar.h" | 24 #import "ios/third_party/material_components_ios/src/components/NavigationBar/sr
c/MaterialNavigationBar.h" |
27 #include "ui/base/l10n/l10n_util_mac.h" | 25 #include "ui/base/l10n/l10n_util_mac.h" |
28 | 26 |
| 27 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 28 #error "This file requires ARC support." |
| 29 #endif |
| 30 |
29 namespace { | 31 namespace { |
30 // Shadow opacity for the clear browsing button and the header when scrolling. | 32 // Shadow opacity for the clear browsing button and the header when scrolling. |
31 CGFloat kShadowOpacity = 0.2f; | 33 CGFloat kShadowOpacity = 0.2f; |
32 } // namespace | 34 } // namespace |
33 | 35 |
34 @interface HistoryPanelViewController ()< | 36 @interface HistoryPanelViewController ()< |
35 HistoryCollectionViewControllerDelegate, | 37 HistoryCollectionViewControllerDelegate, |
36 HistorySearchViewControllerDelegate> { | 38 HistorySearchViewControllerDelegate> { |
37 // Controller for collection view that displays history entries. | 39 // Controller for collection view that displays history entries. |
38 base::scoped_nsobject<HistoryCollectionViewController> | 40 HistoryCollectionViewController* _historyCollectionController; |
39 _historyCollectionController; | |
40 // Bar at the bottom of the history panel the displays options for entry | 41 // Bar at the bottom of the history panel the displays options for entry |
41 // deletion, including "Clear Browsing Data..." which takes the user to | 42 // deletion, including "Clear Browsing Data..." which takes the user to |
42 // Privacy settings, or "Edit" for entering a mode for deleting individual | 43 // Privacy settings, or "Edit" for entering a mode for deleting individual |
43 // entries. When in edit mode, the bar displays options to Delete or Cancel. | 44 // entries. When in edit mode, the bar displays options to Delete or Cancel. |
44 base::scoped_nsobject<ClearBrowsingBar> _clearBrowsingBar; | 45 ClearBrowsingBar* _clearBrowsingBar; |
45 // View controller for the search bar. | 46 // View controller for the search bar. |
46 base::scoped_nsobject<HistorySearchViewController> _searchViewController; | 47 HistorySearchViewController* _searchViewController; |
47 // Container view for history collection and clear browsing button to enable | 48 // Container view for history collection and clear browsing button to enable |
48 // use of autolayout in conjuction with Material App Bar. | 49 // use of autolayout in conjuction with Material App Bar. |
49 base::scoped_nsobject<UIView> _containerView; | 50 UIView* _containerView; |
50 // The header view. | 51 // The header view. |
51 base::scoped_nsobject<MDCAppBar> _appBar; | 52 MDCAppBar* _appBar; |
52 // Left bar button item for Search. | 53 // Left bar button item for Search. |
53 base::scoped_nsobject<UIBarButtonItem> _leftBarButtonItem; | 54 UIBarButtonItem* _leftBarButtonItem; |
54 // Right bar button item for Dismiss history action. | 55 // Right bar button item for Dismiss history action. |
55 base::scoped_nsobject<UIBarButtonItem> _rightBarButtonItem; | 56 UIBarButtonItem* _rightBarButtonItem; |
56 } | 57 } |
57 // Closes history. | 58 // Closes history. |
58 - (void)closeHistory; | 59 - (void)closeHistory; |
59 // Closes history, invoking completionHandler once dismissal is complete. | 60 // Closes history, invoking completionHandler once dismissal is complete. |
60 - (void)closeHistoryWithCompletion:(ProceduralBlock)completionHandler; | 61 - (void)closeHistoryWithCompletion:(ProceduralBlock)completionHandler; |
61 // Opens Privacy settings. | 62 // Opens Privacy settings. |
62 - (void)openPrivacySettings; | 63 - (void)openPrivacySettings; |
63 // Configure view for editing mode. | 64 // Configure view for editing mode. |
64 - (void)enterEditingMode; | 65 - (void)enterEditingMode; |
65 // Configure view for non-editing mode. | 66 // Configure view for non-editing mode. |
(...skipping 10 matching lines...) Expand all Loading... |
76 // collection. | 77 // collection. |
77 - (void)configureClearBrowsingBar; | 78 - (void)configureClearBrowsingBar; |
78 @end | 79 @end |
79 | 80 |
80 @implementation HistoryPanelViewController | 81 @implementation HistoryPanelViewController |
81 | 82 |
82 - (instancetype)initWithLoader:(id<UrlLoader>)loader | 83 - (instancetype)initWithLoader:(id<UrlLoader>)loader |
83 browserState:(ios::ChromeBrowserState*)browserState { | 84 browserState:(ios::ChromeBrowserState*)browserState { |
84 self = [super initWithNibName:nil bundle:nil]; | 85 self = [super initWithNibName:nil bundle:nil]; |
85 if (self) { | 86 if (self) { |
86 _historyCollectionController.reset([[HistoryCollectionViewController alloc] | 87 _historyCollectionController = |
87 initWithLoader:loader | 88 [[HistoryCollectionViewController alloc] initWithLoader:loader |
88 browserState:browserState | 89 browserState:browserState |
89 delegate:self]); | 90 delegate:self]; |
90 | 91 |
91 // Configure modal presentation. | 92 // Configure modal presentation. |
92 [self setModalPresentationStyle:UIModalPresentationFormSheet]; | 93 [self setModalPresentationStyle:UIModalPresentationFormSheet]; |
93 [self setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; | 94 [self setModalTransitionStyle:UIModalTransitionStyleCoverVertical]; |
94 | 95 |
95 // Add and configure header. | 96 // Add and configure header. |
96 _appBar.reset([[MDCAppBar alloc] init]); | 97 _appBar = [[MDCAppBar alloc] init]; |
97 [self addChildViewController:_appBar.get().headerViewController]; | 98 [self addChildViewController:_appBar.headerViewController]; |
98 } | 99 } |
99 return self; | 100 return self; |
100 } | 101 } |
101 | 102 |
102 - (instancetype)initWithNibName:(NSString*)nibNameOrNil | 103 - (instancetype)initWithNibName:(NSString*)nibNameOrNil |
103 bundle:(NSBundle*)nibBundleOrNil { | 104 bundle:(NSBundle*)nibBundleOrNil { |
104 NOTREACHED(); | 105 NOTREACHED(); |
105 return nil; | 106 return nil; |
106 } | 107 } |
107 | 108 |
108 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 109 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
109 NOTREACHED(); | 110 NOTREACHED(); |
110 return nil; | 111 return nil; |
111 } | 112 } |
112 | 113 |
113 + (UIViewController*)controllerToPresentForBrowserState: | 114 + (UIViewController*)controllerToPresentForBrowserState: |
114 (ios::ChromeBrowserState*)browserState | 115 (ios::ChromeBrowserState*)browserState |
115 loader:(id<UrlLoader>)loader { | 116 loader:(id<UrlLoader>)loader { |
116 HistoryPanelViewController* historyPanelController = | 117 HistoryPanelViewController* historyPanelController = |
117 [[[HistoryPanelViewController alloc] initWithLoader:loader | 118 [[HistoryPanelViewController alloc] initWithLoader:loader |
118 browserState:browserState] | 119 browserState:browserState]; |
119 autorelease]; | |
120 return historyPanelController; | 120 return historyPanelController; |
121 } | 121 } |
122 | 122 |
123 - (void)viewDidLoad { | 123 - (void)viewDidLoad { |
124 [super viewDidLoad]; | 124 [super viewDidLoad]; |
125 [self setTitle:l10n_util::GetNSString(IDS_HISTORY_TITLE)]; | 125 [self setTitle:l10n_util::GetNSString(IDS_HISTORY_TITLE)]; |
126 | 126 |
127 _containerView.reset([[UIView alloc] initWithFrame:self.view.frame]); | 127 _containerView = [[UIView alloc] initWithFrame:self.view.frame]; |
128 [_containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 128 [_containerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
129 UIViewAutoresizingFlexibleHeight]; | 129 UIViewAutoresizingFlexibleHeight]; |
130 [self.view addSubview:_containerView]; | 130 [self.view addSubview:_containerView]; |
131 | 131 |
132 [[_historyCollectionController view] | 132 [[_historyCollectionController view] |
133 setTranslatesAutoresizingMaskIntoConstraints:NO]; | 133 setTranslatesAutoresizingMaskIntoConstraints:NO]; |
134 [_historyCollectionController willMoveToParentViewController:self]; | 134 [_historyCollectionController willMoveToParentViewController:self]; |
135 [_containerView addSubview:[_historyCollectionController view]]; | 135 [_containerView addSubview:[_historyCollectionController view]]; |
136 [self addChildViewController:_historyCollectionController]; | 136 [self addChildViewController:_historyCollectionController]; |
137 [_historyCollectionController didMoveToParentViewController:self]; | 137 [_historyCollectionController didMoveToParentViewController:self]; |
138 | 138 |
139 _clearBrowsingBar.reset([[ClearBrowsingBar alloc] initWithFrame:CGRectZero]); | 139 _clearBrowsingBar = [[ClearBrowsingBar alloc] initWithFrame:CGRectZero]; |
140 [_clearBrowsingBar setClearBrowsingDataTarget:self | 140 [_clearBrowsingBar setClearBrowsingDataTarget:self |
141 action:@selector(openPrivacySettings)]; | 141 action:@selector(openPrivacySettings)]; |
142 [_clearBrowsingBar setEditTarget:self action:@selector(enterEditingMode)]; | 142 [_clearBrowsingBar setEditTarget:self action:@selector(enterEditingMode)]; |
143 [_clearBrowsingBar setCancelTarget:self action:@selector(exitEditingMode)]; | 143 [_clearBrowsingBar setCancelTarget:self action:@selector(exitEditingMode)]; |
144 [_clearBrowsingBar setDeleteTarget:self | 144 [_clearBrowsingBar setDeleteTarget:self |
145 action:@selector(deleteSelectedItems)]; | 145 action:@selector(deleteSelectedItems)]; |
146 [_clearBrowsingBar setTranslatesAutoresizingMaskIntoConstraints:NO]; | 146 [_clearBrowsingBar setTranslatesAutoresizingMaskIntoConstraints:NO]; |
147 [_containerView addSubview:_clearBrowsingBar]; | 147 [_containerView addSubview:_clearBrowsingBar]; |
148 [self configureClearBrowsingBar]; | 148 [self configureClearBrowsingBar]; |
149 | 149 |
150 ConfigureAppBarWithCardStyle(_appBar); | 150 ConfigureAppBarWithCardStyle(_appBar); |
151 [_appBar headerViewController].headerView.trackingScrollView = | 151 [_appBar headerViewController].headerView.trackingScrollView = |
152 [_historyCollectionController collectionView]; | 152 [_historyCollectionController collectionView]; |
153 [_appBar addSubviewsToParent]; | 153 [_appBar addSubviewsToParent]; |
154 | 154 |
155 // Add navigation bar buttons. | 155 // Add navigation bar buttons. |
156 _leftBarButtonItem.reset([[ChromeIcon | 156 _leftBarButtonItem = |
157 templateBarButtonItemWithImage:[ChromeIcon searchIcon] | 157 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon searchIcon] |
158 target:self | 158 target:self |
159 action:@selector(enterSearchMode)] retain]); | 159 action:@selector(enterSearchMode)]; |
160 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; | 160 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; |
161 _rightBarButtonItem.reset([[UIBarButtonItem alloc] | 161 _rightBarButtonItem = [[UIBarButtonItem alloc] |
162 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) | 162 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) |
163 style:UIBarButtonItemStylePlain | 163 style:UIBarButtonItemStylePlain |
164 target:self | 164 target:self |
165 action:@selector(closeHistory)]); | 165 action:@selector(closeHistory)]; |
166 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; | 166 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; |
167 [self configureNavigationBar]; | 167 [self configureNavigationBar]; |
168 } | 168 } |
169 | 169 |
170 - (void)updateViewConstraints { | 170 - (void)updateViewConstraints { |
171 NSDictionary* views = @{ | 171 NSDictionary* views = @{ |
172 @"collectionView" : [_historyCollectionController view], | 172 @"collectionView" : [_historyCollectionController view], |
173 @"clearBrowsingBar" : _clearBrowsingBar, | 173 @"clearBrowsingBar" : _clearBrowsingBar, |
174 }; | 174 }; |
175 NSArray* constraints = @[ | 175 NSArray* constraints = @[ |
(...skipping 28 matching lines...) Expand all Loading... |
204 [self setNeedsStatusBarAppearanceUpdate]; | 204 [self setNeedsStatusBarAppearanceUpdate]; |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 - (UIViewController*)childViewControllerForStatusBarHidden { | 208 - (UIViewController*)childViewControllerForStatusBarHidden { |
209 if (!base::ios::IsRunningOnIOS10OrLater()) { | 209 if (!base::ios::IsRunningOnIOS10OrLater()) { |
210 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is | 210 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is |
211 // dropped. | 211 // dropped. |
212 return nil; | 212 return nil; |
213 } else { | 213 } else { |
214 return _appBar.get().headerViewController; | 214 return _appBar.headerViewController; |
215 } | 215 } |
216 } | 216 } |
217 | 217 |
218 - (BOOL)prefersStatusBarHidden { | 218 - (BOOL)prefersStatusBarHidden { |
219 if (!base::ios::IsRunningOnIOS10OrLater()) { | 219 if (!base::ios::IsRunningOnIOS10OrLater()) { |
220 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is | 220 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is |
221 // dropped. | 221 // dropped. |
222 return NO; | 222 return NO; |
223 } else { | 223 } else { |
224 return [super prefersStatusBarHidden]; | 224 return [super prefersStatusBarHidden]; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 - (UIViewController*)childViewControllerForStatusBarStyle { | 228 - (UIViewController*)childViewControllerForStatusBarStyle { |
229 if (!base::ios::IsRunningOnIOS10OrLater()) { | 229 if (!base::ios::IsRunningOnIOS10OrLater()) { |
230 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is | 230 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is |
231 // dropped. | 231 // dropped. |
232 return nil; | 232 return nil; |
233 } else { | 233 } else { |
234 return _appBar.get().headerViewController; | 234 return _appBar.headerViewController; |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 - (UIStatusBarStyle)preferredStatusBarStyle { | 238 - (UIStatusBarStyle)preferredStatusBarStyle { |
239 if (!base::ios::IsRunningOnIOS10OrLater()) { | 239 if (!base::ios::IsRunningOnIOS10OrLater()) { |
240 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is | 240 // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is |
241 // dropped. | 241 // dropped. |
242 if (IsIPadIdiom() && !IsCompact()) { | 242 if (IsIPadIdiom() && !IsCompact()) { |
243 return UIStatusBarStyleLightContent; | 243 return UIStatusBarStyleLightContent; |
244 } else { | 244 } else { |
245 return UIStatusBarStyleDefault; | 245 return UIStatusBarStyleDefault; |
246 } | 246 } |
247 } else { | 247 } else { |
248 return [super preferredStatusBarStyle]; | 248 return [super preferredStatusBarStyle]; |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
252 #pragma mark - HistoryCollectionViewControllerDelegate | 252 #pragma mark - HistoryCollectionViewControllerDelegate |
253 | 253 |
254 - (void)historyCollectionViewController: | 254 - (void)historyCollectionViewController: |
255 (HistoryCollectionViewController*)collectionViewcontroller | 255 (HistoryCollectionViewController*)collectionViewcontroller |
256 shouldCloseWithCompletion:(ProceduralBlock)completionHandler { | 256 shouldCloseWithCompletion:(ProceduralBlock)completionHandler { |
257 [self closeHistoryWithCompletion:completionHandler]; | 257 [self closeHistoryWithCompletion:completionHandler]; |
258 } | 258 } |
259 | 259 |
260 - (void)historyCollectionViewController: | 260 - (void)historyCollectionViewController: |
261 (HistoryCollectionViewController*)controller | 261 (HistoryCollectionViewController*)controller |
262 didScrollToOffset:(CGPoint)offset { | 262 didScrollToOffset:(CGPoint)offset { |
263 // Display a shadow on the header when the collection is scrolled. | 263 // Display a shadow on the header when the collection is scrolled. |
264 MDCFlexibleHeaderView* headerView = | 264 MDCFlexibleHeaderView* headerView = _appBar.headerViewController.headerView; |
265 _appBar.get().headerViewController.headerView; | |
266 headerView.visibleShadowOpacity = | 265 headerView.visibleShadowOpacity = |
267 offset.y > -CGRectGetHeight(headerView.frame) ? kShadowOpacity : 0.0f; | 266 offset.y > -CGRectGetHeight(headerView.frame) ? kShadowOpacity : 0.0f; |
268 } | 267 } |
269 | 268 |
270 - (void)historyCollectionViewControllerDidChangeEntries: | 269 - (void)historyCollectionViewControllerDidChangeEntries: |
271 (HistoryCollectionViewController*)controller { | 270 (HistoryCollectionViewController*)controller { |
272 // Reconfigure the navigation and clear browsing bars to reflect currently | 271 // Reconfigure the navigation and clear browsing bars to reflect currently |
273 // displayed entries. | 272 // displayed entries. |
274 [self configureNavigationBar]; | 273 [self configureNavigationBar]; |
275 [self configureClearBrowsingBar]; | 274 [self configureClearBrowsingBar]; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 - (void)openPrivacySettings { | 309 - (void)openPrivacySettings { |
311 [self exitSearchMode]; | 310 [self exitSearchMode]; |
312 base::RecordAction( | 311 base::RecordAction( |
313 base::UserMetricsAction("HistoryPage_InitClearBrowsingData")); | 312 base::UserMetricsAction("HistoryPage_InitClearBrowsingData")); |
314 ShowClearBrowsingData(); | 313 ShowClearBrowsingData(); |
315 } | 314 } |
316 | 315 |
317 - (void)enterEditingMode { | 316 - (void)enterEditingMode { |
318 [_historyCollectionController setEditing:YES]; | 317 [_historyCollectionController setEditing:YES]; |
319 [_clearBrowsingBar setEditing:YES]; | 318 [_clearBrowsingBar setEditing:YES]; |
320 if (_historyCollectionController.get().searching) { | 319 if (_historyCollectionController.searching) { |
321 [_searchViewController setEnabled:NO]; | 320 [_searchViewController setEnabled:NO]; |
322 } | 321 } |
323 DCHECK([_historyCollectionController isEditing]); | 322 DCHECK([_historyCollectionController isEditing]); |
324 [self configureNavigationBar]; | 323 [self configureNavigationBar]; |
325 } | 324 } |
326 | 325 |
327 - (void)exitEditingMode { | 326 - (void)exitEditingMode { |
328 [_historyCollectionController setEditing:NO]; | 327 [_historyCollectionController setEditing:NO]; |
329 [_clearBrowsingBar setEditing:NO]; | 328 [_clearBrowsingBar setEditing:NO]; |
330 if (_historyCollectionController.get().searching) { | 329 if (_historyCollectionController.searching) { |
331 [_searchViewController setEnabled:YES]; | 330 [_searchViewController setEnabled:YES]; |
332 } | 331 } |
333 DCHECK(![_historyCollectionController isEditing]); | 332 DCHECK(![_historyCollectionController isEditing]); |
334 [self configureNavigationBar]; | 333 [self configureNavigationBar]; |
335 } | 334 } |
336 | 335 |
337 - (void)deleteSelectedItems { | 336 - (void)deleteSelectedItems { |
338 [_historyCollectionController deleteSelectedItemsFromHistory]; | 337 [_historyCollectionController deleteSelectedItemsFromHistory]; |
339 base::RecordAction(base::UserMetricsAction("HistoryPage_RemoveSelected")); | 338 base::RecordAction(base::UserMetricsAction("HistoryPage_RemoveSelected")); |
340 [self exitEditingMode]; | 339 [self exitEditingMode]; |
341 } | 340 } |
342 - (void)enterSearchMode { | 341 - (void)enterSearchMode { |
343 if (!_searchViewController) { | 342 if (!_searchViewController) { |
344 _searchViewController.reset([[HistorySearchViewController alloc] init]); | 343 _searchViewController = [[HistorySearchViewController alloc] init]; |
345 [_searchViewController setDelegate:self]; | 344 [_searchViewController setDelegate:self]; |
346 } | 345 } |
347 | 346 |
348 UIView* searchBarView = [_searchViewController view]; | 347 UIView* searchBarView = [_searchViewController view]; |
349 [_searchViewController willMoveToParentViewController:self]; | 348 [_searchViewController willMoveToParentViewController:self]; |
350 [self.view addSubview:searchBarView]; | 349 [self.view addSubview:searchBarView]; |
351 _historyCollectionController.get().searching = YES; | 350 _historyCollectionController.searching = YES; |
352 [_searchViewController didMoveToParentViewController:self]; | 351 [_searchViewController didMoveToParentViewController:self]; |
353 base::RecordAction(base::UserMetricsAction("HistoryPage_Search")); | 352 base::RecordAction(base::UserMetricsAction("HistoryPage_Search")); |
354 | 353 |
355 // Constraints to make search bar cover header. | 354 // Constraints to make search bar cover header. |
356 [searchBarView setTranslatesAutoresizingMaskIntoConstraints:NO]; | 355 [searchBarView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
357 MDCFlexibleHeaderView* headerView = | 356 MDCFlexibleHeaderView* headerView = _appBar.headerViewController.headerView; |
358 _appBar.get().headerViewController.headerView; | |
359 NSArray* constraints = @[ | 357 NSArray* constraints = @[ |
360 [[searchBarView topAnchor] constraintEqualToAnchor:headerView.topAnchor], | 358 [[searchBarView topAnchor] constraintEqualToAnchor:headerView.topAnchor], |
361 [[searchBarView leadingAnchor] | 359 [[searchBarView leadingAnchor] |
362 constraintEqualToAnchor:headerView.leadingAnchor], | 360 constraintEqualToAnchor:headerView.leadingAnchor], |
363 [[searchBarView heightAnchor] | 361 [[searchBarView heightAnchor] |
364 constraintEqualToAnchor:headerView.heightAnchor], | 362 constraintEqualToAnchor:headerView.heightAnchor], |
365 [[searchBarView widthAnchor] constraintEqualToAnchor:headerView.widthAnchor] | 363 [[searchBarView widthAnchor] constraintEqualToAnchor:headerView.widthAnchor] |
366 ]; | 364 ]; |
367 [NSLayoutConstraint activateConstraints:constraints]; | 365 [NSLayoutConstraint activateConstraints:constraints]; |
368 // Workaround so navigationItems are not voice-over selectable while hidden by | 366 // Workaround so navigationItems are not voice-over selectable while hidden by |
369 // the search view. We might have to re factor the view hierarchy in order to | 367 // the search view. We might have to re factor the view hierarchy in order to |
370 // properly solve this issue. See: https://codereview.chromium.org/2605023002/ | 368 // properly solve this issue. See: https://codereview.chromium.org/2605023002/ |
371 self.navigationItem.leftBarButtonItem = nil; | 369 self.navigationItem.leftBarButtonItem = nil; |
372 self.navigationItem.rightBarButtonItem = nil; | 370 self.navigationItem.rightBarButtonItem = nil; |
373 } | 371 } |
374 | 372 |
375 - (void)exitSearchMode { | 373 - (void)exitSearchMode { |
376 if (_historyCollectionController.get().searching) { | 374 if (_historyCollectionController.searching) { |
377 // Resets the navigation items to their initial state. | 375 // Resets the navigation items to their initial state. |
378 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; | 376 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; |
379 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; | 377 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; |
380 [self configureNavigationBar]; | 378 [self configureNavigationBar]; |
381 | 379 |
382 [[_searchViewController view] removeFromSuperview]; | 380 [[_searchViewController view] removeFromSuperview]; |
383 [_searchViewController removeFromParentViewController]; | 381 [_searchViewController removeFromParentViewController]; |
384 _historyCollectionController.get().searching = NO; | 382 _historyCollectionController.searching = NO; |
385 [_historyCollectionController showHistoryMatchingQuery:nil]; | 383 [_historyCollectionController showHistoryMatchingQuery:nil]; |
386 } | 384 } |
387 } | 385 } |
388 | 386 |
389 - (void)configureNavigationBar { | 387 - (void)configureNavigationBar { |
390 // The search button should only be enabled if there are history entries to | 388 // The search button should only be enabled if there are history entries to |
391 // search, and if history is not in edit mode. | 389 // search, and if history is not in edit mode. |
392 self.navigationItem.leftBarButtonItem.enabled = | 390 self.navigationItem.leftBarButtonItem.enabled = |
393 [_historyCollectionController hasHistoryEntries] && | 391 [_historyCollectionController hasHistoryEntries] && |
394 ![_historyCollectionController isEditing]; | 392 ![_historyCollectionController isEditing]; |
395 } | 393 } |
396 | 394 |
397 - (void)configureClearBrowsingBar { | 395 - (void)configureClearBrowsingBar { |
398 _clearBrowsingBar.get().editing = _historyCollectionController.get().editing; | 396 _clearBrowsingBar.editing = _historyCollectionController.editing; |
399 _clearBrowsingBar.get().deleteButtonEnabled = | 397 _clearBrowsingBar.deleteButtonEnabled = |
400 [_historyCollectionController hasSelectedEntries]; | 398 [_historyCollectionController hasSelectedEntries]; |
401 _clearBrowsingBar.get().editButtonEnabled = | 399 _clearBrowsingBar.editButtonEnabled = |
402 [_historyCollectionController hasHistoryEntries]; | 400 [_historyCollectionController hasHistoryEntries]; |
403 } | 401 } |
404 | 402 |
405 #pragma mark - UIResponder | 403 #pragma mark - UIResponder |
406 | 404 |
407 - (NSArray*)keyCommands { | 405 - (NSArray*)keyCommands { |
408 base::WeakNSObject<HistoryPanelViewController> weakSelf(self); | 406 __weak HistoryPanelViewController* weakSelf = self; |
409 return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape | 407 return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape |
410 modifierFlags:Cr_UIKeyModifierNone | 408 modifierFlags:Cr_UIKeyModifierNone |
411 title:nil | 409 title:nil |
412 action:^{ | 410 action:^{ |
413 [weakSelf closeHistory]; | 411 [weakSelf closeHistory]; |
414 }] ]; | 412 }] ]; |
415 } | 413 } |
416 | 414 |
417 @end | 415 @end |
OLD | NEW |