Sitelet https://github.com/flutter/flutter/pull/185256
Skip to content

[macOS] Implement size to content regular and dialog windows. - #185256

Merged
knopp merged 20 commits into
flutter:masterfrom
knopp:macos_size_to_content
Sep 9, 2026
Merged

knopp merged 20 commits into
flutter:masterfrom
knopp:macos_size_to_content

Conversation

@knopp

@knopp knopp commented Apr 19, 2026 •

Copy link
Copy Markdown
Member

Implements size to content in both resizable and non-resizable regular and dialog windows.
Delays displaying windows until first render.

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@knopp
knopp requested a review from a team as a code owner April 19, 2026 18:58
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine related. See also e: labels. platform-macos Building on or for macOS specifically a: desktop Running on desktop team-macos Owned by the macOS platform team labels Apr 19, 2026
@knopp
knopp marked this pull request as draft April 19, 2026 18:58

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request implements support for windows sized to their content by adding sizedToContent factory constructors to window controllers and introducing a resizable property. The macOS implementation is updated with a FlutterViewContentDelegate to manage content-based resizing. Review feedback highlights a logic error in FlutterWindowController.mm where the window resizing condition on the first frame is inverted, potentially ignoring preferred sizes. A typo was also noted in the source comments.

@knopp knopp added the CICD Run CI/CD label Apr 20, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 21, 2026
@knopp knopp added the CICD Run CI/CD label Apr 21, 2026
@knopp
knopp marked this pull request as ready for review April 21, 2026 13:51

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for windows sized to their content by introducing a sizedToContent factory for window controllers and a resizable property. The macOS implementation is updated to use a FlutterViewContentDelegate for content-based resizing and an onFirstFrame callback for window visibility. A potential retain cycle was identified in FlutterWindowController.mm where self is strongly captured within a block.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 21, 2026
@gaaclarke
gaaclarke self-requested a review April 21, 2026 18:14
@gaaclarke gaaclarke added the CICD Run CI/CD label Apr 22, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I looked through everything and it is looking good to me. Maybe we can get loic's review too since he'll probably be more familiar with any potential problems in this code.

Comment on lines 246 to 251
if (self.onFirstFrame) {
self.onFirstFrame();
self.onFirstFrame = nil;
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this only in the else branch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a case where window positioner disagrees with window size. In which case we tighten the constraints and regenerate frame. We don't want to show the window if this happens, it's better to delay showing by one frame (on next frame with new constraints the else branch will happen).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Working that into the comment will help. This logic is a bit fiddly.

@knopp knopp Apr 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the logic. When positioner disagrees with the size, new constraints are sent and the method exits early. That removes the onFirstFrame() from the else block. Seems a bit less fiddly to me.

@knopp
knopp force-pushed the macos_size_to_content branch from b14d6e3 to 319f23c Compare April 28, 2026 10:54
@github-actions github-actions Bot removed a: tests "flutter test", flutter_test, or one of our tests CICD Run CI/CD labels Apr 28, 2026
@knopp
knopp requested a review from gaaclarke April 28, 2026 10:58
@knopp knopp added the CICD Run CI/CD label Apr 28, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 28, 2026
@knopp knopp added the CICD Run CI/CD label Apr 28, 2026
gaaclarke
gaaclarke previously approved these changes Apr 28, 2026

@gaaclarke gaaclarke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code looks good to me and testing looks good. The logic is a bit fiddly. It would be nice if @loic-sharma could give it a look too since he's more familiar with this code and he might have an idea on how to simplify or make it more clear.

Comment thread engine/src/flutter/shell/platform/darwin/macos/framework/Source/FlutterView.h Outdated
Comment on lines 246 to 251
if (self.onFirstFrame) {
self.onFirstFrame();
self.onFirstFrame = nil;
}
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Working that into the comment will help. This logic is a bit fiddly.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 28, 2026
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Apr 28, 2026
@knopp
knopp force-pushed the macos_size_to_content branch from 55105dc to 0e81599 Compare September 9, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. framework flutter/packages/flutter repository. See also f: labels. platform-macos Building on or for macOS specifically team-macos Owned by the macOS platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants