fix: window maximizing with Mica (#45456)
* fix: window maximizing with Mica * Fix rounded corners after restore
This commit is contained in:
parent
96460becf9
commit
9199d5c610
3 changed files with 75 additions and 57 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue