From 0bceb4797b505c49cb3474cc034aa4ce5e5b27e0 Mon Sep 17 00:00:00 2001 From: Roger Wang Date: Thu, 27 Feb 2020 01:45:54 -0700 Subject: [PATCH] nw2: Fix window bound priorities saved > API parameter > default in manifest > default value Fix nwjs/nw.js#7370 CC nwjs/nw.js#7322 CC nwjs/nw.js#7314 --- chrome/browser/resources/nwjs/newwin.js | 7 ++++--- chrome/browser/ui/window_sizer/window_sizer.cc | 14 +++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/chrome/browser/resources/nwjs/newwin.js b/chrome/browser/resources/nwjs/newwin.js index efcd3b5aff6ee..179aaf18ecfec 100644 --- a/chrome/browser/resources/nwjs/newwin.js +++ b/chrome/browser/resources/nwjs/newwin.js @@ -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) diff --git a/chrome/browser/ui/window_sizer/window_sizer.cc b/chrome/browser/ui/window_sizer/window_sizer.cc index 155331249e735..dc49e32d073c5 100644 --- a/chrome/browser/ui/window_sizer/window_sizer.cc +++ b/chrome/browser/ui/window_sizer/window_sizer.cc @@ -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);