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

Side by Side Diff: ios/clean/chrome/browser/ui/context_menu/context_menu_mediator.mm

Issue 2862783002: [iOS Clean] Wired up ContextMenuCommands. (Closed)
Patch Set: fix deps 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_mediator.h" 5 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_mediator.h"
6 6
7 #import "ios/clean/chrome/browser/ui/commands/context_menu_commands.h"
7 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_consumer.h" 8 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_consumer.h"
8 #import "ios/web/public/web_state/context_menu_params.h" 9 #import "ios/clean/chrome/browser/ui/context_menu/context_menu_context_impl.h"
10 #import "ios/shared/chrome/browser/ui/browser_list/browser.h"
11 #import "ios/web/public/url_scheme_util.h"
12 #include "url/gurl.h"
9 13
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 14 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support." 15 #error "This file requires ARC support."
12 #endif 16 #endif
13 17
14 @interface ContextMenuMediator () 18 @interface ContextMenuMediator ()
15 @property(nonatomic, weak) id<ContextMenuConsumer> consumer; 19
20 // The ContextMenuItem to use for script menus.
21 + (ContextMenuItem*)scriptItem;
22
23 // The ContextMenuItems to use for link menus.
24 + (NSArray<ContextMenuItem*>*)linkItems;
25
26 // The ContextMenuItems to use for image menus.
27 + (NSArray<ContextMenuItem*>*)imageItems;
28
29 // The cancel item to use.
30 + (ContextMenuItem*)cancelItem;
31
16 @end 32 @end
17 33
18 @implementation ContextMenuMediator 34 @implementation ContextMenuMediator
19 @synthesize consumer = _consumer;
20 35
21 - (instancetype)initWithConsumer:(id<ContextMenuConsumer>)consumer { 36 + (void)updateConsumer:(id<ContextMenuConsumer>)consumer
22 if ((self = [super init])) { 37 withContext:(ContextMenuContextImpl*)context {
23 _consumer = consumer; 38 DCHECK(consumer);
24 [self updateConsumer]; 39 DCHECK(context);
25 } 40 // Set the context and menu title.
26 return self; 41 [consumer setContextMenuContext:context];
42 [consumer setContextMenuTitle:context.menuTitle];
43 // Add the appropriate items.
44 NSMutableArray<ContextMenuItem*>* items = [[NSMutableArray alloc] init];
45 if (context.script.size())
46 [items addObject:[self scriptItem]];
47 BOOL showLinkOptions =
48 context.linkURL.is_valid() && web::UrlHasWebScheme(context.linkURL);
49 if (showLinkOptions)
50 [items addObjectsFromArray:[self linkItems]];
51 BOOL showImageOptions = context.imageURL.is_valid();
52 if (showImageOptions)
53 [items addObjectsFromArray:[self imageItems]];
54 [consumer setContextMenuItems:[items copy] cancelItem:[self cancelItem]];
27 } 55 }
28 56
29 // Update the consumer. 57 #pragma mark -
30 - (void)updateConsumer {
31 // PLACEHOLDER. Fake title.
32 [self.consumer setContextMenuTitle:@"http://some/link.html"];
33 NSMutableArray<ContextMenuItem*>* items =
34 [[NSMutableArray<ContextMenuItem*> alloc] init];
35 58
36 // PLACEHOLDER. Two non-functional items. 59 + (ContextMenuItem*)scriptItem {
37 [items 60 std::vector<SEL> commands(2U);
38 addObject:[ContextMenuItem itemWithTitle:@"Open in New Tab" command:nil]]; 61 commands[0] = @selector(executeContextMenuScript:);
39 [items 62 commands[1] = @selector(hideContextMenu:);
40 addObject:[ContextMenuItem itemWithTitle:@"Copy Link URL" command:nil]]; 63 return [ContextMenuItem itemWithTitle:@"Execute Script" commands:commands];
41 [self.consumer setContextMenuItems:[items copy]]; 64 }
65
66 + (NSArray<ContextMenuItem*>*)linkItems {
67 // Opening the link in a new Tab will stop this context menu's coordinator, so
68 // there's no need to hide it.
69 std::vector<SEL> newTabCommands(1U);
70 newTabCommands[0] = @selector(openContextMenuLinkInNewTab:);
71 // TODO: Add |-openContextMenuLinkInNewIncognitoTab:| as the first command for
72 // "Open In New Incognito Tab" once the incognito tab grid is implemented.
73 std::vector<SEL> newIncognitoTabCommands(1U);
74 newIncognitoTabCommands[0] = @selector(hideContextMenu:);
75 // TODO: Add |-copyContextMenuLink:| as the first command for "Copy Link" once
76 // copying to pasteboard is implemented.
77 std::vector<SEL> copyLinkCommands(1U);
78 newIncognitoTabCommands[0] = @selector(hideContextMenu:);
79 return @[
80 [ContextMenuItem itemWithTitle:@"Open In New Tab" commands:newTabCommands],
81 [ContextMenuItem itemWithTitle:@"Open In New Incognito Tab"
82 commands:newIncognitoTabCommands],
83 [ContextMenuItem itemWithTitle:@"Copy Link" commands:copyLinkCommands],
84 ];
85 }
86
87 + (NSArray<ContextMenuItem*>*)imageItems {
88 // TODO: Add |-saveContextMenuImage:| as the first command for "Save Image"
89 // once camera roll access has been implemented.
90 std::vector<SEL> saveImageCommands(1U);
91 saveImageCommands[0] = @selector(hideContextMenu:);
92 std::vector<SEL> openImageCommands(2U);
93 openImageCommands[0] = @selector(openContextMenuImage:);
94 openImageCommands[1] = @selector(hideContextMenu:);
95 // Opening the image in a new Tab will stop this context menu's coordinator,
96 // so there's no need to hide it.
97 std::vector<SEL> openImageInNewTabCommands(1U);
98 openImageInNewTabCommands[0] = @selector(openContextMenuImageInNewTab:);
99 return @[
100 [ContextMenuItem itemWithTitle:@"Save Image" commands:saveImageCommands],
101 [ContextMenuItem itemWithTitle:@"Open Image" commands:openImageCommands],
102 [ContextMenuItem itemWithTitle:@"Open Image In New Tab"
103 commands:openImageInNewTabCommands],
104 ];
105 }
106
107 + (ContextMenuItem*)cancelItem {
108 std::vector<SEL> cancelCommands(1U);
109 cancelCommands[0] = @selector(hideContextMenu:);
110 return [ContextMenuItem itemWithTitle:@"Cancel" commands:cancelCommands];
42 } 111 }
43 112
44 @end 113 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698