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 webPreferences.enablePreferredSizeMode #25874

Merged
merged 5 commits into from Oct 21, 2020

Conversation

samuelmaddock
Copy link
Member

@samuelmaddock samuelmaddock commented Oct 10, 2020

Description of Change

For Chrome extension popups and options windows, the size of their frame corresponds to the minimum size of their document's layout. To enable this, RenderViewHost::EnablePreferredSizeMode exists to notify the RenderView to send back updates with its size. This gives an interesting result where the document can dictate its frame's size.

In practice, it looks like this:
2020-10-10_14-45-18

Example code:

const view = new BrowserView({
  webPreferences: {
    preferredSizeMode: true,
  },
})
view.webContents.on('preferred-size-changed', (event, size) => {
  view.setBounds({ x: 0, y: 0, width: size.width, height: size.height })
})

I could see this being useful for specialized modal popups as well.

cc @electron/wg-api -- Question for you: is it worth adding tests for just adding bindings to existing Chromium functionality?

relates to #19447

Checklist

Release Notes

Notes: Added webPreferences.preferredSizeMode to allow sizing views according to their document's minimum size.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Oct 10, 2020
samuelmaddock added a commit to samuelmaddock/electron-browser-shell that referenced this pull request Oct 10, 2020
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (web_preferences &&
web_preferences->IsEnabled(options::kPreferredSizeMode))
web_contents()->GetRenderViewHost()->EnablePreferredSizeMode();
Copy link
Member Author

Choose a reason for hiding this comment

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

@sentialx
Copy link
Contributor

Great job! Could this be backported to 9-x-y?

@samuelmaddock
Copy link
Member Author

Great job! Could this be backported to 9-x-y?

At the will of @electron/wg-releases, probably. I'd like to target 11-x-y at the least.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Oct 11, 2020
docs/api/browser-window.md Outdated Show resolved Hide resolved
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

This is pretty nice.

@ckerr
Copy link
Member

ckerr commented Oct 13, 2020

linux CI failure seems unrelated: E1013 02:31:23.397542 22963 gomacc.cc:409] GOMA: compiler proxy not working?

@samuelmaddock samuelmaddock changed the title feat: add webPreferences.preferredSizeMode feat: add webPreferences.enablePreferredSizeMode Oct 19, 2020
@jkleinsc
Copy link
Contributor

The API WG approved this at our Oct 19 2020 meeting.

@codebytere codebytere merged commit 10a209e into electron:master Oct 21, 2020
@release-clerk
Copy link

release-clerk bot commented Oct 21, 2020

Release Notes Persisted

Added webPreferences.preferredSizeMode to allow sizing views according to their document's minimum size.

@samuelmaddock samuelmaddock deleted the feat/preferred-size-mode branch October 22, 2020 04:06
@samuelmaddock
Copy link
Member Author

@codebytere oof, I just realized the notes were not updated to reflect the renamed API. It should be webPreferences.enablePreferredSizeMode. How would one go about correcting that in the persisted release notes?

gerhardberger pushed a commit to gerhardberger/electron that referenced this pull request Dec 26, 2021
…ectron#78)

* feat: add preferredSizeMode preference

* docs: webPreferences.preferredSizeMode and event

* docs: better explain preferred size

* docs: small improvement

* refactor: preferredSizeMode -> enablePreferredSizeMode
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

6 participants