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 262ed72348
commit 39e64d8cc9
33 changed files with 521 additions and 195 deletions

View File

@@ -141,10 +141,7 @@ bool CefBrowserViewImpl::HandleKeyboardEvent(
}
// Give the CefWindowDelegate a chance to handle the event.
CefRefPtr<CefWindow> window =
view_util::GetWindowFor(root_view()->GetWidget());
CefWindowImpl* window_impl = static_cast<CefWindowImpl*>(window.get());
if (window_impl) {
if (auto* window_impl = cef_window()) {
CefKeyEvent cef_event;
if (browser_util::GetCefKeyEvent(event, cef_event) &&
window_impl->OnKeyEvent(cef_event)) {
@@ -319,6 +316,12 @@ ChromeBrowserView* CefBrowserViewImpl::chrome_browser_view() const {
return static_cast<ChromeBrowserView*>(root_view());
}
CefWindowImpl* CefBrowserViewImpl::cef_window() const {
CefRefPtr<CefWindow> window =
view_util::GetWindowFor(root_view()->GetWidget());
return static_cast<CefWindowImpl*>(window.get());
}
bool CefBrowserViewImpl::HandleAccelerator(
const content::NativeWebKeyboardEvent& event,
views::FocusManager* focus_manager) {

View File

@@ -18,6 +18,7 @@
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
class CefBrowserHostBase;
class CefWindowImpl;
class ChromeBrowserView;
class CefBrowserViewImpl
@@ -83,6 +84,9 @@ class CefBrowserViewImpl
// Return the CEF specialization of BrowserView.
ChromeBrowserView* chrome_browser_view() const;
// Return the CefWindowImpl hosting this object.
CefWindowImpl* cef_window() const;
private:
// Create a new implementation object.
// Always call Initialize() after creation.

View File

@@ -48,6 +48,9 @@ class CefNativeWidgetMac : public views::NativeWidgetMac {
const CefRefPtr<CefWindow> window_;
CefWindowDelegate* const window_delegate_;
// Returns true if the CefWindow is fully initialized.
bool IsCefWindowInitialized() const;
BrowserView* browser_view_ = nullptr;
};

View File

@@ -7,6 +7,7 @@
#include "include/views/cef_window.h"
#include "include/views/cef_window_delegate.h"
#include "libcef/browser/views/ns_window.h"
#include "libcef/browser/views/window_impl.h"
#include "chrome/browser/apps/app_shim/app_shim_host_mac.h"
#include "chrome/browser/apps/app_shim/app_shim_manager_mac.h"
@@ -118,12 +119,16 @@ void CefNativeWidgetMac::GetWindowFrameTitlebarHeight(
void CefNativeWidgetMac::OnWindowFullscreenTransitionStart() {
views::NativeWidgetMac::OnWindowFullscreenTransitionStart();
window_delegate_->OnWindowFullscreenTransition(window_, false);
if (IsCefWindowInitialized()) {
window_delegate_->OnWindowFullscreenTransition(window_, false);
}
}
void CefNativeWidgetMac::OnWindowFullscreenTransitionComplete() {
views::NativeWidgetMac::OnWindowFullscreenTransitionComplete();
window_delegate_->OnWindowFullscreenTransition(window_, true);
if (IsCefWindowInitialized()) {
window_delegate_->OnWindowFullscreenTransition(window_, true);
}
}
void CefNativeWidgetMac::OnWindowInitialized() {
@@ -142,3 +147,7 @@ void CefNativeWidgetMac::OnWindowInitialized() {
}
}
}
bool CefNativeWidgetMac::IsCefWindowInitialized() const {
return static_cast<CefWindowImpl*>(window_.get())->initialized();
}

View File

@@ -5,6 +5,7 @@
#include "libcef/browser/views/window_impl.h"
#include "libcef/browser/browser_util.h"
#include "libcef/browser/chrome/views/chrome_browser_frame.h"
#include "libcef/browser/thread_util.h"
#include "libcef/browser/views/browser_view_impl.h"
#include "libcef/browser/views/display_impl.h"
@@ -12,6 +13,7 @@
#include "libcef/browser/views/layout_util.h"
#include "libcef/browser/views/view_util.h"
#include "libcef/browser/views/window_view.h"
#include "libcef/features/runtime.h"
#include "base/i18n/rtl.h"
#include "components/constrained_window/constrained_window_views.h"
@@ -116,9 +118,6 @@ CefRefPtr<CefWindowImpl> CefWindowImpl::Create(
CefRefPtr<CefWindowImpl> window = new CefWindowImpl(delegate);
window->Initialize();
window->CreateWidget(parent_widget);
if (delegate) {
delegate->OnWindowCreated(window.get());
}
return window;
}
@@ -253,7 +252,29 @@ void CefWindowImpl::Restore() {
void CefWindowImpl::SetFullscreen(bool fullscreen) {
CEF_REQUIRE_VALID_RETURN_VOID();
if (widget_ && fullscreen != widget_->IsFullscreen()) {
if (cef::IsChromeRuntimeEnabled()) {
// If a BrowserView exists, toggle fullscreen mode via the Chrome command
// for consistent behavior.
auto* browser_frame = static_cast<ChromeBrowserFrame*>(widget_);
if (browser_frame->browser_view()) {
browser_frame->ToggleFullscreenMode();
return;
}
}
// Call the Widget method directly with Alloy runtime, or Chrome runtime
// when no BrowserView exists.
widget_->SetFullscreen(fullscreen);
// Use a synchronous callback notification on Windows/Linux. Chrome runtime
// on Windows/Linux gets notified synchronously via ChromeBrowserDelegate
// callbacks when a BrowserView exists. MacOS (both runtimes) gets notified
// asynchronously via CefNativeWidgetMac callbacks.
#if !BUILDFLAG(IS_MAC)
if (delegate()) {
delegate()->OnWindowFullscreenTransition(this, /*is_completed=*/true);
}
#endif
}
}
@@ -714,7 +735,7 @@ void CefWindowImpl::RemoveAllAccelerators() {
}
CefWindowImpl::CefWindowImpl(CefRefPtr<CefWindowDelegate> delegate)
: ParentClass(delegate), widget_(nullptr), destroyed_(false) {}
: ParentClass(delegate) {}
CefWindowView* CefWindowImpl::CreateRootView() {
return new CefWindowView(delegate(), this);
@@ -740,4 +761,10 @@ void CefWindowImpl::CreateWidget(gfx::AcceleratedWidget parent_widget) {
// keep an owned reference.
std::unique_ptr<views::View> view_ptr = view_util::PassOwnership(this);
[[maybe_unused]] views::View* view = view_ptr.release();
initialized_ = true;
if (delegate()) {
delegate()->OnWindowCreated(this);
}
}

View File

@@ -132,6 +132,7 @@ class CefWindowImpl
void MenuClosed();
views::Widget* widget() const { return widget_; }
bool initialized() const { return initialized_; }
private:
// Create a new implementation object.
@@ -146,10 +147,13 @@ class CefWindowImpl
// Initialize the Widget.
void CreateWidget(gfx::AcceleratedWidget parent_widget);
views::Widget* widget_;
views::Widget* widget_ = nullptr;
// True if the window has been initialized.
bool initialized_ = false;
// True if the window has been destroyed.
bool destroyed_;
bool destroyed_ = false;
// The currently active menu model and runner.
CefRefPtr<CefMenuModelImpl> menu_model_;