Make WebView from WebKit a drag and drop mouse in Cocoa

I would like to create a view of the working widget and it is very easy to style it with HTML / CSS. I decided to use WebView for this task.

I have a limitless NSWindow with a WebView inside. I want to make it draggable with the mouse (since any regular window can be dragged using its name, but by clicking somewhere inside my WebView ). Tried to subclass WebView and override mouseDown and mouseDragged , but this did not work (for obvious reasons).

Of course, I can create a transparent view above the WebView to solve the problem, but I really want to find a better way. Does anyone know how to do this?

+6
source share
1 answer

The problem was solved by overriding the - (void)sendEvent: in the parent subclass of NSWindow , for example:

 //Overriding mouse events - (void)sendEvent:(NSEvent *)theEvent { if ([theEvent type] == NSLeftMouseDown) { [self mouseDown:theEvent]; } else if ([theEvent type] == NSLeftMouseDragged) { [self mouseDragged:theEvent]; } else { [super sendEvent:theEvent]; } } 

I think this is the best solution.

+4
source

Source: https://habr.com/ru/post/892940/


All Articles