| 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/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // Privacy settings, or "Edit" for entering a mode for deleting individual | 38 // Privacy settings, or "Edit" for entering a mode for deleting individual |
| 39 // entries. When in edit mode, the bar displays options to Delete or Cancel. | 39 // entries. When in edit mode, the bar displays options to Delete or Cancel. |
| 40 base::scoped_nsobject<ClearBrowsingBar> _clearBrowsingBar; | 40 base::scoped_nsobject<ClearBrowsingBar> _clearBrowsingBar; |
| 41 // View controller for the search bar. | 41 // View controller for the search bar. |
| 42 base::scoped_nsobject<HistorySearchViewController> _searchViewController; | 42 base::scoped_nsobject<HistorySearchViewController> _searchViewController; |
| 43 // Container view for history collection and clear browsing button to enable | 43 // Container view for history collection and clear browsing button to enable |
| 44 // use of autolayout in conjuction with Material App Bar. | 44 // use of autolayout in conjuction with Material App Bar. |
| 45 base::scoped_nsobject<UIView> _containerView; | 45 base::scoped_nsobject<UIView> _containerView; |
| 46 // The header view. | 46 // The header view. |
| 47 base::scoped_nsobject<MDCAppBar> _appBar; | 47 base::scoped_nsobject<MDCAppBar> _appBar; |
| 48 // Left bar button item for Search. |
| 49 base::scoped_nsobject<UIBarButtonItem> _leftBarButtonItem; |
| 50 // Right bar button item for Dismiss history action. |
| 51 base::scoped_nsobject<UIBarButtonItem> _rightBarButtonItem; |
| 48 } | 52 } |
| 49 // Closes history. | 53 // Closes history. |
| 50 - (void)closeHistory; | 54 - (void)closeHistory; |
| 51 // Closes history, invoking completionHandler once dismissal is complete. | 55 // Closes history, invoking completionHandler once dismissal is complete. |
| 52 - (void)closeHistoryWithCompletion:(ProceduralBlock)completionHandler; | 56 - (void)closeHistoryWithCompletion:(ProceduralBlock)completionHandler; |
| 53 // Opens Privacy settings. | 57 // Opens Privacy settings. |
| 54 - (void)openPrivacySettings; | 58 - (void)openPrivacySettings; |
| 55 // Configure view for editing mode. | 59 // Configure view for editing mode. |
| 56 - (void)enterEditingMode; | 60 - (void)enterEditingMode; |
| 57 // Configure view for non-editing mode. | 61 // Configure view for non-editing mode. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 [_clearBrowsingBar setTranslatesAutoresizingMaskIntoConstraints:NO]; | 142 [_clearBrowsingBar setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 139 [_containerView addSubview:_clearBrowsingBar]; | 143 [_containerView addSubview:_clearBrowsingBar]; |
| 140 [self configureClearBrowsingBar]; | 144 [self configureClearBrowsingBar]; |
| 141 | 145 |
| 142 ConfigureAppBarWithCardStyle(_appBar); | 146 ConfigureAppBarWithCardStyle(_appBar); |
| 143 [_appBar headerViewController].headerView.trackingScrollView = | 147 [_appBar headerViewController].headerView.trackingScrollView = |
| 144 [_historyCollectionController collectionView]; | 148 [_historyCollectionController collectionView]; |
| 145 [_appBar addSubviewsToParent]; | 149 [_appBar addSubviewsToParent]; |
| 146 | 150 |
| 147 // Add navigation bar buttons. | 151 // Add navigation bar buttons. |
| 148 self.navigationItem.leftBarButtonItem = | 152 _leftBarButtonItem.reset([[ChromeIcon |
| 149 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon searchIcon] | 153 templateBarButtonItemWithImage:[ChromeIcon searchIcon] |
| 150 target:self | 154 target:self |
| 151 action:@selector(enterSearchMode)]; | 155 action:@selector(enterSearchMode)] retain]); |
| 152 self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] | 156 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; |
| 157 _rightBarButtonItem.reset([[UIBarButtonItem alloc] |
| 153 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) | 158 initWithTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) |
| 154 style:UIBarButtonItemStylePlain | 159 style:UIBarButtonItemStylePlain |
| 155 target:self | 160 target:self |
| 156 action:@selector(closeHistory)] autorelease]; | 161 action:@selector(closeHistory)]); |
| 162 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; |
| 157 [self configureNavigationBar]; | 163 [self configureNavigationBar]; |
| 158 } | 164 } |
| 159 | 165 |
| 160 - (void)updateViewConstraints { | 166 - (void)updateViewConstraints { |
| 161 NSDictionary* views = @{ | 167 NSDictionary* views = @{ |
| 162 @"collectionView" : [_historyCollectionController view], | 168 @"collectionView" : [_historyCollectionController view], |
| 163 @"clearBrowsingBar" : _clearBrowsingBar, | 169 @"clearBrowsingBar" : _clearBrowsingBar, |
| 164 }; | 170 }; |
| 165 NSArray* constraints = @[ | 171 NSArray* constraints = @[ |
| 166 @"V:|[collectionView][clearBrowsingBar(==48)]|", @"H:|[collectionView]|", | 172 @"V:|[collectionView][clearBrowsingBar(==48)]|", @"H:|[collectionView]|", |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 _appBar.get().headerViewController.headerView; | 350 _appBar.get().headerViewController.headerView; |
| 345 NSArray* constraints = @[ | 351 NSArray* constraints = @[ |
| 346 [[searchBarView topAnchor] constraintEqualToAnchor:headerView.topAnchor], | 352 [[searchBarView topAnchor] constraintEqualToAnchor:headerView.topAnchor], |
| 347 [[searchBarView leadingAnchor] | 353 [[searchBarView leadingAnchor] |
| 348 constraintEqualToAnchor:headerView.leadingAnchor], | 354 constraintEqualToAnchor:headerView.leadingAnchor], |
| 349 [[searchBarView heightAnchor] | 355 [[searchBarView heightAnchor] |
| 350 constraintEqualToAnchor:headerView.heightAnchor], | 356 constraintEqualToAnchor:headerView.heightAnchor], |
| 351 [[searchBarView widthAnchor] constraintEqualToAnchor:headerView.widthAnchor] | 357 [[searchBarView widthAnchor] constraintEqualToAnchor:headerView.widthAnchor] |
| 352 ]; | 358 ]; |
| 353 [NSLayoutConstraint activateConstraints:constraints]; | 359 [NSLayoutConstraint activateConstraints:constraints]; |
| 360 // Workaround so navigationItems are not voice-over selectable while hidden by |
| 361 // the search view. We might have to re factor the view hierarchy in order to |
| 362 // properly solve this issue. See: https://codereview.chromium.org/2605023002/ |
| 363 self.navigationItem.leftBarButtonItem = nil; |
| 364 self.navigationItem.rightBarButtonItem = nil; |
| 354 } | 365 } |
| 355 | 366 |
| 356 - (void)exitSearchMode { | 367 - (void)exitSearchMode { |
| 357 if (_historyCollectionController.get().searching) { | 368 if (_historyCollectionController.get().searching) { |
| 369 // Resets the navigation items to their initial state. |
| 370 self.navigationItem.leftBarButtonItem = _leftBarButtonItem; |
| 371 self.navigationItem.rightBarButtonItem = _rightBarButtonItem; |
| 372 [self configureNavigationBar]; |
| 373 |
| 358 [[_searchViewController view] removeFromSuperview]; | 374 [[_searchViewController view] removeFromSuperview]; |
| 359 [_searchViewController removeFromParentViewController]; | 375 [_searchViewController removeFromParentViewController]; |
| 360 _historyCollectionController.get().searching = NO; | 376 _historyCollectionController.get().searching = NO; |
| 361 [_historyCollectionController showHistoryMatchingQuery:nil]; | 377 [_historyCollectionController showHistoryMatchingQuery:nil]; |
| 362 } | 378 } |
| 363 } | 379 } |
| 364 | 380 |
| 365 - (void)configureNavigationBar { | 381 - (void)configureNavigationBar { |
| 366 // The search button should only be enabled if there are history entries to | 382 // The search button should only be enabled if there are history entries to |
| 367 // search, and if history is not in edit mode. | 383 // search, and if history is not in edit mode. |
| 368 self.navigationItem.leftBarButtonItem.enabled = | 384 self.navigationItem.leftBarButtonItem.enabled = |
| 369 [_historyCollectionController hasHistoryEntries] && | 385 [_historyCollectionController hasHistoryEntries] && |
| 370 ![_historyCollectionController isEditing]; | 386 ![_historyCollectionController isEditing]; |
| 371 } | 387 } |
| 372 | 388 |
| 373 - (void)configureClearBrowsingBar { | 389 - (void)configureClearBrowsingBar { |
| 374 _clearBrowsingBar.get().editing = _historyCollectionController.get().editing; | 390 _clearBrowsingBar.get().editing = _historyCollectionController.get().editing; |
| 375 _clearBrowsingBar.get().deleteButtonEnabled = | 391 _clearBrowsingBar.get().deleteButtonEnabled = |
| 376 [_historyCollectionController hasSelectedEntries]; | 392 [_historyCollectionController hasSelectedEntries]; |
| 377 _clearBrowsingBar.get().editButtonEnabled = | 393 _clearBrowsingBar.get().editButtonEnabled = |
| 378 [_historyCollectionController hasHistoryEntries]; | 394 [_historyCollectionController hasHistoryEntries]; |
| 379 } | 395 } |
| 380 | 396 |
| 381 @end | 397 @end |
| OLD | NEW |