Match chromium's workaround when setting size of unresizable windows

This commit is contained in:
Heilig Benedek
2018-05-14 21:57:34 +02:00
parent 324b769751
commit e2e70e9b1e
4 changed files with 79 additions and 24 deletions

View File

@@ -4,6 +4,7 @@
#include "atom/browser/native_window.h"
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
@@ -47,10 +48,35 @@
#include "ui/gfx/font_render_params.h"
#endif
#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(
brightray::InspectableWebContents* inspectable_web_contents,
const mate::Dictionary& options,
@@ -307,6 +333,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

@@ -41,7 +41,7 @@ namespace gfx {
class Point;
class Rect;
class Size;
}
} // namespace gfx
namespace mate {
class Dictionary;
@@ -109,6 +109,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();
@@ -160,15 +162,14 @@ class NativeWindow : public base::SupportsUserData,
// Taskbar/Dock APIs.
enum ProgressState {
PROGRESS_NONE, // no progress, no marking
PROGRESS_INDETERMINATE, // progress, indeterminate
PROGRESS_ERROR, // progress, errored (red)
PROGRESS_PAUSED, // progress, paused (yellow)
PROGRESS_NORMAL, // progress, not marked (green)
PROGRESS_NONE, // no progress, no marking
PROGRESS_INDETERMINATE, // progress, indeterminate
PROGRESS_ERROR, // progress, errored (red)
PROGRESS_PAUSED, // progress, paused (yellow)
PROGRESS_NORMAL, // progress, not marked (green)
};
virtual void SetProgressBar(double progress,
const ProgressState state) = 0;
virtual void SetProgressBar(double progress, const ProgressState state) = 0;
virtual void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) = 0;
@@ -230,12 +231,11 @@ class NativeWindow : public base::SupportsUserData,
virtual void HandleKeyboardEvent(
content::WebContents*,
const content::NativeWebKeyboardEvent& event) {}
virtual void ShowAutofillPopup(
content::RenderFrameHost* frame_host,
content::WebContents* web_contents,
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {}
virtual void ShowAutofillPopup(content::RenderFrameHost* frame_host,
content::WebContents* web_contents,
const gfx::RectF& bounds,
const std::vector<base::string16>& values,
const std::vector<base::string16>& labels) {}
virtual void HideAutofillPopup(content::RenderFrameHost* frame_host) {}
virtual void UpdateDraggableRegionViews() {}
@@ -270,13 +270,11 @@ class NativeWindow : public base::SupportsUserData,
const base::DictionaryValue& details);
void NotifyNewWindowForTab();
#if defined(OS_WIN)
#if defined(OS_WIN)
void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param);
#endif
#endif
void AddObserver(NativeWindowObserver* obs) {
observers_.AddObserver(obs);
}
void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); }
void RemoveObserver(NativeWindowObserver* obs) {
observers_.RemoveObserver(obs);
}
@@ -390,11 +388,11 @@ class NativeWindow : public base::SupportsUserData,
};
// This class provides a hook to get a NativeWindow from a WebContents.
class NativeWindowRelay :
public content::WebContentsUserData<NativeWindowRelay> {
class NativeWindowRelay
: public content::WebContentsUserData<NativeWindowRelay> {
public:
explicit NativeWindowRelay(base::WeakPtr<NativeWindow> window)
: key(UserDataKey()), window(window) {}
: key(UserDataKey()), window(window) {}
static void* UserDataKey() {
return content::WebContentsUserData<NativeWindowRelay>::UserDataKey();

View File

@@ -104,11 +104,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

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