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

Side by Side Diff: ios/chrome/browser/ui/key_commands_provider.mm

Issue 2804703002: [ObjC ARC] Converts ios/chrome/browser/ui:ui_internal_arc to ARC. (Closed)
Patch Set: comments Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/chrome/browser/ui/key_commands_provider.h" 5 #import "ios/chrome/browser/ui/key_commands_provider.h"
6 6
7 #import "base/ios/weak_nsobject.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 9 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
11 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" 10 #include "ios/chrome/browser/ui/commands/ios_command_ids.h"
12 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" 11 #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h"
13 #include "ios/chrome/browser/ui/rtl_geometry.h" 12 #include "ios/chrome/browser/ui/rtl_geometry.h"
14 #include "ios/chrome/grit/ios_strings.h" 13 #include "ios/chrome/grit/ios_strings.h"
15 #include "ui/base/l10n/l10n_util_mac.h" 14 #include "ui/base/l10n/l10n_util_mac.h"
16 15
16 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support."
18 #endif
19
17 @implementation KeyCommandsProvider 20 @implementation KeyCommandsProvider
18 21
19 - (NSArray*)keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer 22 - (NSArray*)keyCommandsForConsumer:(id<KeyCommandsPlumbing>)consumer
20 editingText:(BOOL)editingText { 23 editingText:(BOOL)editingText {
21 base::WeakNSProtocol<id<KeyCommandsPlumbing>> weakConsumer(consumer); 24 __weak id<KeyCommandsPlumbing> weakConsumer = consumer;
22 25
23 // Block to execute a command from the |tag|. 26 // Block to execute a command from the |tag|.
24 void (^execute)(NSInteger) = [[^(NSInteger tag) { 27 void (^execute)(NSInteger) = ^(NSInteger tag) {
25 [weakConsumer 28 [weakConsumer
26 chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]]; 29 chromeExecuteCommand:[GenericChromeCommand commandWithTag:tag]];
27 } copy] autorelease]; 30 };
28 31
29 // Block to have the tab model open the tab at |index|, if there is one. 32 // Block to have the tab model open the tab at |index|, if there is one.
30 void (^focusTab)(NSUInteger) = [[^(NSUInteger index) { 33 void (^focusTab)(NSUInteger) = ^(NSUInteger index) {
31 [weakConsumer focusTabAtIndex:index]; 34 [weakConsumer focusTabAtIndex:index];
32 } copy] autorelease]; 35 };
33 36
34 const BOOL hasTabs = [consumer tabsCount] > 0; 37 const BOOL hasTabs = [consumer tabsCount] > 0;
35 38
36 const BOOL useRTLLayout = UseRTLLayout(); 39 const BOOL useRTLLayout = UseRTLLayout();
37 const NSInteger browseLeft = useRTLLayout ? IDC_FORWARD : IDC_BACK; 40 const NSInteger browseLeft = useRTLLayout ? IDC_FORWARD : IDC_BACK;
38 const NSInteger browseRight = useRTLLayout ? IDC_BACK : IDC_FORWARD; 41 const NSInteger browseRight = useRTLLayout ? IDC_BACK : IDC_FORWARD;
39 const int browseLeftDescriptionID = useRTLLayout 42 const int browseLeftDescriptionID = useRTLLayout
40 ? IDS_IOS_KEYBOARD_HISTORY_FORWARD 43 ? IDS_IOS_KEYBOARD_HISTORY_FORWARD
41 : IDS_IOS_KEYBOARD_HISTORY_BACK; 44 : IDS_IOS_KEYBOARD_HISTORY_BACK;
42 const int browseRightDescriptionID = useRTLLayout 45 const int browseRightDescriptionID = useRTLLayout
43 ? IDS_IOS_KEYBOARD_HISTORY_BACK 46 ? IDS_IOS_KEYBOARD_HISTORY_BACK
44 : IDS_IOS_KEYBOARD_HISTORY_FORWARD; 47 : IDS_IOS_KEYBOARD_HISTORY_FORWARD;
45 BOOL (^canBrowseLeft)() = [[^() { 48 BOOL (^canBrowseLeft)() = ^() {
46 return useRTLLayout ? [weakConsumer canGoForward] 49 return useRTLLayout ? [weakConsumer canGoForward]
47 : [weakConsumer canGoBack]; 50 : [weakConsumer canGoBack];
48 } copy] autorelease]; 51 };
49 BOOL (^canBrowseRight)() = [[^() { 52 BOOL (^canBrowseRight)() = ^() {
50 return useRTLLayout ? [weakConsumer canGoBack] 53 return useRTLLayout ? [weakConsumer canGoBack]
51 : [weakConsumer canGoForward]; 54 : [weakConsumer canGoForward];
52 } copy] autorelease]; 55 };
53 56
54 // Initialize the array of commands with an estimated capacity. 57 // Initialize the array of commands with an estimated capacity.
55 NSMutableArray* keyCommands = [NSMutableArray arrayWithCapacity:32]; 58 NSMutableArray* keyCommands = [NSMutableArray arrayWithCapacity:32];
56 59
57 // List the commands that always appear in the HUD. They appear in the HUD 60 // List the commands that always appear in the HUD. They appear in the HUD
58 // since they have titles. 61 // since they have titles.
59 [keyCommands addObjectsFromArray:@[ 62 [keyCommands addObjectsFromArray:@[
60 [UIKeyCommand cr_keyCommandWithInput:@"t" 63 [UIKeyCommand cr_keyCommandWithInput:@"t"
61 modifierFlags:UIKeyModifierCommand 64 modifierFlags:UIKeyModifierCommand
62 title:l10n_util::GetNSStringWithFixup( 65 title:l10n_util::GetNSStringWithFixup(
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 action:^{ 315 action:^{
313 [weakConsumer focusNextTab]; 316 [weakConsumer focusNextTab];
314 }], 317 }],
315 ]]; 318 ]];
316 } 319 }
317 320
318 return keyCommands; 321 return keyCommands;
319 } 322 }
320 323
321 @end 324 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/fullscreen_controller.mm ('k') | ios/chrome/browser/ui/open_in_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698