diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 0fbb96aa3a14..85848e3d48a2 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 @@ -15,10 +16,35 @@ #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" +#endif + 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 +280,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); +#else + return maximum_size; +#endif +} + void NativeWindow::SetSheetOffset(const double offsetX, const double offsetY) { sheet_offset_x_ = offsetX; sheet_offset_y_ = offsetY; @@ -520,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; 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', () => {