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.
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/views/window_impl.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
#include "base/i18n/rtl.h"
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-07-02 20:16:55 +02:00
|
|
|
#include "cef/libcef/browser/browser_event_util.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
|
|
|
#include "cef/libcef/browser/views/browser_view_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/display_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/fill_layout_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/layout_util.h"
|
|
|
|
#include "cef/libcef/browser/views/view_util.h"
|
|
|
|
#include "cef/libcef/browser/views/widget.h"
|
|
|
|
#include "cef/libcef/browser/views/window_view.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "components/constrained_window/constrained_window_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/base/test/ui_controls.h"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "ui/compositor/compositor.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2019-07-16 19:59:21 +02:00
|
|
|
#include "ui/views/controls/button/menu_button.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/views/controls/menu/menu_runner.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "ui/views/controls/webview/webview.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#if defined(USE_AURA)
|
2017-02-17 00:19:43 +01:00
|
|
|
#include "ui/aura/window.h"
|
2021-10-19 00:17:16 +02:00
|
|
|
#endif // defined(USE_AURA)
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-05-30 10:55:32 +02:00
|
|
|
#include "ui/aura/test/ui_controls_aurawin.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "ui/display/win/screen_win.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Based on chrome/test/base/interactive_ui_tests_main.cc.
|
|
|
|
void InitializeUITesting() {
|
|
|
|
static bool initialized = false;
|
|
|
|
if (!initialized) {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-05-30 10:55:32 +02:00
|
|
|
aura::test::EnableUIControlsAuraWin();
|
|
|
|
#else
|
2023-02-27 19:52:38 +01:00
|
|
|
ui_controls::EnableUIControls();
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
initialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
|
|
|
|
// This class forwards KeyEvents to the CefWindowImpl associated with a widget.
|
|
|
|
// This allows KeyEvents to be processed after all other targets.
|
|
|
|
// Events originating from CefBrowserView will instead be delivered via
|
|
|
|
// CefBrowserViewImpl::HandleKeyboardEvent.
|
|
|
|
class CefUnhandledKeyEventHandler : public ui::EventHandler {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
CefUnhandledKeyEventHandler(CefWindowImpl* window_impl, views::Widget* widget)
|
|
|
|
: window_impl_(window_impl),
|
|
|
|
widget_(widget),
|
|
|
|
window_(widget->GetNativeWindow()) {
|
2017-02-17 00:19:43 +01:00
|
|
|
DCHECK(window_);
|
|
|
|
window_->AddPostTargetHandler(this);
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CefUnhandledKeyEventHandler(const CefUnhandledKeyEventHandler&) = delete;
|
|
|
|
CefUnhandledKeyEventHandler& operator=(const CefUnhandledKeyEventHandler&) =
|
|
|
|
delete;
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
~CefUnhandledKeyEventHandler() override {
|
|
|
|
window_->RemovePostTargetHandler(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implementation of ui::EventHandler:
|
|
|
|
void OnKeyEvent(ui::KeyEvent* event) override {
|
|
|
|
// Give the FocusManager a chance to handle accelerators first.
|
|
|
|
// Widget::OnKeyEvent would normally call this after all EventHandlers have
|
|
|
|
// had a shot but we don't want to wait.
|
|
|
|
if (widget_->GetFocusManager() &&
|
|
|
|
!widget_->GetFocusManager()->OnKeyEvent(*event)) {
|
|
|
|
event->StopPropagation();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefKeyEvent cef_event;
|
2024-07-02 20:16:55 +02:00
|
|
|
if (GetCefKeyEvent(*event, cef_event) &&
|
2017-02-17 00:19:43 +01:00
|
|
|
window_impl_->OnKeyEvent(cef_event)) {
|
|
|
|
event->StopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Members are guaranteed to outlive this object.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefWindowImpl> window_impl_;
|
|
|
|
raw_ptr<views::Widget> widget_;
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
// |window_| is the event target that is associated with this class.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<aura::Window> window_;
|
2017-02-17 00:19:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // defined(USE_AURA)
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefWindow> CefWindow::CreateTopLevelWindow(
|
|
|
|
CefRefPtr<CefWindowDelegate> delegate) {
|
2022-04-08 22:48:56 +02:00
|
|
|
return CefWindowImpl::Create(delegate, gfx::kNullAcceleratedWidget);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefWindowImpl> CefWindowImpl::Create(
|
2022-04-08 22:48:56 +02:00
|
|
|
CefRefPtr<CefWindowDelegate> delegate,
|
|
|
|
gfx::AcceleratedWidget parent_widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UIT_RETURN(nullptr);
|
|
|
|
CefRefPtr<CefWindowImpl> window = new CefWindowImpl(delegate);
|
|
|
|
window->Initialize();
|
2022-04-08 22:48:56 +02:00
|
|
|
window->CreateWidget(parent_widget);
|
2016-01-19 21:09:01 +01:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Show() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2023-06-14 10:20:02 +02:00
|
|
|
shown_as_browser_modal_ = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Show();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
void CefWindowImpl::ShowAsBrowserModalDialog(
|
|
|
|
CefRefPtr<CefBrowserView> browser_view) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (widget_) {
|
|
|
|
auto* browser_view_impl =
|
|
|
|
static_cast<CefBrowserViewImpl*>(browser_view.get());
|
|
|
|
|
|
|
|
// |browser_view| must belong to the host widget.
|
2024-01-12 00:32:08 +01:00
|
|
|
auto* host_widget = cef_window_view()->host_widget();
|
2023-06-14 10:20:02 +02:00
|
|
|
CHECK(host_widget &&
|
|
|
|
browser_view_impl->root_view()->GetWidget() == host_widget);
|
|
|
|
|
|
|
|
if (auto web_view = browser_view_impl->web_view()) {
|
|
|
|
if (auto web_contents = web_view->web_contents()) {
|
|
|
|
shown_as_browser_modal_ = true;
|
|
|
|
constrained_window::ShowModalDialog(widget_->GetNativeWindow(),
|
|
|
|
web_contents);
|
|
|
|
|
|
|
|
// NativeWebContentsModalDialogManagerViews::ManageDialog() disables
|
|
|
|
// movement. That has no impact on native frames but interferes with
|
|
|
|
// draggable regions.
|
|
|
|
widget_->set_movement_disabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowImpl::Hide() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Hide();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::CenterWindow(const CefSize& size) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->CenterWindow(gfx::Size(size.width, size.height));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Close() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && !widget_->IsClosed()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Close();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsClosed() {
|
|
|
|
CEF_REQUIRE_UIT_RETURN(false);
|
|
|
|
return destroyed_ || (widget_ && widget_->IsClosed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Activate() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && widget_->CanActivate() && !widget_->IsActive()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Activate();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Deactivate() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && widget_->CanActivate() && widget_->IsActive()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Deactivate();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsActive() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget_->IsActive();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::BringToTop() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->StackAtTop();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetAlwaysOnTop(bool on_top) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2019-09-04 17:13:32 +02:00
|
|
|
if (widget_ && on_top != (widget_->GetZOrderLevel() ==
|
|
|
|
ui::ZOrderLevel::kFloatingWindow)) {
|
|
|
|
widget_->SetZOrderLevel(on_top ? ui::ZOrderLevel::kFloatingWindow
|
|
|
|
: ui::ZOrderLevel::kNormal);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsAlwaysOnTop() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2019-09-04 17:13:32 +02:00
|
|
|
return widget_->GetZOrderLevel() == ui::ZOrderLevel::kFloatingWindow;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Maximize() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && !widget_->IsMaximized()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Maximize();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Minimize() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && !widget_->IsMinimized()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Minimize();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Restore() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && (widget_->IsMaximized() || widget_->IsMinimized())) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->Restore();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetFullscreen(bool fullscreen) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && fullscreen != widget_->IsFullscreen()) {
|
2024-03-29 17:48:33 +01:00
|
|
|
if (CefWidget::GetForWidget(widget_)->ToggleFullscreenMode()) {
|
|
|
|
// Received special handling.
|
|
|
|
return;
|
2023-09-25 21:40:17 +02:00
|
|
|
}
|
|
|
|
|
2024-06-26 02:12:37 +02:00
|
|
|
// Call the Widget method directly with Alloy style, or Chrome style
|
2023-09-25 21:40:17 +02:00
|
|
|
// when no BrowserView exists.
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->SetFullscreen(fullscreen);
|
2023-09-25 21:40:17 +02:00
|
|
|
|
2024-06-26 02:12:37 +02:00
|
|
|
// Use a synchronous callback notification on Windows/Linux. Chrome style
|
2023-09-25 21:40:17 +02:00
|
|
|
// on Windows/Linux gets notified synchronously via ChromeBrowserDelegate
|
2024-06-26 02:12:37 +02:00
|
|
|
// callbacks when a BrowserView exists. MacOS (both runtime styles) gets
|
|
|
|
// notified asynchronously via CefNativeWidgetMac callbacks.
|
2023-09-25 21:40:17 +02:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
|
|
|
if (delegate()) {
|
|
|
|
delegate()->OnWindowFullscreenTransition(this, /*is_completed=*/true);
|
|
|
|
}
|
|
|
|
#endif
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsMaximized() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget_->IsMaximized();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsMinimized() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget_->IsMinimized();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsFullscreen() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget_->IsFullscreen();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-11-05 20:58:45 +01:00
|
|
|
CefRefPtr<CefView> CefWindowImpl::GetFocusedView() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
if (widget_ && widget_->GetFocusManager()) {
|
|
|
|
if (auto* focused_view = widget_->GetFocusManager()->GetFocusedView()) {
|
|
|
|
return view_util::GetFor(focused_view, /*find_known_parent=*/true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowImpl::SetTitle(const CefString& title) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
root_view()->SetTitle(title);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefWindowImpl::GetTitle() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(CefString());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return root_view()->title();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return CefString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetWindowIcon(CefRefPtr<CefImage> image) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
root_view()->SetWindowIcon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefImage> CefWindowImpl::GetWindowIcon() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return root_view()->window_icon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetWindowAppIcon(CefRefPtr<CefImage> image) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
root_view()->SetWindowAppIcon(image);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefImage> CefWindowImpl::GetWindowAppIcon() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return root_view()->window_app_icon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefOverlayController> CefWindowImpl::AddOverlayView(
|
|
|
|
CefRefPtr<CefView> view,
|
2023-10-25 11:16:57 +02:00
|
|
|
cef_docking_mode_t docking_mode,
|
|
|
|
bool can_activate) {
|
2021-08-28 03:55:15 +02:00
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2023-10-25 11:16:57 +02:00
|
|
|
return root_view()->AddOverlayView(view, docking_mode, can_activate);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2023-01-30 22:42:40 +01:00
|
|
|
void CefWindowImpl::GetDebugInfo(base::Value::Dict* info,
|
2016-01-19 21:09:01 +01:00
|
|
|
bool include_children) {
|
|
|
|
ParentClass::GetDebugInfo(info, include_children);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2023-01-30 22:42:40 +01:00
|
|
|
info->Set("title", root_view()->title());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::ShowMenu(CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
cef_menu_anchor_position_t anchor_position) {
|
|
|
|
ShowMenu(nullptr, menu_model, screen_point, anchor_position);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::Detach() {
|
|
|
|
// OnDeleteDelegate should always be called before Detach().
|
|
|
|
DCHECK(!widget_);
|
|
|
|
|
|
|
|
ParentClass::Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetBounds(const CefRect& bounds) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (widget_) {
|
|
|
|
widget_->SetBounds(
|
|
|
|
gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRect CefWindowImpl::GetBounds() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(CefRect());
|
|
|
|
gfx::Rect bounds;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
bounds = widget_->GetWindowBoundsInScreen();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return CefRect(bounds.x(), bounds.y(), bounds.width(), bounds.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRect CefWindowImpl::GetBoundsInScreen() {
|
|
|
|
return GetBounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetSize(const CefSize& size) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->SetSize(gfx::Size(size.width, size.height));
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetPosition(const CefPoint& position) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (widget_) {
|
|
|
|
gfx::Rect bounds = widget_->GetWindowBoundsInScreen();
|
|
|
|
bounds.set_origin(gfx::Point(position.x, position.y));
|
|
|
|
widget_->SetBounds(bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SizeToPreferredSize() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (widget_) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_->non_client_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->SetSize(widget_->non_client_view()->GetPreferredSize());
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->SetSize(root_view()->GetPreferredSize());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetVisible(bool visible) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (visible) {
|
2016-01-19 21:09:01 +01:00
|
|
|
Show();
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2016-01-19 21:09:01 +01:00
|
|
|
Hide();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsVisible() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget_->IsVisible();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::IsDrawn() {
|
|
|
|
return IsVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetBackgroundColor(cef_color_t color) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
ParentClass::SetBackgroundColor(color);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_ && widget_->GetCompositor()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_->GetCompositor()->SetBackgroundColor(color);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::CanWidgetClose() {
|
2023-06-14 10:20:02 +02:00
|
|
|
if (shown_as_browser_modal_) {
|
|
|
|
// Always allow the close for browser modal dialogs to avoid an infinite
|
|
|
|
// loop in WebContentsModalDialogManager::CloseAllDialogs().
|
|
|
|
return true;
|
|
|
|
}
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return delegate()->CanClose(this);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void CefWindowImpl::OnWindowClosing() {
|
|
|
|
#if defined(USE_AURA)
|
|
|
|
unhandled_key_event_handler_.reset();
|
|
|
|
#endif
|
2022-10-28 20:17:18 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate()) {
|
2022-10-28 20:17:18 +02:00
|
|
|
delegate()->OnWindowClosing(this);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowImpl::OnWindowViewDeleted() {
|
|
|
|
CancelMenu();
|
|
|
|
|
|
|
|
destroyed_ = true;
|
|
|
|
widget_ = nullptr;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
delegate()->OnWindowDestroyed(this);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Call Detach() here instead of waiting for the root View to be deleted so
|
|
|
|
// that any following attempts to call CefWindow methods from the delegate
|
|
|
|
// will fail.
|
|
|
|
Detach();
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Will only be called if CanHandleAccelerators() returns true.
|
|
|
|
bool CefWindowImpl::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
|
|
|
for (const auto& entry : accelerator_map_) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (entry.second == accelerator) {
|
2017-02-17 00:19:43 +01:00
|
|
|
return delegate()->OnAccelerator(this, entry.first);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::CanHandleAccelerators() const {
|
2024-11-04 20:17:30 +01:00
|
|
|
if (delegate() && widget_ && root_view()) {
|
|
|
|
return root_view()->CanHandleAccelerators();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowImpl::OnKeyEvent(const CefKeyEvent& event) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (delegate()) {
|
2017-02-17 00:19:43 +01:00
|
|
|
return delegate()->OnKeyEvent(this, event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowImpl::ShowMenu(views::MenuButton* menu_button,
|
|
|
|
CefRefPtr<CefMenuModel> menu_model,
|
|
|
|
const CefPoint& screen_point,
|
|
|
|
cef_menu_anchor_position_t anchor_position) {
|
|
|
|
CancelMenu();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!widget_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefMenuModelImpl* menu_model_impl =
|
|
|
|
static_cast<CefMenuModelImpl*>(menu_model.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!menu_model_impl || !menu_model_impl->model()) {
|
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
|
|
|
|
|
|
|
menu_model_ = menu_model_impl;
|
2017-02-22 19:05:27 +01:00
|
|
|
|
|
|
|
// We'll send the MenuClosed notification manually for better accuracy.
|
|
|
|
menu_model_->set_auto_notify_menu_closed(false);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
menu_runner_ = std::make_unique<views::MenuRunner>(
|
2021-06-04 03:34:56 +02:00
|
|
|
menu_model_impl->model(),
|
|
|
|
menu_button ? views::MenuRunner::HAS_MNEMONICS
|
|
|
|
: views::MenuRunner::CONTEXT_MENU,
|
2024-01-20 23:48:57 +01:00
|
|
|
base::BindRepeating(&CefWindowImpl::MenuClosed, this));
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2017-05-31 17:33:30 +02:00
|
|
|
menu_runner_->RunMenuAt(
|
2019-07-20 00:16:59 +02:00
|
|
|
widget_, menu_button ? menu_button->button_controller() : nullptr,
|
2016-01-19 21:09:01 +01:00
|
|
|
gfx::Rect(gfx::Point(screen_point.x, screen_point.y), gfx::Size()),
|
|
|
|
static_cast<views::MenuAnchorPosition>(anchor_position),
|
|
|
|
ui::MENU_SOURCE_NONE);
|
|
|
|
}
|
|
|
|
|
2017-02-22 19:05:27 +01:00
|
|
|
void CefWindowImpl::MenuClosed() {
|
|
|
|
menu_model_->NotifyMenuClosed();
|
|
|
|
menu_model_ = nullptr;
|
|
|
|
menu_runner_.reset(nullptr);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowImpl::CancelMenu() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (menu_runner_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
menu_runner_->Cancel();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(!menu_model_);
|
|
|
|
DCHECK(!menu_runner_);
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefDisplay> CefWindowImpl::GetDisplay() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(nullptr);
|
|
|
|
if (widget_ && root_view()) {
|
2016-05-25 01:35:43 +02:00
|
|
|
const display::Display& display = root_view()->GetDisplay();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (display.is_valid()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return new CefDisplayImpl(display);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRect CefWindowImpl::GetClientAreaBoundsInScreen() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(CefRect());
|
|
|
|
if (widget_) {
|
|
|
|
gfx::Rect bounds = widget_->GetClientAreaBoundsInScreen();
|
|
|
|
|
|
|
|
views::NonClientFrameView* non_client_frame_view =
|
|
|
|
root_view()->GetNonClientFrameView();
|
|
|
|
if (non_client_frame_view) {
|
|
|
|
// When using a custom drawn NonClientFrameView the native Window will not
|
|
|
|
// know the actual client bounds. Adjust the native Window bounds for the
|
|
|
|
// reported client bounds.
|
|
|
|
const gfx::Rect& client_bounds =
|
|
|
|
non_client_frame_view->GetBoundsForClientView();
|
|
|
|
bounds.set_origin(bounds.origin() + client_bounds.OffsetFromOrigin());
|
|
|
|
bounds.set_size(client_bounds.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
return CefRect(bounds.x(), bounds.y(), bounds.width(), bounds.height());
|
|
|
|
}
|
|
|
|
return CefRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
root_view()->SetDraggableRegions(regions);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowHandle CefWindowImpl::GetWindowHandle() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(kNullWindowHandle);
|
|
|
|
return view_util::GetWindowHandle(widget_);
|
|
|
|
}
|
|
|
|
|
2023-06-01 16:06:15 +02:00
|
|
|
void CefWindowImpl::SendKeyPress(int key_code, uint32_t event_flags) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
InitializeUITesting();
|
|
|
|
|
|
|
|
gfx::NativeWindow native_window = view_util::GetNativeWindow(widget_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!native_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
|
|
|
|
|
|
|
ui_controls::SendKeyPress(native_window,
|
|
|
|
static_cast<ui::KeyboardCode>(key_code),
|
|
|
|
!!(event_flags & EVENTFLAG_CONTROL_DOWN),
|
|
|
|
!!(event_flags & EVENTFLAG_SHIFT_DOWN),
|
|
|
|
!!(event_flags & EVENTFLAG_ALT_DOWN),
|
|
|
|
false); // Command key is not supported by Aura.
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SendMouseMove(int screen_x, int screen_y) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
InitializeUITesting();
|
|
|
|
|
2022-07-27 19:57:53 +02:00
|
|
|
// Converts to pixel coordinates internally on Windows.
|
2016-01-19 21:09:01 +01:00
|
|
|
gfx::Point point(screen_x, screen_y);
|
|
|
|
ui_controls::SendMouseMove(point.x(), point.y());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::SendMouseEvents(cef_mouse_button_type_t button,
|
|
|
|
bool mouse_down,
|
|
|
|
bool mouse_up) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!mouse_down && !mouse_up) {
|
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
|
|
|
|
|
|
|
InitializeUITesting();
|
|
|
|
|
|
|
|
ui_controls::MouseButton type = ui_controls::LEFT;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (button == MBT_MIDDLE) {
|
2016-01-19 21:09:01 +01:00
|
|
|
type = ui_controls::MIDDLE;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (button == MBT_RIGHT) {
|
2016-01-19 21:09:01 +01:00
|
|
|
type = ui_controls::RIGHT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
int state = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mouse_down) {
|
2016-01-19 21:09:01 +01:00
|
|
|
state |= ui_controls::DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (mouse_up) {
|
2016-01-19 21:09:01 +01:00
|
|
|
state |= ui_controls::UP;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
ui_controls::SendMouseEvents(type, state);
|
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void CefWindowImpl::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) {
|
2017-02-17 00:19:43 +01:00
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!widget_) {
|
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
|
|
|
|
|
|
|
AcceleratorMap::const_iterator it = accelerator_map_.find(command_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it != accelerator_map_.end()) {
|
2017-02-17 00:19:43 +01:00
|
|
|
RemoveAccelerator(command_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
int modifiers = 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (shift_pressed) {
|
2017-02-17 00:19:43 +01:00
|
|
|
modifiers |= ui::EF_SHIFT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (ctrl_pressed) {
|
2017-02-17 00:19:43 +01:00
|
|
|
modifiers |= ui::EF_CONTROL_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (alt_pressed) {
|
2017-02-17 00:19:43 +01:00
|
|
|
modifiers |= ui::EF_ALT_DOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-02-17 00:19:43 +01:00
|
|
|
ui::Accelerator accelerator(static_cast<ui::KeyboardCode>(key_code),
|
|
|
|
modifiers);
|
|
|
|
|
|
|
|
accelerator_map_.insert(std::make_pair(command_id, accelerator));
|
|
|
|
|
|
|
|
views::FocusManager* focus_manager = widget_->GetFocusManager();
|
|
|
|
DCHECK(focus_manager);
|
|
|
|
focus_manager->RegisterAccelerator(
|
2023-11-08 20:27:50 +01:00
|
|
|
accelerator,
|
|
|
|
high_priority ? ui::AcceleratorManager::kHighPriority
|
|
|
|
: ui::AcceleratorManager::kNormalPriority,
|
|
|
|
this);
|
2017-02-17 00:19:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::RemoveAccelerator(int command_id) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!widget_) {
|
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
|
|
|
|
|
|
|
AcceleratorMap::iterator it = accelerator_map_.find(command_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (it == accelerator_map_.end()) {
|
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
|
|
|
|
|
|
|
ui::Accelerator accelerator = it->second;
|
|
|
|
|
|
|
|
accelerator_map_.erase(it);
|
|
|
|
|
|
|
|
views::FocusManager* focus_manager = widget_->GetFocusManager();
|
|
|
|
DCHECK(focus_manager);
|
|
|
|
focus_manager->UnregisterAccelerator(accelerator, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::RemoveAllAccelerators() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!widget_) {
|
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
|
|
|
|
|
|
|
accelerator_map_.clear();
|
|
|
|
|
|
|
|
views::FocusManager* focus_manager = widget_->GetFocusManager();
|
|
|
|
DCHECK(focus_manager);
|
|
|
|
focus_manager->UnregisterAccelerators(this);
|
|
|
|
}
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
void CefWindowImpl::SetThemeColor(int color_id, cef_color_t color) {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (root_view()) {
|
|
|
|
view_util::SetColor(root_view(), color_id, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowImpl::ThemeChanged() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN_VOID();
|
|
|
|
if (widget_) {
|
|
|
|
widget_->ThemeChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
cef_runtime_style_t CefWindowImpl::GetRuntimeStyle() {
|
|
|
|
CEF_REQUIRE_VALID_RETURN(CEF_RUNTIME_STYLE_DEFAULT);
|
|
|
|
if (auto* window_view = cef_window_view()) {
|
|
|
|
return window_view->IsAlloyStyle() ? CEF_RUNTIME_STYLE_ALLOY
|
|
|
|
: CEF_RUNTIME_STYLE_CHROME;
|
|
|
|
}
|
|
|
|
return CEF_RUNTIME_STYLE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
CefWindowView* CefWindowImpl::cef_window_view() const {
|
|
|
|
return static_cast<CefWindowView*>(root_view());
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefWindowImpl::CefWindowImpl(CefRefPtr<CefWindowDelegate> delegate)
|
2023-09-25 21:40:17 +02:00
|
|
|
: ParentClass(delegate) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CefWindowView* CefWindowImpl::CreateRootView() {
|
|
|
|
return new CefWindowView(delegate(), this);
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
void CefWindowImpl::InitializeRootView() {
|
2024-01-12 00:32:08 +01:00
|
|
|
cef_window_view()->Initialize();
|
2016-07-21 23:21:32 +02:00
|
|
|
}
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
void CefWindowImpl::CreateWidget(gfx::AcceleratedWidget parent_widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(!widget_);
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
root_view()->CreateWidget(parent_widget);
|
2016-01-19 21:09:01 +01:00
|
|
|
widget_ = root_view()->GetWidget();
|
|
|
|
DCHECK(widget_);
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
unhandled_key_event_handler_ =
|
2018-03-20 21:15:08 +01:00
|
|
|
std::make_unique<CefUnhandledKeyEventHandler>(this, widget_);
|
2017-02-17 00:19:43 +01:00
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// The Widget and root View are owned by the native window. Therefore don't
|
|
|
|
// keep an owned reference.
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<views::View> view_ptr = view_util::PassOwnership(this);
|
2022-02-21 23:23:40 +01:00
|
|
|
[[maybe_unused]] views::View* view = view_ptr.release();
|
2023-09-25 21:40:17 +02:00
|
|
|
|
|
|
|
initialized_ = true;
|
|
|
|
|
|
|
|
if (delegate()) {
|
|
|
|
delegate()->OnWindowCreated(this);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|