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

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: Replace http:// with https:// 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;
17 return object; 21 return object;
18 } 22 }
19 23
20 NSDictionary* DictionaryForKey(NSDictionary* dict, NSString* key) { 24 NSDictionary* DictionaryForKey(NSDictionary* dict, NSString* key) {
21 return ObjectForKey(dict, key, [NSDictionary class]); 25 return ObjectForKey(dict, key, [NSDictionary class]);
22 } 26 }
23 27
24 NSArray* ArrayForKey(NSDictionary* dict, NSString* key) { 28 NSArray* ArrayForKey(NSDictionary* dict, NSString* key) {
25 return ObjectForKey(dict, key, [NSArray class]); 29 return ObjectForKey(dict, key, [NSArray class]);
26 } 30 }
27 31
28 NSNumber* NumberForKey(NSDictionary* dict, NSString* key) { 32 NSNumber* NumberForKey(NSDictionary* dict, NSString* key) {
29 return ObjectForKey(dict, key, [NSNumber class]); 33 return ObjectForKey(dict, key, [NSNumber class]);
30 } 34 }
31 35
32 NSString* StringForKey(NSDictionary* dict, NSString* key) { 36 NSString* StringForKey(NSDictionary* dict, NSString* key) {
33 return ObjectForKey(dict, key, [NSString class]); 37 return ObjectForKey(dict, key, [NSString class]);
34 } 38 }
35 39
40 NSDictionary* kDefaultSymbolicHotKeys = @{
Avi (use Gerrit) 2016/04/01 20:03:56 Does using @{} at the top level cause static initi
chongz 2016/04/01 20:46:46 Done.
41 // Default Window switch key binding: Command + `
42 // Copied from local com.apple.symbolichotkeys.plist file since @"27" might
43 // missing but should still be handled as reserved.
44 // Note: The first parameter @96 is not used by |SystemHotkeyMap|.
45 @"27" : @{
46 @"enabled" : @YES,
47 @"value" : @{
48 @"type" : @"standard",
49 @"parameters" :
50 @[ @96 /* unused */, @(kVK_ANSI_Grave), @(NSCommandKeyMask) ],
51 }
52 }
53 };
54
36 } // namespace 55 } // namespace
37 56
38 #pragma mark - SystemHotkey 57 #pragma mark - SystemHotkey
39 58
40 namespace content { 59 namespace content {
41 60
42 struct SystemHotkey { 61 struct SystemHotkey {
43 unsigned short key_code; 62 unsigned short key_code;
44 NSUInteger modifiers; 63 NSUInteger modifiers;
45 }; 64 };
(...skipping 22 matching lines...) Expand all
68 87
69 return dictionary; 88 return dictionary;
70 } 89 }
71 90
72 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) { 91 bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) {
73 system_hotkeys_.clear(); 92 system_hotkeys_.clear();
74 93
75 if (!dictionary) 94 if (!dictionary)
76 return false; 95 return false;
77 96
78 NSDictionary* hotkey_dictionaries = 97 NSDictionary* user_hotkey_dictionaries =
79 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys"); 98 DictionaryForKey(dictionary, @"AppleSymbolicHotKeys");
80 if (!hotkey_dictionaries) 99 if (!user_hotkey_dictionaries)
81 return false; 100 return false;
82 101
102 // Start with a dictionary of default OS X hotkeys that are not necessarily
103 // listed in com.apple.symbolichotkeys.plist. If the user has overridden or
104 // disabled any of these hotkeys,
105 // -NSMutableDictionary addEntriesFromDictionary:] will ensure that the new
106 // values are used.
107 // See https://crbug.com/145062#c8
108 base::scoped_nsobject<NSMutableDictionary> hotkey_dictionaries(
109 [kDefaultSymbolicHotKeys mutableCopy]);
110 [hotkey_dictionaries addEntriesFromDictionary:user_hotkey_dictionaries];
Avi (use Gerrit) 2016/04/01 20:03:56 ... or rather than having a "constant" global kDef
chongz 2016/04/01 20:46:46 Didn't find a way to initialize NSMutableDictionar
111
83 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) { 112 for (NSString* hotkey_system_effect in [hotkey_dictionaries allKeys]) {
84 if (![hotkey_system_effect isKindOfClass:[NSString class]]) 113 if (![hotkey_system_effect isKindOfClass:[NSString class]])
85 continue; 114 continue;
86 115
87 NSDictionary* hotkey_dictionary = 116 NSDictionary* hotkey_dictionary =
88 [hotkey_dictionaries objectForKey:hotkey_system_effect]; 117 [hotkey_dictionaries objectForKey:hotkey_system_effect];
89 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]]) 118 if (![hotkey_dictionary isKindOfClass:[NSDictionary class]])
90 continue; 119 continue;
91 120
92 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled"); 121 NSNumber* enabled = NumberForKey(hotkey_dictionary, @"enabled");
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if ((modifiers & required_modifiers) == 0) 185 if ((modifiers & required_modifiers) == 0)
157 return; 186 return;
158 187
159 SystemHotkey hotkey; 188 SystemHotkey hotkey;
160 hotkey.key_code = key_code; 189 hotkey.key_code = key_code;
161 hotkey.modifiers = modifiers; 190 hotkey.modifiers = modifiers;
162 system_hotkeys_.push_back(hotkey); 191 system_hotkeys_.push_back(hotkey);
163 } 192 }
164 193
165 } // namespace content 194 } // 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