-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IOS][Bkmrks] Create bookmarks folder chooser mediator
This cl creates a skeleton bookmarks folder chooser mediator and transfers ownership of `selectedFolder` property from the coordinator. This properties can be modified by callers, BookmarkModelBridge observer and user selection. The mediator is now the source of truth for this property. Also the mediator takes a pointer to the set of editedNodes from the coordinator. This property is only initialized once and is readonly later on for coordinator clients. Mediator makes changes to this set, through the pointer that it owns, depending on model changes but the coordinator is the owner of the set. BookmarkModelBridge observer will be moved in a following cl. Bug: 1405746 Change-Id: Ieea58ee52b19c4720af708a2ad083578ddc654d4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4307538 Reviewed-by: Jérôme Lebel <jlebel@chromium.org> Commit-Queue: Tanmoy Mollik <triploblastic@google.com> Cr-Commit-Position: refs/heads/main@{#1115677}
- Loading branch information
Tanmoy Mollik
authored and
Chromium LUCI CQ
committed
Mar 10, 2023
1 parent
65b032a
commit e4733d4
Showing
10 changed files
with
271 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_consumer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_CONSUMER_H_ | ||
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_CONSUMER_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <set> | ||
#import <vector> | ||
|
||
namespace bookmarks { | ||
class BookmarkNode; | ||
} | ||
|
||
// Consumer protocol to receive updates from the model layer. | ||
@protocol BookmarksFolderChooserConsumer <NSObject> | ||
|
||
// Notifies the UI layer that model layer has been updated. | ||
- (void)notifyModelUpdated; | ||
|
||
@end | ||
|
||
// TODO(crbug.com/1405746): Refactor all the methods in this protocol after the | ||
// view controller has been refactored. View controller should not know about | ||
// BookmarkNode. | ||
// Data source protocol to get data on demand. | ||
@protocol BookmarksFolderChooserDataSource <NSObject> | ||
|
||
// Root folder in the bookmark model tree. | ||
- (const bookmarks::BookmarkNode*)rootFolder; | ||
// The folder that should have a blue check mark beside it in the UI. | ||
- (const bookmarks::BookmarkNode*)selectedFolder; | ||
// TODO(crbug.com/1405746): Delete this method and return visible folders | ||
// instead after BookmarkModelBridge is configured inside the mediator. | ||
- (const std::set<const bookmarks::BookmarkNode*>&)editedNodes; | ||
// The list of visible folders to show in the folder chooser UI. | ||
- (std::vector<const bookmarks::BookmarkNode*>)visibleFolders; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_CONSUMER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_mediator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MEDIATOR_H_ | ||
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MEDIATOR_H_ | ||
|
||
#import "ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_consumer.h" | ||
#import "ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_mutator.h" | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <set> | ||
|
||
namespace bookmarks { | ||
class BookmarkModel; | ||
class BookmarkNode; | ||
} // namespace bookmarks | ||
|
||
// A mediator class to encapsulate BookmarkModel from the view controller. | ||
@interface BookmarksFolderChooserMediator | ||
: NSObject <BookmarksFolderChooserDataSource, BookmarksFolderChooserMutator> | ||
|
||
// Consumer to reflect model changes in the UI. | ||
@property(nonatomic, weak) id<BookmarksFolderChooserConsumer> consumer; | ||
// The currently selected folder. | ||
@property(nonatomic, assign) const bookmarks::BookmarkNode* selectedFolder; | ||
|
||
// Initialize the mediator with a bookmark model. | ||
// `bookmarkModel` must not be `nullptr` and must be loaded. | ||
// `editedNodes` are the list of nodes to hide when displaying folders. This is | ||
// to avoid to move a folder inside a child folder. These are also the list of | ||
// nodes that are being edited (moved to a folder). | ||
- (instancetype)initWithBookmarkModel:(bookmarks::BookmarkModel*)model | ||
editedNodes: | ||
(std::set<const bookmarks::BookmarkNode*>*)nodes | ||
NS_DESIGNATED_INITIALIZER; | ||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MEDIATOR_H_ |
69 changes: 69 additions & 0 deletions
69
ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_mediator.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// 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/folder_chooser/bookmarks_folder_chooser_mediator.h" | ||
|
||
#import "base/containers/contains.h" | ||
#import "components/bookmarks/browser/bookmark_model.h" | ||
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h" | ||
#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | ||
#import "ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_consumer.h" | ||
#import "ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_mutator.h" | ||
|
||
#if !defined(__has_feature) || !__has_feature(objc_arc) | ||
#error "This file requires ARC support." | ||
#endif | ||
|
||
using bookmarks::BookmarkModel; | ||
using bookmarks::BookmarkNode; | ||
|
||
@interface BookmarksFolderChooserMediator () <BookmarksFolderChooserMutator> { | ||
BookmarkModel* _bookmarkModel; | ||
std::set<const BookmarkNode*>* _editedNodes; | ||
} | ||
|
||
@end | ||
|
||
@implementation BookmarksFolderChooserMediator | ||
|
||
- (instancetype)initWithBookmarkModel:(BookmarkModel*)model | ||
editedNodes:(std::set<const BookmarkNode*>*)nodes { | ||
DCHECK(model); | ||
DCHECK(model->loaded()); | ||
|
||
self = [super init]; | ||
if (self) { | ||
_bookmarkModel = model; | ||
_editedNodes = nodes; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - BookmarksFolderChooserDataSource | ||
|
||
- (const BookmarkNode*)rootFolder { | ||
return _bookmarkModel->root_node(); | ||
} | ||
|
||
- (const std::set<const BookmarkNode*>&)editedNodes { | ||
return *_editedNodes; | ||
} | ||
|
||
- (std::vector<const BookmarkNode*>)visibleFolders { | ||
return bookmark_utils_ios::VisibleNonDescendantNodes(*_editedNodes, | ||
_bookmarkModel); | ||
} | ||
|
||
#pragma mark - BookmarksFolderChooserMutator | ||
|
||
- (void)setSelectedFolder:(const BookmarkNode*)folder { | ||
_selectedFolder = folder; | ||
[_consumer notifyModelUpdated]; | ||
} | ||
|
||
- (void)removeFromEditedNodes:(const BookmarkNode*)node { | ||
_editedNodes->erase(node); | ||
} | ||
|
||
@end |
27 changes: 27 additions & 0 deletions
27
ios/chrome/browser/ui/bookmarks/folder_chooser/bookmarks_folder_chooser_mutator.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MUTATOR_H_ | ||
#define IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MUTATOR_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
namespace bookmarks { | ||
class BookmarkNode; | ||
} // namespace bookmarks | ||
|
||
// A model mutator class for folder chooser view controller to make changes to | ||
// te model. | ||
@protocol BookmarksFolderChooserMutator <NSObject> | ||
|
||
// TODO(crbug.com/1405746): Change parameter signature. View controller should | ||
// not know about BookmarkNode. | ||
- (void)setSelectedFolder:(const bookmarks::BookmarkNode*)folder; | ||
// TODO(crbug.com/1405746): Delete this method after the mediator is configured | ||
// to observe BookmarkModelBridge. | ||
- (void)removeFromEditedNodes:(const bookmarks::BookmarkNode*)node; | ||
|
||
@end | ||
|
||
#endif // IOS_CHROME_BROWSER_UI_BOOKMARKS_FOLDER_CHOOSER_BOOKMARKS_FOLDER_CHOOSER_MUTATOR_H_ |
Oops, something went wrong.