2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2016 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/views_window.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "include/base/cef_build.h"
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/cef_app.h"
|
2021-08-28 03:55:15 +02:00
|
|
|
#include "include/cef_i18n_util.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/views/cef_box_layout.h"
|
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2021-04-11 22:10:11 +02:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/resource.h"
|
2017-02-25 06:03:31 +01:00
|
|
|
#include "tests/cefclient/browser/views_style.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/common/client_switches.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#if !defined(OS_WIN)
|
2017-08-04 00:55:19 +02:00
|
|
|
#define VK_ESCAPE 0x1B
|
2016-01-19 21:09:01 +01:00
|
|
|
#define VK_RETURN 0x0D
|
2017-05-17 11:29:28 +02:00
|
|
|
#define VK_MENU 0x12 // ALT key.
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
// Default window size.
|
|
|
|
constexpr int kDefaultWidth = 800;
|
|
|
|
constexpr int kDefaultHeight = 600;
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
constexpr int kTitleBarHeight = 35;
|
|
|
|
constexpr int kWindowButtonsWidth = 80;
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Control IDs for Views in the top-level Window.
|
|
|
|
enum ControlIds {
|
|
|
|
ID_WINDOW = 1,
|
2017-02-25 06:03:31 +01:00
|
|
|
ID_BROWSER_VIEW,
|
2016-01-19 21:09:01 +01:00
|
|
|
ID_BACK_BUTTON,
|
|
|
|
ID_FORWARD_BUTTON,
|
|
|
|
ID_STOP_BUTTON,
|
|
|
|
ID_RELOAD_BUTTON,
|
|
|
|
ID_URL_TEXTFIELD,
|
|
|
|
ID_MENU_BUTTON,
|
2017-02-22 19:05:27 +01:00
|
|
|
|
|
|
|
// Reserved range of top menu button IDs.
|
|
|
|
ID_TOP_MENU_FIRST,
|
|
|
|
ID_TOP_MENU_LAST = ID_TOP_MENU_FIRST + 10,
|
2016-01-19 21:09:01 +01:00
|
|
|
};
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
typedef std::vector<CefRefPtr<CefLabelButton>> LabelButtons;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Make all |buttons| the same size.
|
|
|
|
void MakeButtonsSameSize(const LabelButtons& buttons) {
|
|
|
|
CefSize size;
|
|
|
|
|
|
|
|
// Determine the largest button size.
|
2024-01-20 03:22:56 +01:00
|
|
|
for (const auto& button : buttons) {
|
|
|
|
const CefSize& button_size = button->GetPreferredSize();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (size.width < button_size.width) {
|
2016-01-19 21:09:01 +01:00
|
|
|
size.width = button_size.width;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (size.height < button_size.height) {
|
2016-01-19 21:09:01 +01:00
|
|
|
size.height = button_size.height;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
for (const auto& button : buttons) {
|
2016-01-19 21:09:01 +01:00
|
|
|
// Set the button's minimum size.
|
2024-01-20 03:22:56 +01:00
|
|
|
button->SetMinimumSize(size);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Re-layout the button and all parent Views.
|
2024-01-20 03:22:56 +01:00
|
|
|
button->InvalidateLayout();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
void AddTestMenuItems(CefRefPtr<CefMenuModel> test_menu) {
|
2017-05-17 11:29:28 +02:00
|
|
|
test_menu->AddItem(ID_TESTS_GETSOURCE, "Get Source");
|
|
|
|
test_menu->AddItem(ID_TESTS_GETTEXT, "Get Text");
|
|
|
|
test_menu->AddItem(ID_TESTS_WINDOW_NEW, "New Window");
|
|
|
|
test_menu->AddItem(ID_TESTS_WINDOW_POPUP, "Popup Window");
|
2023-06-14 10:20:02 +02:00
|
|
|
test_menu->AddItem(ID_TESTS_WINDOW_DIALOG, "Dialog Window");
|
2017-05-17 11:29:28 +02:00
|
|
|
test_menu->AddItem(ID_TESTS_REQUEST, "Request");
|
|
|
|
test_menu->AddItem(ID_TESTS_ZOOM_IN, "Zoom In");
|
|
|
|
test_menu->AddItem(ID_TESTS_ZOOM_OUT, "Zoom Out");
|
|
|
|
test_menu->AddItem(ID_TESTS_ZOOM_RESET, "Zoom Reset");
|
|
|
|
test_menu->AddItem(ID_TESTS_TRACING_BEGIN, "Begin Tracing");
|
|
|
|
test_menu->AddItem(ID_TESTS_TRACING_END, "End Tracing");
|
|
|
|
test_menu->AddItem(ID_TESTS_PRINT, "Print");
|
|
|
|
test_menu->AddItem(ID_TESTS_PRINT_TO_PDF, "Print to PDF");
|
2019-02-26 17:44:17 +01:00
|
|
|
test_menu->AddItem(ID_TESTS_MUTE_AUDIO, "Mute Audio");
|
|
|
|
test_menu->AddItem(ID_TESTS_UNMUTE_AUDIO, "Unmute Audio");
|
2017-05-17 11:29:28 +02:00
|
|
|
test_menu->AddItem(ID_TESTS_OTHER_TESTS, "Other Tests");
|
2024-07-02 20:08:16 +02:00
|
|
|
test_menu->AddItem(ID_TESTS_DUMP_WITHOUT_CRASHING, "Dump without crashing");
|
2017-02-18 03:08:51 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
void AddFileMenuItems(CefRefPtr<CefMenuModel> file_menu) {
|
2017-02-18 03:08:51 +01:00
|
|
|
file_menu->AddItem(ID_QUIT, "E&xit");
|
|
|
|
|
|
|
|
// Show the accelerator shortcut text in the menu.
|
2017-05-17 11:29:28 +02:00
|
|
|
file_menu->SetAcceleratorAt(file_menu->GetCount() - 1, 'X', false, false,
|
|
|
|
true);
|
2017-02-18 03:08:51 +01:00
|
|
|
}
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
CefBrowserViewDelegate::ChromeToolbarType CalculateChromeToolbarType(
|
2024-04-17 18:01:26 +02:00
|
|
|
bool use_alloy_style,
|
2023-02-28 19:34:12 +01:00
|
|
|
const std::string& toolbar_type,
|
|
|
|
bool hide_toolbar,
|
|
|
|
bool with_overlay_controls) {
|
2024-04-17 18:01:26 +02:00
|
|
|
if (use_alloy_style || toolbar_type == "none" || hide_toolbar) {
|
2023-02-28 19:34:12 +01:00
|
|
|
return CEF_CTT_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toolbar_type == "location") {
|
|
|
|
return CEF_CTT_LOCATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
return with_overlay_controls ? CEF_CTT_LOCATION : CEF_CTT_NORMAL;
|
|
|
|
}
|
|
|
|
|
2024-03-26 23:18:20 +01:00
|
|
|
void SetViewEnabled(CefRefPtr<CefWindow> window, int id, bool enable) {
|
|
|
|
if (auto view = window->GetViewForID(id)) {
|
|
|
|
view->SetEnabled(enable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<ViewsWindow> ViewsWindow::Create(
|
2023-06-14 10:20:02 +02:00
|
|
|
WindowType type,
|
2016-01-19 21:09:01 +01:00
|
|
|
Delegate* delegate,
|
|
|
|
CefRefPtr<CefClient> client,
|
|
|
|
const CefString& url,
|
|
|
|
const CefBrowserSettings& settings,
|
2023-11-29 02:33:44 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
CefRefPtr<CefCommandLine> command_line) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(delegate);
|
|
|
|
|
|
|
|
// Create a new ViewsWindow.
|
2023-06-14 10:20:02 +02:00
|
|
|
CefRefPtr<ViewsWindow> views_window =
|
2023-11-29 02:33:44 +01:00
|
|
|
new ViewsWindow(type, delegate, nullptr, command_line);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
const auto expected_browser_runtime_style = views_window->use_alloy_style_
|
|
|
|
? CEF_RUNTIME_STYLE_ALLOY
|
|
|
|
: CEF_RUNTIME_STYLE_CHROME;
|
|
|
|
const auto expected_window_runtime_style =
|
|
|
|
views_window->use_alloy_style_window_ ? CEF_RUNTIME_STYLE_ALLOY
|
|
|
|
: CEF_RUNTIME_STYLE_CHROME;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create a new BrowserView.
|
|
|
|
CefRefPtr<CefBrowserView> browser_view = CefBrowserView::CreateBrowserView(
|
2020-01-15 15:28:12 +01:00
|
|
|
client, url, settings, nullptr, request_context, views_window);
|
2024-04-17 18:01:26 +02:00
|
|
|
CHECK_EQ(expected_browser_runtime_style, browser_view->GetRuntimeStyle());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Associate the BrowserView with the ViewsWindow.
|
|
|
|
views_window->SetBrowserView(browser_view);
|
|
|
|
|
|
|
|
// Create a new top-level Window. It will show itself after creation.
|
2024-04-17 18:01:26 +02:00
|
|
|
auto window = CefWindow::CreateTopLevelWindow(views_window);
|
|
|
|
CHECK_EQ(expected_window_runtime_style, window->GetRuntimeStyle());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
return views_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::Show() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2023-06-14 10:20:02 +02:00
|
|
|
if (type_ == WindowType::DIALOG) {
|
|
|
|
if (use_window_modal_dialog_) {
|
|
|
|
// Show as a window modal dialog (IsWindowModalDialog() will return
|
|
|
|
// true).
|
|
|
|
window_->Show();
|
|
|
|
} else {
|
|
|
|
CefRefPtr<CefBrowserView> browser_view;
|
|
|
|
if (auto parent_window = delegate_->GetParentWindow()) {
|
|
|
|
if (auto view = parent_window->GetViewForID(ID_BROWSER_VIEW)) {
|
|
|
|
browser_view = view->AsBrowserView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK(browser_view);
|
|
|
|
|
|
|
|
// Show as a browser modal dialog (relative to |browser_view|).
|
|
|
|
window_->ShowAsBrowserModalDialog(browser_view);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
window_->Show();
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-09-07 16:04:55 +02:00
|
|
|
if (browser_view_ && !window_->IsMinimized()) {
|
2017-08-04 00:55:19 +02:00
|
|
|
// Give keyboard focus to the BrowserView.
|
|
|
|
browser_view_->RequestFocus();
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::Hide() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->Hide();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::Minimize() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->Minimize();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::Maximize() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->Maximize();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetBounds(const CefRect& bounds) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetBounds(bounds);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void ViewsWindow::SetBrowserSize(const CefSize& size,
|
|
|
|
bool has_position,
|
|
|
|
const CefPoint& position) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_view_) {
|
2017-08-04 00:55:19 +02:00
|
|
|
browser_view_->SetSize(size);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
if (window_) {
|
|
|
|
window_->SizeToPreferredSize();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (has_position) {
|
2017-08-04 00:55:19 +02:00
|
|
|
window_->SetPosition(position);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ViewsWindow::Close(bool force) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_view_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-29 19:38:25 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
if (hide_on_close_) {
|
|
|
|
// Don't hide on close if we actually want to close.
|
|
|
|
hide_on_close_ = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
|
|
|
if (browser) {
|
|
|
|
// This will result in a call to CefWindow::Close() which will then call
|
|
|
|
// ViewsWindow::CanClose().
|
|
|
|
browser->GetHost()->CloseBrowser(force);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetAddress(const std::string& url) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
// |location_bar_| may instead be a Chrome toolbar.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (location_bar_ && location_bar_->AsTextfield()) {
|
2021-08-28 03:55:15 +02:00
|
|
|
location_bar_->AsTextfield()->SetText(url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetTitle(const std::string& title) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetTitle(title);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetFavicon(CefRefPtr<CefImage> image) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Window icons should be 16 DIP in size.
|
|
|
|
DCHECK_EQ(std::max(image->GetWidth(), image->GetHeight()), 16U);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetWindowIcon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetFullscreen(bool fullscreen) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// For Chrome style we ignore this notification from
|
|
|
|
// ClientHandler::OnFullscreenModeChange(). Chrome style will trigger
|
2023-09-25 21:40:17 +02:00
|
|
|
// the fullscreen change internally and then call
|
|
|
|
// OnWindowFullscreenTransition().
|
2024-04-17 18:01:26 +02:00
|
|
|
if (!use_alloy_style_) {
|
2023-09-25 21:40:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// For Alloy style we need to explicitly trigger the fullscreen change.
|
2023-09-25 21:40:17 +02:00
|
|
|
if (window_) {
|
|
|
|
// Results in a call to OnWindowFullscreenTransition().
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetFullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 05:47:36 +01:00
|
|
|
void ViewsWindow::SetAlwaysOnTop(bool on_top) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
if (window_) {
|
|
|
|
window_->SetAlwaysOnTop(on_top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ViewsWindow::SetLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
|
|
|
bool canGoForward) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-03-26 23:18:20 +01:00
|
|
|
|
|
|
|
is_loading_ = isLoading;
|
|
|
|
can_go_back_ = canGoBack;
|
|
|
|
can_go_forward_ = canGoForward;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_ || chrome_toolbar_type_ == CEF_CTT_NORMAL) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-03-26 23:18:20 +01:00
|
|
|
// |toolbar_| may be nullptr for the initial notification after CefBrowser
|
|
|
|
// creation, in which case the initial state will be appled in AddControls.
|
|
|
|
if (with_controls_ && toolbar_) {
|
|
|
|
UpdateToolbarButtonState();
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_ || !browser_view_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Convert the regions from BrowserView to Window coordinates.
|
2023-02-28 19:34:12 +01:00
|
|
|
std::vector<CefDraggableRegion> window_regions = regions;
|
|
|
|
for (auto& region : window_regions) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CefPoint origin = CefPoint(region.bounds.x, region.bounds.y);
|
|
|
|
browser_view_->ConvertPointToWindow(origin);
|
|
|
|
region.bounds.x = origin.x;
|
|
|
|
region.bounds.y = origin.y;
|
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
if (overlay_controls_) {
|
|
|
|
// Exclude all regions obscured by overlays.
|
|
|
|
overlay_controls_->UpdateDraggableRegions(window_regions);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
window_->SetDraggableRegions(window_regions);
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void ViewsWindow::TakeFocus(bool next) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_) {
|
2017-02-17 00:19:43 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
if (chrome_toolbar_type_ == CEF_CTT_NORMAL) {
|
2023-06-30 14:17:02 +02:00
|
|
|
toolbar_->RequestFocus();
|
2021-08-28 03:55:15 +02:00
|
|
|
} else if (location_bar_) {
|
|
|
|
// Give focus to the location bar.
|
|
|
|
location_bar_->RequestFocus();
|
2021-04-11 22:10:11 +02:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
void ViewsWindow::OnBeforeContextMenu(CefRefPtr<CefMenuModel> model) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
views_style::ApplyTo(model);
|
|
|
|
}
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
// static
|
|
|
|
bool ViewsWindow::SupportsWindowRestore(WindowType type) {
|
|
|
|
// Only support window restore with normal windows.
|
|
|
|
return type == WindowType::NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::SupportsWindowRestore() const {
|
|
|
|
return SupportsWindowRestore(type_);
|
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
bool ViewsWindow::GetWindowRestorePreferences(
|
|
|
|
cef_show_state_t& show_state,
|
|
|
|
std::optional<CefRect>& dip_bounds) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-11-14 18:16:43 +01:00
|
|
|
DCHECK(SupportsWindowRestore());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_) {
|
2022-10-28 20:17:18 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-10-28 20:17:18 +02:00
|
|
|
|
|
|
|
show_state = CEF_SHOW_STATE_NORMAL;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (window_->IsMinimized()) {
|
2022-10-28 20:17:18 +02:00
|
|
|
show_state = CEF_SHOW_STATE_MINIMIZED;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (window_->IsFullscreen()) {
|
2023-09-25 21:40:17 +02:00
|
|
|
// On MacOS, IsMaximized() will also return true for fullscreen, so check
|
|
|
|
// IsFullscreen() first.
|
2022-10-28 20:17:18 +02:00
|
|
|
show_state = CEF_SHOW_STATE_FULLSCREEN;
|
2023-09-25 21:40:17 +02:00
|
|
|
} else if (window_->IsMaximized()) {
|
|
|
|
show_state = CEF_SHOW_STATE_MAXIMIZED;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-10-28 20:17:18 +02:00
|
|
|
|
|
|
|
if (show_state == CEF_SHOW_STATE_NORMAL) {
|
|
|
|
// Use the current visible bounds.
|
|
|
|
dip_bounds = window_->GetBoundsInScreen();
|
|
|
|
} else {
|
|
|
|
// Use the last known visible bounds.
|
|
|
|
dip_bounds = last_visible_bounds_;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
void ViewsWindow::SetTitlebarHeight(const std::optional<float>& height) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
if (height.has_value()) {
|
|
|
|
override_titlebar_height_ = height;
|
|
|
|
} else {
|
|
|
|
override_titlebar_height_ = default_titlebar_height_;
|
|
|
|
}
|
|
|
|
NudgeWindow();
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefBrowserViewDelegate> ViewsWindow::GetDelegateForPopupBrowserView(
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefBrowserView> browser_view,
|
2017-08-04 00:55:19 +02:00
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
2016-01-19 21:09:01 +01:00
|
|
|
bool is_devtools) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// The popup browser client is created in CefLifeSpanHandler::OnBeforePopup()
|
|
|
|
// (e.g. via RootWindowViews::InitAsPopup()). The Delegate (RootWindowViews)
|
|
|
|
// knows the association between |client| and itself.
|
2017-08-04 00:55:19 +02:00
|
|
|
Delegate* popup_delegate = delegate_->GetDelegateForPopup(client);
|
|
|
|
|
2022-04-11 22:54:33 +02:00
|
|
|
// May be nullptr when using the default popup behavior.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!popup_delegate) {
|
2022-04-11 22:54:33 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-04-11 22:54:33 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Should not be the same RootWindowViews that owns |this|.
|
2022-04-11 22:54:33 +02:00
|
|
|
DCHECK(popup_delegate != delegate_);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Create a new ViewsWindow for the popup BrowserView.
|
2023-11-14 18:16:43 +01:00
|
|
|
return new ViewsWindow(
|
|
|
|
is_devtools ? WindowType::DEVTOOLS : WindowType::NORMAL, popup_delegate,
|
2023-11-29 02:33:44 +01:00
|
|
|
nullptr, command_line_);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::OnPopupBrowserViewCreated(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view,
|
|
|
|
CefRefPtr<CefBrowserView> popup_browser_view,
|
|
|
|
bool is_devtools) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
// Retrieve the ViewsWindow created in GetDelegateForPopupBrowserView.
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<ViewsWindow> popup_window =
|
2017-08-04 00:55:19 +02:00
|
|
|
static_cast<ViewsWindow*>(static_cast<CefBrowserViewDelegate*>(
|
|
|
|
popup_browser_view->GetDelegate().get()));
|
|
|
|
|
2022-04-11 22:54:33 +02:00
|
|
|
// May be nullptr when using the default popup behavior.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!popup_window) {
|
2022-04-11 22:54:33 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-04-11 22:54:33 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Should not be the same ViewsWindow as |this|.
|
2022-04-11 22:54:33 +02:00
|
|
|
DCHECK(popup_window != this);
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
// Associate the ViewsWindow with the new popup browser.
|
|
|
|
popup_window->SetBrowserView(popup_browser_view);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Create a new top-level Window for the popup. It will show itself after
|
|
|
|
// creation.
|
|
|
|
CefWindow::CreateTopLevelWindow(popup_window);
|
|
|
|
|
|
|
|
// We created the Window.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
CefBrowserViewDelegate::ChromeToolbarType ViewsWindow::GetChromeToolbarType(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) {
|
2021-04-11 22:10:11 +02:00
|
|
|
return chrome_toolbar_type_;
|
|
|
|
}
|
|
|
|
|
2023-09-07 19:28:27 +02:00
|
|
|
bool ViewsWindow::UseFramelessWindowForPictureInPicture(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) {
|
|
|
|
return hide_pip_frame_;
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t ViewsWindow::GetBrowserRuntimeStyle() {
|
|
|
|
if (use_alloy_style_) {
|
|
|
|
return CEF_RUNTIME_STYLE_ALLOY;
|
|
|
|
}
|
|
|
|
return CEF_RUNTIME_STYLE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ViewsWindow::OnButtonPressed(CefRefPtr<CefButton> button) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(with_controls_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_view_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
switch (button->GetID()) {
|
|
|
|
case ID_BACK_BUTTON:
|
|
|
|
browser->GoBack();
|
|
|
|
break;
|
|
|
|
case ID_FORWARD_BUTTON:
|
|
|
|
browser->GoForward();
|
|
|
|
break;
|
|
|
|
case ID_STOP_BUTTON:
|
|
|
|
browser->StopLoad();
|
|
|
|
break;
|
|
|
|
case ID_RELOAD_BUTTON:
|
|
|
|
browser->Reload();
|
|
|
|
break;
|
|
|
|
case ID_MENU_BUTTON:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTREACHED();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
void ViewsWindow::OnMenuButtonPressed(
|
|
|
|
CefRefPtr<CefMenuButton> menu_button,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
CefRefPtr<CefMenuButtonPressedLock> button_pressed_lock) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
DCHECK(with_controls_ || with_overlay_controls_);
|
2024-05-03 20:13:38 +02:00
|
|
|
DCHECK_EQ(ID_MENU_BUTTON, menu_button->GetID());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
const auto button_bounds = menu_button->GetBoundsInScreen();
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
auto point = screen_point;
|
|
|
|
if (with_overlay_controls_) {
|
|
|
|
// Align the menu correctly under the button.
|
|
|
|
if (CefIsRTL()) {
|
2023-06-30 14:17:02 +02:00
|
|
|
point.x += button_bounds.width - 4;
|
2021-08-28 03:55:15 +02:00
|
|
|
} else {
|
2023-06-30 14:17:02 +02:00
|
|
|
point.x -= button_bounds.width - 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_bottom_controls_) {
|
|
|
|
const auto display_bounds =
|
|
|
|
menu_button->GetWindow()->GetDisplay()->GetWorkArea();
|
|
|
|
const int available_height = display_bounds.y + display_bounds.height -
|
|
|
|
button_bounds.y - button_bounds.height;
|
|
|
|
|
|
|
|
// Approximation of the menu height.
|
|
|
|
const int menu_height =
|
2023-07-06 12:19:51 +02:00
|
|
|
static_cast<int>(button_menu_model_->GetCount()) * button_bounds.height;
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_height > available_height) {
|
|
|
|
// The menu will go upwards, so place it above the button.
|
|
|
|
point.y -= button_bounds.height - 8;
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_button->ShowMenu(button_menu_model_, point,
|
|
|
|
with_overlay_controls_ ? CEF_MENU_ANCHOR_TOPLEFT
|
|
|
|
: CEF_MENU_ANCHOR_TOPRIGHT);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::ExecuteCommand(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
int command_id,
|
|
|
|
cef_event_flags_t event_flags) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2021-08-28 03:55:15 +02:00
|
|
|
DCHECK(with_controls_ || with_overlay_controls_);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
if (command_id == ID_QUIT) {
|
|
|
|
delegate_->OnExit();
|
|
|
|
} else if (command_id >= ID_TESTS_FIRST && command_id <= ID_TESTS_LAST) {
|
|
|
|
delegate_->OnTest(command_id);
|
|
|
|
} else {
|
|
|
|
NOTREACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::OnKeyEvent(CefRefPtr<CefTextfield> textfield,
|
|
|
|
const CefKeyEvent& event) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK_EQ(ID_URL_TEXTFIELD, textfield->GetID());
|
|
|
|
|
|
|
|
// Trigger when the return key is pressed.
|
2017-05-17 11:29:28 +02:00
|
|
|
if (window_ && browser_view_ && event.type == KEYEVENT_RAWKEYDOWN &&
|
2016-01-19 21:09:01 +01:00
|
|
|
event.windows_key_code == VK_RETURN) {
|
|
|
|
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
|
|
|
if (browser) {
|
2021-08-28 03:55:15 +02:00
|
|
|
const CefString& url = textfield->GetText();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!url.empty()) {
|
2021-08-28 03:55:15 +02:00
|
|
|
browser->GetMainFrame()->LoadURL(url);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// We handled the event.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-25 21:40:17 +02:00
|
|
|
void ViewsWindow::OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
|
|
|
|
bool is_completed) {
|
|
|
|
#if defined(OS_MAC)
|
|
|
|
// On MacOS we get two asynchronous callbacks, and we want to change the UI on
|
|
|
|
// |is_completed=false| (e.g. when the fullscreen transition begins).
|
|
|
|
const bool should_change = !is_completed;
|
|
|
|
#else
|
|
|
|
// On other platforms we only get a single synchronous callback with
|
|
|
|
// |is_completed=true|.
|
|
|
|
DCHECK(is_completed);
|
|
|
|
const bool should_change = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Hide the top controls while in fullscreen mode.
|
|
|
|
if (should_change && with_controls_) {
|
|
|
|
ShowTopControls(!window->IsFullscreen());
|
|
|
|
}
|
2023-11-07 22:40:29 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// With Alloy style we need to explicitly exit browser fullscreen when
|
|
|
|
// exiting window fullscreen. Chrome style handles this internally.
|
|
|
|
if (use_alloy_style_ && should_change && !window->IsFullscreen()) {
|
2023-11-07 22:40:29 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2024-01-29 19:38:25 +01:00
|
|
|
|
|
|
|
#if defined(OS_MAC)
|
|
|
|
// Continue hide logic from CanClose.
|
|
|
|
if (is_completed && hide_after_fullscreen_exit_) {
|
|
|
|
hide_after_fullscreen_exit_ = false;
|
|
|
|
window->Hide();
|
|
|
|
}
|
|
|
|
#endif
|
2023-09-25 21:40:17 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void ViewsWindow::OnThemeColorsChanged(CefRefPtr<CefWindow> window,
|
|
|
|
bool chrome_theme) {
|
|
|
|
// Apply color overrides to the current theme.
|
|
|
|
views_style::ApplyTo(window);
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t ViewsWindow::GetWindowRuntimeStyle() {
|
|
|
|
if (use_alloy_style_window_) {
|
|
|
|
return CEF_RUNTIME_STYLE_ALLOY;
|
|
|
|
}
|
|
|
|
return CEF_RUNTIME_STYLE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2024-08-05 18:12:33 +02:00
|
|
|
#if defined(OS_LINUX)
|
|
|
|
bool ViewsWindow::GetLinuxWindowProperties(
|
|
|
|
CefRefPtr<CefWindow> window,
|
|
|
|
CefLinuxWindowProperties& properties) {
|
|
|
|
CefString(&properties.wayland_app_id) =
|
|
|
|
CefString(&properties.wm_class_class) =
|
|
|
|
CefString(&properties.wm_class_name) =
|
|
|
|
CefString(&properties.wm_role_name) = "cef";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(browser_view_);
|
|
|
|
DCHECK(!window_);
|
|
|
|
DCHECK(window);
|
|
|
|
|
|
|
|
window_ = window;
|
|
|
|
window_->SetID(ID_WINDOW);
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// Apply color overrides to the current native/OS theme. This is only
|
|
|
|
// necessary until the CefBrowserView is added to the CefWindow, at which time
|
|
|
|
// the Chrome theme will be applied (triggering a call to OnThemeColorsChanged
|
|
|
|
// with |chrome_theme=true|).
|
|
|
|
views_style::ApplyTo(window_);
|
|
|
|
window_->ThemeChanged();
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
delegate_->OnViewsWindowCreated(this);
|
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
if (type_ == WindowType::NORMAL || type_ == WindowType::DEVTOOLS) {
|
2023-06-14 10:20:02 +02:00
|
|
|
const CefRect bounds = delegate_->GetInitialBounds();
|
|
|
|
if (bounds.IsEmpty()) {
|
|
|
|
// Size the Window and center it at the default size.
|
|
|
|
window_->CenterWindow(CefSize(kDefaultWidth, kDefaultHeight));
|
2023-11-14 18:16:43 +01:00
|
|
|
} else if (SupportsWindowRestore()) {
|
2023-06-14 10:20:02 +02:00
|
|
|
// Remember the bounds from the previous application run in case the user
|
|
|
|
// does not move or resize the window during this application run.
|
|
|
|
last_visible_bounds_ = bounds;
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
if (with_controls_ || with_overlay_controls_) {
|
|
|
|
// Create the MenuModel that will be displayed via the menu button.
|
|
|
|
CreateMenuModel();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (with_controls_) {
|
2024-03-26 23:18:20 +01:00
|
|
|
// Add the BrowserView to the Window. Other controls will be added after the
|
|
|
|
// BrowserView is added.
|
2021-08-28 03:55:15 +02:00
|
|
|
AddBrowserView();
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
// Add keyboard accelerators to the Window.
|
|
|
|
AddAccelerators();
|
2021-09-07 16:04:55 +02:00
|
|
|
|
|
|
|
// Hide the top controls while in full-screen mode.
|
2022-10-28 20:17:18 +02:00
|
|
|
if (delegate_->GetInitialShowState() == CEF_SHOW_STATE_FULLSCREEN) {
|
2021-09-07 16:04:55 +02:00
|
|
|
ShowTopControls(false);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
} else {
|
|
|
|
// Add the BrowserView as the only child of the Window.
|
|
|
|
window_->AddChildView(browser_view_);
|
|
|
|
|
2024-05-03 20:13:38 +02:00
|
|
|
// Choose a reasonable minimum window size.
|
|
|
|
minimum_window_size_ = CefSize(100, 100);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
if (!delegate_->InitiallyHidden()) {
|
|
|
|
// Show the Window.
|
|
|
|
Show();
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
void ViewsWindow::OnWindowClosing(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(window_);
|
|
|
|
|
|
|
|
delegate_->OnViewsWindowClosing(this);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ViewsWindow::OnWindowDestroyed(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(window_);
|
|
|
|
|
|
|
|
delegate_->OnViewsWindowDestroyed(this);
|
|
|
|
|
2020-01-15 15:28:12 +01:00
|
|
|
browser_view_ = nullptr;
|
|
|
|
button_menu_model_ = nullptr;
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_bar_) {
|
|
|
|
menu_bar_->Reset();
|
|
|
|
menu_bar_ = nullptr;
|
2017-02-22 19:05:27 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
menu_button_ = nullptr;
|
2020-01-15 15:28:12 +01:00
|
|
|
window_ = nullptr;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2022-04-12 21:46:09 +02:00
|
|
|
void ViewsWindow::OnWindowActivationChanged(CefRefPtr<CefWindow> window,
|
|
|
|
bool active) {
|
2022-10-28 20:17:18 +02:00
|
|
|
if (!active) {
|
2022-04-12 21:46:09 +02:00
|
|
|
return;
|
2022-10-28 20:17:18 +02:00
|
|
|
}
|
2022-04-12 21:46:09 +02:00
|
|
|
|
|
|
|
delegate_->OnViewsWindowActivated(this);
|
|
|
|
}
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
void ViewsWindow::OnWindowBoundsChanged(CefRefPtr<CefWindow> window,
|
|
|
|
const CefRect& new_bounds) {
|
2023-11-14 18:16:43 +01:00
|
|
|
if (SupportsWindowRestore() && !window->IsMinimized() &&
|
2023-06-14 10:20:02 +02:00
|
|
|
!window->IsMaximized() && !window->IsFullscreen()) {
|
2022-10-28 20:17:18 +02:00
|
|
|
// Track the last visible bounds for window restore purposes.
|
|
|
|
last_visible_bounds_ = new_bounds;
|
|
|
|
}
|
2023-02-28 19:34:12 +01:00
|
|
|
|
|
|
|
#if defined(OS_MAC)
|
2023-06-30 14:17:02 +02:00
|
|
|
if (frameless_ && with_standard_buttons_ && toolbar_) {
|
|
|
|
auto insets = toolbar_->GetInsets();
|
2023-02-28 19:34:12 +01:00
|
|
|
insets.left = window->IsFullscreen() ? 0 : kWindowButtonsWidth;
|
2023-06-30 14:17:02 +02:00
|
|
|
toolbar_->SetInsets(insets);
|
2023-02-28 19:34:12 +01:00
|
|
|
}
|
|
|
|
#endif
|
2022-10-28 20:17:18 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
bool ViewsWindow::CanClose(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2024-01-29 19:38:25 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
// On MacOS we might hide the window instead of closing it.
|
|
|
|
if (hide_on_close_) {
|
|
|
|
if (window->IsFullscreen()) {
|
|
|
|
// Need to exit fullscreen mode before hiding the window.
|
|
|
|
// Execution continues in OnWindowFullscreenTransition.
|
|
|
|
hide_after_fullscreen_exit_ = true;
|
|
|
|
window->SetFullscreen(false);
|
|
|
|
} else {
|
|
|
|
window->Hide();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Allow the window to close if the browser says it's OK.
|
|
|
|
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return browser->GetHost()->TryCloseBrowser();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefWindow> ViewsWindow::GetParentWindow(CefRefPtr<CefWindow> window,
|
|
|
|
bool* is_menu,
|
|
|
|
bool* can_activate_menu) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2024-05-03 20:13:38 +02:00
|
|
|
return delegate_->GetParentWindow();
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
bool ViewsWindow::IsWindowModalDialog(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(delegate_->GetParentWindow());
|
|
|
|
return use_window_modal_dialog_;
|
|
|
|
}
|
|
|
|
|
2021-08-04 20:20:31 +02:00
|
|
|
CefRect ViewsWindow::GetInitialBounds(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2022-10-28 20:17:18 +02:00
|
|
|
const CefRect bounds = delegate_->GetInitialBounds();
|
2022-10-25 01:47:04 +02:00
|
|
|
if (frameless_ && bounds.IsEmpty()) {
|
2021-08-04 20:20:31 +02:00
|
|
|
// Need to provide a size for frameless windows that will be centered.
|
2022-10-25 01:47:04 +02:00
|
|
|
return CefRect(0, 0, kDefaultWidth, kDefaultHeight);
|
2021-08-04 20:20:31 +02:00
|
|
|
}
|
2022-10-25 01:47:04 +02:00
|
|
|
return bounds;
|
2021-08-04 20:20:31 +02:00
|
|
|
}
|
|
|
|
|
2021-09-07 16:04:55 +02:00
|
|
|
cef_show_state_t ViewsWindow::GetInitialShowState(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2022-10-28 20:17:18 +02:00
|
|
|
return delegate_->GetInitialShowState();
|
2021-09-07 16:04:55 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
bool ViewsWindow::IsFrameless(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return frameless_;
|
|
|
|
}
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
bool ViewsWindow::WithStandardWindowButtons(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return with_standard_buttons_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::GetTitlebarHeight(CefRefPtr<CefWindow> window,
|
|
|
|
float* titlebar_height) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
#if defined(OS_MAC)
|
2023-03-16 18:19:50 +01:00
|
|
|
if (override_titlebar_height_.has_value()) {
|
|
|
|
*titlebar_height = override_titlebar_height_.value();
|
2023-02-28 19:34:12 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-12 17:49:31 +02:00
|
|
|
cef_state_t ViewsWindow::AcceptsFirstMouse(CefRefPtr<CefWindow> window) {
|
|
|
|
if (accepts_first_mouse_) {
|
|
|
|
return STATE_ENABLED;
|
|
|
|
}
|
|
|
|
return STATE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool ViewsWindow::CanResize(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-11-14 18:16:43 +01:00
|
|
|
// Only allow resize of normal and DevTools windows.
|
|
|
|
return type_ == WindowType::NORMAL || type_ == WindowType::DEVTOOLS;
|
2023-06-14 10:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::CanMaximize(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-11-14 18:16:43 +01:00
|
|
|
return CanResize(window);
|
2023-06-14 10:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::CanMinimize(CefRefPtr<CefWindow> window) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2023-11-14 18:16:43 +01:00
|
|
|
return CanResize(window);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
bool ViewsWindow::OnAccelerator(CefRefPtr<CefWindow> window, int command_id) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (command_id == ID_QUIT) {
|
|
|
|
delegate_->OnExit();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ViewsWindow::OnKeyEvent(CefRefPtr<CefWindow> window,
|
|
|
|
const CefKeyEvent& event) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2024-05-03 20:13:38 +02:00
|
|
|
if (!window_ || !with_controls_) {
|
2017-02-17 00:19:43 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
if (event.type == KEYEVENT_RAWKEYDOWN && event.windows_key_code == VK_MENU) {
|
2017-02-25 06:03:31 +01:00
|
|
|
// ALT key is pressed.
|
|
|
|
int last_focused_view = last_focused_view_;
|
|
|
|
bool menu_had_focus = menu_has_focus_;
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
// Toggle menu button focusable.
|
|
|
|
SetMenuFocusable(!menu_has_focus_);
|
|
|
|
|
|
|
|
if (menu_had_focus && last_focused_view != 0) {
|
|
|
|
// Restore focus to the view that was previously focused.
|
|
|
|
window_->GetViewForID(last_focused_view)->RequestFocus();
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_has_focus_ && menu_bar_) {
|
|
|
|
return menu_bar_->OnKeyEvent(event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-23 21:24:45 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
CefSize ViewsWindow::GetPreferredSize(CefRefPtr<CefView> view) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (view->GetID() == ID_WINDOW && type_ == WindowType::DIALOG) {
|
|
|
|
// Preferred size for a browser modal dialog. The dialog will be shrunk to
|
|
|
|
// fit inside the parent browser view if necessary.
|
|
|
|
return CefSize(kDefaultWidth, kDefaultHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CefSize();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefSize ViewsWindow::GetMinimumSize(CefRefPtr<CefView> view) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view->GetID() == ID_WINDOW) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return minimum_window_size_;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
return CefSize();
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
void ViewsWindow::OnFocus(CefRefPtr<CefView> view) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2017-02-25 06:03:31 +01:00
|
|
|
const int view_id = view->GetID();
|
|
|
|
|
|
|
|
// Keep track of the non-menu view that was last focused.
|
|
|
|
if (last_focused_view_ != view_id &&
|
2023-06-30 14:17:02 +02:00
|
|
|
(!menu_bar_ || !menu_bar_->HasMenuId(view_id))) {
|
2017-02-25 06:03:31 +01:00
|
|
|
last_focused_view_ = view_id;
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
// When focus leaves the menu buttons make them unfocusable.
|
|
|
|
if (menu_has_focus_) {
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_bar_) {
|
|
|
|
if (!menu_bar_->HasMenuId(view_id)) {
|
2017-02-18 03:08:51 +01:00
|
|
|
SetMenuFocusable(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-18 03:08:51 +01:00
|
|
|
} else if (view_id != ID_MENU_BUTTON) {
|
|
|
|
SetMenuFocusable(false);
|
|
|
|
}
|
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
void ViewsWindow::OnWindowChanged(CefRefPtr<CefView> view, bool added) {
|
|
|
|
const int view_id = view->GetID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view_id != ID_BROWSER_VIEW) {
|
2021-04-11 22:10:11 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
if (added) {
|
|
|
|
if (with_controls_) {
|
|
|
|
AddControls();
|
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
if (with_overlay_controls_) {
|
2023-02-28 19:34:12 +01:00
|
|
|
// Add window buttons if we don't have standard ones
|
|
|
|
const bool with_window_buttons = !with_standard_buttons_;
|
2023-06-30 14:17:02 +02:00
|
|
|
overlay_controls_ =
|
|
|
|
new ViewsOverlayControls(with_window_buttons, use_bottom_controls_);
|
2021-08-28 03:55:15 +02:00
|
|
|
overlay_controls_->Initialize(window_, CreateMenuButton(),
|
|
|
|
CreateLocationBar(),
|
|
|
|
chrome_toolbar_type_ != CEF_CTT_NONE);
|
2021-04-11 22:10:11 +02:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
} else {
|
2023-06-30 14:17:02 +02:00
|
|
|
// Remove any controls that may include the Chrome toolbar before removing
|
|
|
|
// the BrowserView.
|
2021-08-28 03:55:15 +02:00
|
|
|
if (overlay_controls_) {
|
|
|
|
overlay_controls_->Destroy();
|
|
|
|
overlay_controls_ = nullptr;
|
|
|
|
location_bar_ = nullptr;
|
2023-06-30 14:17:02 +02:00
|
|
|
} else if (use_bottom_controls_) {
|
|
|
|
if (toolbar_) {
|
|
|
|
window_->RemoveChildView(toolbar_);
|
|
|
|
toolbar_ = nullptr;
|
|
|
|
location_bar_ = nullptr;
|
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
void ViewsWindow::OnLayoutChanged(CefRefPtr<CefView> view,
|
|
|
|
const CefRect& new_bounds) {
|
|
|
|
const int view_id = view->GetID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (view_id != ID_BROWSER_VIEW) {
|
2021-08-28 03:55:15 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
if (overlay_controls_) {
|
|
|
|
overlay_controls_->UpdateControls();
|
2021-04-11 22:10:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-23 00:51:00 +01:00
|
|
|
void ViewsWindow::OnThemeChanged(CefRefPtr<CefView> view) {
|
|
|
|
// Apply colors when the theme changes.
|
2024-03-29 17:48:33 +01:00
|
|
|
views_style::OnThemeChanged(view);
|
2024-03-23 00:51:00 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 19:05:27 +01:00
|
|
|
void ViewsWindow::MenuBarExecuteCommand(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
int command_id,
|
|
|
|
cef_event_flags_t event_flags) {
|
|
|
|
ExecuteCommand(menu_model, command_id, event_flags);
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
ViewsWindow::ViewsWindow(WindowType type,
|
|
|
|
Delegate* delegate,
|
2023-11-29 02:33:44 +01:00
|
|
|
CefRefPtr<CefBrowserView> browser_view,
|
|
|
|
CefRefPtr<CefCommandLine> command_line)
|
2024-04-17 18:01:26 +02:00
|
|
|
: type_(type),
|
|
|
|
delegate_(delegate),
|
|
|
|
use_alloy_style_(delegate->UseAlloyStyle()),
|
|
|
|
command_line_(command_line) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(delegate_);
|
2023-11-29 02:33:44 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_view) {
|
2016-01-19 21:09:01 +01:00
|
|
|
SetBrowserView(browser_view);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-06-26 02:12:37 +02:00
|
|
|
use_alloy_style_window_ =
|
|
|
|
use_alloy_style_ &&
|
|
|
|
!command_line_->HasSwitch(switches::kUseChromeStyleWindow);
|
2024-04-17 18:01:26 +02:00
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
const bool is_normal_type = type_ == WindowType::NORMAL;
|
|
|
|
|
|
|
|
with_controls_ = is_normal_type && delegate_->WithControls();
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
const bool hide_frame = command_line->HasSwitch(switches::kHideFrame);
|
2023-06-14 10:20:02 +02:00
|
|
|
const bool hide_overlays =
|
|
|
|
!is_normal_type || command_line->HasSwitch(switches::kHideOverlays);
|
|
|
|
const bool hide_toolbar = hide_overlays && !with_controls_;
|
2023-02-28 19:34:12 +01:00
|
|
|
const bool show_window_buttons =
|
|
|
|
command_line->HasSwitch(switches::kShowWindowButtons);
|
2024-04-12 17:49:31 +02:00
|
|
|
accepts_first_mouse_ = command_line->HasSwitch(switches::kAcceptsFirstMouse);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
// Without a window frame.
|
2024-05-03 20:13:38 +02:00
|
|
|
frameless_ = hide_frame;
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
// With an overlay that mimics window controls.
|
2023-06-14 10:20:02 +02:00
|
|
|
with_overlay_controls_ = hide_frame && !hide_overlays && !with_controls_;
|
2017-02-22 19:05:27 +01:00
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
// If window has frame or flag passed explicitly
|
|
|
|
with_standard_buttons_ = !frameless_ || show_window_buttons;
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
if (frameless_ && with_standard_buttons_) {
|
|
|
|
default_titlebar_height_ = kTitleBarHeight;
|
|
|
|
override_titlebar_height_ = kTitleBarHeight;
|
|
|
|
}
|
2024-01-29 19:38:25 +01:00
|
|
|
|
|
|
|
hide_on_close_ = command_line->HasSwitch(switches::kHideWindowOnClose);
|
2023-03-16 18:19:50 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
const std::string& toolbar_type =
|
|
|
|
command_line->GetSwitchValue(switches::kShowChromeToolbar);
|
2024-04-17 18:01:26 +02:00
|
|
|
chrome_toolbar_type_ = CalculateChromeToolbarType(
|
|
|
|
use_alloy_style_, toolbar_type, hide_toolbar, with_overlay_controls_);
|
2021-04-11 22:10:11 +02:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
use_bottom_controls_ = command_line->HasSwitch(switches::kUseBottomControls);
|
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
#if !defined(OS_MAC)
|
|
|
|
// On Mac we don't show a top menu on the window. The options are available in
|
|
|
|
// the app menu instead.
|
2017-02-25 06:03:31 +01:00
|
|
|
if (!command_line->HasSwitch(switches::kHideTopMenu)) {
|
2023-06-30 14:17:02 +02:00
|
|
|
menu_bar_ = new ViewsMenuBar(this, ID_TOP_MENU_FIRST, use_bottom_controls_);
|
2017-02-25 06:03:31 +01:00
|
|
|
}
|
2021-02-23 21:08:33 +01:00
|
|
|
#endif
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
use_window_modal_dialog_ =
|
|
|
|
command_line->HasSwitch(switches::kUseWindowModalDialog);
|
2023-09-07 19:28:27 +02:00
|
|
|
hide_pip_frame_ = command_line->HasSwitch(switches::kHidePipFrame);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::SetBrowserView(CefRefPtr<CefBrowserView> browser_view) {
|
|
|
|
DCHECK(!browser_view_);
|
|
|
|
DCHECK(browser_view);
|
|
|
|
DCHECK(browser_view->IsValid());
|
|
|
|
DCHECK(!browser_view->IsAttached());
|
|
|
|
browser_view_ = browser_view;
|
2017-02-25 06:03:31 +01:00
|
|
|
browser_view_->SetID(ID_BROWSER_VIEW);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::CreateMenuModel() {
|
2017-02-18 03:08:51 +01:00
|
|
|
// Create the menu button model.
|
|
|
|
button_menu_model_ = CefMenuModel::CreateMenuModel(this);
|
|
|
|
CefRefPtr<CefMenuModel> test_menu =
|
|
|
|
button_menu_model_->AddSubMenu(0, "&Tests");
|
2017-02-25 06:03:31 +01:00
|
|
|
views_style::ApplyTo(button_menu_model_);
|
2017-02-18 03:08:51 +01:00
|
|
|
AddTestMenuItems(test_menu);
|
2017-02-25 06:03:31 +01:00
|
|
|
AddFileMenuItems(button_menu_model_);
|
2017-02-18 03:08:51 +01:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_bar_) {
|
2017-02-22 19:05:27 +01:00
|
|
|
// Add the menus to the top menu bar.
|
2023-06-30 14:17:02 +02:00
|
|
|
AddFileMenuItems(menu_bar_->CreateMenuModel("&File", nullptr));
|
|
|
|
AddTestMenuItems(menu_bar_->CreateMenuModel("&Tests", nullptr));
|
2017-02-18 03:08:51 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefLabelButton> ViewsWindow::CreateBrowseButton(
|
|
|
|
const std::string& label,
|
|
|
|
int id) {
|
|
|
|
CefRefPtr<CefLabelButton> button =
|
2019-07-16 19:59:21 +02:00
|
|
|
CefLabelButton::CreateLabelButton(this, label);
|
2016-01-19 21:09:01 +01:00
|
|
|
button->SetID(id);
|
2021-08-28 03:55:15 +02:00
|
|
|
button->SetInkDropEnabled(true);
|
2017-05-17 11:29:28 +02:00
|
|
|
button->SetEnabled(false); // Disabled by default.
|
2016-01-19 21:09:01 +01:00
|
|
|
button->SetFocusable(false); // Don't give focus to the button.
|
2017-02-25 06:03:31 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefMenuButton> ViewsWindow::CreateMenuButton() {
|
|
|
|
// Create the menu button.
|
|
|
|
DCHECK(!menu_button_);
|
|
|
|
menu_button_ = CefMenuButton::CreateMenuButton(this, CefString());
|
|
|
|
menu_button_->SetID(ID_MENU_BUTTON);
|
|
|
|
menu_button_->SetImage(
|
|
|
|
CEF_BUTTON_STATE_NORMAL,
|
|
|
|
delegate_->GetImageCache()->GetCachedImage("menu_icon"));
|
|
|
|
menu_button_->SetInkDropEnabled(true);
|
|
|
|
// Override the default minimum size.
|
|
|
|
menu_button_->SetMinimumSize(CefSize(0, 0));
|
|
|
|
return menu_button_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefView> ViewsWindow::CreateLocationBar() {
|
|
|
|
DCHECK(!location_bar_);
|
|
|
|
if (chrome_toolbar_type_ == CEF_CTT_LOCATION) {
|
|
|
|
// Chrome will provide a minimal location bar.
|
|
|
|
location_bar_ = browser_view_->GetChromeToolbar();
|
|
|
|
DCHECK(location_bar_);
|
|
|
|
}
|
|
|
|
if (!location_bar_) {
|
|
|
|
// Create the URL textfield.
|
|
|
|
CefRefPtr<CefTextfield> url_textfield = CefTextfield::CreateTextfield(this);
|
|
|
|
url_textfield->SetID(ID_URL_TEXTFIELD);
|
|
|
|
location_bar_ = url_textfield;
|
|
|
|
}
|
|
|
|
return location_bar_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::AddBrowserView() {
|
2016-01-19 21:09:01 +01:00
|
|
|
// Use a vertical box layout for |window|.
|
|
|
|
CefBoxLayoutSettings window_layout_settings;
|
|
|
|
window_layout_settings.horizontal = false;
|
|
|
|
window_layout_settings.between_child_spacing = 2;
|
|
|
|
CefRefPtr<CefBoxLayout> window_layout =
|
|
|
|
window_->SetToBoxLayout(window_layout_settings);
|
|
|
|
|
|
|
|
window_->AddChildView(browser_view_);
|
|
|
|
|
|
|
|
// Allow |browser_view_| to grow and fill any remaining space.
|
|
|
|
window_layout->SetFlexForView(browser_view_, 1);
|
|
|
|
|
2021-04-11 22:10:11 +02:00
|
|
|
// Remaining setup will be performed in OnWindowChanged after the BrowserView
|
|
|
|
// is added to the CefWindow. This is necessary because Chrome toolbars are
|
|
|
|
// only available after the BrowserView is added.
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
void ViewsWindow::AddControls() {
|
|
|
|
// Build the remainder of the UI now that the BrowserView has been added to
|
|
|
|
// the CefWindow. This is a requirement to use Chrome toolbars.
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
CefRefPtr<CefPanel> menu_panel;
|
|
|
|
if (menu_bar_) {
|
|
|
|
menu_panel = menu_bar_->GetMenuPanel();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
LabelButtons browse_buttons;
|
|
|
|
|
|
|
|
if (chrome_toolbar_type_ == CEF_CTT_NORMAL) {
|
|
|
|
// Chrome will provide a normal toolbar with location, menu, etc.
|
2023-06-30 14:17:02 +02:00
|
|
|
toolbar_ = browser_view_->GetChromeToolbar();
|
|
|
|
DCHECK(toolbar_);
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
if (!toolbar_) {
|
2021-08-28 03:55:15 +02:00
|
|
|
// Create the browse buttons.
|
|
|
|
browse_buttons.push_back(CreateBrowseButton("Back", ID_BACK_BUTTON));
|
|
|
|
browse_buttons.push_back(CreateBrowseButton("Forward", ID_FORWARD_BUTTON));
|
|
|
|
browse_buttons.push_back(CreateBrowseButton("Reload", ID_RELOAD_BUTTON));
|
|
|
|
browse_buttons.push_back(CreateBrowseButton("Stop", ID_STOP_BUTTON));
|
|
|
|
|
|
|
|
CreateLocationBar();
|
|
|
|
CreateMenuButton();
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
// Create the toolbar panel.
|
2024-03-29 17:48:33 +01:00
|
|
|
CefRefPtr<CefPanel> panel = CefPanel::CreatePanel(this);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
// Use a horizontal box layout for |panel|.
|
|
|
|
CefBoxLayoutSettings panel_layout_settings;
|
|
|
|
panel_layout_settings.horizontal = true;
|
|
|
|
CefRefPtr<CefBoxLayout> panel_layout =
|
|
|
|
panel->SetToBoxLayout(panel_layout_settings);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
// Add the buttons and URL textfield to |panel|.
|
2023-06-14 10:20:02 +02:00
|
|
|
for (auto& browse_button : browse_buttons) {
|
2023-06-30 14:17:02 +02:00
|
|
|
panel->AddChildView(browse_button);
|
2023-06-14 10:20:02 +02:00
|
|
|
}
|
2023-06-30 14:17:02 +02:00
|
|
|
panel->AddChildView(location_bar_);
|
|
|
|
panel->AddChildView(menu_button_);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
// Allow |location| to grow and fill any remaining space.
|
2023-06-30 14:17:02 +02:00
|
|
|
panel_layout->SetFlexForView(location_bar_, 1);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
toolbar_ = panel;
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
if (frameless_ && with_standard_buttons_) {
|
2023-06-30 14:17:02 +02:00
|
|
|
auto insets = toolbar_->GetInsets();
|
2023-02-28 19:34:12 +01:00
|
|
|
insets.left = kWindowButtonsWidth;
|
2023-06-30 14:17:02 +02:00
|
|
|
toolbar_->SetInsets(insets);
|
2023-02-28 19:34:12 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
if (use_bottom_controls_) {
|
|
|
|
// Add the panel at the bottom of |window|.
|
|
|
|
window_->AddChildView(toolbar_);
|
|
|
|
if (menu_panel) {
|
|
|
|
window_->AddChildView(menu_panel);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Add the panel at the top of |window|.
|
|
|
|
int index = 0;
|
|
|
|
if (menu_panel) {
|
|
|
|
window_->AddChildViewAt(menu_panel, index++);
|
|
|
|
}
|
|
|
|
window_->AddChildViewAt(toolbar_, index);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
// Lay out |window| so we can get the default button sizes.
|
|
|
|
window_->Layout();
|
|
|
|
|
|
|
|
int min_width = 200;
|
|
|
|
if (!browse_buttons.empty()) {
|
|
|
|
// Make all browse buttons the same size.
|
|
|
|
MakeButtonsSameSize(browse_buttons);
|
|
|
|
|
|
|
|
// Lay out |window| again with the new button sizes.
|
|
|
|
window_->Layout();
|
|
|
|
|
2023-02-28 19:34:12 +01:00
|
|
|
const int buttons_number = static_cast<int>(browse_buttons.size());
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
// Minimum window width is the size of all buttons plus some extra.
|
2023-02-28 19:34:12 +01:00
|
|
|
min_width = browse_buttons[0]->GetBounds().width * buttons_number +
|
2021-08-28 03:55:15 +02:00
|
|
|
menu_button_->GetBounds().width + 100;
|
|
|
|
}
|
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
// Minimum window height is the hight of the toolbar plus some extra.
|
|
|
|
int min_height = toolbar_->GetBounds().height + 100;
|
|
|
|
if (menu_panel) {
|
|
|
|
min_height += menu_panel->GetBounds().height;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
minimum_window_size_ = CefSize(min_width, min_height);
|
2024-03-26 23:18:20 +01:00
|
|
|
|
|
|
|
// Apply the state that we may have missed when SetLoadingState was called
|
|
|
|
// initially.
|
|
|
|
UpdateToolbarButtonState();
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void ViewsWindow::AddAccelerators() {
|
|
|
|
// Specify the accelerators to handle. OnAccelerator will be called when the
|
|
|
|
// accelerator is triggered.
|
2023-11-08 20:27:50 +01:00
|
|
|
window_->SetAccelerator(ID_QUIT, 'X', /*shift_pressed=*/false,
|
|
|
|
/*ctrl_pressed=*/false, /*alt_pressed=*/true,
|
|
|
|
/*high_priority=*/true);
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
void ViewsWindow::SetMenuFocusable(bool focusable) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_ || !with_controls_) {
|
2017-02-18 03:08:51 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-18 03:08:51 +01:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
if (menu_bar_) {
|
|
|
|
menu_bar_->SetMenuFocusable(focusable);
|
2017-02-18 03:08:51 +01:00
|
|
|
} else {
|
|
|
|
window_->GetViewForID(ID_MENU_BUTTON)->SetFocusable(focusable);
|
|
|
|
|
|
|
|
if (focusable) {
|
|
|
|
// Give focus to menu button.
|
|
|
|
window_->GetViewForID(ID_MENU_BUTTON)->RequestFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_has_focus_ = focusable;
|
|
|
|
}
|
|
|
|
|
2024-03-26 23:18:20 +01:00
|
|
|
void ViewsWindow::UpdateToolbarButtonState() {
|
|
|
|
SetViewEnabled(window_, ID_BACK_BUTTON, can_go_back_);
|
|
|
|
SetViewEnabled(window_, ID_FORWARD_BUTTON, can_go_forward_);
|
|
|
|
SetViewEnabled(window_, ID_RELOAD_BUTTON, !is_loading_);
|
|
|
|
SetViewEnabled(window_, ID_STOP_BUTTON, is_loading_);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewsWindow::ShowTopControls(bool show) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_ || !with_controls_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-06-30 14:17:02 +02:00
|
|
|
// Change the visibility of the toolbar.
|
|
|
|
if (toolbar_->IsVisible() != show) {
|
|
|
|
toolbar_->SetVisible(show);
|
|
|
|
toolbar_->InvalidateLayout();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
#if !defined(OS_MAC)
|
|
|
|
void ViewsWindow::NudgeWindow() {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
} // namespace client
|