From eae0674f61a205ecd0468b2f7cb43fe9d07bc60b Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 12 May 2018 17:37:31 +0200 Subject: [PATCH 1/4] Match chromium's workaround when setting size of unresizable windows --- atom/browser/native_window.cc | 37 +++++++++++++++++++++++++ atom/browser/native_window.h | 2 ++ atom/browser/ui/views/frameless_view.cc | 4 +-- spec/api-browser-window-spec.js | 18 ++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 0fbb96aa3a14..f31205e653e6 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -4,6 +4,7 @@ #include "atom/browser/native_window.h" +#include #include #include #include @@ -13,12 +14,35 @@ #include "atom/common/color_util.h" #include "atom/common/options_switches.h" #include "native_mate/dictionary.h" +#include "ui/base/win/shell.h" +#include "ui/display/win/screen_win.h" #include "ui/views/widget/widget.h" DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::NativeWindowRelay); namespace atom { +namespace { + +#if defined(OS_WIN) + gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { + if (!window->transparent() || !ui::win::IsAeroGlassEnabled()) + return size; + + gfx::Size min_size = display::win::ScreenWin::ScreenToDIPSize( + window->GetAcceleratedWidget(), gfx::Size(64, 64)); + + // Some AMD drivers can't display windows that are less than 64x64 pixels, + // so expand them to be at least that size. http://crbug.com/286609 + gfx::Size expanded( + std::max(size.width(), min_size.width()), + std::max(size.height(), min_size.height())); + return expanded; + } +#endif + +} // namespace + NativeWindow::NativeWindow(const mate::Dictionary& options, NativeWindow* parent) : widget_(new views::Widget), @@ -254,6 +278,19 @@ gfx::Size NativeWindow::GetMaximumSize() const { return GetSizeConstraints().GetMaximumSize(); } +gfx::Size NativeWindow::GetContentMinimumSize() const { + return GetContentSizeConstraints().GetMinimumSize(); +} + +gfx::Size NativeWindow::GetContentMaximumSize() const { + gfx::Size maximum_size = GetContentSizeConstraints().GetMaximumSize(); +#if defined(OS_WIN) + return GetExpandedWindowSize(this, maximum_size); +#elif + return maximum_size; +#endif +} + void NativeWindow::SetSheetOffset(const double offsetX, const double offsetY) { sheet_offset_x_ = offsetX; sheet_offset_y_ = offsetY; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 4f3b5719abf6..89281f65c995 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -102,6 +102,8 @@ class NativeWindow : public base::SupportsUserData, virtual gfx::Size GetMinimumSize() const; virtual void SetMaximumSize(const gfx::Size& size); virtual gfx::Size GetMaximumSize() const; + virtual gfx::Size GetContentMinimumSize() const; + virtual gfx::Size GetContentMaximumSize() const; virtual void SetSheetOffset(const double offsetX, const double offsetY); virtual double GetSheetOffsetX(); virtual double GetSheetOffsetY(); diff --git a/atom/browser/ui/views/frameless_view.cc b/atom/browser/ui/views/frameless_view.cc index 60220e93c308..579419659a51 100644 --- a/atom/browser/ui/views/frameless_view.cc +++ b/atom/browser/ui/views/frameless_view.cc @@ -100,11 +100,11 @@ gfx::Size FramelessView::CalculatePreferredSize() const { } gfx::Size FramelessView::GetMinimumSize() const { - return window_->GetContentSizeConstraints().GetMinimumSize(); + return window_->GetContentMinimumSize(); } gfx::Size FramelessView::GetMaximumSize() const { - return window_->GetContentSizeConstraints().GetMaximumSize(); + return window_->GetContentMaximumSize(); } const char* FramelessView::GetClassName() const { diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 47d8cd1ecf01..dbc02006fbf3 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -2235,6 +2235,24 @@ describe('BrowserWindow module', () => { assert.equal(w.isResizable(), false) } }) + + if (process.platform === 'win32') { + it('works for a window smaller than 64x64', () => { + w.destroy() + w = new BrowserWindow({ + show: false, + frame: false, + resizable: false, + transparent: true + }) + w.setContentSize(60, 60) + assertBoundsEqual(w.getContentSize(), [60, 60]) + w.setContentSize(30, 30) + assertBoundsEqual(w.getContentSize(), [30, 30]) + w.setContentSize(10, 10) + assertBoundsEqual(w.getContentSize(), [10, 10]) + }) + } }) describe('loading main frame state', () => { From f1fd457411dce0a8d495ca8f70784e9e0bcfbcf5 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 12 May 2018 19:51:19 +0200 Subject: [PATCH 2/4] Format code with clang-format --- atom/browser/native_window.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index f31205e653e6..35fdfa09edd5 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -25,20 +25,19 @@ namespace atom { namespace { #if defined(OS_WIN) - gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { - if (!window->transparent() || !ui::win::IsAeroGlassEnabled()) - return size; +gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { + if (!window->transparent() || !ui::win::IsAeroGlassEnabled()) + return size; - gfx::Size min_size = display::win::ScreenWin::ScreenToDIPSize( + gfx::Size min_size = display::win::ScreenWin::ScreenToDIPSize( window->GetAcceleratedWidget(), gfx::Size(64, 64)); - // Some AMD drivers can't display windows that are less than 64x64 pixels, - // so expand them to be at least that size. http://crbug.com/286609 - gfx::Size expanded( - std::max(size.width(), min_size.width()), - std::max(size.height(), min_size.height())); - return expanded; - } + // Some AMD drivers can't display windows that are less than 64x64 pixels, + // so expand them to be at least that size. http://crbug.com/286609 + gfx::Size expanded(std::max(size.width(), min_size.width()), + std::max(size.height(), min_size.height())); + return expanded; +} #endif } // namespace From c6bf39b283a38069663c74520030bab8a7bba27d Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 12 May 2018 21:33:47 +0200 Subject: [PATCH 3/4] Only include windows headers on windows --- atom/browser/native_window.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 35fdfa09edd5..a24652744161 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -14,9 +14,12 @@ #include "atom/common/color_util.h" #include "atom/common/options_switches.h" #include "native_mate/dictionary.h" +#include "ui/views/widget/widget.h" + +#if defined(OS_WIN) #include "ui/base/win/shell.h" #include "ui/display/win/screen_win.h" -#include "ui/views/widget/widget.h" +#endif DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::NativeWindowRelay); @@ -556,7 +559,7 @@ const views::Widget* NativeWindow::GetWidget() const { } NativeWindowRelay::NativeWindowRelay(base::WeakPtr window) - : key(UserDataKey()), window(window) {} + : key(UserDataKey()), window(window) {} NativeWindowRelay::~NativeWindowRelay() = default; From ce8af7d49992530c6fe1314c331980978df2dfdb Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 12 May 2018 22:05:25 +0200 Subject: [PATCH 4/4] #else instead of #elif --- atom/browser/native_window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index a24652744161..85848e3d48a2 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -288,7 +288,7 @@ gfx::Size NativeWindow::GetContentMaximumSize() const { gfx::Size maximum_size = GetContentSizeConstraints().GetMaximumSize(); #if defined(OS_WIN) return GetExpandedWindowSize(this, maximum_size); -#elif +#else return maximum_size; #endif }