Skip to content

Instantly share code, notes, and snippets.

@statonjr
Created July 31, 2010 04:58
Show Gist options
  • Save statonjr/501773 to your computer and use it in GitHub Desktop.
Save statonjr/501773 to your computer and use it in GitHub Desktop.
Implementing mouseDown: on WebKit input elements
#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