Let every click subscriber hear a mission-label click

A click a painted overlay handled, such as a Space Missions label, returned
before any click subscriber ran, so the layers that close their cards or let
go of their selection on a click never heard it. Now only the picking the
label replaces is skipped: subscribers still hear the click, marked as an
overlay click whose hit is the label (no draw set, no id, nothing drilled),
and the geometry beneath it is not picked.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-18 16:36:00 -08:00
1 parent ee37511332
commit 9ac937af82
4 files changed
+109 -13

No files matched your search

+37 -6
View File
@@ -182,6 +182,9 @@ function topHitOf(hit, foreign) {
* when the adapter has none.
* @property {unknown} pick `native.pick`, for code still bound to the
* engine's pick objects that reads it here.
* @property {boolean} overlay Whether a painted overlay target took the
* click ({@link InputDispatcher.onOverlayClick}). Its hits then name only
* that target: something drawn outside the draw port, with no id.
* @property {(width: number, height: number) => unknown} pickWindow
* `native.pickWindow`, the same.
*/
@@ -192,7 +195,9 @@ function topHitOf(hit, foreign) {
* Ambient click subscription. Returns its unsubscribe.
* @property {(fn: (event: ClickEvent) => boolean) => () => void} onOverlayClick
* Hit-test a painted overlay before ambient clicks. Return true after
* handling its topmost target to stop delivery to the geometry beneath it.
* handling its topmost target: the geometry beneath it is not picked, and
* the click subscribers hear the click as one on that target (`overlay`
* true, `topHit` a hit with no set and no id, nothing drilled).
* @property {(type: 'down'|'move'|'up'|'click'|'dblclick', fn: Function, options?: {lease?: object|(() => object|null)}) => () => void} onPointer
* Raw pointer subscription: `click` gets the {@link ClickEvent}, the others
* `{position}` (`move`: `{startPosition, endPosition, pickPosition}`, its
@@ -331,7 +336,7 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
click: (ev) => {
if (!unmodifiedLeft(ev)) return;
const ambient = free();
const event = createClickEvent(
const { event, cover } = createClickEvent(
viewer,
queryOf,
xy(ev.position),
@@ -340,7 +345,12 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
if (ambient) {
for (const handle of [...overlayClicks]) {
try {
if (handle(event) === true) return;
// A handled overlay target hides the geometry beneath it; every
// subscriber still hears the click, as a click on that target.
if (handle(event) === true) {
cover();
break;
}
} catch (error) {
console.error('Pointer input handler failed', error);
}
@@ -437,6 +447,10 @@ function createDispatcher(viewer, { query: givenQuery, ...portOptions } = {}) {
return self;
}
/** What a click handled by a painted overlay target hits: that target,
* drawn outside the draw port and named by no pick id. */
const OVERLAY_HIT = Object.freeze({ set: '', id: null, surface: false });
/** A drill is run at least this deep and sliced, so callers asking for
* different depths on one click share one pass. */
const DRILL_DEPTH = 16;
@@ -446,7 +460,8 @@ const DRILL_DEPTH = 16;
* @param {() => import('../render/contract/query').QueryPort|null} queryOf
* @param {{x: number, y: number}} at Where the click is, CSS pixels.
* @param {ClickGesture} gesture
* @returns {ClickEvent}
* @returns {{event: ClickEvent, cover: () => void}} The click, and how a
* handled overlay target hides the geometry beneath it from the click.
*/
function createClickEvent(viewer, queryOf, at, gesture) {
const position = sensorPickPosition(viewer, at, canvasOf(viewer));
@@ -465,11 +480,25 @@ function createClickEvent(viewer, queryOf, at, gesture) {
};
/** @type {Map<string, {limit: number, hits: Hit[]}>} */
const drills = new Map();
let covered = false;
const cover = () => {
covered = true;
memo.clear();
drills.clear();
memo.set('top', OVERLAY_HIT);
memo.set('hit', OVERLAY_HIT);
memo.set('id', null);
memo.set('ownerId', null);
memo.set('native', null);
};
return {
const event = {
screenPosition: at,
position,
gesture,
get overlay() {
return covered;
},
get topHit() {
return once('top', () => {
const hit = pick();
@@ -515,6 +544,7 @@ function createClickEvent(viewer, queryOf, at, gesture) {
return !this.hit;
},
windowHit(width, height) {
if (covered) return { id: null, drawHit: null, surface: false };
return once(`windowHit:${width}x${height}`, () => {
const picked = pick({ width, height });
void native()?.native.pickWindow(width, height);
@@ -535,7 +565,7 @@ function createClickEvent(viewer, queryOf, at, gesture) {
// A deeper pass already made holds these. (One that came back short
// may not hold every hit: it drops what is not a draw-set item.)
if (done && limit <= done.limit) return done.hits.slice(0, limit);
const q = query();
const q = covered ? null : query();
if (!q) return [];
// Only the default window is shared between layers; round that one up.
const depth =
@@ -568,4 +598,5 @@ function createClickEvent(viewer, queryOf, at, gesture) {
return native()?.native.pickWindow(width, height);
},
};
return { event, cover };
}
+61 -1
View File
@@ -145,7 +145,8 @@ test('a painted overlay can claim a click before its underlying owner', (t) => {
h.input.onPointer('click', () => clicks.push('ambient pointer'));
h.click();
assert.deepEqual(clicks, ['mission label']);
// The click still reaches every subscriber, as one on the label.
assert.deepEqual(clicks, ['mission label', 'ambient pointer', null]);
assert.equal(h.calls.pick, 0);
h.click(11, 10);
@@ -154,12 +155,71 @@ test('a painted overlay can claim a click before its underlying owner', (t) => {
assert.deepEqual(clicks, [
'mission label',
'ambient pointer',
null,
'ambient pointer',
'satellites',
'ambient pointer',
'satellites',
]);
});
test('a click a painted overlay handles still reaches subscribers that clear selection', (t) => {
const h = harness({
pick: () => ({ set: 'flights', id: 'abc123' }),
drillPick: () => [{ set: 'flights', id: 'abc123' }],
});
t.after(() => h.input.destroy());
let seenByOverlay = null;
h.input.onOverlayClick((event) => {
seenByOverlay = event;
return true;
});
const seen = [];
h.input.onClick((event) => {
seen.push({
same: event === seenByOverlay,
overlay: event.overlay,
topHit: event.topHit,
drawHit: event.drawHit,
hit: event.hit,
id: event.id,
ownerId: event.ownerId,
surface: event.surface,
drill: event.drill(4),
windowHit: event.windowHit(8, 8),
pick: event.pick,
});
});
h.click();
assert.deepEqual(seen, [
{
same: true,
overlay: true,
topHit: { set: '', id: null, surface: false },
drawHit: null,
hit: { set: '', id: null, surface: false },
id: null,
ownerId: null,
surface: false,
drill: [],
windowHit: { id: null, drawHit: null, surface: false },
pick: undefined,
},
]);
assert.equal(h.calls.pick, 0, 'the geometry beneath is not picked');
assert.equal(h.calls.drillPick, 0);
// Without an overlay target the same click picks the geometry.
seen.length = 0;
h.input.destroy();
const g = harness({ pick: () => ({ set: 'flights', id: 'abc123' }) });
t.after(() => g.input.destroy());
g.input.onClick((event) => seen.push([event.overlay, event.topHit]));
g.click();
assert.equal(seen[0][0], false);
assert.equal(g.calls.pick, 1);
});
test('the gesture carries summed travel and press time', (t) => {
const h = harness();
t.after(() => h.input.destroy());
+10 -5
View File
@@ -118,11 +118,15 @@ const label = (
entryId,
});
test('a mission label click focuses its launch and stops the click there', (t) => {
const r = rig(t, { overlayHit: label('launch:L2') });
test('a mission label click focuses its launch and covers the geometry beneath', (t) => {
const r = rig(t, { overlayHit: label('launch:L2'), geometryLaunchId: 'L1' });
r.click();
assert.deepEqual(r.focused, ['L2']);
assert.equal(r.ambient.length, 0, 'the layers beneath do not see it');
assert.deepEqual(r.focused, ['L2'], 'the mission beneath is not picked');
// Other layers still hear it, to close their cards or clear selection,
// as a click on the label rather than on the geometry beneath.
assert.equal(r.ambient.length, 1);
assert.equal(r.ambient[0].overlay, true);
assert.equal(r.ambient[0].drawHit, null);
r.setHit(label('launch:L1', ROCKET_MISSION_SELECTED_OVERLAY_SOURCE_ID));
r.click();
@@ -156,7 +160,8 @@ test('a throwing globe-pick listener does not stop the pick', (t) => {
r.click();
assert.deepEqual(r.focused, ['L1']);
assert.deepEqual(heard, ['L1']);
assert.equal(r.ambient.length, 0);
assert.equal(r.ambient.length, 1);
assert.equal(r.ambient[0].overlay, true);
});
test('a mission label for an unknown launch falls through to other layers', (t) => {