|
@@ -7,6 +7,8 @@
|
|
|
#include "base/strings/sys_string_conversions.h"
|
|
|
#include "electron/mas.h"
|
|
|
#include "shell/browser/native_window_mac.h"
|
|
|
+#include "shell/browser/ui/cocoa/delayed_native_view_host.h"
|
|
|
+#include "shell/browser/ui/cocoa/electron_inspectable_web_contents_view.h"
|
|
|
#include "shell/browser/ui/cocoa/electron_preview_item.h"
|
|
|
#include "shell/browser/ui/cocoa/electron_touch_bar.h"
|
|
|
#include "shell/browser/ui/cocoa/root_view_mac.h"
|
|
@@ -189,6 +191,42 @@ void SwizzleSwipeWithEvent(NSView* view, SEL swiz_selector) {
|
|
|
|
|
|
// NSWindow overrides.
|
|
|
|
|
|
+- (void)sendEvent:(NSEvent*)event {
|
|
|
+ // Draggable regions only respond to left-click dragging, but the system will
|
|
|
+ // still suppress right-clicks in a draggable region. Forwarding right-clicks
|
|
|
+ // and ctrl+left-clicks allows the underlying views to respond to right-click
|
|
|
+ // to potentially bring up a frame context menu. WebContentsView is now a
|
|
|
+ // sibling view of the NSWindow contentView, so we need to intercept the event
|
|
|
+ // here as NativeWidgetMacNSWindow won't forward it to the WebContentsView
|
|
|
+ // anymore.
|
|
|
+ if (event.type == NSEventTypeRightMouseDown ||
|
|
|
+ (event.type == NSEventTypeLeftMouseDown &&
|
|
|
+ ([event modifierFlags] & NSEventModifierFlagControl))) {
|
|
|
+ // The WebContentsView is added a sibling of BaseWindow's contentView at
|
|
|
+ // index 0 before it in the paint order - see
|
|
|
+ // https://github.com/electron/electron/pull/41256.
|
|
|
+ const auto& children = shell_->GetContentsView()->children();
|
|
|
+ if (children.empty())
|
|
|
+ return;
|
|
|
+
|
|
|
+ auto* wcv = children.front().get();
|
|
|
+ if (!wcv)
|
|
|
+ return;
|
|
|
+
|
|
|
+ auto ns_view = static_cast<electron::DelayedNativeViewHost*>(wcv)
|
|
|
+ ->GetNativeView()
|
|
|
+ .GetNativeNSView();
|
|
|
+ if (!ns_view)
|
|
|
+ return;
|
|
|
+
|
|
|
+ [static_cast<ElectronInspectableWebContentsView*>(ns_view)
|
|
|
+ redispatchContextMenuEvent:base::apple::OwnedNSEvent(event)];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ [super sendEvent:event];
|
|
|
+}
|
|
|
+
|
|
|
- (void)rotateWithEvent:(NSEvent*)event {
|
|
|
shell_->NotifyWindowRotateGesture(event.rotation);
|
|
|
}
|