OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/common/extensions/command.h" | 5 #include "chrome/common/extensions/command.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 accelerator); | 70 accelerator); |
71 return ui::Accelerator(); | 71 return ui::Accelerator(); |
72 } | 72 } |
73 | 73 |
74 // Now, parse it into an accelerator. | 74 // Now, parse it into an accelerator. |
75 int modifiers = ui::EF_NONE; | 75 int modifiers = ui::EF_NONE; |
76 ui::KeyboardCode key = ui::VKEY_UNKNOWN; | 76 ui::KeyboardCode key = ui::VKEY_UNKNOWN; |
77 for (size_t i = 0; i < tokens.size(); i++) { | 77 for (size_t i = 0; i < tokens.size(); i++) { |
78 if (tokens[i] == values::kKeyCtrl) { | 78 if (tokens[i] == values::kKeyCtrl) { |
79 modifiers |= ui::EF_CONTROL_DOWN; | 79 modifiers |= ui::EF_CONTROL_DOWN; |
80 } else if (tokens[i] == values::kKeyCommand) { | 80 } else if (tokens[i] == values::kKeyCommand || |
81 if (platform_key == values::kKeybindingPlatformMac) { | 81 tokens[i] == values::kKeySearch) { |
Finnur
2014/08/21 11:18:11
This isn't right. This makes Search map over to Co
David Tseng
2014/08/21 16:03:04
Hmm...this cl was branched off of the other change
| |
82 if (platform_key == values::kKeybindingPlatformMac || | |
83 platform_key == values::kKeybindingPlatformChromeOs) { | |
82 // Either the developer specified Command+foo in the manifest for Mac or | 84 // Either the developer specified Command+foo in the manifest for Mac or |
83 // they specified Ctrl and it got normalized to Command (to get Ctrl on | 85 // they specified Ctrl and it got normalized to Command (to get Ctrl on |
84 // Mac the developer has to specify MacCtrl). Therefore we treat this | 86 // Mac the developer has to specify MacCtrl). Therefore we treat this |
85 // as Command. | 87 // as Command. |
88 // Search maps to command on Chrome OS. | |
86 modifiers |= ui::EF_COMMAND_DOWN; | 89 modifiers |= ui::EF_COMMAND_DOWN; |
87 #if defined(OS_MACOSX) | 90 #if defined(OS_MACOSX) |
88 } else if (platform_key == values::kKeybindingPlatformDefault) { | 91 } else if (platform_key == values::kKeybindingPlatformDefault) { |
89 // If we see "Command+foo" in the Default section it can mean two | 92 // If we see "Command+foo" in the Default section it can mean two |
90 // things, depending on the platform: | 93 // things, depending on the platform: |
91 // The developer specified "Ctrl+foo" for Default and it got normalized | 94 // The developer specified "Ctrl+foo" for Default and it got normalized |
92 // on Mac to "Command+foo". This is fine. Treat it as Command. | 95 // on Mac to "Command+foo". This is fine. Treat it as Command. |
93 modifiers |= ui::EF_COMMAND_DOWN; | 96 modifiers |= ui::EF_COMMAND_DOWN; |
94 #endif | 97 #endif |
95 } else { | 98 } else { |
96 // No other platform supports Command. | 99 // No other platform supports Command. |
97 key = ui::VKEY_UNKNOWN; | 100 key = ui::VKEY_UNKNOWN; |
98 break; | 101 break; |
99 } | 102 } |
103 } else if (tokens[i] == values::kKeySearch) { | |
104 // Search is a special modifier only on ChromeOS and maps to 'Command'. | |
105 if (platform_key == values::kKeybindingPlatformChromeOs) { | |
106 modifiers |= ui::EF_COMMAND_DOWN; | |
107 #if defined(OS_CHROMEOS) | |
108 } else if (platform_key == values::kKeybindingPlatformDefault) { | |
109 // Allow the search modifier here (similar to the treatment of command). | |
110 modifiers |= ui::EF_COMMAND_DOWN; | |
111 #endif | |
112 } else { | |
113 // No other platform supports search. | |
114 key = ui::VKEY_UNKNOWN; | |
115 break; | |
116 } | |
Finnur
2014/08/21 11:18:10
Is this copy-pasted from an old version of a CL I
David Tseng
2014/08/21 16:17:56
Acknowledged.
| |
100 } else if (tokens[i] == values::kKeyAlt) { | 117 } else if (tokens[i] == values::kKeyAlt) { |
101 modifiers |= ui::EF_ALT_DOWN; | 118 modifiers |= ui::EF_ALT_DOWN; |
102 } else if (tokens[i] == values::kKeyShift) { | 119 } else if (tokens[i] == values::kKeyShift) { |
103 modifiers |= ui::EF_SHIFT_DOWN; | 120 modifiers |= ui::EF_SHIFT_DOWN; |
104 } else if (tokens[i].size() == 1 || // A-Z, 0-9. | 121 } else if (tokens[i].size() == 1 || // A-Z, 0-9. |
105 tokens[i] == values::kKeyComma || | 122 tokens[i] == values::kKeyComma || |
106 tokens[i] == values::kKeyPeriod || | 123 tokens[i] == values::kKeyPeriod || |
107 tokens[i] == values::kKeyUp || | 124 tokens[i] == values::kKeyUp || |
108 tokens[i] == values::kKeyDown || | 125 tokens[i] == values::kKeyDown || |
109 tokens[i] == values::kKeyLeft || | 126 tokens[i] == values::kKeyLeft || |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 | 313 |
297 // Ctrl and Alt are mutually exclusive. | 314 // Ctrl and Alt are mutually exclusive. |
298 if (accelerator.IsCtrlDown()) | 315 if (accelerator.IsCtrlDown()) |
299 shortcut += values::kKeyCtrl; | 316 shortcut += values::kKeyCtrl; |
300 else if (accelerator.IsAltDown()) | 317 else if (accelerator.IsAltDown()) |
301 shortcut += values::kKeyAlt; | 318 shortcut += values::kKeyAlt; |
302 if (!shortcut.empty()) | 319 if (!shortcut.empty()) |
303 shortcut += values::kKeySeparator; | 320 shortcut += values::kKeySeparator; |
304 | 321 |
305 if (accelerator.IsCmdDown()) { | 322 if (accelerator.IsCmdDown()) { |
323 #if defined(OS_CHROMEOS) | |
324 shortcut += values::kKeySearch; | |
325 #else | |
306 shortcut += values::kKeyCommand; | 326 shortcut += values::kKeyCommand; |
327 #endif | |
Finnur
2014/08/21 11:18:10
Yeah, it seems like this CL could use a sync up wi
David Tseng
2014/08/21 16:17:56
Acknowledged.
| |
307 shortcut += values::kKeySeparator; | 328 shortcut += values::kKeySeparator; |
308 } | 329 } |
309 | 330 |
310 if (accelerator.IsShiftDown()) { | 331 if (accelerator.IsShiftDown()) { |
311 shortcut += values::kKeyShift; | 332 shortcut += values::kKeyShift; |
312 shortcut += values::kKeySeparator; | 333 shortcut += values::kKeySeparator; |
313 } | 334 } |
314 | 335 |
315 if (accelerator.key_code() >= ui::VKEY_0 && | 336 if (accelerator.key_code() >= ui::VKEY_0 && |
316 accelerator.key_code() <= ui::VKEY_9) { | 337 accelerator.key_code() <= ui::VKEY_9) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 extension_data->SetBoolean("active", active); | 555 extension_data->SetBoolean("active", active); |
535 extension_data->SetString("keybinding", accelerator().GetShortcutText()); | 556 extension_data->SetString("keybinding", accelerator().GetShortcutText()); |
536 extension_data->SetString("command_name", command_name()); | 557 extension_data->SetString("command_name", command_name()); |
537 extension_data->SetString("extension_id", extension->id()); | 558 extension_data->SetString("extension_id", extension->id()); |
538 extension_data->SetBoolean("global", global()); | 559 extension_data->SetBoolean("global", global()); |
539 extension_data->SetBoolean("extension_action", extension_action); | 560 extension_data->SetBoolean("extension_action", extension_action); |
540 return extension_data; | 561 return extension_data; |
541 } | 562 } |
542 | 563 |
543 } // namespace extensions | 564 } // namespace extensions |
OLD | NEW |