Index: content/browser/cocoa/system_hotkey_map.mm |
diff --git a/chrome/browser/ui/cocoa/system_hotkey_map.mm b/content/browser/cocoa/system_hotkey_map.mm |
similarity index 67% |
rename from chrome/browser/ui/cocoa/system_hotkey_map.mm |
rename to content/browser/cocoa/system_hotkey_map.mm |
index 9b649fbc729ca3745f81c1c926c0123543f566db..da04fa8b8442c66fa5c47410c25adeb2190fd3df 100644 |
--- a/chrome/browser/ui/cocoa/system_hotkey_map.mm |
+++ b/content/browser/cocoa/system_hotkey_map.mm |
@@ -2,9 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#import "chrome/browser/ui/cocoa/system_hotkey_map.h" |
- |
-#import <Cocoa/Cocoa.h> |
+#import "content/browser/cocoa/system_hotkey_map.h" |
#pragma mark - NSDictionary Helper Functions |
@@ -31,13 +29,19 @@ NSNumber* NumberForKey(NSDictionary* dict, NSString* key) { |
return ObjectForKey(dict, key, [NSNumber class]); |
} |
+NSString* StringForKey(NSDictionary* dict, NSString* key) { |
+ return ObjectForKey(dict, key, [NSString class]); |
+} |
+ |
} // namespace |
#pragma mark - SystemHotkey |
+namespace content { |
+ |
struct SystemHotkey { |
- int key_code; |
- int modifiers; |
+ unsigned short key_code; |
+ NSUInteger modifiers; |
}; |
#pragma mark - SystemHotkeyMap |
@@ -47,8 +51,9 @@ SystemHotkeyMap::SystemHotkeyMap() { |
SystemHotkeyMap::~SystemHotkeyMap() { |
} |
-bool SystemHotkeyMap::ParseData(NSData* data) { |
- system_hotkeys_.clear(); |
+NSDictionary* SystemHotkeyMap::DictionaryFromData(NSData* data) { |
+ if (!data) |
+ return nil; |
NSError* error = nil; |
NSPropertyListFormat format; |
@@ -57,10 +62,17 @@ bool SystemHotkeyMap::ParseData(NSData* data) { |
options:0 |
format:&format |
error:&error]; |
- if (error) |
- return false; |
if (![dictionary isKindOfClass:[NSDictionary class]]) |
+ return nil; |
+ |
+ return dictionary; |
+} |
+ |
+bool SystemHotkeyMap::ParseDictionary(NSDictionary* dictionary) { |
+ system_hotkeys_.clear(); |
+ |
+ if (!dictionary) |
return false; |
NSDictionary* hotkey_dictionaries = |
@@ -85,6 +97,10 @@ bool SystemHotkeyMap::ParseData(NSData* data) { |
if (!value) |
continue; |
+ NSString* type = StringForKey(value, @"type"); |
+ if (!type || ![type isEqualToString:@"standard"]) |
+ continue; |
+ |
NSArray* parameters = ArrayForKey(value, @"parameters"); |
if (!parameters || [parameters count] != 3) |
continue; |
@@ -97,14 +113,22 @@ bool SystemHotkeyMap::ParseData(NSData* data) { |
if (![modifiers isKindOfClass:[NSNumber class]]) |
continue; |
- ReserveHotkey(key_code.intValue, modifiers.intValue, hotkey_system_effect); |
+ ReserveHotkey(key_code.unsignedShortValue, |
+ modifiers.unsignedIntegerValue, |
+ hotkey_system_effect); |
} |
return true; |
} |
-bool SystemHotkeyMap::IsHotkeyReserved(int key_code, int modifiers) { |
- std::vector<SystemHotkey>::iterator it; |
+bool SystemHotkeyMap::IsEventReserved(NSEvent* event) const { |
+ return IsHotkeyReserved(event.keyCode, event.modifierFlags); |
+} |
+ |
+bool SystemHotkeyMap::IsHotkeyReserved(unsigned short key_code, |
+ NSUInteger modifiers) const { |
+ modifiers &= NSDeviceIndependentModifierFlagsMask; |
+ std::vector<SystemHotkey>::const_iterator it; |
for (it = system_hotkeys_.begin(); it != system_hotkeys_.end(); ++it) { |
if (it->key_code == key_code && it->modifiers == modifiers) |
return true; |
@@ -112,8 +136,8 @@ bool SystemHotkeyMap::IsHotkeyReserved(int key_code, int modifiers) { |
return false; |
} |
-void SystemHotkeyMap::ReserveHotkey(int key_code, |
- int modifiers, |
+void SystemHotkeyMap::ReserveHotkey(unsigned short key_code, |
+ NSUInteger modifiers, |
NSString* system_effect) { |
ReserveHotkey(key_code, modifiers); |
@@ -123,9 +147,19 @@ void SystemHotkeyMap::ReserveHotkey(int key_code, |
ReserveHotkey(key_code, modifiers | NSShiftKeyMask); |
} |
-void SystemHotkeyMap::ReserveHotkey(int key_code, int modifiers) { |
+void SystemHotkeyMap::ReserveHotkey(unsigned short key_code, |
+ NSUInteger modifiers) { |
+ // Hotkeys require at least one of control, command, or alternate keys to be |
+ // down. |
+ NSUInteger required_modifiers = |
+ NSControlKeyMask | NSCommandKeyMask | NSAlternateKeyMask; |
+ if ((modifiers & required_modifiers) == 0) |
+ return; |
+ |
SystemHotkey hotkey; |
hotkey.key_code = key_code; |
hotkey.modifiers = modifiers; |
system_hotkeys_.push_back(hotkey); |
} |
+ |
+} // namespace content |