Chromium Code Reviews| 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 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h" | 5 #include "ios/chrome/browser/ui/history/history_collection_view_controller.h" |
| 6 | 6 |
| 7 #import <MobileCoreServices/MobileCoreServices.h> | 7 #import <MobileCoreServices/MobileCoreServices.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // Fetches history prior to |time| for search text |query|. If |query| is nil or | 107 // Fetches history prior to |time| for search text |query|. If |query| is nil or |
| 108 // the empty string, all history is fetched. | 108 // the empty string, all history is fetched. |
| 109 - (void)fetchHistoryForQuery:(NSString*)query | 109 - (void)fetchHistoryForQuery:(NSString*)query |
| 110 priorToTime:(const base::Time&)time; | 110 priorToTime:(const base::Time&)time; |
| 111 // Updates header section to provide relevant information about the currently | 111 // Updates header section to provide relevant information about the currently |
| 112 // displayed history entries. | 112 // displayed history entries. |
| 113 - (void)updateEntriesStatusMessage; | 113 - (void)updateEntriesStatusMessage; |
| 114 // Removes selected items from the visible collection, but does not delete them | 114 // Removes selected items from the visible collection, but does not delete them |
| 115 // from browser history. | 115 // from browser history. |
| 116 - (void)removeSelectedItemsFromCollection; | 116 - (void)removeSelectedItemsFromCollection; |
| 117 // Removes all items in the collection that are not included in entries. | 117 // Selects all items in the collection that are not included in entries. |
| 118 - (void)filterForHistoryEntries:(NSArray*)entries; | 118 - (void)filterForHistoryEntries:(NSArray*)entries; |
| 119 // Deletes all items in the collection which indexes are included in indexArray, | |
| 120 // needs to be run inside a performBatchUpdates block. | |
| 121 - (void)deleteItemsFromCollectionViewModelWithIndex:(NSArray*)indexArray; | |
| 119 // Adds loading indicator to the top of the history collection, if one is not | 122 // Adds loading indicator to the top of the history collection, if one is not |
| 120 // already present. | 123 // already present. |
| 121 - (void)addLoadingIndicator; | 124 - (void)addLoadingIndicator; |
| 122 // Displays context menu on cell pressed with gestureRecognizer. | 125 // Displays context menu on cell pressed with gestureRecognizer. |
| 123 - (void)displayContextMenuInvokedByGestureRecognizer: | 126 - (void)displayContextMenuInvokedByGestureRecognizer: |
| 124 (UILongPressGestureRecognizer*)gestureRecognizer; | 127 (UILongPressGestureRecognizer*)gestureRecognizer; |
| 125 // Opens URL in the current tab and dismisses the history view. | 128 // Opens URL in the current tab and dismisses the history view. |
| 126 - (void)openURL:(const GURL&)URL; | 129 - (void)openURL:(const GURL&)URL; |
| 127 // Opens URL in a new non-incognito tab and dismisses the history view. | 130 // Opens URL in a new non-incognito tab and dismisses the history view. |
| 128 - (void)openURLInNewTab:(const GURL&)URL; | 131 - (void)openURLInNewTab:(const GURL&)URL; |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 HistoryEntryItem* item = | 365 HistoryEntryItem* item = |
| 363 [[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry | 366 [[HistoryEntryItem alloc] initWithType:ItemTypeHistoryEntry |
| 364 historyEntry:entry | 367 historyEntry:entry |
| 365 browserState:_browserState | 368 browserState:_browserState |
| 366 delegate:self]; | 369 delegate:self]; |
| 367 [self.entryInserter insertHistoryEntryItem:item]; | 370 [self.entryInserter insertHistoryEntryItem:item]; |
| 368 if ([self isSearching] || self.filterQueryResult) { | 371 if ([self isSearching] || self.filterQueryResult) { |
| 369 [filterResults addObject:item]; | 372 [filterResults addObject:item]; |
| 370 } | 373 } |
| 371 } | 374 } |
| 372 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; | 375 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; |
|
sczs
2017/04/05 01:57:50
We can clearly see now that this was being called
| |
| 376 if (([self isSearching] && [searchQuery length] > 0 && | |
| 377 [self.currentQuery isEqualToString:searchQuery]) || | |
| 378 self.filterQueryResult) { | |
| 379 // If in search mode, filter out entries that are not | |
| 380 // part of the search result. | |
| 381 [self filterForHistoryEntries:filterResults]; | |
| 382 NSArray* deletedIndexPaths = | |
| 383 self.collectionView.indexPathsForSelectedItems; | |
| 384 [self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths]; | |
|
ramyasharma
2017/04/06 06:23:27
Why not call this inline? Especially since this me
sczs
2017/04/07 02:03:25
Since removeSelectedItemsFromCollection can't be r
| |
| 385 self.filterQueryResult = NO; | |
| 386 } | |
| 373 } | 387 } |
| 374 completion:^(BOOL) { | 388 completion:^(BOOL) { |
|
lpromero
2017/04/05 09:48:05
This is the same completion block as in the remove
sczs
2017/04/07 02:03:25
Exactly right! The exact same code is being execut
| |
| 375 if (([self isSearching] && [searchQuery length] > 0 && | 389 // If only the header section remains, there are no history entries. |
| 376 [self.currentQuery isEqualToString:searchQuery]) || | 390 if ([self.collectionViewModel numberOfSections] == 1) { |
| 377 self.filterQueryResult) { | 391 self.entriesType = NO_ENTRIES; |
| 378 // If in search mode, filter out entries that are not | |
| 379 // part of the search result. | |
| 380 [self filterForHistoryEntries:filterResults]; | |
| 381 self.filterQueryResult = NO; | |
| 382 } | 392 } |
| 393 [self updateEntriesStatusMessage]; | |
| 394 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; | |
| 383 }]; | 395 }]; |
| 384 } | 396 } |
| 385 | 397 |
| 386 - (void)historyServiceFacade:(HistoryServiceFacade*)facade | 398 - (void)historyServiceFacade:(HistoryServiceFacade*)facade |
| 387 shouldShowNoticeAboutOtherFormsOfBrowsingHistory:(BOOL)shouldShowNotice { | 399 shouldShowNoticeAboutOtherFormsOfBrowsingHistory:(BOOL)shouldShowNotice { |
| 388 self.shouldShowNoticeAboutOtherFormsOfBrowsingHistory = shouldShowNotice; | 400 self.shouldShowNoticeAboutOtherFormsOfBrowsingHistory = shouldShowNotice; |
| 389 // Update the history entries status message if there is no query in progress. | 401 // Update the history entries status message if there is no query in progress. |
| 390 if (!self.isLoading) { | 402 if (!self.isLoading) { |
| 391 [self updateEntriesStatusMessage]; | 403 [self updateEntriesStatusMessage]; |
| 392 } | 404 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 fromSectionWithIdentifier:kEntriesStatusSectionIdentifier]; | 620 fromSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| 609 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; | 621 [self.collectionView deleteItemsAtIndexPaths:@[ indexPath ]]; |
| 610 } | 622 } |
| 611 [self.collectionViewModel addItem:entriesStatusItem | 623 [self.collectionViewModel addItem:entriesStatusItem |
| 612 toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; | 624 toSectionWithIdentifier:kEntriesStatusSectionIdentifier]; |
| 613 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; | 625 [self.collectionView insertItemsAtIndexPaths:@[ indexPath ]]; |
| 614 } | 626 } |
| 615 completion:nil]; | 627 completion:nil]; |
| 616 } | 628 } |
| 617 | 629 |
| 618 - (void)removeSelectedItemsFromCollection { | 630 - (void)removeSelectedItemsFromCollection { |
|
ramyasharma
2017/04/06 06:23:27
Should this be removed? Is this used elsewhere?
sczs
2017/04/07 02:03:25
This is also used when deleting items from History
| |
| 619 NSArray* deletedIndexPaths = self.collectionView.indexPathsForSelectedItems; | 631 NSArray* deletedIndexPaths = self.collectionView.indexPathsForSelectedItems; |
| 620 [self.collectionView performBatchUpdates:^{ | 632 [self.collectionView performBatchUpdates:^{ |
| 621 [self collectionView:self.collectionView | 633 [self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths]; |
| 622 willDeleteItemsAtIndexPaths:deletedIndexPaths]; | |
| 623 [self.collectionView deleteItemsAtIndexPaths:deletedIndexPaths]; | |
| 624 | |
| 625 // Remove any empty sections, except the header section. | |
| 626 for (int section = self.collectionView.numberOfSections - 1; section > 0; | |
| 627 --section) { | |
| 628 if (![self.collectionViewModel numberOfItemsInSection:section]) { | |
| 629 [self.entryInserter removeSection:section]; | |
| 630 } | |
| 631 } | |
| 632 } | 634 } |
| 633 completion:^(BOOL) { | 635 completion:^(BOOL) { |
| 634 // If only the header section remains, there are no history entries. | 636 // If only the header section remains, there are no history entries. |
| 635 if ([self.collectionViewModel numberOfSections] == 1) { | 637 if ([self.collectionViewModel numberOfSections] == 1) { |
| 636 self.entriesType = NO_ENTRIES; | 638 self.entriesType = NO_ENTRIES; |
| 637 } | 639 } |
| 638 [self updateEntriesStatusMessage]; | 640 [self updateEntriesStatusMessage]; |
| 639 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; | 641 [self.delegate historyCollectionViewControllerDidChangeEntries:self]; |
| 640 }]; | 642 }]; |
| 641 } | 643 } |
| 642 | 644 |
| 645 - (void)deleteItemsFromCollectionViewModelWithIndex:(NSArray*)indexArray { | |
| 646 [self collectionView:self.collectionView | |
| 647 willDeleteItemsAtIndexPaths:indexArray]; | |
| 648 [self.collectionView deleteItemsAtIndexPaths:indexArray]; | |
| 649 | |
| 650 // Remove any empty sections, except the header section. | |
| 651 for (int section = self.collectionView.numberOfSections - 1; section > 0; | |
| 652 --section) { | |
| 653 if (![self.collectionViewModel numberOfItemsInSection:section]) { | |
| 654 [self.entryInserter removeSection:section]; | |
| 655 } | |
| 656 } | |
| 657 } | |
| 658 | |
| 643 - (void)filterForHistoryEntries:(NSArray*)entries { | 659 - (void)filterForHistoryEntries:(NSArray*)entries { |
| 644 self.collectionView.allowsMultipleSelection = YES; | 660 self.collectionView.allowsMultipleSelection = YES; |
| 645 for (int section = 1; section < [self.collectionViewModel numberOfSections]; | 661 for (int section = 1; section < [self.collectionViewModel numberOfSections]; |
| 646 ++section) { | 662 ++section) { |
| 647 NSInteger sectionIdentifier = | 663 NSInteger sectionIdentifier = |
| 648 [self.collectionViewModel sectionIdentifierForSection:section]; | 664 [self.collectionViewModel sectionIdentifierForSection:section]; |
| 649 if ([self.collectionViewModel | 665 if ([self.collectionViewModel |
| 650 hasSectionForSectionIdentifier:sectionIdentifier]) { | 666 hasSectionForSectionIdentifier:sectionIdentifier]) { |
| 651 NSArray* items = [self.collectionViewModel | 667 NSArray* items = [self.collectionViewModel |
| 652 itemsInSectionWithIdentifier:sectionIdentifier]; | 668 itemsInSectionWithIdentifier:sectionIdentifier]; |
| 653 for (id item in items) { | 669 for (id item in items) { |
| 654 HistoryEntryItem* historyItem = | 670 HistoryEntryItem* historyItem = |
| 655 base::mac::ObjCCastStrict<HistoryEntryItem>(item); | 671 base::mac::ObjCCastStrict<HistoryEntryItem>(item); |
| 656 if (![entries containsObject:historyItem]) { | 672 if (![entries containsObject:historyItem]) { |
| 657 NSIndexPath* indexPath = | 673 NSIndexPath* indexPath = |
| 658 [self.collectionViewModel indexPathForItem:historyItem | 674 [self.collectionViewModel indexPathForItem:historyItem |
| 659 inSectionWithIdentifier:sectionIdentifier]; | 675 inSectionWithIdentifier:sectionIdentifier]; |
| 660 [self.collectionView | 676 [self.collectionView |
| 661 selectItemAtIndexPath:indexPath | 677 selectItemAtIndexPath:indexPath |
| 662 animated:NO | 678 animated:NO |
| 663 scrollPosition:UICollectionViewScrollPositionNone]; | 679 scrollPosition:UICollectionViewScrollPositionNone]; |
| 664 } | 680 } |
| 665 } | 681 } |
| 666 } | 682 } |
| 667 } | 683 } |
| 668 [self removeSelectedItemsFromCollection]; | |
| 669 } | 684 } |
| 670 | 685 |
| 671 - (void)addLoadingIndicator { | 686 - (void)addLoadingIndicator { |
| 672 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; | 687 NSIndexPath* indexPath = [NSIndexPath indexPathForItem:0 inSection:0]; |
| 673 if ([self.collectionViewModel hasItemAtIndexPath:indexPath] && | 688 if ([self.collectionViewModel hasItemAtIndexPath:indexPath] && |
| 674 [self.collectionViewModel itemTypeForIndexPath:indexPath] == | 689 [self.collectionViewModel itemTypeForIndexPath:indexPath] == |
| 675 ItemTypeActivityIndicator) { | 690 ItemTypeActivityIndicator) { |
| 676 // Do not add indicator a second time. | 691 // Do not add indicator a second time. |
| 677 return; | 692 return; |
| 678 } | 693 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 797 shouldCloseWithCompletion:^{ | 812 shouldCloseWithCompletion:^{ |
| 798 [self.URLLoader webPageOrderedOpen:copiedURL | 813 [self.URLLoader webPageOrderedOpen:copiedURL |
| 799 referrer:web::Referrer() | 814 referrer:web::Referrer() |
| 800 inIncognito:YES | 815 inIncognito:YES |
| 801 inBackground:NO | 816 inBackground:NO |
| 802 appendTo:kLastTab]; | 817 appendTo:kLastTab]; |
| 803 }]; | 818 }]; |
| 804 } | 819 } |
| 805 | 820 |
| 806 @end | 821 @end |
| OLD | NEW |