1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00: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
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. * This is used to simultaneously fade in the inline menu elements.
*/ */
private setInlineMenuFadeInTimeout() { 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) { if (this.inlineMenuFadeInTimeout) {
globalThis.clearTimeout(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, { isInlineMenuHidden, setTransparentInlineMenu }: OverlayBackgroundExtensionMessage,
sender: chrome.runtime.MessageSender, sender: chrome.runtime.MessageSender,
) { ) {
if (isInlineMenuHidden) {
this.clearInlineMenuFadeInTimeout();
}
if (setTransparentInlineMenu) {
this.setInlineMenuFadeInTimeout();
}
const display = isInlineMenuHidden ? "none" : "block"; const display = isInlineMenuHidden ? "none" : "block";
let styles: { display: string; opacity?: number } = { display }; let styles: { display: string; opacity?: string } = { display };
if (typeof setTransparentInlineMenu !== "undefined") { if (typeof setTransparentInlineMenu !== "undefined") {
const opacity = setTransparentInlineMenu ? 0 : 1; const opacity = setTransparentInlineMenu ? "0" : "1";
styles = { ...styles, opacity }; styles = { ...styles, opacity };
} }

View File

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

View File

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