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

feat: add win.setTopBrowserView() so that BrowserViews can be raised #27007

Merged
merged 13 commits into from Feb 10, 2021

Conversation

stewartlord
Copy link
Contributor

@stewartlord stewartlord commented Dec 15, 2020

Description of Change

This PR adds win.setTopBrowserView() so that browser views can be raised without removing them and re-adding them to the window. Raising browser views is necessary to control which view receives pointer events when there are overlapping views. Removing and re-adding a view also works, but has the problem of introducing a noticeable flicker.

I'm unable to write a test for this because it does not appear possible to test which browser view receives pointer events.

Checklist

Release Notes

Notes: Added win.setTopBrowserView() so that BrowserViews can be raised.

stewartlord and others added 4 commits December 8, 2020 13:40
This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Dec 15, 2020
zcbenz
zcbenz previously requested changes Dec 15, 2020
Copy link
Member

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

It seems that this API is essentially win.removeBrowserView(view) && win.addBrowserView(view)?

@zcbenz zcbenz dismissed their stale review December 15, 2020 02:31

Sorry I did not see the PR description.

@zcbenz
Copy link
Member

zcbenz commented Dec 15, 2020

I think we should probably allow moving browser view to arbitrary position, like win.reorderBrowserView(view, index), otherwise we might have to add another API to move a BrowserView to bottom in future.

@zcbenz zcbenz added semver/patch backwards-compatible bug fixes api-review/requested 🗳 labels Dec 15, 2020
@stewartlord
Copy link
Contributor Author

I think we should probably allow moving browser view to arbitrary position, like win.reorderBrowserView(view, index), otherwise we might have to add another API to move a BrowserView to bottom in future.

Yes this was on my mind was well. Ultimately I went for the simplest possible solution, but am happy to entertain alternatives.

My hesitation with arbitrary reordering is that I didn't want to take on any additional bookkeeping as I don't believe that the existing browser_views_ (std::map) reflects stacking order. That's not necessarily a problem for Windows and Linux as the underlying Chromium API supports this via ReorderChildView. The Mac/NSView API doesn't work that way, but it is doable with a touch more effort.

Do we think users would be confused that they can set the indexes, but getBrowserViews doesn't reflect the order they set?

@zcbenz
Copy link
Member

zcbenz commented Dec 15, 2020

Do we think users would be confused that they can set the indexes, but getBrowserViews doesn't reflect the order they set?

I think if we allow reordering the views then we should make getBrowserViews reflect the order, since this API returns an Array instead of Set.

But yeah it requires additional bookkeeping so it might not really worth the efforts. Not sure how others in @electron/wg-api think.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Dec 16, 2020
@itsananderson itsananderson added semver/minor backwards-compatible functionality and removed semver/patch backwards-compatible bug fixes labels Dec 16, 2020
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Dec 16, 2020
@itsananderson
Copy link
Contributor

Bumped to semver/minor since this is adding new functionality

@codebytere codebytere added semver/major incompatible API changes semver/minor backwards-compatible functionality and removed semver/minor backwards-compatible functionality semver/major incompatible API changes labels Dec 17, 2020
@stewartlord
Copy link
Contributor Author

Do we think users would be confused that they can set the indexes, but getBrowserViews doesn't reflect the order they set?

I think if we allow reordering the views then we should make getBrowserViews reflect the order, since this API returns an Array instead of Set.

But yeah it requires additional bookkeeping so it might not really worth the efforts. Not sure how others in @electron/wg-api think.

Does the wg-api group meet regularly to consider questions like this? Just curious what the next steps are. Thanks!

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Dec 22, 2020
@stewartlord
Copy link
Contributor Author

An alternative change that might provoke less anxiety would be to add a moveTop method to BrowserView directly. This would align with the moveTop method on BrowserWindow.

@zcbenz
Copy link
Member

zcbenz commented Jan 15, 2021

On the API itself, I prefer having APIs supporting arbitrary reordering, but I'm also OK with a simple setTopBrowserView API.

@jkleinsc jkleinsc added semver/minor backwards-compatible functionality and removed semver/minor backwards-compatible functionality labels Jan 20, 2021
sentialx added a commit to sentialx/electron that referenced this pull request Feb 11, 2021
electron#27007)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>
@trop
Copy link
Contributor

trop bot commented Feb 11, 2021

@sentialx has manually backported this PR to "10-x-y", please check out #27711

sentialx added a commit to sentialx/electron that referenced this pull request Feb 11, 2021
electron#27007)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>
@trop
Copy link
Contributor

trop bot commented Feb 11, 2021

@sentialx has manually backported this PR to "11-x-y", please check out #27712

sentialx added a commit to sentialx/electron that referenced this pull request Feb 11, 2021
electron#27007)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>
@trop
Copy link
Contributor

trop bot commented Feb 11, 2021

@sentialx has manually backported this PR to "12-x-y", please check out #27713

zcbenz pushed a commit that referenced this pull request Feb 18, 2021
#27007) (#27712)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>

Co-authored-by: Stewart Lord <stew@offbynone.com>
zcbenz pushed a commit that referenced this pull request Feb 18, 2021
#27007) (#27713)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>

Co-authored-by: Stewart Lord <stew@offbynone.com>
@trop trop bot removed the in-flight/10-x-y label Feb 18, 2021
zcbenz pushed a commit that referenced this pull request Feb 18, 2021
#27711)

* feat: add `win.setTopBrowserView()` so that BrowserViews can be raised (#27007)

* feat: Raise a browser view via `BrowserWindow.setTopBrowserView()`.

This is similar to removing and re-adding a browser view, but avoids a visible flicker as the browser view is not removed from the window when using `setTopBrowserView`. Note: if the given browser view is not attached to the window, it will be added.

This commit contains the macOS implementation.

* feat: setTopBrowserView support for Windows and Linux

* docs: add info about setTopBrowserView

* docs: Clarify behavior when browserView is not yet attached.

* fix: throw en error when browserView is not attached to the window

* fix: build error

* fix: test

* fix: add test case

* fix: tests

* fix: reparenting

* fix: close second window in tests

Co-authored-by: sentialx <sentialx@gmail.com>

* fix: build error

Co-authored-by: Stewart Lord <stew@offbynone.com>
@trop trop bot added the merged/10-x-y label Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants