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 #ifndef CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_MAP_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_SYSTEM_HOTKEY_MAP_H_ |
6 #define CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_MAP_H_ | 6 #define CHROME_BROWSER_UI_COCOA_SYSTEM_HOTKEY_MAP_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Foundation/Foundation.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/gtest_prod_util.h" | |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "content/common/content_export.h" | |
14 | |
15 namespace content { | |
16 | 12 |
17 struct SystemHotkey; | 13 struct SystemHotkey; |
18 | 14 |
19 // Maintains a listing of all OSX system hotkeys. e.g. (cmd + `) These hotkeys | 15 // Maintains a listing of all OSX user modifiable hotkeys. e.g. (cmd + `) |
20 // should have higher priority than web content, so NSEvents that correspond to | 16 class SystemHotkeyMap { |
21 // a system hotkey should not be passed to the renderer. | |
22 class CONTENT_EXPORT SystemHotkeyMap { | |
23 public: | 17 public: |
24 SystemHotkeyMap(); | 18 SystemHotkeyMap(); |
25 ~SystemHotkeyMap(); | 19 ~SystemHotkeyMap(); |
26 | 20 |
27 // Converts the plist stored in |data| into an NSDictionary. Returns nil on | |
28 // error. | |
29 static NSDictionary* DictionaryFromData(NSData* data); | |
30 | |
31 // Parses the property list data commonly stored at | 21 // Parses the property list data commonly stored at |
32 // ~/Library/Preferences/com.apple.symbolichotkeys.plist | 22 // ~/Library/Preferences/com.apple.symbolichotkeys.plist |
33 // Returns false on encountering an irrecoverable error. | 23 // Returns false on encountering an irrecoverable error. |
34 // Can be called multiple times. Only the results from the most recent | 24 // Can be called multiple times. Only the results from the most recent |
35 // invocation are stored. | 25 // invocation are stored. |
36 bool ParseDictionary(NSDictionary* dictionary); | 26 bool ParseData(NSData* data); |
37 | 27 |
38 // Whether the event corresponds to a hotkey that has been reserved by the | 28 // Whether the hotkey has been reserved by the user. |
39 // system. | 29 bool IsHotkeyReserved(int key_code, int modifiers); |
40 bool IsEventReserved(NSEvent* event) const; | |
41 | 30 |
42 private: | 31 private: |
43 FRIEND_TEST_ALL_PREFIXES(SystemHotkeyMapTest, Parse); | |
44 | |
45 // Whether the hotkey has been reserved by the user. | |
46 bool IsHotkeyReserved(int key_code, int modifiers) const; | |
47 | |
48 // Create at least one record of a hotkey that is reserved by the user. | 32 // Create at least one record of a hotkey that is reserved by the user. |
49 // Certain system hotkeys automatically reserve multiple key combinations. | 33 // Certain system hotkeys automatically reserve multiple key combinations. |
50 void ReserveHotkey(int key_code, int modifiers, NSString* system_effect); | 34 void ReserveHotkey(int key_code, int modifiers, NSString* system_effect); |
51 | 35 |
52 // Create a record of a hotkey that is reserved by the user. | 36 // Create a record of a hotkey that is reserved by the user. |
53 void ReserveHotkey(int key_code, int modifiers); | 37 void ReserveHotkey(int key_code, int modifiers); |
54 | 38 |
55 std::vector<SystemHotkey> system_hotkeys_; | 39 std::vector<SystemHotkey> system_hotkeys_; |
56 | 40 |
57 DISALLOW_COPY_AND_ASSIGN(SystemHotkeyMap); | 41 DISALLOW_COPY_AND_ASSIGN(SystemHotkeyMap); |
58 }; | 42 }; |
59 | 43 |
60 } // namespace content | 44 #endif // CHROME_BROWSER_UI_COCOA_SYSTEM_HOTKEY_MAP_H_ |
61 | |
62 #endif // CONTENT_BROWSER_COCOA_SYSTEM_HOTKEY_MAP_H_ | |
OLD | NEW |