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.
|
|
|
|
|
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_
|
|
|
|
#pragma once
|
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
#include <optional>
|
2017-08-04 00:55:19 +02:00
|
|
|
#include <set>
|
2016-01-19 21:09:01 +01:00
|
|
|
#include <string>
|
2017-08-04 00:55:19 +02:00
|
|
|
#include <vector>
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "include/base/cef_callback_forward.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/cef_menu_model_delegate.h"
|
|
|
|
#include "include/views/cef_browser_view.h"
|
|
|
|
#include "include/views/cef_browser_view_delegate.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "include/views/cef_button_delegate.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/views/cef_label_button.h"
|
|
|
|
#include "include/views/cef_menu_button.h"
|
|
|
|
#include "include/views/cef_menu_button_delegate.h"
|
2021-08-28 03:55:15 +02:00
|
|
|
#include "include/views/cef_overlay_controller.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/views/cef_textfield.h"
|
|
|
|
#include "include/views/cef_textfield_delegate.h"
|
|
|
|
#include "include/views/cef_window.h"
|
|
|
|
#include "include/views/cef_window_delegate.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "tests/cefclient/browser/image_cache.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "tests/cefclient/browser/root_window.h"
|
2017-02-22 19:05:27 +01:00
|
|
|
#include "tests/cefclient/browser/views_menu_bar.h"
|
2021-08-28 03:55:15 +02:00
|
|
|
#include "tests/cefclient/browser/views_overlay_controls.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
// Implements a CefWindow that hosts a single CefBrowserView and optional
|
2023-11-29 02:33:44 +01:00
|
|
|
// Views-hosted controls. All methods must be called on the browser process UI
|
2016-01-19 21:09:01 +01:00
|
|
|
// thread.
|
|
|
|
class ViewsWindow : public CefBrowserViewDelegate,
|
|
|
|
public CefMenuButtonDelegate,
|
|
|
|
public CefMenuModelDelegate,
|
|
|
|
public CefTextfieldDelegate,
|
2017-02-22 19:05:27 +01:00
|
|
|
public CefWindowDelegate,
|
|
|
|
public ViewsMenuBar::Delegate {
|
2016-01-19 21:09:01 +01:00
|
|
|
public:
|
|
|
|
// Delegate methods will be called on the browser process UI thread.
|
|
|
|
class Delegate {
|
|
|
|
public:
|
2024-04-17 18:01:26 +02:00
|
|
|
// Returns true if the window should use Alloy style, otherwise Chrome
|
|
|
|
// style.
|
|
|
|
virtual bool UseAlloyStyle() const = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Return true if the window should show controls.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual bool WithControls() = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Return true if the window should be created initially hidden.
|
|
|
|
virtual bool InitiallyHidden() = 0;
|
|
|
|
|
|
|
|
// Returns the parent for this window.
|
|
|
|
virtual CefRefPtr<CefWindow> GetParentWindow() = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Return the initial window bounds.
|
2022-10-28 20:17:18 +02:00
|
|
|
virtual CefRect GetInitialBounds() = 0;
|
|
|
|
|
|
|
|
// Return the initial window show state.
|
|
|
|
virtual cef_show_state_t GetInitialShowState() = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Returns the ImageCache.
|
|
|
|
virtual scoped_refptr<ImageCache> GetImageCache() = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Called when the ViewsWindow is created.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual void OnViewsWindowCreated(CefRefPtr<ViewsWindow> window) = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2022-10-28 20:17:18 +02:00
|
|
|
// Called when the ViewsWindow is closing.
|
|
|
|
virtual void OnViewsWindowClosing(CefRefPtr<ViewsWindow> window) = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Called when the ViewsWindow is destroyed. All references to |window|
|
|
|
|
// should be released in this callback.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual void OnViewsWindowDestroyed(CefRefPtr<ViewsWindow> window) = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
// Called when the ViewsWindow is activated (becomes the foreground window).
|
|
|
|
virtual void OnViewsWindowActivated(CefRefPtr<ViewsWindow> window) = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Return the Delegate for the popup window controlled by |client|.
|
2017-05-17 11:29:28 +02:00
|
|
|
virtual Delegate* GetDelegateForPopup(CefRefPtr<CefClient> client) = 0;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Called to execute a test. See resource.h for |test_id| values.
|
|
|
|
virtual void OnTest(int test_id) = 0;
|
|
|
|
|
|
|
|
// Called to exit the application.
|
|
|
|
virtual void OnExit() = 0;
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 03:22:56 +01:00
|
|
|
virtual ~Delegate() = default;
|
2016-01-19 21:09:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create a new top-level ViewsWindow hosting a browser with the specified
|
|
|
|
// configuration.
|
|
|
|
static CefRefPtr<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
|
|
|
|
|
|
|
void Show();
|
|
|
|
void Hide();
|
|
|
|
void Minimize();
|
|
|
|
void Maximize();
|
|
|
|
void SetBounds(const CefRect& bounds);
|
2017-08-04 00:55:19 +02:00
|
|
|
void SetBrowserSize(const CefSize& size,
|
|
|
|
bool has_position,
|
|
|
|
const CefPoint& position);
|
2016-01-19 21:09:01 +01:00
|
|
|
void Close(bool force);
|
|
|
|
void SetAddress(const std::string& url);
|
|
|
|
void SetTitle(const std::string& title);
|
|
|
|
void SetFavicon(CefRefPtr<CefImage> image);
|
|
|
|
void SetFullscreen(bool fullscreen);
|
2018-02-28 05:47:36 +01:00
|
|
|
void SetAlwaysOnTop(bool on_top);
|
2017-05-17 11:29:28 +02:00
|
|
|
void SetLoadingState(bool isLoading, bool canGoBack, bool canGoForward);
|
2016-01-19 21:09:01 +01:00
|
|
|
void SetDraggableRegions(const std::vector<CefDraggableRegion>& regions);
|
2017-02-17 00:19:43 +01:00
|
|
|
void TakeFocus(bool next);
|
2017-02-25 06:03:31 +01:00
|
|
|
void OnBeforeContextMenu(CefRefPtr<CefMenuModel> model);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-11-14 18:16:43 +01:00
|
|
|
static bool SupportsWindowRestore(WindowType type);
|
|
|
|
bool SupportsWindowRestore() const;
|
2022-10-28 20:17:18 +02:00
|
|
|
bool GetWindowRestorePreferences(cef_show_state_t& show_state,
|
|
|
|
std::optional<CefRect>& dip_bounds);
|
2023-03-16 18:19:50 +01:00
|
|
|
void SetTitlebarHeight(const std::optional<float>& height);
|
2022-10-28 20:17:18 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// CefBrowserViewDelegate methods:
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefBrowserViewDelegate> GetDelegateForPopupBrowserView(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view,
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefClient> client,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool is_devtools) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
bool OnPopupBrowserViewCreated(CefRefPtr<CefBrowserView> browser_view,
|
|
|
|
CefRefPtr<CefBrowserView> popup_browser_view,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool is_devtools) override;
|
2023-09-07 19:28:27 +02:00
|
|
|
ChromeToolbarType GetChromeToolbarType(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) override;
|
|
|
|
bool UseFramelessWindowForPictureInPicture(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) override;
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t GetBrowserRuntimeStyle() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefButtonDelegate methods:
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnButtonPressed(CefRefPtr<CefButton> button) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefMenuButtonDelegate methods:
|
2017-08-04 00:55:19 +02:00
|
|
|
void OnMenuButtonPressed(
|
|
|
|
CefRefPtr<CefMenuButton> menu_button,
|
|
|
|
const CefPoint& screen_point,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRefPtr<CefMenuButtonPressedLock> button_pressed_lock) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefMenuModelDelegate methods:
|
|
|
|
void ExecuteCommand(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
int command_id,
|
2021-06-17 21:43:06 +02:00
|
|
|
cef_event_flags_t event_flags) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefTextfieldDelegate methods:
|
|
|
|
bool OnKeyEvent(CefRefPtr<CefTextfield> textfield,
|
2021-06-17 21:43:06 +02:00
|
|
|
const CefKeyEvent& event) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefWindowDelegate methods:
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
|
2022-10-28 20:17:18 +02:00
|
|
|
void OnWindowClosing(CefRefPtr<CefWindow> window) override;
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override;
|
2022-04-12 21:46:09 +02:00
|
|
|
void OnWindowActivationChanged(CefRefPtr<CefWindow> window,
|
|
|
|
bool active) override;
|
2022-10-28 20:17:18 +02:00
|
|
|
void OnWindowBoundsChanged(CefRefPtr<CefWindow> window,
|
|
|
|
const CefRect& new_bounds) override;
|
2017-08-04 00:55:19 +02:00
|
|
|
CefRefPtr<CefWindow> GetParentWindow(CefRefPtr<CefWindow> window,
|
|
|
|
bool* is_menu,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool* can_activate_menu) override;
|
2023-06-14 10:20:02 +02:00
|
|
|
bool IsWindowModalDialog(CefRefPtr<CefWindow> window) override;
|
2021-08-04 20:20:31 +02:00
|
|
|
CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override;
|
2021-09-07 16:04:55 +02:00
|
|
|
cef_show_state_t GetInitialShowState(CefRefPtr<CefWindow> window) override;
|
2021-06-17 21:43:06 +02:00
|
|
|
bool IsFrameless(CefRefPtr<CefWindow> window) override;
|
2023-02-28 19:34:12 +01:00
|
|
|
bool WithStandardWindowButtons(CefRefPtr<CefWindow> window) override;
|
|
|
|
bool GetTitlebarHeight(CefRefPtr<CefWindow> window,
|
|
|
|
float* titlebar_height) override;
|
2024-04-12 17:49:31 +02:00
|
|
|
cef_state_t AcceptsFirstMouse(CefRefPtr<CefWindow> window) override;
|
2021-06-17 21:43:06 +02:00
|
|
|
bool CanResize(CefRefPtr<CefWindow> window) override;
|
2023-06-14 10:20:02 +02:00
|
|
|
bool CanMaximize(CefRefPtr<CefWindow> window) override;
|
|
|
|
bool CanMinimize(CefRefPtr<CefWindow> window) override;
|
2021-06-17 21:43:06 +02:00
|
|
|
bool CanClose(CefRefPtr<CefWindow> window) override;
|
|
|
|
bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id) override;
|
2017-02-17 00:19:43 +01:00
|
|
|
bool OnKeyEvent(CefRefPtr<CefWindow> window,
|
2021-06-17 21:43:06 +02:00
|
|
|
const CefKeyEvent& event) override;
|
2023-09-25 21:40:17 +02:00
|
|
|
void OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
|
|
|
|
bool is_completed) override;
|
2024-03-29 17:48:33 +01:00
|
|
|
void OnThemeColorsChanged(CefRefPtr<CefWindow> window,
|
|
|
|
bool chrome_theme) override;
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t GetWindowRuntimeStyle() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefViewDelegate methods:
|
2023-06-14 10:20:02 +02:00
|
|
|
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
|
2021-06-17 21:43:06 +02:00
|
|
|
CefSize GetMinimumSize(CefRefPtr<CefView> view) override;
|
|
|
|
void OnFocus(CefRefPtr<CefView> view) override;
|
|
|
|
void OnWindowChanged(CefRefPtr<CefView> view, bool added) override;
|
2021-08-28 03:55:15 +02:00
|
|
|
void OnLayoutChanged(CefRefPtr<CefView> view,
|
|
|
|
const CefRect& new_bounds) override;
|
2024-03-23 00:51:00 +01:00
|
|
|
void OnThemeChanged(CefRefPtr<CefView> view) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-22 19:05:27 +01:00
|
|
|
// ViewsMenuBar::Delegate methods:
|
|
|
|
void MenuBarExecuteCommand(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
int command_id,
|
2021-06-17 21:43:06 +02:00
|
|
|
cef_event_flags_t event_flags) override;
|
2017-02-22 19:05:27 +01:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
|
|
|
// |delegate| is guaranteed to outlive this object.
|
2021-06-17 22:08:01 +02:00
|
|
|
// |browser_view| may be nullptr, in which case SetBrowserView() will be
|
|
|
|
// called.
|
2023-06-14 10:20:02 +02:00
|
|
|
ViewsWindow(WindowType type,
|
|
|
|
Delegate* delegate,
|
2023-11-29 02:33:44 +01:00
|
|
|
CefRefPtr<CefBrowserView> browser_view,
|
|
|
|
CefRefPtr<CefCommandLine> command_line);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void SetBrowserView(CefRefPtr<CefBrowserView> browser_view);
|
|
|
|
|
|
|
|
// Create controls.
|
|
|
|
void CreateMenuModel();
|
|
|
|
CefRefPtr<CefLabelButton> CreateBrowseButton(const std::string& label,
|
|
|
|
int id);
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefMenuButton> CreateMenuButton();
|
|
|
|
CefRefPtr<CefView> CreateLocationBar();
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
// Add the BrowserView to the Window.
|
|
|
|
void AddBrowserView();
|
|
|
|
|
|
|
|
// Add other controls to the Window.
|
2016-01-19 21:09:01 +01:00
|
|
|
void AddControls();
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Add keyboard accelerators to the Window.
|
|
|
|
void AddAccelerators();
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
// Control whether the top menu butons are focusable.
|
|
|
|
void SetMenuFocusable(bool focusable);
|
|
|
|
|
2024-03-26 23:18:20 +01:00
|
|
|
// Update the toolbar button state.
|
|
|
|
void UpdateToolbarButtonState();
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Show/hide top controls on the Window.
|
|
|
|
void ShowTopControls(bool show);
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
void NudgeWindow();
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
const WindowType type_;
|
2016-01-19 21:09:01 +01:00
|
|
|
Delegate* delegate_; // Not owned by this object.
|
2024-04-17 18:01:26 +02:00
|
|
|
const bool use_alloy_style_;
|
|
|
|
bool use_alloy_style_window_;
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefBrowserView> browser_view_;
|
2023-11-29 02:33:44 +01:00
|
|
|
CefRefPtr<CefCommandLine> command_line_;
|
2016-01-19 21:09:01 +01:00
|
|
|
bool frameless_;
|
|
|
|
bool with_controls_;
|
2021-08-28 03:55:15 +02:00
|
|
|
bool with_overlay_controls_;
|
2023-02-28 19:34:12 +01:00
|
|
|
bool with_standard_buttons_;
|
2021-04-11 22:10:11 +02:00
|
|
|
ChromeToolbarType chrome_toolbar_type_;
|
2023-06-14 10:20:02 +02:00
|
|
|
bool use_window_modal_dialog_;
|
2023-06-30 14:17:02 +02:00
|
|
|
bool use_bottom_controls_;
|
2023-09-07 19:28:27 +02:00
|
|
|
bool hide_pip_frame_;
|
2024-04-12 17:49:31 +02:00
|
|
|
bool accepts_first_mouse_;
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefWindow> window_;
|
|
|
|
|
2017-02-18 03:08:51 +01:00
|
|
|
CefRefPtr<CefMenuModel> button_menu_model_;
|
2023-06-30 14:17:02 +02:00
|
|
|
CefRefPtr<ViewsMenuBar> menu_bar_;
|
|
|
|
CefRefPtr<CefView> toolbar_;
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefMenuButton> menu_button_;
|
|
|
|
CefRefPtr<CefView> location_bar_;
|
2024-01-20 03:22:56 +01:00
|
|
|
bool menu_has_focus_ = false;
|
|
|
|
int last_focused_view_ = false;
|
2022-10-28 20:17:18 +02:00
|
|
|
std::optional<CefRect> last_visible_bounds_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CefSize minimum_window_size_;
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<ViewsOverlayControls> overlay_controls_;
|
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
std::optional<float> default_titlebar_height_;
|
|
|
|
std::optional<float> override_titlebar_height_;
|
|
|
|
|
2024-01-29 19:38:25 +01:00
|
|
|
#if defined(OS_MAC)
|
|
|
|
bool hide_on_close_ = false;
|
|
|
|
bool hide_after_fullscreen_exit_ = false;
|
|
|
|
#endif
|
|
|
|
|
2024-03-26 23:18:20 +01:00
|
|
|
// Current loading state.
|
|
|
|
bool is_loading_ = false;
|
|
|
|
bool can_go_back_ = false;
|
|
|
|
bool can_go_forward_ = false;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
IMPLEMENT_REFCOUNTING(ViewsWindow);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ViewsWindow);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace client
|
|
|
|
|
|
|
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_
|