Merge pull request #12904 from electron/fix-12875

Allow frameless transparent windows to be sized smaller than 64x64 on Windows
This commit is contained in:
John Kleinschmidt 2018-05-14 10:46:40 -04:00 committed by GitHub
commit 0fd8513c80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 3 deletions

View file

@ -4,6 +4,7 @@
#include "atom/browser/native_window.h"
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
@ -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;

View file

@ -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();

View file

@ -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 {

View file

@ -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', () => {