gh-8391: Prevent opening glance when selecting text in link (gh-14164)

This commit is contained in:
Bibhav Adhikari
2026-06-13 07:24:41 -05:00
committed by GitHub
parent 4313bc8aa4
commit 4cb4de2656

View File

@@ -17,8 +17,14 @@ XPCOMUtils.defineLazyPreferenceGetter(
true
);
// A small threshold to allow for minor mouse jitter during a normal click.
// Anything beyond this is likely an intentional drag (like selecting text).
const CLICK_DRAG_THRESHOLD_PX = 4;
export class ZenGlanceChild extends JSWindowActorChild {
#activationMethod;
#mouseDownX = null;
#mouseDownY = null;
constructor() {
super();
@@ -121,9 +127,23 @@ export class ZenGlanceChild extends JSWindowActorChild {
// The problem is that at that stage we don't know the rect or even what
// element has been clicked, so we send the data here.
this.#sendClickDataToParent(node, event.target);
this.#mouseDownX = event.clientX;
this.#mouseDownY = event.clientY;
}
on_click(event) {
// If the user drags to select text inside a link, we shouldn't open glance.
if (this.#mouseDownX !== null && this.#mouseDownY !== null) {
const deltaX = Math.abs(event.clientX - this.#mouseDownX);
const deltaY = Math.abs(event.clientY - this.#mouseDownY);
this.#mouseDownX = null;
this.#mouseDownY = null;
if (deltaX > CLICK_DRAG_THRESHOLD_PX || deltaY > CLICK_DRAG_THRESHOLD_PX) {
return;
}
}
const { node, href, principal } = this.#getTargetFromEvent(event);
if (
event.button !== 0 ||