Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am having trouble detecting events performed on a WebKit WebView. This is my code inside of the WebView subclass:

Code:
- (void)scrollWheel:(NSEvent *)theEvent
{
    if([theEvent phase])
    {
        NSLog(@"Scrolling!!");
    }
    else
    {
        NSLog(@"Scrolling!");    }
}

-(void)mouseDown:(NSEvent *)theEvent{
    NSLog(@"Mouse Down!!");
}

I create my instance of this custom WebView (named BlurWiseWebView) like so (inside the AppDelegate):

Code:
mBlurWiseWebView = [[BlurWiseWebView alloc]initWithFrame:NSMakeRect(0, 0, _window.frame.size.width,   _window.frame.size.height)];

I don't see anything wrong. Could someone please assist me?

Thanks!
 
Last edited:
Short answer this isn't really possible. To my knowledge events are passed directly to a private view inside webview class and you can not subclass.

If you just want the events you can try overriding hit test and passing a second view. It's a hacky way.

If you really want full control over all the events like I needed grab Chromium Embedded Framework.
 
For my purposes I think it might be simpler to overlay the web view with a custom NSView that just tracks the events. Is it possible to put an NSView atop a WebView and have it just log events so that the WebView still gets them and the custom NSView does not?
 
I need to clarify my question. I still need to perform tasks on the events, but I want to do it through the custom NSView that is on top of the WebView. This may not even be necessary though. My end goal is to move the my instance's y-value frame up by a certain increment whenever the user scrolls up. In other words, when a webpage is scrolled up inside the WebView, I would like the WebView itself to move up as well (as in its actual frame.) Is this still the right way to go about doing this?
 
I was trying to modify the events as well. It turned out to be a massive hassle. Using chromium embedded framework ended up being the simplest solution. You could try grabbing the events modifying them. Then reposting them into the event queue.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.