// 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 #include #include #include #include #include "include/base/cef_callback_forward.h" #include "include/cef_menu_model_delegate.h" #include "include/views/cef_browser_view.h" #include "include/views/cef_browser_view_delegate.h" #include "include/views/cef_button_delegate.h" #include "include/views/cef_label_button.h" #include "include/views/cef_menu_button.h" #include "include/views/cef_menu_button_delegate.h" #include "include/views/cef_overlay_controller.h" #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" #include "tests/cefclient/browser/image_cache.h" #include "tests/cefclient/browser/root_window.h" #include "tests/cefclient/browser/views_menu_bar.h" #include "tests/cefclient/browser/views_overlay_controls.h" namespace client { // Implements a CefWindow that hosts a single CefBrowserView and optional // Views-hosted controls. All methods must be called on the browser process UI // thread. class ViewsWindow : public CefBrowserViewDelegate, public CefMenuButtonDelegate, public CefMenuModelDelegate, public CefTextfieldDelegate, public CefWindowDelegate, public ViewsMenuBar::Delegate { public: // Delegate methods will be called on the browser process UI thread. class Delegate { public: // Returns true if the window should use Alloy style, otherwise Chrome // style. virtual bool UseAlloyStyle() const = 0; // Return true if the window should show controls. virtual bool WithControls() = 0; // Return true if the window should be created initially hidden. virtual bool InitiallyHidden() = 0; // Returns the parent for this window. virtual CefRefPtr GetParentWindow() = 0; // Return the initial window bounds. virtual CefRect GetInitialBounds() = 0; // Return the initial window show state. virtual cef_show_state_t GetInitialShowState() = 0; // Returns the ImageCache. virtual scoped_refptr GetImageCache() = 0; // Called when the ViewsWindow is created. virtual void OnViewsWindowCreated(CefRefPtr window) = 0; // Called when the ViewsWindow is closing. virtual void OnViewsWindowClosing(CefRefPtr window) = 0; // Called when the ViewsWindow is destroyed. All references to |window| // should be released in this callback. virtual void OnViewsWindowDestroyed(CefRefPtr window) = 0; // Called when the ViewsWindow is activated (becomes the foreground window). virtual void OnViewsWindowActivated(CefRefPtr window) = 0; // Return the Delegate for the popup window controlled by |client|. virtual Delegate* GetDelegateForPopup(CefRefPtr client) = 0; // 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: virtual ~Delegate() = default; }; // Create a new top-level ViewsWindow hosting a browser with the specified // configuration. static CefRefPtr Create( WindowType type, Delegate* delegate, CefRefPtr client, const CefString& url, const CefBrowserSettings& settings, CefRefPtr request_context, CefRefPtr command_line); void Show(); void Hide(); void Minimize(); void Maximize(); void SetBounds(const CefRect& bounds); void SetBrowserSize(const CefSize& size, bool has_position, const CefPoint& position); void Close(bool force); void SetAddress(const std::string& url); void SetTitle(const std::string& title); void SetFavicon(CefRefPtr image); void SetFullscreen(bool fullscreen); void SetAlwaysOnTop(bool on_top); void SetLoadingState(bool isLoading, bool canGoBack, bool canGoForward); void SetDraggableRegions(const std::vector& regions); void TakeFocus(bool next); void OnBeforeContextMenu(CefRefPtr model); static bool SupportsWindowRestore(WindowType type); bool SupportsWindowRestore() const; bool GetWindowRestorePreferences(cef_show_state_t& show_state, std::optional& dip_bounds); void SetTitlebarHeight(const std::optional& height); // CefBrowserViewDelegate methods: CefRefPtr GetDelegateForPopupBrowserView( CefRefPtr browser_view, const CefBrowserSettings& settings, CefRefPtr client, bool is_devtools) override; bool OnPopupBrowserViewCreated(CefRefPtr browser_view, CefRefPtr popup_browser_view, bool is_devtools) override; ChromeToolbarType GetChromeToolbarType( CefRefPtr browser_view) override; bool UseFramelessWindowForPictureInPicture( CefRefPtr browser_view) override; cef_runtime_style_t GetBrowserRuntimeStyle() override; // CefButtonDelegate methods: void OnButtonPressed(CefRefPtr button) override; // CefMenuButtonDelegate methods: void OnMenuButtonPressed( CefRefPtr menu_button, const CefPoint& screen_point, CefRefPtr button_pressed_lock) override; // CefMenuModelDelegate methods: void ExecuteCommand(CefRefPtr menu_model, int command_id, cef_event_flags_t event_flags) override; // CefTextfieldDelegate methods: bool OnKeyEvent(CefRefPtr textfield, const CefKeyEvent& event) override; // CefWindowDelegate methods: #if defined(OS_LINUX) virtual bool GetLinuxWindowProperties( CefRefPtr window, CefLinuxWindowProperties& properties) override; #endif void OnWindowCreated(CefRefPtr window) override; void OnWindowClosing(CefRefPtr window) override; void OnWindowDestroyed(CefRefPtr window) override; void OnWindowActivationChanged(CefRefPtr window, bool active) override; void OnWindowBoundsChanged(CefRefPtr window, const CefRect& new_bounds) override; CefRefPtr GetParentWindow(CefRefPtr window, bool* is_menu, bool* can_activate_menu) override; bool IsWindowModalDialog(CefRefPtr window) override; CefRect GetInitialBounds(CefRefPtr window) override; cef_show_state_t GetInitialShowState(CefRefPtr window) override; bool IsFrameless(CefRefPtr window) override; bool WithStandardWindowButtons(CefRefPtr window) override; bool GetTitlebarHeight(CefRefPtr window, float* titlebar_height) override; cef_state_t AcceptsFirstMouse(CefRefPtr window) override; bool CanResize(CefRefPtr window) override; bool CanMaximize(CefRefPtr window) override; bool CanMinimize(CefRefPtr window) override; bool CanClose(CefRefPtr window) override; bool OnAccelerator(CefRefPtr window, int command_id) override; bool OnKeyEvent(CefRefPtr window, const CefKeyEvent& event) override; void OnWindowFullscreenTransition(CefRefPtr window, bool is_completed) override; void OnThemeColorsChanged(CefRefPtr window, bool chrome_theme) override; cef_runtime_style_t GetWindowRuntimeStyle() override; // CefViewDelegate methods: CefSize GetPreferredSize(CefRefPtr view) override; CefSize GetMinimumSize(CefRefPtr view) override; void OnFocus(CefRefPtr view) override; void OnWindowChanged(CefRefPtr view, bool added) override; void OnLayoutChanged(CefRefPtr view, const CefRect& new_bounds) override; void OnThemeChanged(CefRefPtr view) override; // ViewsMenuBar::Delegate methods: void MenuBarExecuteCommand(CefRefPtr menu_model, int command_id, cef_event_flags_t event_flags) override; private: // |delegate| is guaranteed to outlive this object. // |browser_view| may be nullptr, in which case SetBrowserView() will be // called. ViewsWindow(WindowType type, Delegate* delegate, CefRefPtr browser_view, CefRefPtr command_line); void SetBrowserView(CefRefPtr browser_view); // Create controls. void CreateMenuModel(); CefRefPtr CreateBrowseButton(const std::string& label, int id); CefRefPtr CreateMenuButton(); CefRefPtr CreateLocationBar(); // Add the BrowserView to the Window. void AddBrowserView(); // Add other controls to the Window. void AddControls(); // Add keyboard accelerators to the Window. void AddAccelerators(); // Control whether the top menu butons are focusable. void SetMenuFocusable(bool focusable); // Update the toolbar button state. void UpdateToolbarButtonState(); // Show/hide top controls on the Window. void ShowTopControls(bool show); void NudgeWindow(); const WindowType type_; Delegate* delegate_; // Not owned by this object. const bool use_alloy_style_; bool use_alloy_style_window_; CefRefPtr browser_view_; CefRefPtr command_line_; bool frameless_; bool with_controls_; bool with_overlay_controls_; bool with_standard_buttons_; ChromeToolbarType chrome_toolbar_type_; bool use_window_modal_dialog_; bool use_bottom_controls_; bool hide_pip_frame_; bool accepts_first_mouse_; CefRefPtr window_; CefRefPtr button_menu_model_; CefRefPtr menu_bar_; CefRefPtr toolbar_; CefRefPtr menu_button_; CefRefPtr location_bar_; bool menu_has_focus_ = false; int last_focused_view_ = false; std::optional last_visible_bounds_; CefSize minimum_window_size_; CefRefPtr overlay_controls_; std::optional default_titlebar_height_; std::optional override_titlebar_height_; #if defined(OS_MAC) bool hide_on_close_ = false; bool hide_after_fullscreen_exit_ = false; #endif // Current loading state. bool is_loading_ = false; bool can_go_back_ = false; bool can_go_forward_ = false; IMPLEMENT_REFCOUNTING(ViewsWindow); DISALLOW_COPY_AND_ASSIGN(ViewsWindow); }; } // namespace client #endif // CEF_TESTS_CEFCLIENT_BROWSER_VIEWS_WINDOW_H_