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

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

Issue 2631733002: Avoid sending IDC_BACK/FORWARD when back/forward is not possible (Closed)
Patch Set: Rebased Created 3 years, 11 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
« no previous file with comments | « ios/chrome/browser/ui/key_commands_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 7 #import "base/ios/weak_nsobject.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.h"
10 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" 10 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
(...skipping 24 matching lines...) Expand all
35 35
36 const BOOL useRTLLayout = UseRTLLayout(); 36 const BOOL useRTLLayout = UseRTLLayout();
37 const NSInteger browseLeft = useRTLLayout ? IDC_FORWARD : IDC_BACK; 37 const NSInteger browseLeft = useRTLLayout ? IDC_FORWARD : IDC_BACK;
38 const NSInteger browseRight = useRTLLayout ? IDC_BACK : IDC_FORWARD; 38 const NSInteger browseRight = useRTLLayout ? IDC_BACK : IDC_FORWARD;
39 const int browseLeftDescriptionID = useRTLLayout 39 const int browseLeftDescriptionID = useRTLLayout
40 ? IDS_IOS_KEYBOARD_HISTORY_FORWARD 40 ? IDS_IOS_KEYBOARD_HISTORY_FORWARD
41 : IDS_IOS_KEYBOARD_HISTORY_BACK; 41 : IDS_IOS_KEYBOARD_HISTORY_BACK;
42 const int browseRightDescriptionID = useRTLLayout 42 const int browseRightDescriptionID = useRTLLayout
43 ? IDS_IOS_KEYBOARD_HISTORY_BACK 43 ? IDS_IOS_KEYBOARD_HISTORY_BACK
44 : IDS_IOS_KEYBOARD_HISTORY_FORWARD; 44 : IDS_IOS_KEYBOARD_HISTORY_FORWARD;
45 BOOL (^canBrowseLeft)() = [[^() {
46 return useRTLLayout ? [weakConsumer canGoForward]
47 : [weakConsumer canGoBack];
48 } copy] autorelease];
49 BOOL (^canBrowseRight)() = [[^() {
50 return useRTLLayout ? [weakConsumer canGoBack]
51 : [weakConsumer canGoForward];
52 } copy] autorelease];
45 53
46 // Initialize the array of commands with an estimated capacity. 54 // Initialize the array of commands with an estimated capacity.
47 NSMutableArray* keyCommands = [NSMutableArray arrayWithCapacity:32]; 55 NSMutableArray* keyCommands = [NSMutableArray arrayWithCapacity:32];
48 56
49 // List the commands that always appear in the HUD. They appear in the HUD 57 // List the commands that always appear in the HUD. They appear in the HUD
50 // since they have titles. 58 // since they have titles.
51 [keyCommands addObjectsFromArray:@[ 59 [keyCommands addObjectsFromArray:@[
52 [UIKeyCommand cr_keyCommandWithInput:@"t" 60 [UIKeyCommand cr_keyCommandWithInput:@"t"
53 modifierFlags:UIKeyModifierCommand 61 modifierFlags:UIKeyModifierCommand
54 title:l10n_util::GetNSStringWithFixup( 62 title:l10n_util::GetNSStringWithFixup(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 143
136 // Since cmd+left and cmd+right are valid system shortcuts when editing 144 // Since cmd+left and cmd+right are valid system shortcuts when editing
137 // text, don't register those if text is being edited. 145 // text, don't register those if text is being edited.
138 if (!editingText) { 146 if (!editingText) {
139 [keyCommands addObjectsFromArray:@[ 147 [keyCommands addObjectsFromArray:@[
140 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputLeftArrow 148 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputLeftArrow
141 modifierFlags:UIKeyModifierCommand 149 modifierFlags:UIKeyModifierCommand
142 title:l10n_util::GetNSStringWithFixup( 150 title:l10n_util::GetNSStringWithFixup(
143 browseLeftDescriptionID) 151 browseLeftDescriptionID)
144 action:^{ 152 action:^{
145 execute(browseLeft); 153 if (canBrowseLeft()) {
154 execute(browseLeft);
155 }
146 }], 156 }],
147 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputRightArrow 157 [UIKeyCommand cr_keyCommandWithInput:UIKeyInputRightArrow
148 modifierFlags:UIKeyModifierCommand 158 modifierFlags:UIKeyModifierCommand
149 title:l10n_util::GetNSStringWithFixup( 159 title:l10n_util::GetNSStringWithFixup(
150 browseRightDescriptionID) 160 browseRightDescriptionID)
151 action:^{ 161 action:^{
152 execute(browseRight); 162 if (canBrowseRight()) {
163 execute(browseRight);
164 }
153 }], 165 }],
154 ]]; 166 ]];
155 } 167 }
156 168
157 NSString* voiceSearchTitle = l10n_util::GetNSStringWithFixup( 169 NSString* voiceSearchTitle = l10n_util::GetNSStringWithFixup(
158 IDS_IOS_VOICE_SEARCH_KEYBOARD_DISCOVERY_TITLE); 170 IDS_IOS_VOICE_SEARCH_KEYBOARD_DISCOVERY_TITLE);
159 [keyCommands addObjectsFromArray:@[ 171 [keyCommands addObjectsFromArray:@[
160 [UIKeyCommand cr_keyCommandWithInput:@"y" 172 [UIKeyCommand cr_keyCommandWithInput:@"y"
161 modifierFlags:UIKeyModifierCommand 173 modifierFlags:UIKeyModifierCommand
162 title:l10n_util::GetNSStringWithFixup( 174 title:l10n_util::GetNSStringWithFixup(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 ]]; 213 ]];
202 214
203 // List the commands that don't appear in the HUD and only appear when there 215 // List the commands that don't appear in the HUD and only appear when there
204 // is at least a tab. 216 // is at least a tab.
205 if (hasTabs) { 217 if (hasTabs) {
206 [keyCommands addObjectsFromArray:@[ 218 [keyCommands addObjectsFromArray:@[
207 [UIKeyCommand cr_keyCommandWithInput:@"[" 219 [UIKeyCommand cr_keyCommandWithInput:@"["
208 modifierFlags:UIKeyModifierCommand 220 modifierFlags:UIKeyModifierCommand
209 title:nil 221 title:nil
210 action:^{ 222 action:^{
211 execute(browseLeft); 223 if (canBrowseLeft()) {
224 execute(browseLeft);
225 }
212 }], 226 }],
213 [UIKeyCommand cr_keyCommandWithInput:@"]" 227 [UIKeyCommand cr_keyCommandWithInput:@"]"
214 modifierFlags:UIKeyModifierCommand 228 modifierFlags:UIKeyModifierCommand
215 title:nil 229 title:nil
216 action:^{ 230 action:^{
217 execute(browseRight); 231 if (canBrowseRight()) {
232 execute(browseRight);
233 }
218 }], 234 }],
219 [UIKeyCommand cr_keyCommandWithInput:@"." 235 [UIKeyCommand cr_keyCommandWithInput:@"."
220 modifierFlags:UIKeyModifierCommand 236 modifierFlags:UIKeyModifierCommand
221 title:nil 237 title:nil
222 action:^{ 238 action:^{
223 execute(IDC_STOP); 239 execute(IDC_STOP);
224 }], 240 }],
225 [UIKeyCommand cr_keyCommandWithInput:@"?" 241 [UIKeyCommand cr_keyCommandWithInput:@"?"
226 modifierFlags:UIKeyModifierCommand 242 modifierFlags:UIKeyModifierCommand
227 title:nil 243 title:nil
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 action:^{ 312 action:^{
297 [weakConsumer focusNextTab]; 313 [weakConsumer focusNextTab];
298 }], 314 }],
299 ]]; 315 ]];
300 } 316 }
301 317
302 return keyCommands; 318 return keyCommands;
303 } 319 }
304 320
305 @end 321 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/key_commands_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698