mac: Update CSS on fullscreen window exit (fixes #3597)

This commit is contained in:
Marshall Greenblatt 2023-11-07 16:40:29 -05:00
parent 21e01d4889
commit 3837f209e1
11 changed files with 186 additions and 10 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=db4fce1215cb4f69346ef2d048974ba34187b2b1$
// $hash=13ba2d807f2c1ac3adfc65f2bdb269baecba57ec$
//
#ifndef CEF_INCLUDE_CAPI_CEF_BROWSER_CAPI_H_
@ -932,6 +932,29 @@ typedef struct _cef_browser_host_t {
/// be called on the UI thread.
///
int(CEF_CALLBACK* is_audio_muted)(struct _cef_browser_host_t* self);
///
/// Returns true (1) if the renderer is currently in browser fullscreen. This
/// differs from window fullscreen in that browser fullscreen is entered using
/// the JavaScript Fullscreen API and modifies CSS attributes such as the
/// ::backdrop pseudo-element and :fullscreen pseudo-structure. This function
/// can only be called on the UI thread.
///
int(CEF_CALLBACK* is_fullscreen)(struct _cef_browser_host_t* self);
///
/// Requests the renderer to exit browser fullscreen. In most cases exiting
/// window fullscreen should also exit browser fullscreen. With the Alloy
/// runtime this function should be called in response to a user action such
/// as clicking the green traffic light button on MacOS
/// (cef_window_delegate_t::OnWindowFullscreenTransition callback) or pressing
/// the "ESC" key (cef_keyboard_handler_t::OnPreKeyEvent callback). With the
/// Chrome runtime these standard exit actions are handled internally but
/// new/additional user actions can use this function. Set |will_cause_resize|
/// to true (1) if exiting browser fullscreen will cause a view resize.
///
void(CEF_CALLBACK* exit_fullscreen)(struct _cef_browser_host_t* self,
int will_cause_resize);
} cef_browser_host_t;
///

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "1920c69ce75671bf41d947677d76cc92e9b0ca3b"
#define CEF_API_HASH_UNIVERSAL "b6896cd6fe1f0a43197f649b0e18be1aac6b918d"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "c1c5f6ed3f032d525d36e737388b0b850f5e0c59"
#define CEF_API_HASH_PLATFORM "4d4214adb1bb3cb7a3f8862e9241f2983a0175ca"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "5a278846114ac057af673f522377552f41e09179"
#define CEF_API_HASH_PLATFORM "762ec50480531244f53add4b884f535c6b11f4be"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "e94defd6a38fb3d2933f5f417ec0e727d6d35abf"
#define CEF_API_HASH_PLATFORM "a18434cc9be44f6e1040f03655908d0a0838d3e7"
#endif
#ifdef __cplusplus

View File

@ -964,6 +964,30 @@ class CefBrowserHost : public virtual CefBaseRefCounted {
///
/*--cef()--*/
virtual bool IsAudioMuted() = 0;
///
/// Returns true if the renderer is currently in browser fullscreen. This
/// differs from window fullscreen in that browser fullscreen is entered using
/// the JavaScript Fullscreen API and modifies CSS attributes such as the
/// ::backdrop pseudo-element and :fullscreen pseudo-class. This method can
/// only be called on the UI thread.
///
/*--cef()--*/
virtual bool IsFullscreen() = 0;
///
/// Requests the renderer to exit browser fullscreen. In most cases exiting
/// window fullscreen should also exit browser fullscreen. With the Alloy
/// runtime this method should be called in response to a user action such as
/// clicking the green traffic light button on MacOS
/// (CefWindowDelegate::OnWindowFullscreenTransition callback) or pressing the
/// "ESC" key (CefKeyboardHandler::OnPreKeyEvent callback). With the Chrome
/// runtime these standard exit actions are handled internally but
/// new/additional user actions can use this method. Set |will_cause_resize|
/// to true if exiting browser fullscreen will cause a view resize.
///
/*--cef()--*/
virtual void ExitFullscreen(bool will_cause_resize) = 0;
};
#endif // CEF_INCLUDE_CEF_BROWSER_H_

View File

@ -633,6 +633,31 @@ void CefBrowserHostBase::NotifyMoveOrResizeStarted() {
#endif
}
bool CefBrowserHostBase::IsFullscreen() {
if (!CEF_CURRENTLY_ON_UIT()) {
DCHECK(false) << "called on invalid thread";
return false;
}
if (auto web_contents = GetWebContents()) {
return web_contents->IsFullscreen();
}
return false;
}
void CefBrowserHostBase::ExitFullscreen(bool will_cause_resize) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::BindOnce(&CefBrowserHostBase::ExitFullscreen,
this, will_cause_resize));
return;
}
auto web_contents = GetWebContents();
if (web_contents && web_contents->IsFullscreen()) {
web_contents->ExitFullscreen(will_cause_resize);
}
}
void CefBrowserHostBase::ReplaceMisspelling(const CefString& word) {
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(

View File

@ -212,6 +212,8 @@ class CefBrowserHostBase : public CefBrowserHost,
bool current_only) override;
CefRefPtr<CefNavigationEntry> GetVisibleNavigationEntry() override;
void NotifyMoveOrResizeStarted() override;
bool IsFullscreen() override;
void ExitFullscreen(bool will_cause_resize) override;
// CefBrowser methods:
bool IsValid() override;

View File

@ -121,12 +121,18 @@ void CefNativeWidgetMac::OnWindowFullscreenTransitionStart() {
views::NativeWidgetMac::OnWindowFullscreenTransitionStart();
if (IsCefWindowInitialized()) {
window_delegate_->OnWindowFullscreenTransition(window_, false);
if (browser_view_) {
browser_view_->FullscreenStateChanging();
}
}
}
void CefNativeWidgetMac::OnWindowFullscreenTransitionComplete() {
views::NativeWidgetMac::OnWindowFullscreenTransitionComplete();
if (IsCefWindowInitialized()) {
if (browser_view_) {
browser_view_->FullscreenStateChanged();
}
window_delegate_->OnWindowFullscreenTransition(window_, true);
}
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=497607653318fe0245cbe18c8911e39867e16249$
// $hash=5358aa617ebb6d7d074e2d346599fbd6777f1770$
//
#include "libcef_dll/cpptoc/browser_host_cpptoc.h"
@ -1435,6 +1435,39 @@ int CEF_CALLBACK browser_host_is_audio_muted(struct _cef_browser_host_t* self) {
return _retval;
}
int CEF_CALLBACK browser_host_is_fullscreen(struct _cef_browser_host_t* self) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return 0;
}
// Execute
bool _retval = CefBrowserHostCppToC::Get(self)->IsFullscreen();
// Return type: bool
return _retval;
}
void CEF_CALLBACK browser_host_exit_fullscreen(struct _cef_browser_host_t* self,
int will_cause_resize) {
shutdown_checker::AssertNotShutdown();
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self) {
return;
}
// Execute
CefBrowserHostCppToC::Get(self)->ExitFullscreen(will_cause_resize ? true
: false);
}
} // namespace
// CONSTRUCTOR - Do not edit by hand.
@ -1512,6 +1545,8 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
GetStruct()->is_background_host = browser_host_is_background_host;
GetStruct()->set_audio_muted = browser_host_set_audio_muted;
GetStruct()->is_audio_muted = browser_host_is_audio_muted;
GetStruct()->is_fullscreen = browser_host_is_fullscreen;
GetStruct()->exit_fullscreen = browser_host_exit_fullscreen;
}
// DESTRUCTOR - Do not edit by hand.

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=cd4e4aa1670f0c887090e23f5e7e3a01e5de9d13$
// $hash=4d51bbece0dd5773f9c97163008d6b2f4bf1ccbf$
//
#include "libcef_dll/ctocpp/browser_host_ctocpp.h"
@ -1229,6 +1229,38 @@ NO_SANITIZE("cfi-icall") bool CefBrowserHostCToCpp::IsAudioMuted() {
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall") bool CefBrowserHostCToCpp::IsFullscreen() {
shutdown_checker::AssertNotShutdown();
cef_browser_host_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, is_fullscreen)) {
return false;
}
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = _struct->is_fullscreen(_struct);
// Return type: bool
return _retval ? true : false;
}
NO_SANITIZE("cfi-icall")
void CefBrowserHostCToCpp::ExitFullscreen(bool will_cause_resize) {
shutdown_checker::AssertNotShutdown();
cef_browser_host_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, exit_fullscreen)) {
return;
}
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
_struct->exit_fullscreen(_struct, will_cause_resize);
}
// CONSTRUCTOR - Do not edit by hand.
CefBrowserHostCToCpp::CefBrowserHostCToCpp() {}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=b4e11c91197cd5d6ccbe3a0d96aaae3792a6e05c$
// $hash=5c1df6572bffebd983970394be27397837db0b25$
//
#ifndef CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_
@ -134,6 +134,8 @@ class CefBrowserHostCToCpp : public CefCToCppRefCounted<CefBrowserHostCToCpp,
bool IsBackgroundHost() override;
void SetAudioMuted(bool mute) override;
bool IsAudioMuted() override;
bool IsFullscreen() override;
void ExitFullscreen(bool will_cause_resize) override;
};
#endif // CEF_LIBCEF_DLL_CTOCPP_BROWSER_HOST_CTOCPP_H_

View File

@ -651,6 +651,18 @@ void ViewsWindow::OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
if (should_change && with_controls_) {
ShowTopControls(!window->IsFullscreen());
}
// With Alloy runtime we need to explicitly exit browser fullscreen when
// exiting window fullscreen. Chrome runtime handles this internally.
if (!MainContext::Get()->UseChromeRuntime() && should_change &&
!window->IsFullscreen()) {
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
if (browser && browser->GetHost()->IsFullscreen()) {
// Will not cause a resize because the fullscreen transition has already
// begun.
browser->GetHost()->ExitFullscreen(/*will_cause_resize=*/false);
}
}
}
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {

View File

@ -2,6 +2,12 @@
<html lang="en-US">
<head>
<title>Window Test</title>
<style>
/* Background becomes pink in fullscreen mode. */
:fullscreen {
background: pink;
}
</style>
<script>
function setup() {
if (location.hostname == 'tests' || location.hostname == 'localhost')
@ -38,10 +44,18 @@ function restore() {
setTimeout(function() { send_message('Restore'); }, 1000);
}
function fullscreen() {
function fullscreenWindow() {
send_message('Fullscreen');
}
function fullscreenBrowser() {
if (document.fullscreenElement) {
document.exitFullscreen();
} else {
document.getElementById('form').requestFullscreen();
}
}
function position() {
var x = parseInt(document.getElementById('x').value);
var y = parseInt(document.getElementById('y').value);
@ -68,7 +82,8 @@ Click a button to perform the associated window action.
<br/><input type="button" onclick="minimize();" value="Minimize">
<br/><input type="button" onclick="maximize();" value="Maximize">
<br/><input type="button" onclick="restore();" value="Restore"> (minimizes and then restores the window as topmost)
<br/><input type="button" onclick="fullscreen();" value="Toggle Fullscreen"> (works with Views)
<br/><input type="button" onclick="fullscreenWindow();" value="Toggle Window Fullscreen"> (works with Views)
<br/><input type="button" onclick="fullscreenBrowser();" value="Toggle Browser Fullscreen"> (uses <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API" target="_new">Fullscreen API</a>; background turns pink)
<br/><input type="button" onclick="position();" value="Set Position">
X: <input type="text" size="4" id="x" value="200">
Y: <input type="text" size="4" id="y" value="100">