Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: window bounds not scaled from screen coordinates #29225

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 16 additions & 12 deletions shell/browser/native_window_views.cc
Expand Up @@ -72,19 +72,7 @@

namespace electron {

namespace {

#if defined(OS_WIN)
const LPCWSTR kUniqueTaskBarClassName = L"Shell_TrayWnd";

void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
if (on)
style |= flag;
else
style &= ~flag;
::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
Expand All @@ -98,6 +86,22 @@ gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
return dip_rect;
}

#endif

namespace {

#if defined(OS_WIN)
const LPCWSTR kUniqueTaskBarClassName = L"Shell_TrayWnd";

void FlipWindowStyle(HWND handle, bool on, DWORD flag) {
DWORD style = ::GetWindowLong(handle, GWL_STYLE);
if (on)
style |= flag;
else
style &= ~flag;
::SetWindowLong(handle, GWL_STYLE, style);
}

gfx::Rect DIPToScreenRect(HWND hwnd, const gfx::Rect& pixel_bounds) {
float scale_factor = display::win::ScreenWin::GetScaleFactorForHWND(hwnd);
gfx::Rect screen_rect = ScaleToRoundedRect(pixel_bounds, scale_factor);
Expand Down
4 changes: 4 additions & 0 deletions shell/browser/native_window_views.h
Expand Up @@ -35,6 +35,10 @@ class WindowStateWatcher;
class EventDisabler;
#endif

#if defined(OS_WIN)
gfx::Rect ScreenToDIPRect(HWND hwnd, const gfx::Rect& pixel_bounds);
#endif

class NativeWindowViews : public NativeWindow,
public views::WidgetObserver,
public ui::EventHandler {
Expand Down
18 changes: 10 additions & 8 deletions shell/browser/native_window_views_win.cc
Expand Up @@ -260,11 +260,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
case WM_SIZING: {
is_resizing_ = true;
bool prevent_default = false;
NotifyWindowWillResize(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
&prevent_default);
gfx::Rect bounds = gfx::Rect(*reinterpret_cast<RECT*>(l_param));
HWND hwnd = GetAcceleratedWidget();
gfx::Rect dpi_bounds = ScreenToDIPRect(hwnd, bounds);
NotifyWindowWillResize(dpi_bounds, &prevent_default);
if (prevent_default) {
::GetWindowRect(GetAcceleratedWidget(),
reinterpret_cast<RECT*>(l_param));
::GetWindowRect(hwnd, reinterpret_cast<RECT*>(l_param));
return true; // Tells Windows that the Sizing is handled.
}
return false;
Expand All @@ -288,11 +289,12 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
case WM_MOVING: {
is_moving_ = true;
bool prevent_default = false;
NotifyWindowWillMove(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
&prevent_default);
gfx::Rect bounds = gfx::Rect(*reinterpret_cast<RECT*>(l_param));
HWND hwnd = GetAcceleratedWidget();
gfx::Rect dpi_bounds = ScreenToDIPRect(hwnd, bounds);
NotifyWindowWillMove(dpi_bounds, &prevent_default);
if (!movable_ || prevent_default) {
::GetWindowRect(GetAcceleratedWidget(),
reinterpret_cast<RECT*>(l_param));
::GetWindowRect(hwnd, reinterpret_cast<RECT*>(l_param));
return true; // Tells Windows that the Move is handled. If not true,
// frameless windows can be moved using
// -webkit-app-region: drag elements.
Expand Down