Created
July 31, 2010 04:58
-
-
Save statonjr/501773 to your computer and use it in GitHub Desktop.
Implementing mouseDown: on WebKit input elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "MainWindow.h" | |
// MainWindow subclasses NSWindow | |
@implementation MainWindow | |
@synthesize webView, isHTMLInputElement; | |
// We intercept the sendEvent: method at the NSWindow level to inspect it. | |
// If the event type is a click ("NSLeftMouseDown") and the element that the mouse | |
// is hovering over is an input, then we do something | |
- (void)sendEvent:(NSEvent *)theEvent { | |
if ([theEvent type] == NSLeftMouseDown && isHTMLInputElement) { | |
[self doSomething]; | |
}; | |
[super sendEvent:theEvent]; | |
} | |
// MainWindow acts as the UIDelegate for your WebView | |
// When your mouse moves over an input, we set our BOOL isHTMLInputElement to YES | |
- (void)webView:(WebView *)sender mouseDidMoveOverElement:(NSDictionary *)elementInformation modifierFlags:(NSUInteger)modifierFlags { | |
DOMNode *node = [elementInformation objectForKey:@"WebElementDOMNode"]; | |
NSString *nodeName = [node nodeName]; | |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES 'INPUT'"]; | |
isHTMLInputElement = [predicate evaluateWithObject:nodeName]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment