windows: Fix size/placement with multi-DPI screen setup (fixes issue #3359)

Use ScreenWin functions to correctly compute DIP/pixel conversions for
CEF-created top-level windows.

Fix incorrect DIPToScreenRect usage in DesktopWindowTreeHostWin when
|has_external_parent_| is true.
This commit is contained in:
Marshall Greenblatt
2022-10-24 19:47:04 -04:00
parent 07bf5dbacc
commit 767c4422ac
8 changed files with 160 additions and 144 deletions

View File

@@ -6,6 +6,8 @@
#include <algorithm>
#include "ui/gfx/geometry/rect.h"
namespace {
constexpr int kMinWidth = 0;
@@ -25,15 +27,17 @@ int clamp_segment_start(int start, int len, int min, int max) {
} // namespace
CefRect MakeVisibleOnScreenRect(const CefRect& rect, const CefRect& screen) {
const int width = std::clamp(rect.width, kMinWidth, screen.width);
const int height = std::clamp(rect.height, kMinHeight, screen.height);
gfx::Rect MakeVisibleOnScreenRect(const gfx::Rect& rect,
const gfx::Rect& screen) {
const int width = std::clamp(rect.width(), kMinWidth, screen.width());
const int height = std::clamp(rect.height(), kMinHeight, screen.height());
const int right_border = screen.x + screen.width;
const int x = clamp_segment_start(rect.x, width, screen.x, right_border);
const int right_border = screen.x() + screen.width();
const int x = clamp_segment_start(rect.x(), width, screen.x(), right_border);
const int bottom_border = screen.y + screen.height;
const int y = clamp_segment_start(rect.y, height, screen.y, bottom_border);
const int bottom_border = screen.y() + screen.height();
const int y =
clamp_segment_start(rect.y(), height, screen.y(), bottom_border);
return CefRect(x, y, width, height);
return gfx::Rect(x, y, width, height);
}