Skip to content

Commit

Permalink
nw2: Fix window bound priorities
Browse files Browse the repository at this point in the history
saved > API parameter > default in manifest > default value

Fix nwjs/nw.js#7370
CC nwjs/nw.js#7322
CC nwjs/nw.js#7314
  • Loading branch information
rogerwang committed Feb 27, 2020
1 parent 2ef0824 commit 0bceb47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 4 additions & 3 deletions chrome/browser/resources/nwjs/newwin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ var options = { 'url' : manifest.main, 'type': 'popup' };
var title = null;
if (manifest.window) {
//options.innerBounds = {};
// do NOT set option.width/height here. it will override the saved
// window placement. the default manifest size is handled in
// WindowSizer::GetDefaultWindowBounds() NWJS#7314
if (manifest.window.frame === false)
options.frameless = true;
if (manifest.window.resizable === false)
options.resizable = false;
if (manifest.window.height)
options.height = manifest.window.height;
if (manifest.window.width)
options.width = manifest.window.width;
if (manifest.window.min_width)
options.minWidth = manifest.window.min_width;
if (manifest.window.max_width)
Expand Down
14 changes: 11 additions & 3 deletions chrome/browser/ui/window_sizer/window_sizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,22 @@ void WindowSizer::DetermineWindowBoundsAndShowState(
return;
#endif

if (bounds->IsEmpty()) {
// In upstream, non empty case is only used in chrome tests, so we ignore it.
// In NW, the non empty value is the API parameter passed by browser->override_bounds()
// Use this strategy as the central place to determine window size
// priority: saved > API parameter > default in manifest > default value
if (true || bounds->IsEmpty()) {
// See if there's last active window's placement information.
if (GetLastActiveWindowBounds(bounds, show_state))
return;
gfx::Rect saved;
// See if there's saved placement information.
if (GetSavedWindowBounds(bounds, show_state))
if (GetSavedWindowBounds(&saved, show_state)) {
*bounds = saved;
return;
}
if (!bounds->IsEmpty())
return;

// No saved placement, figure out some sensible default size based on
// the user's screen size.
GetDefaultWindowBounds(GetDisplayForNewWindow(), bounds);
Expand Down

0 comments on commit 0bceb47

Please sign in to comment.