fix: webContents interaction with draggable browserviews (#26496)
This commit is contained in:
parent
cad2d8b4aa
commit
d97612ed21
2 changed files with 47 additions and 28 deletions
|
@ -10,10 +10,10 @@ kinds of utility windows. Similarly for `disableAutoHideCursor`.
|
||||||
Additionally, disables usage of some private APIs in MAS builds.
|
Additionally, disables usage of some private APIs in MAS builds.
|
||||||
|
|
||||||
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
|
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
|
||||||
index eae6d8c330a523e85c7997e59091be0ce42031dc..3f23af8dca0d8a1fa149877cde1a553360610eba 100644
|
index eae6d8c330a523e85c7997e59091be0ce42031dc..d90f13139cfc9291c76824a6529e2931176d1079 100644
|
||||||
--- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
|
--- a/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
|
||||||
+++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
|
+++ b/content/app_shim_remote_cocoa/render_widget_host_view_cocoa.mm
|
||||||
@@ -154,6 +154,11 @@ void ExtractUnderlines(NSAttributedString* string,
|
@@ -154,6 +154,15 @@ void ExtractUnderlines(NSAttributedString* string,
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -21,11 +21,15 @@ index eae6d8c330a523e85c7997e59091be0ce42031dc..3f23af8dca0d8a1fa149877cde1a5533
|
||||||
+- (BOOL)acceptsFirstMouse;
|
+- (BOOL)acceptsFirstMouse;
|
||||||
+- (BOOL)disableAutoHideCursor;
|
+- (BOOL)disableAutoHideCursor;
|
||||||
+@end
|
+@end
|
||||||
|
+
|
||||||
|
+@interface NSView (ElectronCustomMethods)
|
||||||
|
+- (BOOL)shouldIgnoreMouseEvent;
|
||||||
|
+@end
|
||||||
+
|
+
|
||||||
// These are not documented, so use only after checking -respondsToSelector:.
|
// These are not documented, so use only after checking -respondsToSelector:.
|
||||||
@interface NSApplication (UndocumentedSpeechMethods)
|
@interface NSApplication (UndocumentedSpeechMethods)
|
||||||
- (void)speakString:(NSString*)string;
|
- (void)speakString:(NSString*)string;
|
||||||
@@ -573,6 +578,9 @@ - (BOOL)acceptsMouseEventsWhenInactive {
|
@@ -573,6 +582,9 @@ - (BOOL)acceptsMouseEventsWhenInactive {
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
|
- (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {
|
||||||
|
@ -35,7 +39,18 @@ index eae6d8c330a523e85c7997e59091be0ce42031dc..3f23af8dca0d8a1fa149877cde1a5533
|
||||||
return [self acceptsMouseEventsWhenInactive];
|
return [self acceptsMouseEventsWhenInactive];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -996,6 +1004,10 @@ - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv {
|
@@ -648,6 +660,10 @@ - (BOOL)shouldIgnoreMouseEvent:(NSEvent*)theEvent {
|
||||||
|
// its parent view.
|
||||||
|
BOOL hitSelf = NO;
|
||||||
|
while (view) {
|
||||||
|
+ if ([view respondsToSelector:@selector(shouldIgnoreMouseEvent)] && ![view shouldIgnoreMouseEvent]) {
|
||||||
|
+ return NO;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
if (view == self)
|
||||||
|
hitSelf = YES;
|
||||||
|
if ([view isKindOfClass:[self class]] && ![view isEqual:self] &&
|
||||||
|
@@ -996,6 +1012,10 @@ - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv {
|
||||||
eventType == NSKeyDown &&
|
eventType == NSKeyDown &&
|
||||||
!(modifierFlags & NSCommandKeyMask);
|
!(modifierFlags & NSCommandKeyMask);
|
||||||
|
|
||||||
|
@ -46,7 +61,7 @@ index eae6d8c330a523e85c7997e59091be0ce42031dc..3f23af8dca0d8a1fa149877cde1a5533
|
||||||
// We only handle key down events and just simply forward other events.
|
// We only handle key down events and just simply forward other events.
|
||||||
if (eventType != NSKeyDown) {
|
if (eventType != NSKeyDown) {
|
||||||
_hostHelper->ForwardKeyboardEvent(event, latency_info);
|
_hostHelper->ForwardKeyboardEvent(event, latency_info);
|
||||||
@@ -1772,9 +1784,11 @@ - (NSAccessibilityRole)accessibilityRole {
|
@@ -1772,9 +1792,11 @@ - (NSAccessibilityRole)accessibilityRole {
|
||||||
// Since this implementation doesn't have to wait any IPC calls, this doesn't
|
// Since this implementation doesn't have to wait any IPC calls, this doesn't
|
||||||
// make any key-typing jank. --hbono 7/23/09
|
// make any key-typing jank. --hbono 7/23/09
|
||||||
//
|
//
|
||||||
|
@ -58,7 +73,7 @@ index eae6d8c330a523e85c7997e59091be0ce42031dc..3f23af8dca0d8a1fa149877cde1a5533
|
||||||
|
|
||||||
- (NSArray*)validAttributesForMarkedText {
|
- (NSArray*)validAttributesForMarkedText {
|
||||||
// This code is just copied from WebKit except renaming variables.
|
// This code is just copied from WebKit except renaming variables.
|
||||||
@@ -1783,7 +1797,10 @@ - (NSArray*)validAttributesForMarkedText {
|
@@ -1783,7 +1805,10 @@ - (NSArray*)validAttributesForMarkedText {
|
||||||
initWithObjects:NSUnderlineStyleAttributeName,
|
initWithObjects:NSUnderlineStyleAttributeName,
|
||||||
NSUnderlineColorAttributeName,
|
NSUnderlineColorAttributeName,
|
||||||
NSMarkedClauseSegmentAttributeName,
|
NSMarkedClauseSegmentAttributeName,
|
||||||
|
|
|
@ -34,10 +34,16 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSView*)hitTest:(NSPoint)aPoint {
|
- (BOOL)shouldIgnoreMouseEvent {
|
||||||
// Pass-through events that don't hit one of the exclusion zones
|
NSEventType type = [[NSApp currentEvent] type];
|
||||||
|
return type != NSEventTypeLeftMouseDragged &&
|
||||||
|
type != NSEventTypeLeftMouseDown;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSView*)hitTest:(NSPoint)point {
|
||||||
|
// Pass-through events that hit one of the exclusion zones
|
||||||
for (NSView* exclusion_zones in [self subviews]) {
|
for (NSView* exclusion_zones in [self subviews]) {
|
||||||
if ([exclusion_zones hitTest:aPoint])
|
if ([exclusion_zones hitTest:point])
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +51,8 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent*)event {
|
- (void)mouseDown:(NSEvent*)event {
|
||||||
|
[super mouseDown:event];
|
||||||
|
|
||||||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
||||||
// According to Google, using performWindowDragWithEvent:
|
// According to Google, using performWindowDragWithEvent:
|
||||||
// does not generate a NSWindowWillMoveNotification. Hence post one.
|
// does not generate a NSWindowWillMoveNotification. Hence post one.
|
||||||
|
@ -65,7 +73,7 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
self.initialLocation = [event locationInWindow];
|
self.initialLocation = [event locationInWindow];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDragged:(NSEvent*)theEvent {
|
- (void)mouseDragged:(NSEvent*)event {
|
||||||
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
if ([self.window respondsToSelector:@selector(performWindowDragWithEvent)]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -125,15 +133,13 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
[self.window setFrameOrigin:newOrigin];
|
[self.window setFrameOrigin:newOrigin];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugging tips:
|
// For debugging purposes only.
|
||||||
// Uncomment the following four lines to color DragRegionView bright red
|
- (void)drawRect:(NSRect)aRect {
|
||||||
// #ifdef DEBUG_DRAG_REGIONS
|
if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) {
|
||||||
// - (void)drawRect:(NSRect)aRect
|
[[[NSColor greenColor] colorWithAlphaComponent:0.5] set];
|
||||||
// {
|
NSRectFill([self bounds]);
|
||||||
// [[NSColor redColor] set];
|
}
|
||||||
// NSRectFill([self bounds]);
|
}
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -146,15 +152,13 @@ const NSAutoresizingMaskOptions kDefaultAutoResizingMask =
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debugging tips:
|
// For debugging purposes only.
|
||||||
// Uncomment the following four lines to color ExcludeDragRegionView bright red
|
- (void)drawRect:(NSRect)aRect {
|
||||||
// #ifdef DEBUG_DRAG_REGIONS
|
if (getenv("ELECTRON_DEBUG_DRAG_REGIONS")) {
|
||||||
// - (void)drawRect:(NSRect)aRect
|
[[[NSColor redColor] colorWithAlphaComponent:0.5] set];
|
||||||
// {
|
NSRectFill([self bounds]);
|
||||||
// [[NSColor greenColor] set];
|
}
|
||||||
// NSRectFill([self bounds]);
|
}
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue