2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 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_LIBCEF_BROWSER_VIEWS_WINDOW_IMPL_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_WINDOW_IMPL_H_
|
|
|
|
#pragma once
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
#include <map>
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/views/cef_window.h"
|
|
|
|
#include "cef/include/views/cef_window_delegate.h"
|
|
|
|
#include "cef/libcef/browser/menu_model_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/panel_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/window_view.h"
|
2017-02-17 00:19:43 +01:00
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/views/controls/menu/menu_runner.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
|
|
|
namespace views {
|
|
|
|
class MenuButton;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class CefWindowImpl
|
|
|
|
: public CefPanelImpl<CefWindowView, CefWindow, CefWindowDelegate>,
|
|
|
|
public CefWindowView::Delegate,
|
|
|
|
public ui::AcceleratorTarget {
|
2016-01-19 21:09:01 +01:00
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
using ParentClass = CefPanelImpl<CefWindowView, CefWindow, CefWindowDelegate>;
|
|
|
|
|
|
|
|
CefWindowImpl(const CefWindowImpl&) = delete;
|
|
|
|
CefWindowImpl& operator=(const CefWindowImpl&) = delete;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
// Create a new CefWindow instance. |delegate| may be nullptr. |parent_widget|
|
|
|
|
// will be used when creating a Chrome child window.
|
|
|
|
static CefRefPtr<CefWindowImpl> Create(CefRefPtr<CefWindowDelegate> delegate,
|
|
|
|
gfx::AcceleratedWidget parent_widget);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefWindow methods:
|
|
|
|
void Show() override;
|
2023-06-14 10:20:02 +02:00
|
|
|
void ShowAsBrowserModalDialog(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void Hide() override;
|
|
|
|
void CenterWindow(const CefSize& size) override;
|
|
|
|
void Close() override;
|
|
|
|
bool IsClosed() override;
|
|
|
|
void Activate() override;
|
|
|
|
void Deactivate() override;
|
|
|
|
bool IsActive() override;
|
|
|
|
void BringToTop() override;
|
|
|
|
void SetAlwaysOnTop(bool on_top) override;
|
|
|
|
bool IsAlwaysOnTop() override;
|
|
|
|
void Maximize() override;
|
|
|
|
void Minimize() override;
|
|
|
|
void Restore() override;
|
|
|
|
void SetFullscreen(bool fullscreen) override;
|
|
|
|
bool IsMaximized() override;
|
|
|
|
bool IsMinimized() override;
|
|
|
|
bool IsFullscreen() override;
|
2024-11-05 20:58:45 +01:00
|
|
|
CefRefPtr<CefView> GetFocusedView() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void SetTitle(const CefString& title) override;
|
|
|
|
CefString GetTitle() override;
|
|
|
|
void SetWindowIcon(CefRefPtr<CefImage> image) override;
|
|
|
|
CefRefPtr<CefImage> GetWindowIcon() override;
|
|
|
|
void SetWindowAppIcon(CefRefPtr<CefImage> image) override;
|
|
|
|
CefRefPtr<CefImage> GetWindowAppIcon() override;
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefOverlayController> AddOverlayView(
|
|
|
|
CefRefPtr<CefView> view,
|
2023-10-25 11:16:57 +02:00
|
|
|
cef_docking_mode_t docking_mode,
|
|
|
|
bool can_activate) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void ShowMenu(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
cef_menu_anchor_position_t anchor_position) override;
|
|
|
|
void CancelMenu() override;
|
|
|
|
CefRefPtr<CefDisplay> GetDisplay() override;
|
|
|
|
CefRect GetClientAreaBoundsInScreen() override;
|
|
|
|
void SetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) override;
|
|
|
|
CefWindowHandle GetWindowHandle() override;
|
2023-06-01 16:06:15 +02:00
|
|
|
void SendKeyPress(int key_code, uint32_t event_flags) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void SendMouseMove(int screen_x, int screen_y) override;
|
|
|
|
void SendMouseEvents(cef_mouse_button_type_t button,
|
|
|
|
bool mouse_down,
|
|
|
|
bool mouse_up) override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void SetAccelerator(int command_id,
|
|
|
|
int key_code,
|
|
|
|
bool shift_pressed,
|
|
|
|
bool ctrl_pressed,
|
2023-11-08 20:27:50 +01:00
|
|
|
bool alt_pressed,
|
|
|
|
bool high_priority) override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void RemoveAccelerator(int command_id) override;
|
|
|
|
void RemoveAllAccelerators() override;
|
2024-03-29 17:48:33 +01:00
|
|
|
void SetThemeColor(int color_id, cef_color_t color) override;
|
|
|
|
void ThemeChanged() override;
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t GetRuntimeStyle() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefViewAdapter methods:
|
|
|
|
void Detach() override;
|
|
|
|
|
|
|
|
// CefPanel methods:
|
|
|
|
CefRefPtr<CefWindow> AsWindow() override { return this; }
|
|
|
|
|
|
|
|
// CefView methods:
|
|
|
|
void SetBounds(const CefRect& bounds) override;
|
|
|
|
CefRect GetBounds() override;
|
|
|
|
CefRect GetBoundsInScreen() override;
|
|
|
|
void SetSize(const CefSize& bounds) override;
|
|
|
|
void SetPosition(const CefPoint& position) override;
|
|
|
|
void SizeToPreferredSize() override;
|
|
|
|
void SetVisible(bool visible) override;
|
|
|
|
bool IsVisible() override;
|
|
|
|
bool IsDrawn() override;
|
|
|
|
void SetBackgroundColor(cef_color_t color) override;
|
|
|
|
|
|
|
|
// CefWindowView::Delegate methods:
|
|
|
|
bool CanWidgetClose() override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void OnWindowClosing() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
void OnWindowViewDeleted() override;
|
|
|
|
|
|
|
|
// CefViewAdapter methods:
|
|
|
|
std::string GetDebugType() override { return "Window"; }
|
2023-01-30 22:42:40 +01:00
|
|
|
void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// ui::AcceleratorTarget methods:
|
|
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
|
|
|
bool CanHandleAccelerators() const override;
|
|
|
|
|
|
|
|
// Called for key events that have not been handled by other controls in the
|
|
|
|
// window. Returns true if the event was handled.
|
|
|
|
bool OnKeyEvent(const CefKeyEvent& event);
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void ShowMenu(views::MenuButton* menu_button,
|
|
|
|
CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
cef_menu_anchor_position_t anchor_position);
|
2017-02-22 19:05:27 +01:00
|
|
|
void MenuClosed();
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
CefWindowView* cef_window_view() const;
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
views::Widget* widget() const { return widget_; }
|
2023-09-25 21:40:17 +02:00
|
|
|
bool initialized() const { return initialized_; }
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
|
|
|
// Create a new implementation object.
|
|
|
|
// Always call Initialize() after creation.
|
|
|
|
// |delegate| may be nullptr.
|
|
|
|
explicit CefWindowImpl(CefRefPtr<CefWindowDelegate> delegate);
|
|
|
|
|
|
|
|
// CefViewImpl methods:
|
|
|
|
CefWindowView* CreateRootView() override;
|
2016-07-21 23:21:32 +02:00
|
|
|
void InitializeRootView() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Initialize the Widget.
|
2022-04-08 22:48:56 +02:00
|
|
|
void CreateWidget(gfx::AcceleratedWidget parent_widget);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<views::Widget> widget_ = nullptr;
|
2023-09-25 21:40:17 +02:00
|
|
|
|
|
|
|
// True if the window has been initialized.
|
|
|
|
bool initialized_ = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// True if the window has been destroyed.
|
2023-09-25 21:40:17 +02:00
|
|
|
bool destroyed_ = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// The currently active menu model and runner.
|
|
|
|
CefRefPtr<CefMenuModelImpl> menu_model_;
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<views::MenuRunner> menu_runner_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Map of command_id to accelerator.
|
2021-12-06 21:40:25 +01:00
|
|
|
using AcceleratorMap = std::map<int, ui::Accelerator>;
|
2017-02-17 00:19:43 +01:00
|
|
|
AcceleratorMap accelerator_map_;
|
|
|
|
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
// Native widget's handler to receive events after the event target.
|
|
|
|
std::unique_ptr<ui::EventHandler> unhandled_key_event_handler_;
|
|
|
|
#endif
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
// True if this window was shown using ShowAsBrowserModalDialog().
|
|
|
|
bool shown_as_browser_modal_ = false;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefWindowImpl);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_WINDOW_IMPL_H_
|