MouseDown: not working in subclass of WebView

I think it should be pretty simple, but I can't get it to work.

I want to detect mouse clicks in a WebView ...

I have subclassed WebView, here is the code

#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>

@interface ResultsWebView : WebView {
}
@end

and

#import "ResultsWebView.h"

@implementation ResultsWebView

- (void)mouseDown:(NSEvent *)theEvent {
    NSLog(@"%@", theEvent);
}

@end

In my xib file, I added a WebView and then changed the class to ResultsWebView.

I checked at runtime, and the object is the result of a WebView, but the mouseDown event is never raised ...

What am I missing?

+3
source share
3 answers

The problem is that the message is not sent to WebView. Instead, it is sent to a private WebHTMLView inside your WebView, which actually handles mouse events.

http://trac.webkit.org/browser/trunk/Source/WebKit/mac/WebView/WebHTMLView.mm#L3555

javascript WebView, onmousedown objective-c.

+3

WebUIDelegate .

, WebView NSWindowController:

WebView *aWebView;

UIDelegate, :

[aWebView setUIDelegate:self];

, :

- (void)webView:(WebView *)sender mouseDidMoveOverElement:
(NSDictionary *)elementInformation modifierFlags:(NSUInteger)
modifierFlags
{
if ([[NSApp currentEvent] type] == NSLeftMouseUp)
  NSLog(@"mouseDown event occurred");
}

, elementInformation, DOM, .

+4

, :

[window setAcceptsMouseMovedEvents:YES];
-2

All Articles