mouseDown: not firing in WebView subclass

前端 未结 3 1580
春和景丽
春和景丽 2020-12-18 10:40

I think this should be quite simple, but I cannot make it work.

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

I\'ve subclassed WebView, here

3条回答
  •  情歌与酒
    2020-12-18 11:11

    WebUIDelegate comes into rescue.

    Supposing that you have a WebView instance in your NSWindowController:

    WebView *aWebView;
    

    You can set your controller as UIDelegate, as follow:

    [aWebView setUIDelegate:self];
    

    implementing the following method within your controller, you will have a form of control over mouse click events:

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

    as a bonus, playing with the elementInformation dictionary you can get additional informations about the DOM element in which click event occurred.

提交回复
热议问题