fix: client area inset calculation when maximized for framless windows (#25052)

* adopt per monitor scale factor

* fix: client area inset calculation when maximized

* address review feedback

* pass correct glass insets to GetDwmFrameInsetsInPixels

* remove unused code

* Windows 8 and 10 use the same DWM frame calculation

Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
Robo 2020-08-31 00:55:50 -07:00 committed by GitHub
parent a09694ae85
commit 068b464e13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 6 deletions

View file

@ -4,12 +4,31 @@
#include "shell/browser/ui/views/win_frame_view.h"
#include "base/win/windows_version.h"
#include "shell/browser/native_window_views.h"
#include "ui/display/win/screen_win.h"
#include "ui/views/widget/widget.h"
#include "ui/views/win/hwnd_util.h"
namespace electron {
namespace {
gfx::Insets GetGlassInsets() {
int frame_height =
display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYSIZEFRAME) +
display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXPADDEDBORDER);
int frame_size =
base::win::GetVersion() < base::win::Version::WIN8
? display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXSIZEFRAME)
: 0;
return gfx::Insets(frame_height, frame_size, frame_size, frame_size);
}
} // namespace
const char WinFrameView::kViewClassName[] = "WinFrameView";
WinFrameView::WinFrameView() {}
@ -23,6 +42,17 @@ gfx::Rect WinFrameView::GetWindowBoundsForClientBounds(
client_bounds);
}
gfx::Rect WinFrameView::GetBoundsForClientView() const {
if (window_->IsMaximized() && !window_->has_frame()) {
gfx::Insets insets = GetGlassInsets();
gfx::Rect result(width(), height());
result.Inset(insets);
return result;
} else {
return bounds();
}
}
int WinFrameView::NonClientHitTest(const gfx::Point& point) {
if (window_->has_frame())
return frame_->client_view()->NonClientHitTest(point);

View file

@ -16,6 +16,7 @@ class WinFrameView : public FramelessView {
~WinFrameView() override;
// views::NonClientFrameView:
gfx::Rect GetBoundsForClientView() const override;
gfx::Rect GetWindowBoundsForClientBounds(
const gfx::Rect& client_bounds) const override;
int NonClientHitTest(const gfx::Point& point) override;