4
votes

If I create a WebView and add it to NSThemeFrame like so:

Let window be the NSWindow instance I'm adding to:

NSView * themeFrame = window.contentView;
[themeFrame.superview addSubview:myWebView];

Then any :hover tags of elements in the page I load doesn't work anymore. However, the :hover does appear on mouseDown/mouseUp. So maybe this is a refresh issue. I tried calling [myWebView setNeedsDisplay:YES] in mouseMoved: but no luck.

Is there something special about contentView? I tried the same thing with an NSView and overrode its mouseMoved: method while calling setNeedsDisplay and the NSView handled mouseMove fine. Is there something special about :hover?

Any ideas or ramblings are welcome!

I might have the same problem as Cocoa WebView on os X not firing mouse hover events without having to click and hold left mouse key but there's no answer there.

1
Any progress on this issue?OpenThread

1 Answers

1
votes

I had a similar problem and after debugging and reading the source of WebKit, I found a solution. The crucial part seems to the WebHTMLView class, specifically the method -[WebHTMLView _updateMouseoverWithEvent:]. There's a check whether the view's window is a key window and sure enough, my window wasn't key even though I called makeKeyWindow on it.

My window was a child window of a document window and to solve the hover issue, I created a NSWindow subclass and overrode isKeyWindow like this:

- (BOOL)isKeyWindow
{
    return [super isKeyWindow] || [[self parentWindow] isKeyWindow];
}

This made hover work in WebView in my document's child window.