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

@@ -5,77 +5,79 @@
#include "cef/libcef/browser/screen_util.h"
#include "tests/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
namespace {
constexpr int kScreenWidth = 1024;
constexpr int kScreenHeight = 768;
const CefRect kMainScreen(0, 0, kScreenWidth, kScreenHeight);
const CefRect kLeftScreen(-1024, 0, kScreenWidth, kScreenHeight);
const gfx::Rect kMainScreen(0, 0, kScreenWidth, kScreenHeight);
const gfx::Rect kLeftScreen(-1024, 0, kScreenWidth, kScreenHeight);
} // namespace
TEST(MakeVisibleOnScreenRect, RectSizeIsBiggerThanScreen) {
const CefRect rect{400, 500, 1500, 800};
const gfx::Rect rect{400, 500, 1500, 800};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 0);
EXPECT_EQ(result.width, kMainScreen.width);
EXPECT_EQ(result.y, 0);
EXPECT_EQ(result.height, kMainScreen.height);
EXPECT_EQ(result.x(), 0);
EXPECT_EQ(result.width(), kMainScreen.width());
EXPECT_EQ(result.y(), 0);
EXPECT_EQ(result.height(), kMainScreen.height());
}
TEST(MakeVisibleOnScreenRect, RightBorderIsOutsideTheScreen) {
const CefRect rect{600, 400, 500, 300};
const gfx::Rect rect{600, 400, 500, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 524);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
EXPECT_EQ(result.x(), 524);
EXPECT_EQ(result.width(), rect.width());
EXPECT_EQ(result.y(), rect.y());
EXPECT_EQ(result.height(), rect.height());
}
TEST(MakeVisibleOnScreenRect, LeftBorderIsOutsideTheScreen) {
const CefRect rect{-400, 400, 500, 300};
const gfx::Rect rect{-400, 400, 500, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 0);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
EXPECT_EQ(result.x(), 0);
EXPECT_EQ(result.width(), rect.width());
EXPECT_EQ(result.y(), rect.y());
EXPECT_EQ(result.height(), rect.height());
}
TEST(MakeVisibleOnScreenRect, BottomBorderIsOutsideTheScreen) {
const CefRect rect{600, 500, 300, 300};
const gfx::Rect rect{600, 500, 300, 300};
auto result = MakeVisibleOnScreenRect(rect, kMainScreen);
EXPECT_EQ(result.x, 600);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, 468);
EXPECT_EQ(result.height, rect.height);
EXPECT_EQ(result.x(), 600);
EXPECT_EQ(result.width(), rect.width());
EXPECT_EQ(result.y(), 468);
EXPECT_EQ(result.height(), rect.height());
}
TEST(MakeVisibleOnScreenRect, RectIsVisibleOnTheLeftScreen) {
const CefRect rect{-500, 300, 300, 300};
const gfx::Rect rect{-500, 300, 300, 300};
auto result = MakeVisibleOnScreenRect(rect, kLeftScreen);
EXPECT_EQ(result.x, rect.x);
EXPECT_EQ(result.width, rect.width);
EXPECT_EQ(result.y, rect.y);
EXPECT_EQ(result.height, rect.height);
EXPECT_EQ(result.x(), rect.x());
EXPECT_EQ(result.width(), rect.width());
EXPECT_EQ(result.y(), rect.y());
EXPECT_EQ(result.height(), rect.height());
}
TEST(MakeVisibleOnScreenRect, RectSizeIsBiggerThanLeftScreen) {
const CefRect rect{-500, 300, 3000, 3000};
const gfx::Rect rect{-500, 300, 3000, 3000};
auto result = MakeVisibleOnScreenRect(rect, kLeftScreen);
EXPECT_EQ(result.x, kLeftScreen.x);
EXPECT_EQ(result.width, kLeftScreen.width);
EXPECT_EQ(result.y, kLeftScreen.y);
EXPECT_EQ(result.height, kLeftScreen.height);
EXPECT_EQ(result.x(), kLeftScreen.x());
EXPECT_EQ(result.width(), kLeftScreen.width());
EXPECT_EQ(result.y(), kLeftScreen.y());
EXPECT_EQ(result.height(), kLeftScreen.height());
}