Bug 210462

Summary: Web Inspector: WI.ContextMenu.createFromEvent doesn't work with keydown event
Product: WebKit Reporter: Nikita Vasilyev <nvasilyev>
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: inspector-bugzilla-changes
Priority: P2    
Version: WebKit Nightly Build   
Hardware: All   
OS: All   

Description Nikita Vasilyev 2020-04-13 15:34:34 PDT
Here is one instance where it's needed: bug 210447: Web Inspector: AXI: tabs should be focusable when navigating by pressing Tab.

Currently, InspectorFrontendHost::dispatchEventAsContextMenuEvent only takes mouse events.

WebCore/inspector/InspectorFrontendHost.cpp:

```
void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event& event)
{
#if ENABLE(CONTEXT_MENUS) && USE(ACCESSIBILITY_CONTEXT_MENUS)
    if (!is<MouseEvent>(event))
        return;

    auto& mouseEvent = downcast<MouseEvent>(event);
    auto& frame = *downcast<Node>(mouseEvent.target())->document().frame();
    m_frontendPage->contextMenuController().showContextMenuAt(frame, roundedIntPoint(mouseEvent.absoluteLocation()));
    ...
```

Quick search for `absoluteLocation` showed me WebCore/dom/MouseRelatedEvent.h:

    // Page point in "absolute" coordinates (i.e. post-zoomed, page-relative coords,
    // usable with RenderObject::absoluteToLocal).
    const LayoutPoint& absoluteLocation() const { return m_absoluteLocation; }

Keyboard events currently don't have this method.

---

It would be more future-proof to have a method to show context menu for given x and y coordinates instead of the mouse event.