Commit 0fe1faa1 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Moves remaining methods out of BookmarksTableView.

The only code remaining in BookmarksTableView is directly related to the
UITableView or its loading and empty state backgrounds.

BUG=840381

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I79910f4d1bfbda5a586bb255c2b53f39ee20cb12
Reviewed-on: https://chromium-review.googlesource.com/1052905
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557577}
parent 838fb3bd
...@@ -80,29 +80,11 @@ class ChromeBrowserState; ...@@ -80,29 +80,11 @@ class ChromeBrowserState;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE; + (instancetype) new NS_UNAVAILABLE;
// Called when adding a new folder // Methods to show and hide the loading spinner.
- (void)addNewFolder;
// Returns a vector of edit nodes.
- (std::vector<const bookmarks::BookmarkNode*>)getEditNodesInVector;
// Returns if current root node allows new folder to be created on it.
- (BOOL)allowsNewFolder;
// Returns the row position that is visible.
- (CGFloat)contentPosition;
// Scrolls the table view to the desired row position.
- (void)setContentPosition:(CGFloat)position;
// Called when back or done button of navigation bar is tapped.
- (void)navigateAway;
// TODO(crbug.com/840381): Temporarily made public while migrating code
// out of BookmarkTableView.
- (void)restoreRowSelection;
- (void)showLoadingSpinnerBackground; - (void)showLoadingSpinnerBackground;
- (void)hideLoadingSpinnerBackground; - (void)hideLoadingSpinnerBackground;
// Methods to show and hide the "no bookmarks" background.
- (void)showEmptyBackground; - (void)showEmptyBackground;
- (void)hideEmptyBackground; - (void)hideEmptyBackground;
......
...@@ -92,133 +92,6 @@ using bookmarks::BookmarkNode; ...@@ -92,133 +92,6 @@ using bookmarks::BookmarkNode;
#pragma mark - Public #pragma mark - Public
- (void)addNewFolder {
[self.sharedState.editingFolderCell stopEdit];
if (!self.sharedState.tableViewDisplayedRootNode) {
return;
}
self.sharedState.addingNewFolder = YES;
base::string16 folderTitle = base::SysNSStringToUTF16(
l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_GROUP_DEFAULT_NAME));
self.sharedState.editingFolderNode =
self.sharedState.bookmarkModel->AddFolder(
self.sharedState.tableViewDisplayedRootNode,
self.sharedState.tableViewDisplayedRootNode->child_count(),
folderTitle);
BookmarkHomeNodeItem* nodeItem = [[BookmarkHomeNodeItem alloc]
initWithType:BookmarkHomeItemTypeBookmark
bookmarkNode:self.sharedState.editingFolderNode];
[self.sharedState.tableViewModel
addItem:nodeItem
toSectionWithIdentifier:BookmarkHomeSectionIdentifierBookmarks];
// Insert the new folder cell at the end of the table.
NSIndexPath* newRowIndexPath =
[self.sharedState.tableViewModel indexPathForItem:nodeItem];
NSMutableArray* newRowIndexPaths =
[[NSMutableArray alloc] initWithObjects:newRowIndexPath, nil];
[self.sharedState.tableView beginUpdates];
[self.sharedState.tableView
insertRowsAtIndexPaths:newRowIndexPaths
withRowAnimation:UITableViewRowAnimationNone];
[self.sharedState.tableView endUpdates];
// Scroll to the end of the table
[self.sharedState.tableView
scrollToRowAtIndexPath:newRowIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
}
- (std::vector<const bookmarks::BookmarkNode*>)getEditNodesInVector {
// Create a vector of edit nodes in the same order as the nodes in folder.
std::vector<const bookmarks::BookmarkNode*> nodes;
int childCount = self.sharedState.tableViewDisplayedRootNode->child_count();
for (int i = 0; i < childCount; ++i) {
const BookmarkNode* node =
self.sharedState.tableViewDisplayedRootNode->GetChild(i);
if (self.sharedState.editNodes.find(node) !=
self.sharedState.editNodes.end()) {
nodes.push_back(node);
}
}
return nodes;
}
- (BOOL)allowsNewFolder {
// When the current root node has been removed remotely (becomes NULL),
// creating new folder is forbidden.
return self.sharedState.tableViewDisplayedRootNode != NULL;
}
- (CGFloat)contentPosition {
if (self.sharedState.tableViewDisplayedRootNode ==
self.sharedState.bookmarkModel->root_node()) {
return 0;
}
// Divided the scroll position by cell height so that it will stay correct in
// case the cell height is changed in future.
return self.sharedState.tableView.contentOffset.y /
[BookmarkHomeSharedState cellHeightPt];
}
- (void)setContentPosition:(CGFloat)position {
// The scroll position was divided by the cell height when stored.
[self.sharedState.tableView
setContentOffset:CGPointMake(
0,
position * [BookmarkHomeSharedState cellHeightPt])];
}
- (void)navigateAway {
[self.sharedState.editingFolderCell stopEdit];
}
#pragma mark - UIView
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
// Stop edit of current bookmark folder name, if any.
[self.sharedState.editingFolderCell stopEdit];
}
// Row selection of the tableView will be cleared after reloadData. This
// function is used to restore the row selection. It also updates editNodes in
// case some selected nodes are removed.
- (void)restoreRowSelection {
// Create a new editNodes set to check if some selected nodes are removed.
std::set<const bookmarks::BookmarkNode*> newEditNodes;
// Add selected nodes to editNodes only if they are not removed (still exist
// in the table).
NSArray<TableViewItem*>* items = [self.sharedState.tableViewModel
itemsInSectionWithIdentifier:BookmarkHomeSectionIdentifierBookmarks];
for (TableViewItem* item in items) {
BookmarkHomeNodeItem* nodeItem =
base::mac::ObjCCastStrict<BookmarkHomeNodeItem>(item);
const BookmarkNode* node = nodeItem.bookmarkNode;
if (self.sharedState.editNodes.find(node) !=
self.sharedState.editNodes.end()) {
newEditNodes.insert(node);
// Reselect the row of this node.
NSIndexPath* itemPath =
[self.sharedState.tableViewModel indexPathForItem:nodeItem];
[self.sharedState.tableView
selectRowAtIndexPath:itemPath
animated:NO
scrollPosition:UITableViewScrollPositionNone];
}
}
// if editNodes is changed, update it and tell BookmarkTableViewDelegate.
if (self.sharedState.editNodes.size() != newEditNodes.size()) {
self.sharedState.editNodes = newEditNodes;
[self.delegate bookmarkTableView:self
selectedEditNodes:self.sharedState.editNodes];
}
}
// Shows loading spinner background view. // Shows loading spinner background view.
- (void)showLoadingSpinnerBackground { - (void)showLoadingSpinnerBackground {
if (!self.spinnerView) { if (!self.spinnerView) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment