From b42fd1ddca873b7354e39558935eba517fe1706e Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 26 Jul 2022 19:30:15 +0200 Subject: [PATCH] fix: handle WCO pressed state when going maximized -> minimized (#35070) --- shell/browser/native_window_views.h | 1 + shell/browser/native_window_views_win.cc | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 5454aafaec05..6672e3c2c7fc 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -225,6 +225,7 @@ class NativeWindowViews : public NativeWindow, #if BUILDFLAG(IS_WIN) void HandleSizeEvent(WPARAM w_param, LPARAM l_param); + void ResetWindowControls(); void SetForwardMouseMessages(bool forward); static LRESULT CALLBACK SubclassProc(HWND hwnd, UINT msg, diff --git a/shell/browser/native_window_views_win.cc b/shell/browser/native_window_views_win.cc index 9c0b54393958..dc6f089d06bf 100644 --- a/shell/browser/native_window_views_win.cc +++ b/shell/browser/native_window_views_win.cc @@ -415,6 +415,7 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { last_window_state_ != ui::SHOW_STATE_MAXIMIZED) { last_window_state_ = ui::SHOW_STATE_MAXIMIZED; NotifyWindowMaximize(); + ResetWindowControls(); } else if (w_param == SIZE_MINIMIZED && last_window_state_ != ui::SHOW_STATE_MINIMIZED) { last_window_state_ = ui::SHOW_STATE_MINIMIZED; @@ -440,18 +441,23 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) { default: break; } - // If a given window was minimized/maximized and has since been - // restored, ensure the WCO buttons are set to normal state. - auto* ncv = widget()->non_client_view(); - if (IsWindowControlsOverlayEnabled() && ncv) { - auto* frame_view = static_cast(ncv->frame_view()); - frame_view->caption_button_container()->ResetWindowControls(); - } + ResetWindowControls(); break; } } } +void NativeWindowViews::ResetWindowControls() { + // If a given window was minimized and has since been + // unminimized (restored/maximized), ensure the WCO buttons + // are reset to their default unpressed state. + auto* ncv = widget()->non_client_view(); + if (IsWindowControlsOverlayEnabled() && ncv) { + auto* frame_view = static_cast(ncv->frame_view()); + frame_view->caption_button_container()->ResetWindowControls(); + } +} + void NativeWindowViews::SetForwardMouseMessages(bool forward) { if (forward && !forwarding_mouse_messages_) { forwarding_mouse_messages_ = true;