fix: fallback to old MacOS context menu behavior if no frame is present (#46595)
* fix: fallback to old MacOS context menu behavior if no frame is present Co-authored-by: georgexu99 <georgexu99@electronjs.org> Co-authored-by: erickzhao <erickzhao@electronjs.org> Co-authored-by: clavin <calvin@electronjs.org> * docs: add additional option for focusedFrame * fix: handle frame found, but no view update from rfh * fix: fix conditional Co-authored-by: Calvin <clavin@users.noreply.github.com> --------- Co-authored-by: georgexu99 <georgexu99@electronjs.org> Co-authored-by: erickzhao <erickzhao@electronjs.org> Co-authored-by: clavin <calvin@electronjs.org> Co-authored-by: Calvin <clavin@users.noreply.github.com>
This commit is contained in:
parent
3064b24c9d
commit
a9b2ec514b
2 changed files with 28 additions and 11 deletions
|
@ -74,7 +74,7 @@ The `menu` object has the following instance methods:
|
||||||
* `options` Object (optional)
|
* `options` Object (optional)
|
||||||
* `window` [BaseWindow](base-window.md) (optional) - Default is the focused window.
|
* `window` [BaseWindow](base-window.md) (optional) - Default is the focused window.
|
||||||
* `frame` [WebFrameMain](web-frame-main.md) (optional) - Provide the relevant frame
|
* `frame` [WebFrameMain](web-frame-main.md) (optional) - Provide the relevant frame
|
||||||
if you want certain OS-level features such as Writing Tools on macOS to function correctly. Typically, this should be `params.frame` from the [`context-menu` event](web-contents.md#event-context-menu) on a WebContents.
|
if you want certain OS-level features such as Writing Tools on macOS to function correctly. Typically, this should be `params.frame` from the [`context-menu` event](web-contents.md#event-context-menu) on a WebContents, or the [`focusedFrame` property](web-contents.md#contentsfocusedframe-readonly) of a WebContents.
|
||||||
* `x` number (optional) - Default is the current mouse cursor position.
|
* `x` number (optional) - Default is the current mouse cursor position.
|
||||||
Must be declared if `y` is declared.
|
Must be declared if `y` is declared.
|
||||||
* `y` number (optional) - Default is the current mouse cursor position.
|
* `y` number (optional) - Default is the current mouse cursor position.
|
||||||
|
|
|
@ -164,19 +164,36 @@ void MenuMac::PopupOnUI(const base::WeakPtr<NativeWindow>& native_window,
|
||||||
static_cast<content::RenderWidgetHostViewMac*>(rfh->GetView());
|
static_cast<content::RenderWidgetHostViewMac*>(rfh->GetView());
|
||||||
RenderWidgetHostViewCocoa* cocoa_view = rwhvm->GetInProcessNSView();
|
RenderWidgetHostViewCocoa* cocoa_view = rwhvm->GetInProcessNSView();
|
||||||
view = cocoa_view;
|
view = cocoa_view;
|
||||||
|
|
||||||
|
// TODO: ui::ShowContextMenu does not dispatch the event correctly
|
||||||
|
// if no frame is found. Fix this to remove if/else condition.
|
||||||
|
NSEvent* dummy_event =
|
||||||
|
[NSEvent mouseEventWithType:NSEventTypeRightMouseDown
|
||||||
|
location:position
|
||||||
|
modifierFlags:0
|
||||||
|
timestamp:0
|
||||||
|
windowNumber:nswindow.windowNumber
|
||||||
|
context:nil
|
||||||
|
eventNumber:0
|
||||||
|
clickCount:1
|
||||||
|
pressure:0];
|
||||||
|
ui::ShowContextMenu(menu, dummy_event, view, true);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NSEvent* dummy_event = [NSEvent mouseEventWithType:NSEventTypeRightMouseDown
|
// Make sure events can be pumped while the menu is up.
|
||||||
location:position
|
base::CurrentThread::ScopedAllowApplicationTasksInNativeNestedLoop allow;
|
||||||
modifierFlags:0
|
|
||||||
timestamp:0
|
// One of the events that could be pumped is |window.close()|.
|
||||||
windowNumber:nswindow.windowNumber
|
// User-initiated event-tracking loops protect against this by
|
||||||
context:nil
|
// setting flags in -[CrApplication sendEvent:], but since
|
||||||
eventNumber:0
|
// web-content menus are initiated by IPC message the setup has to
|
||||||
clickCount:1
|
// be done manually.
|
||||||
pressure:0];
|
base::mac::ScopedSendingEvent sendingEventScoper;
|
||||||
ui::ShowContextMenu(menu, dummy_event, view, true);
|
|
||||||
|
// Don't emit unresponsive event when showing menu.
|
||||||
|
[menu popUpMenuPositioningItem:item atLocation:position inView:view];
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuMac::ClosePopupAt(int32_t window_id) {
|
void MenuMac::ClosePopupAt(int32_t window_id) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue