Chromium Code Reviews| Index: ios/clean/chrome/browser/ui/tools/tools_mediator.mm |
| diff --git a/ios/clean/chrome/browser/ui/tools/tools_mediator.mm b/ios/clean/chrome/browser/ui/tools/tools_mediator.mm |
| index f943a4b2c4d5c9358b52f141d37246be6088113b..ddb1052ac2c57c810b5e87dfd1788ee9c8479fb0 100644 |
| --- a/ios/clean/chrome/browser/ui/tools/tools_mediator.mm |
| +++ b/ios/clean/chrome/browser/ui/tools/tools_mediator.mm |
| @@ -4,11 +4,12 @@ |
| #import "ios/clean/chrome/browser/ui/tools/tools_mediator.h" |
| -#import "ios/clean/chrome/browser/ui/commands/settings_commands.h" |
| -#import "ios/clean/chrome/browser/ui/tools/tools_actions.h" |
| +#include "base/macros.h" |
| #import "ios/clean/chrome/browser/ui/tools/tools_consumer.h" |
| #import "ios/clean/chrome/browser/ui/tools/tools_menu_item.h" |
| +#import "ios/clean/chrome/browser/ui/tools/tools_menu_model.h" |
| #import "ios/shared/chrome/browser/ui/tools_menu/tools_menu_configuration.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #if !defined(__has_feature) || !__has_feature(objc_arc) |
| #error "This file requires ARC support." |
| @@ -17,12 +18,21 @@ |
| @interface ToolsMediator () |
| @property(nonatomic, strong) id<ToolsConsumer> consumer; |
| @property(nonatomic, strong) ToolsMenuConfiguration* toolsMenuConfiguration; |
| +@property(nonatomic, strong) NSMutableArray* menuItems; |
| +// Populates the menuItems array by filtering the model data source based on the |
| +// current ToolsMenuConfiguration. |
| +- (void)populateMenuItems; |
| +// Checks if a specific Menu Item should be visibile for the current |
|
lpromero
2017/05/23 09:00:43
*visible
sczs
2017/05/23 20:28:18
Done.
|
| +// configuration. |
| +- (BOOL)itemIsVisibleForCurrentConfiguration:(const MenuModelItem)modelItem; |
| + |
| @end |
| @implementation ToolsMediator |
| @synthesize consumer = _consumer; |
| @synthesize toolsMenuConfiguration = _toolsMenuConfiguration; |
| +@synthesize menuItems = _menuItems; |
| - (instancetype)initWithConsumer:(id<ToolsConsumer>)consumer |
| andConfiguration:(ToolsMenuConfiguration*)menuConfiguration { |
| @@ -37,44 +47,72 @@ |
| - (void)setConsumer:(id<ToolsConsumer>)consumer { |
| _consumer = consumer; |
| - // PLACEHOLDER: Temporary hardcoded consumer model. |
| - NSArray<ToolsMenuItem*>* menuItems = [[NSArray alloc] init]; |
| - menuItems = @[ |
| - [[ToolsMenuItem alloc] init], [[ToolsMenuItem alloc] init], |
| - [[ToolsMenuItem alloc] init], [[ToolsMenuItem alloc] init], |
| - [[ToolsMenuItem alloc] init], [[ToolsMenuItem alloc] init], |
| - [[ToolsMenuItem alloc] init], [[ToolsMenuItem alloc] init], |
| - [[ToolsMenuItem alloc] init], [[ToolsMenuItem alloc] init], |
| - [[ToolsMenuItem alloc] init] |
| - ]; |
| - |
| - menuItems[0].title = @"New Tab"; |
| + [self populateMenuItems]; |
| - menuItems[1].title = @"New Incognito Tab"; |
| - |
| - menuItems[2].title = @"Bookmarks"; |
| + [_consumer setToolsMenuItems:self.menuItems]; |
| + [_consumer |
| + setDisplayOverflowControls:!self.toolsMenuConfiguration.isInTabSwitcher]; |
| +} |
| - menuItems[3].title = @"Reading List"; |
| +#pragma mark - Private Methods |
| - menuItems[4].title = @"Recent Tabs"; |
| +- (void)populateMenuItems { |
| + self.menuItems = [NSMutableArray array]; |
| - menuItems[5].title = @"History"; |
| + for (size_t i = 0; i < arraysize(itemsModelList); ++i) { |
| + const MenuModelItem& modelItem = itemsModelList[i]; |
| - menuItems[6].title = @"Report an Issue"; |
| + if ([self itemIsVisibleForCurrentConfiguration:modelItem]) { |
| + ToolsMenuItem* menuItem = [[ToolsMenuItem alloc] init]; |
| + menuItem.title = l10n_util::GetNSStringWithFixup(modelItem.title_id); |
| + menuItem.action = NSSelectorFromString(modelItem.selector); |
| + [self.menuItems addObject:menuItem]; |
| + } |
| + } |
| +} |
| - menuItems[7].title = @"Find in Pageā¦"; |
| - menuItems[7].action = @selector(showFindInPage); |
| +- (BOOL)itemIsVisibleForCurrentConfiguration:(const MenuModelItem)modelItem { |
| + // We first check if the item should be visible on the current Incognito |
|
lpromero
2017/05/23 09:00:43
Nit: avoid "we". Just remove it, here.
sczs
2017/05/23 20:28:18
Done.
|
| + // state. |
| + switch (modelItem.visibility) { |
| + case kVisibleIncognitoOnly: |
| + if (!self.toolsMenuConfiguration.isInIncognito) { |
| + return NO; |
| + } |
| + break; |
| + case kVisibleNotIncognitoOnly: |
| + if (self.toolsMenuConfiguration.isInIncognito) { |
| + return NO; |
| + } |
| + break; |
| + case kVisibleAlways: |
| + break; |
| + default: |
| + return NO; |
| + } |
| - menuItems[8].title = @"Request Desktop Site"; |
| + // We then check if the item should be visibile for the current Toolbar state. |
|
lpromero
2017/05/23 09:00:43
Idem.
sczs
2017/05/23 20:28:18
Done.
|
| + switch (modelItem.toolbar_types) { |
| + case ToolbarTypeNone: |
| + return NO; |
| + case ToolbarTypeSwitcher: |
| + return self.toolsMenuConfiguration.isInTabSwitcher; |
| + case ToolbarTypeWeb: |
| + return !self.toolsMenuConfiguration.isInTabSwitcher; |
| + case ToolbarTypeAll: |
| + return YES; |
| + default: |
| + return NO; |
|
lpromero
2017/05/23 09:00:44
Should you remove the default case, so that this b
sczs
2017/05/23 20:28:18
I was trying to do this, but without the default c
|
| + } |
| +} |
| - menuItems[9].title = @"Settings"; |
| - menuItems[9].action = @selector(showSettings); |
| +@end |
| - menuItems[10].title = @"Help"; |
| +// Private implementation for testing. |
| +@implementation ToolsMediator (Testing) |
| - [_consumer setToolsMenuItems:menuItems]; |
| - [_consumer |
| - setDisplayOverflowControls:!self.toolsMenuConfiguration.isInTabSwitcher]; |
| +- (NSArray*)menuItemsArray { |
| + return self.menuItems; |
| } |
| @end |