fix: window maximizing with Mica (#45525)

* fix: window maximizing with Mica

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

* Fix rounded corners after restore

Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-02-10 15:38:47 -05:00 committed by GitHub
parent acfe4766d2
commit fc697735c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 57 deletions

View file

@ -8,6 +8,7 @@
#include "base/win/atl.h" // Must be before UIAutomationCore.h
#include "base/win/scoped_handle.h"
#include "base/win/windows_version.h"
#include "content/public/browser/browser_accessibility_state.h"
#include "shell/browser/browser.h"
#include "shell/browser/native_window_views.h"
@ -225,25 +226,6 @@ bool IsScreenReaderActive() {
std::set<NativeWindowViews*> NativeWindowViews::forwarding_windows_;
HHOOK NativeWindowViews::mouse_hook_ = nullptr;
void NativeWindowViews::Maximize() {
// Only use Maximize() when window is NOT transparent style
if (!transparent()) {
if (IsVisible()) {
widget()->Maximize();
} else {
widget()->native_widget_private()->Show(
ui::mojom::WindowShowState::kMaximized, gfx::Rect());
NotifyWindowShow();
}
} else {
restore_bounds_ = GetBounds();
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(
GetNativeWindow());
SetBounds(display.work_area(), false);
NotifyWindowMaximize();
}
}
bool NativeWindowViews::ExecuteWindowsCommand(int command_id) {
const auto command_name = AppCommandToString(command_id);
NotifyWindowExecuteAppCommand(command_name);
@ -535,6 +517,24 @@ void NativeWindowViews::ResetWindowControls() {
}
}
// Windows with |backgroundMaterial| expand to the same dimensions and
// placement as the display to approximate maximization - unless we remove
// rounded corners there will be a gap between the window and the display
// at the corners noticable to users.
void NativeWindowViews::SetRoundedCorners(bool rounded) {
// DWMWA_WINDOW_CORNER_PREFERENCE is supported after Windows 11 Build 22000.
if (base::win::GetVersion() < base::win::Version::WIN11)
return;
DWM_WINDOW_CORNER_PREFERENCE round_pref =
rounded ? DWMWCP_ROUND : DWMWCP_DONOTROUND;
HRESULT result = DwmSetWindowAttribute(GetAcceleratedWidget(),
DWMWA_WINDOW_CORNER_PREFERENCE,
&round_pref, sizeof(round_pref));
if (FAILED(result))
LOG(WARNING) << "Failed to set rounded corners to " << rounded;
}
void NativeWindowViews::SetForwardMouseMessages(bool forward) {
if (forward && !forwarding_mouse_messages_) {
forwarding_mouse_messages_ = true;