render_widget_host_view_mac.patch 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cheng Zhao <[email protected]>
  3. Date: Thu, 20 Sep 2018 17:46:28 -0700
  4. Subject: render_widget_host_view_mac.patch
  5. This allows Electron to override `acceptsFirstMouse` on Mac so that windows can
  6. respond to the first mouse click in their window, which is desirable for some
  7. kinds of utility windows. Similarly for `disableAutoHideCursor`.
  8. diff --git a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  9. index 788a11f06d3912cb50ffc6b493f7266a2eba617b..df6ef6912d0ffad09f0c52d68d7b2e4b46c42c2b 100644
  10. --- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  11. +++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  12. @@ -169,6 +169,15 @@ void ExtractUnderlines(NSAttributedString* string,
  13. } // namespace
  14. +@interface NSWindow (AtomCustomMethods)
  15. +- (BOOL)acceptsFirstMouse;
  16. +- (BOOL)disableAutoHideCursor;
  17. +@end
  18. +
  19. +@interface NSView (ElectronCustomMethods)
  20. +- (BOOL)shouldIgnoreMouseEvent;
  21. +@end
  22. +
  23. // RenderWidgetHostViewCocoa ---------------------------------------------------
  24. // Private methods:
  25. @@ -789,6 +798,9 @@ - (AcceptMouseEventsOption)acceptsMouseEventsOption {
  26. }
  27. - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
  28. + if ([self.window respondsToSelector:@selector(acceptsFirstMouse)] &&
  29. + [self.window acceptsFirstMouse])
  30. + return YES;
  31. // Enable "click-through" if mouse clicks are accepted in inactive windows
  32. return [self acceptsMouseEventsOption] > kAcceptMouseEventsInActiveWindow;
  33. }
  34. @@ -934,6 +946,10 @@ - (BOOL)shouldIgnoreMouseEvent:(NSEvent*)theEvent {
  35. // its parent view.
  36. BOOL hitSelf = NO;
  37. while (view) {
  38. + if ([view respondsToSelector:@selector(shouldIgnoreMouseEvent)] && ![view shouldIgnoreMouseEvent]) {
  39. + return NO;
  40. + }
  41. +
  42. if (view == self)
  43. hitSelf = YES;
  44. if ([view isKindOfClass:[self class]] && ![view isEqual:self] &&
  45. @@ -1268,6 +1284,10 @@ - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv {
  46. eventType == NSEventTypeKeyDown &&
  47. !(modifierFlags & NSEventModifierFlagCommand);
  48. + if ([theEvent.window respondsToSelector:@selector(disableAutoHideCursor)] &&
  49. + [theEvent.window disableAutoHideCursor])
  50. + shouldAutohideCursor = NO;
  51. +
  52. // We only handle key down events and just simply forward other events.
  53. if (eventType != NSEventTypeKeyDown) {
  54. _hostHelper->ForwardKeyboardEvent(event, latencyInfo);