From ad71ec9fdfe069356addbe8bd5192b88a614a13d Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt <magreenblatt@gmail.com> Date: Wed, 4 Aug 2021 14:20:31 -0400 Subject: [PATCH] views: Fix multiple issues with hide-frame (fixes issue #3168) --- libcef/browser/views/window_view.cc | 1 + tests/cefclient/browser/views_window.cc | 31 +++++++++++++++++++------ tests/cefclient/browser/views_window.h | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/libcef/browser/views/window_view.cc b/libcef/browser/views/window_view.cc index ae19e72cf..625d6b866 100644 --- a/libcef/browser/views/window_view.cc +++ b/libcef/browser/views/window_view.cc @@ -182,6 +182,7 @@ class CaptionlessFrameView : public views::NonClientFrameView { void Layout() override { client_view_bounds_.SetRect(0, 0, width(), height()); + views::NonClientFrameView::Layout(); } gfx::Size CalculatePreferredSize() const override { diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 1232c8c42..b948ba77c 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -488,13 +488,7 @@ void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) { delegate_->OnViewsWindowCreated(this); - CefRect bounds = delegate_->GetWindowBounds(); - if (bounds.IsEmpty()) { - // Use the default size. - bounds.width = 800; - bounds.height = 600; - } - + const CefRect bounds = GetInitialBounds(); if (bounds.x == 0 && bounds.y == 0) { // Size the Window and center it. window_->CenterWindow(CefSize(bounds.width, bounds.height)); @@ -569,6 +563,18 @@ CefRefPtr<CefWindow> ViewsWindow::GetParentWindow(CefRefPtr<CefWindow> window, return parent_window; } +CefRect ViewsWindow::GetInitialBounds(CefRefPtr<CefWindow> window) { + CEF_REQUIRE_UI_THREAD(); + if (frameless_) { + // Need to provide a size for frameless windows that will be centered. + const CefRect bounds = GetInitialBounds(); + if (bounds.x == 0 && bounds.y == 0) { + return bounds; + } + } + return CefRect(); +} + bool ViewsWindow::IsFrameless(CefRefPtr<CefWindow> window) { CEF_REQUIRE_UI_THREAD(); return frameless_; @@ -1016,4 +1022,15 @@ void ViewsWindow::OnExtensionWindowClosed() { extension_button_pressed_lock_ = nullptr; } +CefRect ViewsWindow::GetInitialBounds() const { + CEF_REQUIRE_UI_THREAD(); + CefRect bounds = delegate_->GetWindowBounds(); + if (bounds.IsEmpty()) { + // Use the default size. + bounds.width = 800; + bounds.height = 600; + } + return bounds; +} + } // namespace client diff --git a/tests/cefclient/browser/views_window.h b/tests/cefclient/browser/views_window.h index 91f23fd37..a8490f4e6 100644 --- a/tests/cefclient/browser/views_window.h +++ b/tests/cefclient/browser/views_window.h @@ -154,6 +154,7 @@ class ViewsWindow : public CefBrowserViewDelegate, CefRefPtr<CefWindow> GetParentWindow(CefRefPtr<CefWindow> window, bool* is_menu, bool* can_activate_menu) override; + CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override; bool IsFrameless(CefRefPtr<CefWindow> window) override; bool CanResize(CefRefPtr<CefWindow> window) override; bool CanClose(CefRefPtr<CefWindow> window) override; @@ -207,6 +208,8 @@ class ViewsWindow : public CefBrowserViewDelegate, const ImageCache::ImageSet& images); void OnExtensionWindowClosed(); + CefRect GetInitialBounds() const; + Delegate* delegate_; // Not owned by this object. CefRefPtr<CefBrowserView> browser_view_; bool frameless_;