-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PM-14954] implement multi input totp styling #12449
Open
evan-livefront
wants to merge
7
commits into
main
Choose a base branch
from
autofill/PM-14954-implement-multi-input-totp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+227
โ6
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
942c55a
update menu and button position for multi-input totp
6280fc7
update test to better handle breaking changes
9a2d7f0
merge main
7c40eb8
Merge branch 'main' into autofill/PM-14954-implement-multi-input-totp
evan-livefront f9a0391
Merge branch 'main' into autofill/PM-14954-implement-multi-input-totp
evan-livefront 5580fc8
Merge branch 'main' into autofill/PM-14954-implement-multi-input-totp
evan-livefront 8c0e00b
Merge branch 'main' into autofill/PM-14954-implement-multi-input-totp
evan-livefront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,6 +129,7 @@ | |
private currentInlineMenuCiphersCount: number = 0; | ||
private currentAddNewItemData: CurrentAddNewItemData; | ||
private focusedFieldData: FocusedFieldData; | ||
private allFieldData: AutofillField[]; | ||
private isFieldCurrentlyFocused: boolean = false; | ||
private isFieldCurrentlyFilling: boolean = false; | ||
private isInlineMenuButtonVisible: boolean = false; | ||
|
@@ -1344,6 +1345,67 @@ | |
this.isInlineMenuListVisible = false; | ||
} | ||
|
||
/** | ||
* Get all the totp fields for the tab and frame of the currently focused field | ||
*/ | ||
private getTotpFields(): AutofillField[] { | ||
const currentTabId = this.focusedFieldData?.tabId; | ||
const currentFrameId = this.focusedFieldData?.frameId; | ||
const pageDetailsMap = this.pageDetailsForTab[currentTabId]; | ||
const pageDetails = pageDetailsMap?.get(currentFrameId); | ||
|
||
const fields = pageDetails.details.fields; | ||
const totpFields = fields.filter((f) => | ||
this.inlineMenuFieldQualificationService.isTotpField(f), | ||
); | ||
|
||
return totpFields; | ||
} | ||
|
||
/** | ||
* calculates the postion and width for multi-input totp field inline menu | ||
* @param totpFieldArray - the totp fields used to evaluate the position of the menu | ||
*/ | ||
private calculateTotpMultiInputMenuBounds(totpFieldArray: AutofillField[]) { | ||
// Filter the fields based on the provided totpfields | ||
const filteredObjects = this.allFieldData.filter((obj) => | ||
totpFieldArray.some((o) => o.opid === obj.opid), | ||
); | ||
|
||
// Return null if no matching objects are found | ||
if (filteredObjects.length === 0) { | ||
return null; | ||
} | ||
// Calculate the smallest left and largest right values to determine width | ||
const left = Math.min(...filteredObjects.map((obj) => obj.rect.left)); | ||
const largestRight = Math.max(...filteredObjects.map((obj) => obj.rect.right)); | ||
|
||
const width = largestRight - left; | ||
|
||
return { left, width }; | ||
} | ||
|
||
/** | ||
* calculates the postion for multi-input totp field inline button | ||
* @param totpFieldArray - the totp fields used to evaluate the position of the menu | ||
*/ | ||
private calculateTotpMultiInputButtonBounds(totpFieldArray: AutofillField[]) { | ||
const filteredObjects = this.allFieldData.filter((obj) => | ||
totpFieldArray.some((o) => o.opid === obj.opid), | ||
); | ||
|
||
if (filteredObjects.length === 0) { | ||
return null; | ||
} | ||
|
||
const maxRight = Math.max(...filteredObjects.map((obj) => obj.rect.right)); | ||
const maxObject = filteredObjects.find((obj) => obj.rect.right === maxRight); | ||
const top = maxObject.rect.top - maxObject.rect.height * 0.39; | ||
const left = maxRight - maxObject.rect.height * 0.3; | ||
|
||
return { left, top }; | ||
} | ||
|
||
/** | ||
* Updates the position of either the inline menu list or button. The position | ||
* is based on the focused field's position and dimensions. | ||
|
@@ -1445,12 +1507,19 @@ | |
* Gets the position of the focused field and calculates the position | ||
* of the inline menu button based on the focused field's position and dimensions. | ||
*/ | ||
private getInlineMenuButtonPosition(subFrameOffsets: SubFrameOffsetData) { | ||
getInlineMenuButtonPosition(subFrameOffsets: SubFrameOffsetData) { | ||
const subFrameTopOffset = subFrameOffsets?.top || 0; | ||
const subFrameLeftOffset = subFrameOffsets?.left || 0; | ||
|
||
const { top, left, width, height } = this.focusedFieldData.focusedFieldRects; | ||
const { width, height } = this.focusedFieldData.focusedFieldRects; | ||
let { top, left } = this.focusedFieldData.focusedFieldRects; | ||
const { paddingRight, paddingLeft } = this.focusedFieldData.focusedFieldStyles; | ||
|
||
if (this.isTotpFieldForCurrentField()) { | ||
const totpFields = this.getTotpFields(); | ||
({ left, top } = this.calculateTotpMultiInputButtonBounds(totpFields)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit; this reassignment pattern feels weird to me ๐ค |
||
} | ||
|
||
let elementOffset = height * 0.37; | ||
if (height >= 35) { | ||
elementOffset = height >= 50 ? height * 0.47 : height * 0.42; | ||
|
@@ -1485,11 +1554,17 @@ | |
* Gets the position of the focused field and calculates the position | ||
* of the inline menu list based on the focused field's position and dimensions. | ||
*/ | ||
private getInlineMenuListPosition(subFrameOffsets: SubFrameOffsetData) { | ||
getInlineMenuListPosition(subFrameOffsets: SubFrameOffsetData) { | ||
const subFrameTopOffset = subFrameOffsets?.top || 0; | ||
const subFrameLeftOffset = subFrameOffsets?.left || 0; | ||
|
||
const { top, left, width, height } = this.focusedFieldData.focusedFieldRects; | ||
const { top, height } = this.focusedFieldData.focusedFieldRects; | ||
let { left, width } = this.focusedFieldData.focusedFieldRects; | ||
|
||
if (this.isTotpFieldForCurrentField()) { | ||
const totpFields = this.getTotpFields(); | ||
({ left, width } = this.calculateTotpMultiInputMenuBounds(totpFields)); | ||
} | ||
|
||
this.inlineMenuPosition.list = { | ||
top: Math.round(top + height + subFrameTopOffset), | ||
|
@@ -1512,7 +1587,7 @@ | |
* @param sender - The sender of the extension message | ||
*/ | ||
private setFocusedFieldData( | ||
{ focusedFieldData }: OverlayBackgroundExtensionMessage, | ||
{ focusedFieldData, allFieldsRect }: OverlayBackgroundExtensionMessage, | ||
sender: chrome.runtime.MessageSender, | ||
) { | ||
if ( | ||
|
@@ -1529,6 +1604,7 @@ | |
|
||
const previousFocusedFieldData = this.focusedFieldData; | ||
this.focusedFieldData = { ...focusedFieldData, tabId: sender.tab.id, frameId: sender.frameId }; | ||
this.allFieldData = allFieldsRect; | ||
this.isFieldCurrentlyFocused = true; | ||
|
||
if (this.shouldUpdatePasswordGeneratorMenuOnFieldFocus()) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should allow keeping the methods as private (here and elsewhere)