Refactor openGlance method to accept target element and send relevant data

This commit is contained in:
mr. M 2024-10-28 16:59:34 +01:00
parent a942043645
commit 416369c981
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB
3 changed files with 32 additions and 9 deletions

View file

@ -21,10 +21,15 @@
}
observe(subject, topic, data) {
this.openGlance(data);
this.openGlance(JSON.parse(data));
}
openGlance(url) {
openGlance(data) {
const initialX = data.x;
const initialY = data.y;
const initialWidth = data.width;
const initialHeight = data.height;
const url = data.url;
if (this.#currentBrowser) {
return;
}
@ -33,6 +38,11 @@
overlayWrapper.appendChild(this.overlay);
window.requestAnimationFrame(() => {
this.browserWrapper.style.setProperty("--initial-x", `${initialX}px`);
this.browserWrapper.style.setProperty("--initial-y", `${initialY}px`);
this.browserWrapper.style.setProperty("--initial-width", initialWidth + "px");
this.browserWrapper.style.setProperty("--initial-height", initialHeight + "px");
this.overlay.removeAttribute("fade-out");
this.overlay.removeAttribute("hidden");
});
}
@ -41,7 +51,13 @@
this.#currentBrowser?.remove();
this.#currentBrowser = null;
this.overlay.setAttribute("hidden", true);
window.requestAnimationFrame(() => {
this.overlay.setAttribute("fade-out", true);
setTimeout(() => {
this.overlay.setAttribute("hidden", true);
this.overlay.removeAttribute("fade-out");
}, 800);
});
}
onLocationChange(_) {

View file

@ -55,8 +55,15 @@ export class ZenGlanceChild extends JSWindowActorChild {
return !(event.ctrlKey ^ event.altKey ^ event.shiftKey);
}
openGlance(url) {
this.sendAsyncMessage('ZenGlance:OpenGlance', { url });
openGlance(target) {
const rect = target.getBoundingClientRect();
this.sendAsyncMessage('ZenGlance:OpenGlance', {
url: target.href,
x: rect.left,
y: rect.top,
width: rect.width,
height: rect.height,
});
}
handleMouseUp(event) {
@ -71,7 +78,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
const hoverActivationDelay = await this.getHoverActivationDelay();
setTimeout(() => {
if (this.mouseIsDown) {
this.openGlance(event.target.href);
this.openGlance(event.target);
}
}, hoverActivationDelay);
}
@ -96,7 +103,7 @@ export class ZenGlanceChild extends JSWindowActorChild {
event.preventDefault();
event.stopPropagation();
this.openGlance(target.href);
this.openGlance(target);
}
}
}

View file

@ -12,13 +12,13 @@ export class ZenGlanceParent extends JSWindowActorParent {
return Services.prefs.getIntPref('zen.glance.hold-duration', 500);
}
case 'ZenGlance:OpenGlance': {
this.openGlance(message.data.url);
this.openGlance(message.data);
break;
}
}
}
openGlance(data) {
Services.obs.notifyObservers(null, 'zen-glance-open', data);
Services.obs.notifyObservers(null, 'zen-glance-open', JSON.stringify(data));
}
}