chrome: Standardize fullscreen transition behavor/callbacks (fixes #3571)

Use the same code path for all fullscreen transitions so that Chrome UI updates
correctly. All user-initiated fullscreen transitions now result in
CefWindowDelegate::OnWindowFullscreenTransition callbacks.
This commit is contained in:
Marshall Greenblatt
2023-09-25 15:40:17 -04:00
parent 475b91e0ed
commit 885c92cd15
33 changed files with 521 additions and 195 deletions

View File

@@ -36,6 +36,13 @@ void ExpectCloseRects(const CefRect& expected,
EXPECT_LE(abs(expected.height - actual.height), allowed_deviance);
}
void ExpectClosePoints(const CefPoint& expected,
const CefPoint& actual,
int allowed_deviance) {
EXPECT_LE(abs(expected.x - actual.x), allowed_deviance);
EXPECT_LE(abs(expected.y - actual.y), allowed_deviance);
}
void WindowCreateImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
TestWindowDelegate::RunTest(event, std::move(config));
@@ -47,23 +54,106 @@ void WindowCreateFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowShow(CefRefPtr<CefWindow> window) {
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
window->Show();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
void RunWindowShow(cef_show_state_t initial_show_state,
CefRefPtr<CefWindow> window) {
#if defined(OS_MAC)
if (initial_show_state == CEF_SHOW_STATE_FULLSCREEN) {
// On MacOS, starting in fullscreen mode also shows the window on creation.
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
} else
#endif
{
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
window->Show();
}
if (initial_show_state == CEF_SHOW_STATE_MINIMIZED) {
#if !defined(OS_MAC)
// This result is a bit unexpected, but I guess the platform considers a
// window to be visible even when it's minimized.
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
#else
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
#endif
} else {
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
}
switch (initial_show_state) {
case CEF_SHOW_STATE_NORMAL:
EXPECT_FALSE(window->IsMaximized());
EXPECT_FALSE(window->IsMinimized());
EXPECT_FALSE(window->IsFullscreen());
break;
case CEF_SHOW_STATE_MINIMIZED:
EXPECT_FALSE(window->IsMaximized());
#if defined(OS_WIN)
// On MacOS, IsMinimized() state isn't reliable in this callback due to a
// timing issue between NativeWidgetMac::Minimize requesting the minimize
// state change (before this callback) and
// NativeWidgetMacNSWindowHost::OnWindowMiniaturizedChanged indicating the
// completed state change (after this callback).
// On Linux, there's likely a similar timing issue.
EXPECT_TRUE(window->IsMinimized());
#endif
EXPECT_FALSE(window->IsFullscreen());
break;
case CEF_SHOW_STATE_MAXIMIZED:
#if !defined(OS_LINUX)
// On Linux, there's likely a similar timing issue.
EXPECT_TRUE(window->IsMaximized());
#endif
EXPECT_FALSE(window->IsMinimized());
EXPECT_FALSE(window->IsFullscreen());
break;
case CEF_SHOW_STATE_FULLSCREEN:
EXPECT_FALSE(window->IsMaximized());
EXPECT_FALSE(window->IsMinimized());
EXPECT_TRUE(window->IsFullscreen());
break;
}
}
void WindowCreateWithOriginImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->window_origin = {100, 200};
config->on_window_created = base::BindOnce(RunWindowShow);
config->on_window_created =
base::BindOnce(RunWindowShow, config->initial_show_state);
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowShowHide(CefRefPtr<CefWindow> window) {
RunWindowShow(window);
void WindowCreateMinimizedImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->initial_show_state = CEF_SHOW_STATE_MINIMIZED;
config->on_window_created =
base::BindOnce(RunWindowShow, config->initial_show_state);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowCreateMaximizedImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->initial_show_state = CEF_SHOW_STATE_MAXIMIZED;
config->on_window_created =
base::BindOnce(RunWindowShow, config->initial_show_state);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowCreateFullscreenImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->initial_show_state = CEF_SHOW_STATE_FULLSCREEN;
config->on_window_created =
base::BindOnce(RunWindowShow, config->initial_show_state);
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowShowHide(cef_show_state_t initial_show_state,
CefRefPtr<CefWindow> window) {
RunWindowShow(initial_show_state, window);
window->Hide();
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
@@ -71,13 +161,15 @@ void RunWindowShowHide(CefRefPtr<CefWindow> window) {
void WindowShowHideImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowShowHide);
config->on_window_created =
base::BindOnce(RunWindowShowHide, config->initial_show_state);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowShowHideFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowShowHide);
config->on_window_created =
base::BindOnce(RunWindowShowHide, config->initial_show_state);
config->frameless = true;
TestWindowDelegate::RunTest(event, std::move(config));
}
@@ -146,9 +238,9 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
point);
point = CefPoint(0, 0);
EXPECT_TRUE(view2->ConvertPointToScreen(point));
EXPECT_EQ(CefPoint(client_bounds_in_screen.x,
client_bounds_in_screen.y + kWSize / 2),
point);
ExpectClosePoints(CefPoint(client_bounds_in_screen.x,
client_bounds_in_screen.y + kWSize / 2),
point, 1);
// Test view from screen coordinate conversions.
point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y);
@@ -157,7 +249,7 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
point = CefPoint(client_bounds_in_screen.x,
client_bounds_in_screen.y + kWSize / 2);
EXPECT_TRUE(view2->ConvertPointFromScreen(point));
EXPECT_EQ(CefPoint(0, 0), point);
ExpectClosePoints(CefPoint(0, 0), point, 1);
// Test view to window coordinate conversions.
point = CefPoint(0, 0);
@@ -165,7 +257,7 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
EXPECT_EQ(CefPoint(0, 0), point);
point = CefPoint(0, 0);
EXPECT_TRUE(view2->ConvertPointToWindow(point));
EXPECT_EQ(CefPoint(0, kWSize / 2), point);
ExpectClosePoints(CefPoint(0, kWSize / 2), point, 1);
// Test view from window coordinate conversions.
point = CefPoint(0, 0);
@@ -173,23 +265,23 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
EXPECT_EQ(CefPoint(0, 0), point);
point = CefPoint(0, kWSize / 2);
EXPECT_TRUE(view2->ConvertPointFromWindow(point));
EXPECT_EQ(CefPoint(0, 0), point);
ExpectClosePoints(CefPoint(0, 0), point, 1);
// Test view to view coordinate conversions.
point = CefPoint(0, 0);
EXPECT_TRUE(view1->ConvertPointToView(view2, point));
EXPECT_EQ(CefPoint(0, -kWSize / 2), point);
ExpectClosePoints(CefPoint(0, -kWSize / 2), point, 1);
point = CefPoint(0, 0);
EXPECT_TRUE(view2->ConvertPointToView(view1, point));
EXPECT_EQ(CefPoint(0, kWSize / 2), point);
ExpectClosePoints(CefPoint(0, kWSize / 2), point, 1);
// Test view from view coordinate conversions.
point = CefPoint(0, -kWSize / 2);
EXPECT_TRUE(view1->ConvertPointFromView(view2, point));
EXPECT_EQ(CefPoint(0, 0), point);
ExpectClosePoints(CefPoint(0, 0), point, 1);
point = CefPoint(0, kWSize / 2);
EXPECT_TRUE(view2->ConvertPointFromView(view1, point));
EXPECT_EQ(CefPoint(0, 0), point);
ExpectClosePoints(CefPoint(0, 0), point, 1);
CefRefPtr<CefDisplay> display = window->GetDisplay();
EXPECT_TRUE(display.get());
@@ -198,8 +290,8 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y);
display->ConvertPointToPixels(point);
display->ConvertPointFromPixels(point);
EXPECT_EQ(CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y),
point);
ExpectClosePoints(
CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y), point, 1);
// We don't know what the pixel values will be, but they should be reversable.
point = CefPoint(client_bounds_in_screen.x, client_bounds_in_screen.y);
@@ -278,10 +370,15 @@ void VerifyMinimize(CefRefPtr<CefWindow> window) {
EXPECT_FALSE(window->IsMaximized());
EXPECT_FALSE(window->IsFullscreen());
#if defined(OS_WIN)
// This result is a bit unexpected, but I guess the platform considers a
// window to be visible even when it's minimized.
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
#else
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(window->IsDrawn());
#endif
window->Restore();
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyRestore, window),
@@ -316,28 +413,26 @@ void WindowMinimizeFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void VerifyFullscreenExit(CefRefPtr<CefWindow> window) {
void WindowFullscreenTransitionComplete(CefRefPtr<CefWindow> window,
size_t count) {
EXPECT_FALSE(window->IsMinimized());
#if defined(OS_MAC)
// On MacOS, IsMaximized() returns true when IsFullscreen() returns true.
EXPECT_EQ(window->IsFullscreen(), window->IsMaximized());
#else
EXPECT_FALSE(window->IsMaximized());
EXPECT_FALSE(window->IsFullscreen());
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
#endif
// End the test by closing the Window.
window->Close();
}
if (window->IsFullscreen()) {
EXPECT_EQ(1U, count);
window->SetFullscreen(false);
} else {
EXPECT_EQ(2U, count);
void VerifyFullscreen(CefRefPtr<CefWindow> window) {
EXPECT_FALSE(window->IsMinimized());
EXPECT_FALSE(window->IsMaximized());
EXPECT_TRUE(window->IsFullscreen());
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window->IsDrawn());
window->SetFullscreen(false);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyFullscreenExit, window),
kStateDelayMS);
// End the test by closing the Window.
window->Close();
}
}
void RunWindowFullscreen(CefRefPtr<CefWindow> window) {
@@ -350,13 +445,13 @@ void RunWindowFullscreen(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->SetFullscreen(true);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyFullscreen, window),
kStateDelayMS);
}
void WindowFullscreenImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowFullscreen);
config->on_window_fullscreen_transition_complete =
base::BindRepeating(WindowFullscreenTransitionComplete);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
@@ -364,6 +459,8 @@ void WindowFullscreenImpl(CefRefPtr<CefWaitableEvent> event) {
void WindowFullscreenFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowFullscreen);
config->on_window_fullscreen_transition_complete =
base::BindRepeating(WindowFullscreenTransitionComplete);
config->frameless = true;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
@@ -505,6 +602,9 @@ void WindowAcceleratorImpl(CefRefPtr<CefWaitableEvent> event) {
WINDOW_TEST_ASYNC(WindowCreate)
WINDOW_TEST_ASYNC(WindowCreateFrameless)
WINDOW_TEST_ASYNC(WindowCreateWithOrigin)
WINDOW_TEST_ASYNC(WindowCreateMinimized)
WINDOW_TEST_ASYNC(WindowCreateMaximized)
WINDOW_TEST_ASYNC(WindowCreateFullscreen)
WINDOW_TEST_ASYNC(WindowShowHide)
WINDOW_TEST_ASYNC(WindowShowHideFrameless)
WINDOW_TEST_ASYNC(WindowLayoutAndCoords)