Commit 23ab3627 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Mac: ensure modals report correct content rect

Modal sheets use "NSTitleWindowStyleMask" for Reasons (looks like mostly
input handling). This means that when we ask for their content rect, they
account for the title bar, though we don't actually display one!

In practice this means:
1. We've been undersizing modals for a while.
2. If it so happens that if we roundtrip back through NativeWidgetNSWindowBridge::SetBounds
(motivating example: when the window is moved to a screen with different DPI), we lose
*another* title bar's worth of height.

This change modifies the style mask so that the title bar isn't accounted for when
calculating the content rect.

Bug: 982477
Change-Id: I79da0297a1d79eaae3f7eaef85a5986c12b74436
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1721269
Auto-Submit: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681795}
parent 6fe5373e
......@@ -50,9 +50,11 @@ NSInteger StyleMaskForParams(const Widget::InitParams& params) {
// If the Widget is modal, it will be displayed as a sheet. This works best if
// it has NSTitledWindowMask. For example, with NSBorderlessWindowMask, the
// parent window still accepts input.
// NSFullSizeContentViewWindowMask ensures that calculating the modal's
// content rect doesn't account for a nonexistent title bar.
if (params.delegate &&
params.delegate->GetModalType() == ui::MODAL_TYPE_WINDOW)
return NSTitledWindowMask;
return NSTitledWindowMask | NSFullSizeContentViewWindowMask;
// TODO(tapted): Determine better masks when there are use cases for it.
if (params.remove_standard_frame)
......
......@@ -1384,7 +1384,10 @@ TEST_F(NativeWidgetMacTest, WindowModalSheet) {
// Although there is no titlebar displayed, sheets need NSTitledWindowMask in
// order to properly engage window-modal behavior in AppKit.
EXPECT_EQ(NSTitledWindowMask, [sheet_window styleMask]);
EXPECT_TRUE(NSTitledWindowMask & [sheet_window styleMask]);
// But to properly size, sheets also need NSFullSizeContentViewWindowMask.
EXPECT_TRUE(NSFullSizeContentViewWindowMask & [sheet_window styleMask]);
sheet_widget->SetBounds(gfx::Rect(50, 50, 200, 150));
EXPECT_FALSE(sheet_widget->IsVisible());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment