fix: BrowserWindow.center()
should center relative to screen (#42100)
* fix: BrowserWindow.center() should center relative to screen Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> * chore: feedback from review & remove test 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:
parent
9d7b2003e3
commit
431dcfc0fe
1 changed files with 18 additions and 2 deletions
|
@ -39,6 +39,7 @@
|
||||||
#include "shell/common/options_switches.h"
|
#include "shell/common/options_switches.h"
|
||||||
#include "ui/aura/window_tree_host.h"
|
#include "ui/aura/window_tree_host.h"
|
||||||
#include "ui/base/hit_test.h"
|
#include "ui/base/hit_test.h"
|
||||||
|
#include "ui/display/screen.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
#include "ui/gfx/native_widget_types.h"
|
#include "ui/gfx/native_widget_types.h"
|
||||||
#include "ui/ozone/public/ozone_platform.h"
|
#include "ui/ozone/public/ozone_platform.h"
|
||||||
|
@ -80,9 +81,9 @@
|
||||||
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
|
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
|
||||||
#include "skia/ext/skia_utils_win.h"
|
#include "skia/ext/skia_utils_win.h"
|
||||||
#include "ui/base/win/shell.h"
|
#include "ui/base/win/shell.h"
|
||||||
#include "ui/display/screen.h"
|
|
||||||
#include "ui/display/win/screen_win.h"
|
#include "ui/display/win/screen_win.h"
|
||||||
#include "ui/gfx/color_utils.h"
|
#include "ui/gfx/color_utils.h"
|
||||||
|
#include "ui/gfx/win/hwnd_util.h"
|
||||||
#include "ui/gfx/win/msg_util.h"
|
#include "ui/gfx/win/msg_util.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1069,8 +1070,23 @@ ui::ZOrderLevel NativeWindowViews::GetZOrderLevel() const {
|
||||||
return widget()->GetZOrderLevel();
|
return widget()->GetZOrderLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We previous called widget()->CenterWindow() here, but in
|
||||||
|
// Chromium CL 4916277 behavior was changed to center relative to the
|
||||||
|
// parent window if there is one. We want to keep the old behavior
|
||||||
|
// for now to avoid breaking API contract, but should consider the long
|
||||||
|
// term plan for this aligning with upstream.
|
||||||
void NativeWindowViews::Center() {
|
void NativeWindowViews::Center() {
|
||||||
widget()->CenterWindow(GetSize());
|
#if BUILDFLAG(IS_LINUX)
|
||||||
|
auto display =
|
||||||
|
display::Screen::GetScreen()->GetDisplayNearestWindow(GetNativeWindow());
|
||||||
|
gfx::Rect window_bounds_in_screen = display.work_area();
|
||||||
|
window_bounds_in_screen.ClampToCenteredSize(GetSize());
|
||||||
|
widget()->SetBounds(window_bounds_in_screen);
|
||||||
|
#else
|
||||||
|
HWND hwnd = GetAcceleratedWidget();
|
||||||
|
gfx::Size size = display::win::ScreenWin::DIPToScreenSize(hwnd, GetSize());
|
||||||
|
gfx::CenterAndSizeWindow(hwnd, hwnd, size);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::Invalidate() {
|
void NativeWindowViews::Invalidate() {
|
||||||
|
|
Loading…
Reference in a new issue