| 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..2153e229197949af70c9d2c74614093d05049b1a 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 visible for the current
|
| +// 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 {
|
| + // First check if the item should be visible on the current Incognito
|
| + // state.
|
| + switch (modelItem.visibility) {
|
| + case ItemVisibleIncognitoOnly:
|
| + if (!self.toolsMenuConfiguration.isInIncognito) {
|
| + return NO;
|
| + }
|
| + break;
|
| + case ItemVisibleNotIncognitoOnly:
|
| + if (self.toolsMenuConfiguration.isInIncognito) {
|
| + return NO;
|
| + }
|
| + break;
|
| + case ItemVisibleAlways:
|
| + break;
|
| + default:
|
| + return NO;
|
| + }
|
|
|
| - menuItems[8].title = @"Request Desktop Site";
|
| + // Then check if the item should be visibile for the current Toolbar state.
|
| + 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;
|
| + }
|
| +}
|
|
|
| - 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
|
|
|