render_widget_host_view_mac.patch 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. Additionally, disables usage of some private APIs in MAS builds.
  9. 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
  10. index 0bdd7c7813fdbbf148fe1fba2c38ef78d2923efc..c11453b8e3ce6345eead3b80c4f9036a1d07f5c7 100644
  11. --- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  12. +++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
  13. @@ -157,6 +157,15 @@ void ExtractUnderlines(NSAttributedString* string,
  14. } // namespace
  15. +@interface NSWindow (AtomCustomMethods)
  16. +- (BOOL)acceptsFirstMouse;
  17. +- (BOOL)disableAutoHideCursor;
  18. +@end
  19. +
  20. +@interface NSView (ElectronCustomMethods)
  21. +- (BOOL)shouldIgnoreMouseEvent;
  22. +@end
  23. +
  24. // RenderWidgetHostViewCocoa ---------------------------------------------------
  25. // Private methods:
  26. @@ -744,6 +753,9 @@ - (BOOL)acceptsMouseEventsWhenInactive {
  27. }
  28. - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
  29. + if ([self.window respondsToSelector:@selector(acceptsFirstMouse)] &&
  30. + [self.window acceptsFirstMouse])
  31. + return YES;
  32. return [self acceptsMouseEventsWhenInactive];
  33. }
  34. @@ -820,6 +832,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. @@ -1139,6 +1155,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, latency_info);
  55. @@ -1970,15 +1990,21 @@ - (NSAccessibilityRole)accessibilityRole {
  56. // Since this implementation doesn't have to wait any IPC calls, this doesn't
  57. // make any key-typing jank. --hbono 7/23/09
  58. //
  59. +#if !IS_MAS_BUILD()
  60. extern "C" {
  61. extern NSString* NSTextInputReplacementRangeAttributeName;
  62. }
  63. +#endif
  64. - (NSArray*)validAttributesForMarkedText {
  65. // This code is just copied from WebKit except renaming variables.
  66. static NSArray* const kAttributes = @[
  67. NSUnderlineStyleAttributeName, NSUnderlineColorAttributeName,
  68. +#if !IS_MAS_BUILD()
  69. NSMarkedClauseSegmentAttributeName, NSTextInputReplacementRangeAttributeName
  70. +#else
  71. + NSMarkedClauseSegmentAttributeName
  72. +#endif
  73. ];
  74. return kAttributes;
  75. }