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