feat: enable innerWidth and innerHeight for window open (#46749)

* feat: enable innerWidth and innerHeight for window open

* update comment for added special innerWidth and innerHeight

* update 100 min spec requirement handling

* update testing to include getContentSize

* update macOS min requirement handling

* adjust refactored consts

* update const values from nativewindowviews
This commit is contained in:
Michaela Laurencin
2025-05-09 12:03:45 -04:00
committed by GitHub
parent 8ecd731e96
commit b9f0aebb2f
6 changed files with 87 additions and 8 deletions

View File

@@ -119,8 +119,8 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
ui::NativeTheme::GetInstanceForNativeUi()->AddObserver(this);
display::Screen::GetScreen()->AddObserver(this);
const int width = options.ValueOrDefault(options::kWidth, 800);
const int height = options.ValueOrDefault(options::kHeight, 600);
int width = options.ValueOrDefault(options::kWidth, 800);
int height = options.ValueOrDefault(options::kHeight, 600);
NSRect main_screen_rect = [[[NSScreen screens] firstObject] frame];
gfx::Rect bounds(round((NSWidth(main_screen_rect) - width) / 2),
@@ -283,8 +283,23 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
}
// Resize to content bounds.
const bool use_content_size =
// NOTE(@mlaurencin) Spec requirements can be found here:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
constexpr int kMinSizeReqdBySpec = 100;
int inner_width = 0;
int inner_height = 0;
bool use_content_size =
options.ValueOrDefault(options::kUseContentSize, false);
options.Get(options::kinnerWidth, &inner_width);
options.Get(options::kinnerHeight, &inner_height);
if (inner_width || inner_height) {
use_content_size = true;
if (inner_width)
width = std::max(kMinSizeReqdBySpec, inner_width);
if (inner_height)
height = std::max(kMinSizeReqdBySpec, inner_height);
}
if (!has_frame() || use_content_size)
SetContentSize(gfx::Size(width, height));

View File

@@ -259,7 +259,7 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
const int width = options.ValueOrDefault(options::kWidth, 800);
const int height = options.ValueOrDefault(options::kHeight, 600);
const gfx::Rect bounds{0, 0, width, height};
gfx::Rect bounds{0, 0, width, height};
widget_size_ = bounds.size();
widget()->AddObserver(this);
@@ -400,10 +400,25 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options,
// Default content view.
SetContentView(new views::View());
options.Get(options::kUseContentSize, &use_content_size_);
// NOTE(@mlaurencin) Spec requirements can be found here:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/open#width
int kMinSizeReqdBySpec = 100;
int inner_width = 0;
int inner_height = 0;
options.Get(options::kinnerWidth, &inner_width);
options.Get(options::kinnerHeight, &inner_height);
if (inner_width || inner_height) {
use_content_size_ = true;
if (inner_width)
bounds.set_width(std::max(kMinSizeReqdBySpec, inner_width));
if (inner_height)
bounds.set_height(std::max(kMinSizeReqdBySpec, inner_height));
}
gfx::Size size = bounds.size();
if (has_frame() &&
options.Get(options::kUseContentSize, &use_content_size_) &&
use_content_size_)
if (has_frame() && use_content_size_)
size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();
widget()->CenterWindow(size);

View File

@@ -26,6 +26,8 @@ inline constexpr std::string_view kMinWidth = "minWidth";
inline constexpr std::string_view kMinHeight = "minHeight";
inline constexpr std::string_view kMaxWidth = "maxWidth";
inline constexpr std::string_view kMaxHeight = "maxHeight";
inline constexpr std::string_view kinnerWidth = "innerWidth";
inline constexpr std::string_view kinnerHeight = "innerHeight";
inline constexpr std::string_view kResizable = "resizable";
inline constexpr std::string_view kMovable = "movable";
inline constexpr std::string_view kMinimizable = "minimizable";