I made a copy of the extensions/Robot.html sample, and made some changes to be like what you are talking about.
First I modified the node template to add a context-menu-showing button, which I implemented using a solid square Shape (the implementation details shouldn’t matter):
nodeTemplate:
$(go.Node, "Auto",
{
click: nodeClicked,
doubleClick: nodeClicked,
contextMenu:
$("ContextMenu",
$("ContextMenuButton",
$(go.TextBlock, "Properties"),
{ click: showProperties })
)
},
$(go.Shape, "Rectangle",
{ fill: "lightgray" },
{ portId: "", fromLinkable: true, toLinkable: true, cursor: "pointer" }),
$(go.TextBlock,
{ margin: 18 },
new go.Binding("text", "key")),
$(go.Shape,
{
name: "BUTTON",
width: 16, height: 16, alignment: go.Spot.Right,
click: function(e, menuButton) {
e.diagram.commandHandler.showContextMenu(menuButton.part);
}
})),
Then I modified the clickLambda
function that uses the Robot in the sample:
function clickLambda() {
var lambda = myDiagram.findNodeForKey("Lambda");
if (lambda === null) return;
var button = lambda.findObject("BUTTON");
var loc = button.getDocumentBounds().center;
// click on Lambda
robot.mouseDown(loc.x, loc.y, 0, {});
robot.mouseUp(loc.x, loc.y, 100, {});
// Clicking is just a sequence of input events.
// There is no command in CommandHandler for such a basic gesture.
}
Then when I ran the sample, the first thing I did was click on the “Click Lambda” HTML button. As expected, it showed the “Lambda” node’s context menu.
So I do not encounter any problem in showing the node’s context menu by robot-clicking the 16x16 object in the node.
However, I did run into one unexpected side-effect: the whole node was also clicked. At first I thought the problem was that the shape’s click handler didn’t set InputEvent.handled to true, but that wasn’t enough. The behavior is that CommandHandler.showContextMenu basically clicks at the middle of the object that has the context menu defined – the whole node in this case. This is normally desired so that the normal click behavior of the object happens before the context menu is shown, in case for example that the node is expected to be selected by any of the context menu commands. But maybe in your situation you don’t want that.