1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-03-02 03:41:09 +01:00

[PM-5189] Fixing issue found in Safari with how the inline menu is re-positioned

This commit is contained in:
Cesar Gonzalez 2024-06-17 10:44:25 -05:00
parent 8e9b3afe1b
commit ee8b179b6c
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
3 changed files with 34 additions and 9 deletions

View File

@ -686,15 +686,19 @@ export class OverlayBackground implements OverlayBackgroundInterface {
* This is used to simultaneously fade in the inline menu elements.
*/
private setInlineMenuFadeInTimeout() {
this.clearInlineMenuFadeInTimeout();
this.inlineMenuFadeInTimeout = globalThis.setTimeout(() => {
const message = { command: "fadeInAutofillInlineMenuIframe" };
this.inlineMenuButtonPort?.postMessage(message);
this.inlineMenuListPort?.postMessage(message);
}, 125);
}
private clearInlineMenuFadeInTimeout() {
if (this.inlineMenuFadeInTimeout) {
globalThis.clearTimeout(this.inlineMenuFadeInTimeout);
}
this.inlineMenuFadeInTimeout = globalThis.setTimeout(() => {
const message = { command: "updateAutofillInlineMenuPosition", styles: { opacity: "1" } };
this.inlineMenuButtonPort?.postMessage(message);
this.inlineMenuListPort?.postMessage(message);
}, 50);
}
/**
@ -777,11 +781,19 @@ export class OverlayBackground implements OverlayBackgroundInterface {
{ isInlineMenuHidden, setTransparentInlineMenu }: OverlayBackgroundExtensionMessage,
sender: chrome.runtime.MessageSender,
) {
if (isInlineMenuHidden) {
this.clearInlineMenuFadeInTimeout();
}
if (setTransparentInlineMenu) {
this.setInlineMenuFadeInTimeout();
}
const display = isInlineMenuHidden ? "none" : "block";
let styles: { display: string; opacity?: number } = { display };
let styles: { display: string; opacity?: string } = { display };
if (typeof setTransparentInlineMenu !== "undefined") {
const opacity = setTransparentInlineMenu ? 0 : 1;
const opacity = setTransparentInlineMenu ? "0" : "1";
styles = { ...styles, opacity };
}

View File

@ -22,6 +22,7 @@ export type BackgroundPortMessageHandlers = {
message,
}: AutofillInlineMenuIframeExtensionMessageParam) => void;
updateAutofillInlineMenuColorScheme: () => void;
fadeInAutofillInlineMenuIframe: () => void;
};
export interface AutofillInlineMenuIframeService {

View File

@ -18,6 +18,7 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
private ariaAlertElement: HTMLDivElement;
private ariaAlertTimeout: number | NodeJS.Timeout;
private delayedCloseTimeout: number | NodeJS.Timeout;
private fadeInTimeout: number | NodeJS.Timeout;
private readonly fadeInOpacityTransition = "opacity 125ms ease-out 0s";
private readonly fadeOutOpacityTransition = "opacity 65ms ease-out 0s";
private iframeStyles: Partial<CSSStyleDeclaration> = {
@ -53,6 +54,7 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
this.updateElementStyles(this.iframe, message.styles),
updateAutofillInlineMenuColorScheme: () => this.updateAutofillInlineMenuColorScheme(),
triggerDelayedAutofillInlineMenuClosure: () => this.handleDelayedAutofillInlineMenuClosure(),
fadeInAutofillInlineMenuIframe: () => this.handleFadeInInlineMenuIframe(),
};
constructor(
@ -156,7 +158,7 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
return;
}
this.updateElementStyles(this.iframe, { opacity: "0", height: "0px", display: "block" });
this.updateElementStyles(this.iframe, { opacity: "0", height: "0px" });
this.unobserveIframe();
this.port?.onMessage.removeListener(this.handlePortMessage);
this.port?.onDisconnect.removeListener(this.handlePortDisconnect);
@ -305,6 +307,16 @@ export class AutofillInlineMenuIframeService implements AutofillInlineMenuIframe
void this.sendExtensionMessage("closeAutofillInlineMenu", { forceClose: true });
}
private handleFadeInInlineMenuIframe() {
if (this.fadeInTimeout) {
clearTimeout(this.fadeInTimeout);
}
this.fadeInTimeout = globalThis.setTimeout(() => {
this.updateElementStyles(this.iframe, { display: "block", opacity: "1" });
}, 50);
}
/**
* Triggers a delayed closure of the inline menu to ensure that click events are
* caught if focus is programmatically redirected away from the inline menu.