Index: ios/chrome/browser/ui/key_commands_provider.mm |
diff --git a/ios/chrome/browser/ui/key_commands_provider.mm b/ios/chrome/browser/ui/key_commands_provider.mm |
index 6473ddce21a4ef1ed26d65e2c8a4643c56f9f972..f303c71bd9048ad2199e3c244e42b9f45d96eb14 100644 |
--- a/ios/chrome/browser/ui/key_commands_provider.mm |
+++ b/ios/chrome/browser/ui/key_commands_provider.mm |
@@ -39,22 +39,36 @@ |
const BOOL hasTabs = [consumer tabsCount] > 0; |
const BOOL useRTLLayout = UseRTLLayout(); |
- const NSInteger browseLeft = useRTLLayout ? IDC_FORWARD : IDC_BACK; |
- const NSInteger browseRight = useRTLLayout ? IDC_BACK : IDC_FORWARD; |
+ |
+ // Blocks for navigating forward/back. |
+ void (^browseLeft)(); |
+ void (^browseRight)(); |
+ if (useRTLLayout) { |
+ browseLeft = [^{ |
+ if ([weakConsumer canGoForward]) |
+ [weakDispatcher goForward]; |
+ } copy]; |
+ browseRight = [^{ |
+ if ([weakConsumer canGoBack]) |
+ [weakDispatcher goBack]; |
+ } copy]; |
+ } else { |
+ browseLeft = [^{ |
+ if ([weakConsumer canGoBack]) |
+ [weakDispatcher goBack]; |
+ } copy]; |
+ browseRight = [^{ |
+ if ([weakConsumer canGoForward]) |
+ [weakDispatcher goForward]; |
+ } copy]; |
+ } |
+ |
const int browseLeftDescriptionID = useRTLLayout |
? IDS_IOS_KEYBOARD_HISTORY_FORWARD |
: IDS_IOS_KEYBOARD_HISTORY_BACK; |
const int browseRightDescriptionID = useRTLLayout |
? IDS_IOS_KEYBOARD_HISTORY_BACK |
: IDS_IOS_KEYBOARD_HISTORY_FORWARD; |
- BOOL (^canBrowseLeft)() = ^() { |
- return useRTLLayout ? [weakConsumer canGoForward] |
- : [weakConsumer canGoBack]; |
- }; |
- BOOL (^canBrowseRight)() = ^() { |
- return useRTLLayout ? [weakConsumer canGoBack] |
- : [weakConsumer canGoForward]; |
- }; |
// Initialize the array of commands with an estimated capacity. |
NSMutableArray* keyCommands = [NSMutableArray arrayWithCapacity:32]; |
@@ -155,18 +169,14 @@ |
title:l10n_util::GetNSStringWithFixup( |
browseLeftDescriptionID) |
action:^{ |
- if (canBrowseLeft()) { |
- execute(browseLeft); |
- } |
+ browseLeft(); |
}], |
[UIKeyCommand cr_keyCommandWithInput:UIKeyInputRightArrow |
modifierFlags:UIKeyModifierCommand |
title:l10n_util::GetNSStringWithFixup( |
browseRightDescriptionID) |
action:^{ |
- if (canBrowseRight()) { |
- execute(browseRight); |
- } |
+ browseRight(); |
}], |
]]; |
} |
@@ -225,17 +235,13 @@ |
modifierFlags:UIKeyModifierCommand |
title:nil |
action:^{ |
- if (canBrowseLeft()) { |
- execute(browseLeft); |
- } |
+ browseLeft(); |
}], |
[UIKeyCommand cr_keyCommandWithInput:@"]" |
modifierFlags:UIKeyModifierCommand |
title:nil |
action:^{ |
- if (canBrowseRight()) { |
- execute(browseRight); |
- } |
+ browseRight(); |
}], |
[UIKeyCommand cr_keyCommandWithInput:@"." |
modifierFlags:UIKeyModifierCommand |