Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Fix coordinate calculation and apply toolbar UI scale to target element
Browse files Browse the repository at this point in the history
fix #8870

Auditors: @bsclifton, @bbondy

Test Plan:
1. Go to about:preferences#advanced and change different UI scales
2. Go to any sites can trigger autofill popup or username/password popup
3. The context menu location should be just below the target element
  • Loading branch information
darkdh committed May 22, 2017
1 parent 728712d commit c36af01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class Frame extends React.Component {
if (this.frame.isEmpty()) {
return
}
contextMenus.onShowAutofillMenu(e.suggestions, e.rect, this.frame)
contextMenus.onShowAutofillMenu(e.suggestions, e.rect, this.frame, e.target.getBoundingClientRect())
})
this.webview.addEventListener('hide-autofill-popup', (e) => {
if (this.props.isAutFillContextMenu) {
Expand Down
13 changes: 6 additions & 7 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -1453,20 +1453,19 @@ function onShowBookmarkFolderMenu (bookmarks, bookmark, activeFrame, e) {
}))
}

function onShowAutofillMenu (suggestions, boundingRect, frame) {
function onShowAutofillMenu (suggestions, targetRect, frame, boundingClientRect) {
const menuTemplate = autofillTemplateInit(suggestions, frame)
const downloadsBarOffset = windowStore.getState().getIn(['ui', 'downloadsToolbar', 'isVisible']) &&
appStore.state.get('downloads') && appStore.state.get('downloads').size ? getDownloadsBarHeight() : 0
const offset = {
x: (window.innerWidth - boundingRect.clientWidth),
y: (window.innerHeight - boundingRect.clientHeight)
}
// toolbar UI scale ratio
const xRatio = window.innerWidth / window.outerWidth
const yRatio = window.innerHeight / window.outerHeight
const tabId = frame.get('tabId')
windowActions.setContextMenuDetail(Immutable.fromJS({
type: 'autofill',
tabId,
left: offset.x + boundingRect.x,
top: offset.y + (boundingRect.y + boundingRect.height) - downloadsBarOffset,
left: boundingClientRect.left + (targetRect.x * xRatio),
top: boundingClientRect.top + ((targetRect.y + targetRect.height) * yRatio) - downloadsBarOffset,
template: menuTemplate
}))
}
Expand Down

1 comment on commit c36af01

@bsclifton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ 💯

Please sign in to comment.