Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Unified Diff: ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm

Issue 2929993002: Refactoring bookmark viewcontrollers (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm
diff --git a/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm b/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm
deleted file mode 100644
index cd277517d80e8b279519e0ccb78fa1b85a3ca27f..0000000000000000000000000000000000000000
--- a/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h"
-
-#include "components/bookmarks/browser/base_bookmark_model_observer.h"
-#include "components/bookmarks/browser/bookmark_model.h"
-#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
-#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
-#import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h"
-#import "ios/chrome/browser/ui/url_loader.h"
-
-#if !defined(__has_feature) || !__has_feature(objc_arc)
-#error "This file requires ARC support."
-#endif
-
-using bookmarks::BookmarkNode;
-
-@interface BookmarkHomeViewController ()
-
-// Redefined to be readwrite.
-@property(nonatomic, strong, readwrite) NSMutableArray* editIndexPaths;
-
-// Returns the parent, if all the bookmarks are siblings.
-// Otherwise returns the mobile_node.
-+ (const BookmarkNode*)
-defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks
- model:(bookmarks::BookmarkModel*)model;
-@end
-
-@implementation BookmarkHomeViewController
-@synthesize delegate = _delegate;
-@synthesize editIndexPaths = _editIndexPaths;
-@synthesize editing = _editing;
-@synthesize bookmarks = _bookmarks;
-@synthesize loader = _loader;
-@synthesize browserState = _browserState;
-
-- (instancetype)initWithLoader:(id<UrlLoader>)loader
- browserState:(ios::ChromeBrowserState*)browserState {
- DCHECK(browserState);
- self = [super initWithNibName:nil bundle:nil];
- if (self) {
- _browserState = browserState->GetOriginalChromeBrowserState();
- _loader = loader;
-
- _bookmarks = ios::BookmarkModelFactory::GetForBrowserState(_browserState);
- _editIndexPaths = [[NSMutableArray alloc] init];
-
- [self resetEditNodes];
- }
- return self;
-}
-
-- (void)loadView {
- CGRect frame = [[UIScreen mainScreen] bounds];
- self.view = [[UIView alloc] initWithFrame:frame];
-}
-
-- (void)resetEditNodes {
- _editNodes = std::set<const BookmarkNode*>();
- _editNodesOrdered = std::vector<const BookmarkNode*>();
- [self.editIndexPaths removeAllObjects];
-}
-
-- (void)insertEditNode:(const BookmarkNode*)node
- atIndexPath:(NSIndexPath*)indexPath {
- if (_editNodes.find(node) != _editNodes.end())
- return;
- _editNodes.insert(node);
- _editNodesOrdered.push_back(node);
- if (indexPath) {
- [self.editIndexPaths addObject:indexPath];
- } else {
- // We insert null if we don't have the cell to keep the index valid.
- [self.editIndexPaths addObject:[NSNull null]];
- }
-}
-
-- (void)removeEditNode:(const BookmarkNode*)node
- atIndexPath:(NSIndexPath*)indexPath {
- if (_editNodes.find(node) == _editNodes.end())
- return;
-
- _editNodes.erase(node);
- std::vector<const BookmarkNode*>::iterator it =
- std::find(_editNodesOrdered.begin(), _editNodesOrdered.end(), node);
- DCHECK(it != _editNodesOrdered.end());
- _editNodesOrdered.erase(it);
- if (indexPath) {
- [self.editIndexPaths removeObject:indexPath];
- } else {
- // If we don't have the cell, we remove it by using its index.
- const NSUInteger index = std::distance(_editNodesOrdered.begin(), it);
- if (index < self.editIndexPaths.count) {
- [self.editIndexPaths removeObjectAtIndex:index];
- }
- }
-}
-
-- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
- if (_editing == editing)
- return;
-
- _editing = editing;
-
- // Only reset the editing state when leaving edit mode. This allows subclasses
- // to add nodes for editing before entering edit mode.
- if (!editing)
- [self resetEditNodes];
-}
-
-- (void)dismissModals:(BOOL)animated {
- // Do nothing in base class.
-}
-
-+ (const BookmarkNode*)
-defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks
- model:(bookmarks::BookmarkModel*)model {
- if (bookmarks.size() == 0)
- return model->mobile_node();
- const BookmarkNode* firstParent = (*(bookmarks.begin()))->parent();
- for (const BookmarkNode* node : bookmarks) {
- if (node->parent() != firstParent)
- return model->mobile_node();
- }
-
- return firstParent;
-}
-
-@end
-
-@implementation BookmarkHomeViewController (PrivateAPIExposedForTesting)
-
-- (const std::set<const BookmarkNode*>&)editNodes {
- return _editNodes;
-}
-
-- (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes {
- _editNodes = editNodes;
-}
-
-@end

Powered by Google App Engine
This is Rietveld 408576698