6

I'm working on something similar to the native picture in picture.

My window

I want to move this window, but can't because there is no titlebar (it's hidden and window.stylemask is fullSizeContentView) in it and it's fully filled with the webView.

So, I can't just click on titlebar and drag to move this window.

P.S. Sorry for my english. I hope the goal is clear

2 Answers2

7

You can subclass the webview to catch -mouseDown: events, and then pass the NSEvent to -[NSWindow performWindowDragWithEvent:].

Apple has sample code which uses this technique to start a window drag after the mouse moves some minimum distance, while still handling normal clicks. If you want to support basic interaction with the webview, this might be a good approach.

(Overriding -mouseDown: seems to work for WKWebView, it may not work with the legacy WebView. It's a bit of a hack, but you could use an overlay view to catch those events instead.)

Jeff
  • 194
  • 5
0

If you remove the two lines with highlight(true) (line 18) and self.highlight(false) (line ~40) the sample code works also for WKWebView.

MaFi
  • 1
  • 2