render_widget_host_view_mac.patch 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 1393c9c8382dd405edd9a5515210176395a98fe5..38bd45e0ca66af9f78bb532e411db66dc8d9d5da 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. @@ -154,6 +154,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. // These are not documented, so use only after checking -respondsToSelector:.
  25. @interface NSApplication (UndocumentedSpeechMethods)
  26. - (void)speakString:(NSString*)string;
  27. @@ -610,6 +619,9 @@ - (BOOL)acceptsMouseEventsWhenInactive {
  28. }
  29. - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
  30. + if ([self.window respondsToSelector:@selector(acceptsFirstMouse)] &&
  31. + [self.window acceptsFirstMouse])
  32. + return YES;
  33. return [self acceptsMouseEventsWhenInactive];
  34. }
  35. @@ -686,6 +698,10 @@ - (BOOL)shouldIgnoreMouseEvent:(NSEvent*)theEvent {
  36. // its parent view.
  37. BOOL hitSelf = NO;
  38. while (view) {
  39. + if ([view respondsToSelector:@selector(shouldIgnoreMouseEvent)] && ![view shouldIgnoreMouseEvent]) {
  40. + return NO;
  41. + }
  42. +
  43. if (view == self)
  44. hitSelf = YES;
  45. if ([view isKindOfClass:[self class]] && ![view isEqual:self] &&
  46. @@ -1005,6 +1021,10 @@ - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv {
  47. eventType == NSKeyDown &&
  48. !(modifierFlags & NSCommandKeyMask);
  49. + if ([theEvent.window respondsToSelector:@selector(disableAutoHideCursor)] &&
  50. + [theEvent.window disableAutoHideCursor])
  51. + shouldAutohideCursor = NO;
  52. +
  53. // We only handle key down events and just simply forward other events.
  54. if (eventType != NSKeyDown) {
  55. _hostHelper->ForwardKeyboardEvent(event, latency_info);
  56. @@ -1751,9 +1771,11 @@ - (NSAccessibilityRole)accessibilityRole {
  57. // Since this implementation doesn't have to wait any IPC calls, this doesn't
  58. // make any key-typing jank. --hbono 7/23/09
  59. //
  60. +#ifndef MAS_BUILD
  61. extern "C" {
  62. extern NSString* NSTextInputReplacementRangeAttributeName;
  63. }
  64. +#endif
  65. - (NSArray*)validAttributesForMarkedText {
  66. // This code is just copied from WebKit except renaming variables.
  67. @@ -1762,7 +1784,10 @@ - (NSArray*)validAttributesForMarkedText {
  68. initWithObjects:NSUnderlineStyleAttributeName,
  69. NSUnderlineColorAttributeName,
  70. NSMarkedClauseSegmentAttributeName,
  71. - NSTextInputReplacementRangeAttributeName, nil]);
  72. +#ifndef MAS_BUILD
  73. + NSTextInputReplacementRangeAttributeName,
  74. +#endif
  75. + nil]);
  76. }
  77. return _validAttributesForMarkedText.get();
  78. }