ryanmcgrath / cacao

Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
MIT License
1.8k stars 65 forks source link

implement acceptsFirstMouse on webview #69

Closed httnn closed 1 year ago

httnn commented 1 year ago

this change implements the acceptsFirstMouse method on the webview class always returning YES from it.

By default, a mouse-down event in a window that isn’t the key window simply brings the window forward and makes it key; the event isn’t sent to the NSView object over which the mouse click occurs. The NSView can claim an initial mouse-down event, however, by overriding acceptsFirstMouse: to return YES.

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html

there are at least two remaining questions:

  1. should the return value be configurable via the api? e.g. webview.set_accepts_first_mouse(bool)
  2. should this also be implemented on other view classes in cacao?

i can't think of a scenario where someone wouldn't want a webview to behave this way since swallowing the first mouse-down event on a window seems like bad UX to me. i might be missing something obvious though.

ryanmcgrath commented 1 year ago

I'd say yeah, let's make it configurable - and yeah, let's default it to yes. I view cacao as an opinionated approach to macOS/iOS stuff, and I agree most people would want this defaulted - but it's certainly conceivable that someone might want the default behavior.

ryanmcgrath commented 1 year ago

This makes enough sense from a UX perspective that I'm going to go ahead and merge it, and we can see if someone PR's needing the opposite approach. Thanks for the contribution!

httnn commented 1 year ago

yeah, i think most macOS apps behave this way which is why users have probably grown to expect this behaviour and why it makes sense to make this behaviour the default. thanks for merging! :)