fix: window bounds not scaled from screen coordinates (#29162)
This commit is contained in:
parent
2806664bd0
commit
d518b6abc8
3 changed files with 30 additions and 20 deletions
|
@ -82,6 +82,22 @@
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
|
||||||
|
// Similar to the ones in display::win::ScreenWin, but with rounded values
|
||||||
|
// These help to avoid problems that arise from unresizable windows where the
|
||||||
|
// original ceil()-ed values can cause calculation errors, since converting
|
||||||
|
// both ways goes through a ceil() call. Related issue: #15816
|
||||||
|
gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
||||||
|
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
||||||
|
gfx::Rect dip_rect = ScaleToRoundedRect(pixel_bounds, 1.0f / scale_factor);
|
||||||
|
dip_rect.set_origin(
|
||||||
|
display::win::ScreenWin::ScreenToDIPRect(hwnd, pixel_bounds).origin());
|
||||||
|
return dip_rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
|
@ -96,18 +112,6 @@ void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
|
||||||
::SetWindowLong(handle, GWL_STYLE, style);
|
::SetWindowLong(handle, GWL_STYLE, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar to the ones in display::win::ScreenWin, but with rounded values
|
|
||||||
// These help to avoid problems that arise from unresizable windows where the
|
|
||||||
// original ceil()-ed values can cause calculation errors, since converting
|
|
||||||
// both ways goes through a ceil() call. Related issue: #15816
|
|
||||||
gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
|
||||||
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
|
||||||
gfx::Rect dip_rect = ScaleToRoundedRect(pixel_bounds, 1.0f / scale_factor);
|
|
||||||
dip_rect.set_origin(
|
|
||||||
display::win::ScreenWin::ScreenToDIPRect(hwnd, pixel_bounds).origin());
|
|
||||||
return dip_rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Rect DIPToScreenRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
gfx::Rect DIPToScreenRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
|
||||||
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
|
||||||
gfx::Rect screen_rect = ScaleToRoundedRect(pixel_bounds, scale_factor);
|
gfx::Rect screen_rect = ScaleToRoundedRect(pixel_bounds, scale_factor);
|
||||||
|
|
|
@ -35,6 +35,10 @@ class WindowStateWatcher;
|
||||||
class EventDisabler;
|
class EventDisabler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds);
|
||||||
|
#endif
|
||||||
|
|
||||||
class NativeWindowViews : public NativeWindow,
|
class NativeWindowViews : public NativeWindow,
|
||||||
public views::WidgetObserver,
|
public views::WidgetObserver,
|
||||||
public ui::EventHandler {
|
public ui::EventHandler {
|
||||||
|
|
|
@ -260,11 +260,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
case WM_SIZING: {
|
case WM_SIZING: {
|
||||||
is_resizing_ = true;
|
is_resizing_ = true;
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
NotifyWindowWillResize(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
|
gfx::Rect bounds = gfx::Rect(*reinterpret_cast<RECT*>(l_param));
|
||||||
&prevent_default);
|
HWND hwnd = GetAcceleratedWidget();
|
||||||
|
gfx::Rect dpi_bounds = ScreenToDIPRect(hwnd, bounds);
|
||||||
|
NotifyWindowWillResize(dpi_bounds, &prevent_default);
|
||||||
if (prevent_default) {
|
if (prevent_default) {
|
||||||
::GetWindowRect(GetAcceleratedWidget(),
|
::GetWindowRect(hwnd, reinterpret_cast<RECT*>(l_param));
|
||||||
reinterpret_cast<RECT*>(l_param));
|
|
||||||
return true; // Tells Windows that the Sizing is handled.
|
return true; // Tells Windows that the Sizing is handled.
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -288,11 +289,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
|
||||||
case WM_MOVING: {
|
case WM_MOVING: {
|
||||||
is_moving_ = true;
|
is_moving_ = true;
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
NotifyWindowWillMove(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
|
gfx::Rect bounds = gfx::Rect(*reinterpret_cast<RECT*>(l_param));
|
||||||
&prevent_default);
|
HWND hwnd = GetAcceleratedWidget();
|
||||||
|
gfx::Rect dpi_bounds = ScreenToDIPRect(hwnd, bounds);
|
||||||
|
NotifyWindowWillMove(dpi_bounds, &prevent_default);
|
||||||
if (!movable_ || prevent_default) {
|
if (!movable_ || prevent_default) {
|
||||||
::GetWindowRect(GetAcceleratedWidget(),
|
::GetWindowRect(hwnd, reinterpret_cast<RECT*>(l_param));
|
||||||
reinterpret_cast<RECT*>(l_param));
|
|
||||||
return true; // Tells Windows that the Move is handled. If not true,
|
return true; // Tells Windows that the Move is handled. If not true,
|
||||||
// frameless windows can be moved using
|
// frameless windows can be moved using
|
||||||
// -webkit-app-region: drag elements.
|
// -webkit-app-region: drag elements.
|
||||||
|
|
Loading…
Reference in a new issue