WebCore:
[WebKit-https.git] / WebKit / Misc.subproj / WebNSEventExtras.m
1 /*
2     WebNSEventExtras.m
3     Copyright (c) 2003, Apple, Inc. All rights reserved.
4 */
5
6 #import <WebKit/WebNSEventExtras.h>
7
8 #import <AppKit/NSKeyBindingManager.h>
9
10 @implementation NSEvent (WebExtras)
11
12 -(BOOL)_web_isKeyEvent:(unichar)key
13 {
14     int type = [self type];
15     if (type != NSKeyDown && type != NSKeyUp)
16         return NO;
17     
18     NSString *chars = [self charactersIgnoringModifiers];
19     if ([chars length] != 1)
20         return NO;
21     
22     unichar c = [chars characterAtIndex:0];
23     if (c != key)
24         return NO;
25     
26     return YES;
27 }
28
29 - (BOOL)_web_isDeleteKeyEvent
30 {
31     const unichar deleteKey = NSDeleteCharacter;
32     const unichar deleteForwardKey = NSDeleteFunctionKey;
33     return [self _web_isKeyEvent:deleteKey] || [self _web_isKeyEvent:deleteForwardKey];
34 }
35
36 - (BOOL)_web_isEscapeKeyEvent
37 {
38     const unichar escapeKey = 0x001b;
39     return [self _web_isKeyEvent:escapeKey];
40 }
41
42 - (BOOL)_web_isOptionTabKeyEvent
43 {
44     return ([self modifierFlags] & NSAlternateKeyMask) && [self _web_isTabKeyEvent];
45 }
46
47 - (BOOL)_web_isReturnOrEnterKeyEvent
48 {
49     const unichar enterKey = NSEnterCharacter;
50     const unichar returnKey = NSCarriageReturnCharacter;
51     return [self _web_isKeyEvent:enterKey] || [self _web_isKeyEvent:returnKey];
52 }
53
54 - (BOOL)_web_isTabKeyEvent
55 {
56     const unichar tabKey = 0x0009;
57     const unichar shiftTabKey = 0x0019;
58     return [self _web_isKeyEvent:tabKey] || [self _web_isKeyEvent:shiftTabKey];
59 }
60
61 - (BOOL)_web_keyBindingManagerHasBinding
62 {
63     NSDictionary *keyBindings = [[NSKeyBindingManager sharedKeyBindingManager] dictionary];
64     return [keyBindings objectForKey:[self characters]] != nil;
65 }
66
67 @end