Can't Detect Events on a WebView

Discussion in 'Mac Programming' started by Blakeasd, Nov 24, 2013.

  1. Blakeasd, Nov 24, 2013
    Last edited: Nov 24, 2013

    Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    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!
     
  2. teagls macrumors regular

    Joined:
    May 16, 2013
    #2
    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.
     
  3. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    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?
     
  4. teagls macrumors regular

    Joined:
    May 16, 2013
    #4
  5. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #5
    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?
     
  6. teagls macrumors regular

    Joined:
    May 16, 2013
    #6
    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.
     

Share This Page