This seems brittle to just do two levels of ancestors. If the menu was re-designed to have a 3rd level, then there might be taps in the menu that would dismiss it prematurely.  How about IMERender.menu.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_CONTAINED_BY or something similar?