views: mac: Support dynamic resize of title bar height (see #3189)

This is intended for usage with frameless windows that show the standard window
buttons, where resizing the title bar height changes the button offset. Returning a
different value from CefWindowDelegate::GetTitlebarHeight and forcing a resize of
the NSWindow's theme frame (see ViewsWindow::NudgeWindow) will update the
title bar height.

To test:
1. Run `cefclient --use-views --hide-frame --show-window-buttons --url=http://tests/window`
2. Enter a new value for title bar height and click the "Set Titlebar Height" button
This commit is contained in:
Nik Pavlov
2023-03-16 17:19:50 +00:00
committed by Marshall Greenblatt
parent 0a2c7a1070
commit c83b3cda24
19 changed files with 156 additions and 62 deletions

View File

@@ -9,12 +9,15 @@
#include "include/views/cef_window.h"
#include "include/wrapper/cef_helpers.h"
#include "tests/cefclient/browser/root_window_views.h"
#include "tests/cefclient/browser/views_window.h"
namespace client {
namespace window_test {
namespace {
CefRefPtr<CefWindow> GetWindow(CefRefPtr<CefBrowser> browser) {
CefRefPtr<CefWindow> GetWindow(const CefRefPtr<CefBrowser>& browser) {
CEF_REQUIRE_UI_THREAD();
DCHECK(browser->GetHost()->HasView());
@@ -27,6 +30,16 @@ CefRefPtr<CefWindow> GetWindow(CefRefPtr<CefBrowser> browser) {
return window;
}
void SetTitlebarHeight(const CefRefPtr<CefBrowser>& browser,
const std::optional<float>& height) {
CEF_REQUIRE_UI_THREAD();
auto root_window = RootWindow::GetForBrowser(browser->GetIdentifier());
DCHECK(root_window.get());
auto root_window_views = static_cast<RootWindowViews*>(root_window.get());
root_window_views->SetTitlebarHeight(height);
}
} // namespace
WindowTestRunnerViews::WindowTestRunnerViews() {}
@@ -56,5 +69,11 @@ void WindowTestRunnerViews::Restore(CefRefPtr<CefBrowser> browser) {
GetWindow(browser)->Restore();
}
void WindowTestRunnerViews::SetTitleBarHeight(
CefRefPtr<CefBrowser> browser,
const std::optional<float>& height) {
SetTitlebarHeight(browser, height);
}
} // namespace window_test
} // namespace client