Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/cocoa/system_hotkey_map.h" | 5 #import "content/browser/cocoa/system_hotkey_map.h" |
| 6 | 6 |
| 7 #pragma mark - NSDictionary Helper Functions | 7 #pragma mark - NSDictionary Helper Functions |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 | 27 |
| 28 NSNumber* NumberForKey(NSDictionary* dict, NSString* key) { | 28 NSNumber* NumberForKey(NSDictionary* dict, NSString* key) { |
| 29 return ObjectForKey(dict, key, [NSNumber class]); | 29 return ObjectForKey(dict, key, [NSNumber class]); |
| 30 } | 30 } |
| 31 | 31 |
| 32 NSString* StringForKey(NSDictionary* dict, NSString* key) { | 32 NSString* StringForKey(NSDictionary* dict, NSString* key) { |
| 33 return ObjectForKey(dict, key, [NSString class]); | 33 return ObjectForKey(dict, key, [NSString class]); |
| 34 } | 34 } |
| 35 | 35 |
| 36 NSDictionary* kDefaultSymbolicHotKeys = @{ | |
| 37 // Default Window switch key binding: Command + ` | |
| 38 @"27" : @{ | |
| 39 @"enabled" : @YES, | |
| 40 @"value" : @{ | |
| 41 @"type" : @"standard", | |
| 42 @"parameters" : @[ @96, @50, @1048576 ], | |
|
erikchen
2016/04/01 03:55:12
Where did these numbers come from?
chongz
2016/04/01 19:47:18
They come from my local file, replaced with meanin
| |
| 43 } | |
| 44 } | |
| 45 }; | |
| 46 | |
| 36 } // namespace | 47 } // namespace |
| 37 | 48 |
| 38 #pragma mark - SystemHotkey | 49 #pragma mark - SystemHotkey |
| 39 | 50 |
| 40 namespace content { | 51 namespace content { |
| 41 | 52 |
| 42 struct SystemHotkey { | 53 struct SystemHotkey { |
| 43 unsigned short key_code; | 54 unsigned short key_code; |
| 44 NSUInteger modifiers; | 55 NSUInteger modifiers; |
| 45 }; | 56 }; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 68 | 79 |
| 69 return dictionary; | 80 return dictionary; |
| 70 } | 81 } |
| 71 | 82 |
| 72 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) { | 83 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) { |
| 73 system_hotkeys_.clear(); | 84 system_hotkeys_.clear(); |
| 74 | 85 |
| 75 if (!dictionary) | 86 if (!dictionary) |
| 76 return false; | 87 return false; |
| 77 | 88 |
| 78 NSDictionary* hotkey_dictionaries = | 89 NSDictionary* user_hotkey_dictionaries = |
| 79 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys"); | 90 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys"); |
| 80 if (!hotkey_dictionaries) | 91 if (!user_hotkey_dictionaries) |
| 81 return false; | 92 return false; |
| 82 | 93 |
| 94 // Safe for user disabled hotkeys. If a hotkey was disabled it will have | |
|
erikchen
2016/04/01 03:55:11
I don't understand your comment. I think you are t
chongz
2016/04/01 19:47:18
Done. I was trying to emphasize that not only modi
| |
| 95 // |enabled| set to "NO" instead of removed from |user_hotkey_dictionaries|. | |
|
erikchen
2016/04/01 03:55:11
Add a link to https://bugs.chromium.org/p/chromium
chongz
2016/04/01 19:47:18
Done.
| |
| 96 NSMutableDictionary* hotkey_dictionaries = | |
| 97 [kDefaultSymbolicHotKeys mutableCopy]; | |
|
erikchen
2016/04/01 03:55:12
You are leaking a reference. Use scoped_nsobject.
chongz
2016/04/01 19:47:17
Done.
| |
| 98 [hotkey_dictionaries addEntriesFromDictionary:user_hotkey_dictionaries]; | |
| 99 | |
| 83 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) { | 100 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) { |
| 84 if (![hotkey_system_effect isKindOfClass:[NSString class]]) | 101 if (![hotkey_system_effect isKindOfClass:[NSString class]]) |
| 85 continue; | 102 continue; |
| 86 | 103 |
| 87 NSDictionary* hotkey_dictionary = | 104 NSDictionary* hotkey_dictionary = |
| 88 [hotkey_dictionaries objectForKey:hotkey_system_effect]; | 105 [hotkey_dictionaries objectForKey:hotkey_system_effect]; |
| 89 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]]) | 106 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]]) |
| 90 continue; | 107 continue; |
| 91 | 108 |
| 92 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled"); | 109 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled"); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 if ((modifiers & required_modifiers) == 0) | 173 if ((modifiers & required_modifiers) == 0) |
| 157 return; | 174 return; |
| 158 | 175 |
| 159 SystemHotkey hotkey; | 176 SystemHotkey hotkey; |
| 160 hotkey.key_code = key_code; | 177 hotkey.key_code = key_code; |
| 161 hotkey.modifiers = modifiers; | 178 hotkey.modifiers = modifiers; |
| 162 system_hotkeys_.push_back(hotkey); | 179 system_hotkeys_.push_back(hotkey); |
| 163 } | 180 } |
| 164 | 181 |
| 165 } // namespace content | 182 } // namespace content |
| OLD | NEW |