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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.mm

Issue 2586993002: Upstream Chrome on iOS source code [3/11]. (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h"
6
7 #include "base/mac/objc_property_releaser.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "components/bookmarks/browser/base_bookmark_model_observer.h"
10 #include "components/bookmarks/browser/bookmark_model.h"
11 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
12 #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
13 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h"
14 #import "ios/chrome/browser/ui/url_loader.h"
15
16 using bookmarks::BookmarkNode;
17
18 @interface BookmarkHomeViewController () {
19 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHomeViewController;
20 }
21
22 // Redefined to be readwrite.
23 @property(nonatomic, retain, readwrite) NSMutableArray* editIndexPaths;
24
25 // Returns the parent, if all the bookmarks are siblings.
26 // Otherwise returns the mobile_node.
27 + (const BookmarkNode*)
28 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks
29 model:(bookmarks::BookmarkModel*)model;
30 @end
31
32 @implementation BookmarkHomeViewController
33 @synthesize delegate = _delegate;
34 @synthesize editIndexPaths = _editIndexPaths;
35 @synthesize editing = _editing;
36 @synthesize bookmarks = _bookmarks;
37 @synthesize loader = _loader;
38 @synthesize browserState = _browserState;
39
40 - (instancetype)initWithLoader:(id<UrlLoader>)loader
41 browserState:(ios::ChromeBrowserState*)browserState {
42 DCHECK(browserState);
43 self = [super initWithNibName:nil bundle:nil];
44 if (self) {
45 _propertyReleaser_BookmarkHomeViewController.Init(
46 self, [BookmarkHomeViewController class]);
47
48 _browserState = browserState->GetOriginalChromeBrowserState();
49 _loader = loader;
50
51 _bookmarks = ios::BookmarkModelFactory::GetForBrowserState(_browserState);
52 _editIndexPaths = [[NSMutableArray alloc] init];
53
54 [self resetEditNodes];
55 }
56 return self;
57 }
58
59 - (void)loadView {
60 CGRect frame = [[UIScreen mainScreen] bounds];
61 self.view =
62 base::scoped_nsobject<UIView>([[UIView alloc] initWithFrame:frame]);
63 }
64
65 - (void)resetEditNodes {
66 _editNodes = std::set<const BookmarkNode*>();
67 _editNodesOrdered = std::vector<const BookmarkNode*>();
68 [self.editIndexPaths removeAllObjects];
69 }
70
71 - (void)insertEditNode:(const BookmarkNode*)node
72 atIndexPath:(NSIndexPath*)indexPath {
73 if (_editNodes.find(node) != _editNodes.end())
74 return;
75 _editNodes.insert(node);
76 _editNodesOrdered.push_back(node);
77 if (indexPath) {
78 [self.editIndexPaths addObject:indexPath];
79 } else {
80 // We insert null if we don't have the cell to keep the index valid.
81 [self.editIndexPaths addObject:[NSNull null]];
82 }
83 }
84
85 - (void)removeEditNode:(const BookmarkNode*)node
86 atIndexPath:(NSIndexPath*)indexPath {
87 if (_editNodes.find(node) == _editNodes.end())
88 return;
89
90 _editNodes.erase(node);
91 std::vector<const BookmarkNode*>::iterator it =
92 std::find(_editNodesOrdered.begin(), _editNodesOrdered.end(), node);
93 DCHECK(it != _editNodesOrdered.end());
94 _editNodesOrdered.erase(it);
95 if (indexPath) {
96 [self.editIndexPaths removeObject:indexPath];
97 } else {
98 // If we don't have the cell, we remove it by using its index.
99 const NSUInteger index = std::distance(_editNodesOrdered.begin(), it);
100 if (index < self.editIndexPaths.count) {
101 [self.editIndexPaths removeObjectAtIndex:index];
102 }
103 }
104 }
105
106 - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
107 if (_editing == editing)
108 return;
109
110 _editing = editing;
111
112 // Only reset the editing state when leaving edit mode. This allows subclasses
113 // to add nodes for editing before entering edit mode.
114 if (!editing)
115 [self resetEditNodes];
116 }
117
118 - (void)dismissModals:(BOOL)animated {
119 // Do nothing in base class.
120 }
121
122 + (const BookmarkNode*)
123 defaultMoveFolderFromBookmarks:(const std::set<const BookmarkNode*>&)bookmarks
124 model:(bookmarks::BookmarkModel*)model {
125 if (bookmarks.size() == 0)
126 return model->mobile_node();
127 const BookmarkNode* firstParent = (*(bookmarks.begin()))->parent();
128 for (const BookmarkNode* node : bookmarks) {
129 if (node->parent() != firstParent)
130 return model->mobile_node();
131 }
132
133 return firstParent;
134 }
135
136 @end
137
138 @implementation BookmarkHomeViewController (PrivateAPIExposedForTesting)
139
140 - (const std::set<const BookmarkNode*>&)editNodes {
141 return _editNodes;
142 }
143
144 - (void)setEditNodes:(const std::set<const BookmarkNode*>&)editNodes {
145 _editNodes = editNodes;
146 }
147
148 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698