refactor: Use `IContextMenu` to dispatch right clicks by gonfunko · Pull Request #9580 · RaspberryPiFoundation/blockly
The basics
The details
Resolves
Fixes #8842
Proposed Changes
This PR updates Gesture to check for conformance to IContextMenu when dispatching right clicks, rather than hard coding specific kinds of elements.
Although Gesture is still fairly closely tied to specific elements, in general this does open a path for things to just implement IContextMenu to get context menu support. Clicks bubble up from e.g. fields to blocks to the workspace, with each item informing Gesture of a click in turn, and the workspace handler is what ultimately triggers the right click handler. Thus, as long as an element (a) gains focus on (right)click, (b) is a child of the workspace, and (c) implements IContextMenu, Gesture should now trigger display of the context menu when it is right clicked.
While I was here, I also cleaned up the bringing-block-to-front behavior. This was being triggered in various block sub-elements (fields, icons), but because of the bubbling behavior described above, clicks on those will ultimately reach the parent block, so performing bring-to-front when the block becomes the target block covers all these cases, for both left and right clicks.