Skip to content

Make context menu work in web inspector (rebased on v1.4) #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.4-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Source/WebInspectorUI/UserInterface/Base/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ WI.contentLoaded = function()
window.addEventListener("resize", WI._windowResized);
window.addEventListener("keydown", WI._windowKeyDown);
window.addEventListener("keyup", WI._windowKeyUp);
window.addEventListener("mousedown", WI._mouseDown, true);
window.addEventListener("mousemove", WI._mouseMoved, true);
window.addEventListener("pagehide", WI._pageHidden);
window.addEventListener("contextmenu", WI._contextMenuRequested);
Expand Down Expand Up @@ -1876,6 +1877,23 @@ WI._windowKeyUp = function(event)
WI._updateModifierKeys(event);
};

WI._mouseDown = function(event)
{
if (event.button === 2) { // right-click
const contextMenuEvent = new MouseEvent("contextmenu", {
view: window,
bubbles: true,
cancelable: true,
screenX: event.pageX,
screenY: event.pageY,
clientX: event.pageX,
clientY: event.pageY,
...event
});
event.target.dispatchEvent(contextMenuEvent);
}
};

WI._mouseMoved = function(event)
{
WI._updateModifierKeys(event);
Expand Down
9 changes: 7 additions & 2 deletions Source/WebInspectorUI/UserInterface/Views/ContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ WI.ContextMenu = class ContextMenu extends WI.ContextSubMenuItem
this._event.target.addEventListener("contextmenu", this, true);
InspectorFrontendHost.dispatchEventAsContextMenuEvent(this._event);
} else
InspectorFrontendHost.showContextMenu(this._event, menuObject);
this._showSoftContextMenu(this._event, menuObject);
}

if (this._event)
Expand All @@ -234,7 +234,7 @@ WI.ContextMenu = class ContextMenu extends WI.ContextSubMenuItem
callback(this);

this._event.target.removeEventListener("contextmenu", this, true);
InspectorFrontendHost.showContextMenu(event, this._menuObject);
this._showSoftContextMenu(event, this._menuObject);
this._menuObject = null;

event.stopImmediatePropagation();
Expand Down Expand Up @@ -262,6 +262,11 @@ WI.ContextMenu = class ContextMenu extends WI.ContextSubMenuItem
WI.reportInternalError(e);
}
}

_showSoftContextMenu(event, menuObject)
{
new WI.SoftContextMenu(menuObject).show(event);
}
};

WI.ContextMenu.ProposedMenuSymbol = Symbol("context-menu-proposed-menu");