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

Side by Side Diff: content/browser/cocoa/system_hotkey_map.mm

Issue 1853533002: Add default hotkey dictionary for com.apple.symbolichotkeys.plist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: avi's review Created 4 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
« no previous file with comments | « no previous file | content/browser/cocoa/system_hotkey_map_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #import <Carbon/Carbon.h>
8
9 #include "base/mac/scoped_nsobject.h"
10
7 #pragma mark - NSDictionary Helper Functions 11 #pragma mark - NSDictionary Helper Functions
8 12
9 namespace { 13 namespace {
10 14
11 // All 4 following functions return nil if the object doesn't exist, or isn't of 15 // All 4 following functions return nil if the object doesn't exist, or isn't of
12 // the right class. 16 // the right class.
13 id ObjectForKey(NSDictionary* dict, NSString* key, Class aClass) { 17 id ObjectForKey(NSDictionary* dict, NSString* key, Class aClass) {
14 id object = [dict objectForKey:key]; 18 id object = [dict objectForKey:key];
15 if (![object isKindOfClass:aClass]) 19 if (![object isKindOfClass:aClass])
16 return nil; 20 return nil;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 72
69 return dictionary; 73 return dictionary;
70 } 74 }
71 75
72 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) { 76 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) {
73 system_hotkeys_.clear(); 77 system_hotkeys_.clear();
74 78
75 if (!dictionary) 79 if (!dictionary)
76 return false; 80 return false;
77 81
78 NSDictionary* hotkey_dictionaries = 82 NSDictionary* user_hotkey_dictionaries =
79 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys"); 83 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys");
80 if (!hotkey_dictionaries) 84 if (!user_hotkey_dictionaries)
81 return false; 85 return false;
82 86
87 // Start with a dictionary of default OS X hotkeys that are not necessarily
88 // listed in com.apple.symbolichotkeys.plist, but should still be handled as
89 // reserved.
90 // If the user has overridden or disabled any of these hotkeys,
91 // -NSMutableDictionary addEntriesFromDictionary:] will ensure that the new
92 // values are used.
93 // See https://crbug.com/145062#c8
94 base::scoped_nsobject<NSMutableDictionary> hotkey_dictionaries([@{
95 // Default Window switch key binding: Command + `
96 // Note: The first parameter @96 is not used by |SystemHotkeyMap|.
97 @"27" : @{
98 @"enabled" : @YES,
99 @"value" : @{
100 @"type" : @"standard",
101 @"parameters" :
102 @[ @96 /* unused */, @(kVK_ANSI_Grave), @(NSCommandKeyMask) ],
103 }
104 }
105 } mutableCopy]);
106 [hotkey_dictionaries addEntriesFromDictionary:user_hotkey_dictionaries];
107
83 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) { 108 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) {
84 if (![hotkey_system_effect isKindOfClass:[NSString class]]) 109 if (![hotkey_system_effect isKindOfClass:[NSString class]])
85 continue; 110 continue;
86 111
87 NSDictionary* hotkey_dictionary = 112 NSDictionary* hotkey_dictionary =
88 [hotkey_dictionaries objectForKey:hotkey_system_effect]; 113 [hotkey_dictionaries objectForKey:hotkey_system_effect];
89 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]]) 114 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]])
90 continue; 115 continue;
91 116
92 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled"); 117 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled");
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if ((modifiers & required_modifiers) == 0) 181 if ((modifiers & required_modifiers) == 0)
157 return; 182 return;
158 183
159 SystemHotkey hotkey; 184 SystemHotkey hotkey;
160 hotkey.key_code = key_code; 185 hotkey.key_code = key_code;
161 hotkey.modifiers = modifiers; 186 hotkey.modifiers = modifiers;
162 system_hotkeys_.push_back(hotkey); 187 system_hotkeys_.push_back(hotkey);
163 } 188 }
164 189
165 } // namespace content 190 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/cocoa/system_hotkey_map_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698