Skip to content
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

fix: setTopBrowserView focus issue with reordering #42653

Merged
merged 3 commits into from
Jul 1, 2024

Conversation

alicelovescake
Copy link
Member

@alicelovescake alicelovescake commented Jun 25, 2024

Description of Change

fixes: #42637

Summary of bug

  • As highlighted in the issue, prior to v30, when setting a view to setTopBrowserView, the view would focus correctly, and that is because it's using the macOS view ordering APIs to reorder the view to the top without reseting any state.
  • With the new WebContentView changes in v30, we updated our implementation of setTopBrowserView to:
BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
  if (browserView.ownerWindow !== this) { throw new Error('Given BrowserView is not attached to the window'); }
   this.addBrowserView(browserView);
};

The issue arises because this.addBrowserView removes the view from the owner window before re-adding it. This removal removes the view from the focus list and resets its state, causing the top view to incorrectly focus.

Proposed fix

  • This PR has already added Chromium's reordering API inside AddChildViewAt to reorder if the child is already a child of this view. So calling this.contentView.addChildView directly on a view that already exists on the window will reorder it to the top.
  • Tested with my local build of electron and works as expected

Checklist

Release Notes

Notes: Fixed a focus issue when calling BrowserWindow.setTopBrowserView

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jun 25, 2024
@alicelovescake alicelovescake self-assigned this Jun 25, 2024
@alicelovescake alicelovescake changed the title fix: reorder top browser view instead of adding/removing fix: setTopBrowserView focus with reordering Jun 25, 2024
@alicelovescake alicelovescake changed the title fix: setTopBrowserView focus with reordering fix: setTopBrowserView focus issue with reordering Jun 25, 2024
@alicelovescake alicelovescake requested a review from nornagon June 26, 2024 14:22
@codebytere codebytere self-requested a review June 27, 2024 05:53
Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

nice catch!

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/30-x-y PR should also be added to the "30-x-y" branch. target/31-x-y PR should also be added to the "31-x-y" branch. target/32-x-y PR should also be added to the "32-x-y" branch. labels Jun 27, 2024
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jun 27, 2024
@alicelovescake
Copy link
Member Author

@codebytere Thanks for the review! Are you able to help me merge it? Or let me know what else I should do to make the PR ready!

@codebytere
Copy link
Member

Lint is unrelated, fixed in #42715

@codebytere codebytere merged commit e9a93a8 into main Jul 1, 2024
65 of 67 checks passed
Copy link

release-clerk bot commented Jul 1, 2024

Release Notes Persisted

Fixed a focus issue when calling BrowserWindow.setTopBrowserView

@trop
Copy link
Contributor

trop bot commented Jul 1, 2024

I have automatically backported this PR to "32-x-y", please check out #42733

@trop trop bot added the in-flight/32-x-y label Jul 1, 2024
@trop trop bot removed the target/32-x-y PR should also be added to the "32-x-y" branch. label Jul 1, 2024
@trop
Copy link
Contributor

trop bot commented Jul 1, 2024

I have automatically backported this PR to "31-x-y", please check out #42734

@trop
Copy link
Contributor

trop bot commented Jul 1, 2024

I have automatically backported this PR to "30-x-y", please check out #42735

@trop trop bot added merged/31-x-y PR was merged to the "31-x-y" branch. merged/32-x-y PR was merged to the "32-x-y" branch. and removed target/31-x-y PR should also be added to the "31-x-y" branch. target/30-x-y PR should also be added to the "30-x-y" branch. in-flight/31-x-y in-flight/32-x-y labels Jul 1, 2024
@trop trop bot added merged/30-x-y PR was merged to the "30-x-y" branch. and removed in-flight/30-x-y labels Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/30-x-y PR was merged to the "30-x-y" branch. merged/31-x-y PR was merged to the "31-x-y" branch. merged/32-x-y PR was merged to the "32-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Adding a BrowserView to a BrowserWindow "behind" an existing one causes focus/hover to break
2 participants