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/browser_platform_delegate_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/browser_view_impl.h"
|
|
|
|
#include "cef/libcef/browser/views/menu_runner_views.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "content/public/browser/render_view_host.h"
|
|
|
|
#include "content/public/browser/render_widget_host.h"
|
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
|
|
|
|
CefBrowserPlatformDelegateViews::CefBrowserPlatformDelegateViews(
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefBrowserViewImpl> browser_view)
|
2019-07-17 20:47:27 +02:00
|
|
|
: native_delegate_(std::move(native_delegate)) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_view) {
|
2019-07-17 20:47:27 +02:00
|
|
|
SetBrowserView(browser_view);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
native_delegate_->set_windowless_handler(this);
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
void CefBrowserPlatformDelegateViews::SetBrowserView(
|
2024-04-17 18:01:26 +02:00
|
|
|
CefRefPtr<CefBrowserView> browser_view) {
|
2019-07-17 20:47:27 +02:00
|
|
|
DCHECK(!browser_view_);
|
|
|
|
DCHECK(browser_view);
|
2024-10-12 20:52:17 +02:00
|
|
|
browser_view_ =
|
|
|
|
static_cast<CefBrowserViewImpl*>(browser_view.get())->GetWeakPtr();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::WebContentsCreated(
|
2020-07-03 22:13:27 +02:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
bool owned) {
|
2020-07-04 20:21:34 +02:00
|
|
|
CefBrowserPlatformDelegateAlloy::WebContentsCreated(web_contents, owned);
|
2020-09-15 17:03:38 +02:00
|
|
|
native_delegate_->WebContentsCreated(web_contents, /*owned=*/false);
|
2016-01-19 21:09:01 +01:00
|
|
|
browser_view_->WebContentsCreated(web_contents);
|
|
|
|
}
|
|
|
|
|
2020-09-15 17:03:38 +02:00
|
|
|
void CefBrowserPlatformDelegateViews::WebContentsDestroyed(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
CefBrowserPlatformDelegateAlloy::WebContentsDestroyed(web_contents);
|
2024-10-12 20:52:17 +02:00
|
|
|
// |browser_view_| may be destroyed before this callback arrives.
|
|
|
|
if (browser_view_) {
|
|
|
|
browser_view_->WebContentsDestroyed(web_contents);
|
|
|
|
}
|
2020-09-15 17:03:38 +02:00
|
|
|
native_delegate_->WebContentsDestroyed(web_contents);
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefBrowserPlatformDelegateViews::BrowserCreated(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase* browser) {
|
2020-07-04 20:21:34 +02:00
|
|
|
CefBrowserPlatformDelegateAlloy::BrowserCreated(browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2020-09-15 17:03:38 +02:00
|
|
|
native_delegate_->BrowserCreated(browser);
|
2019-07-17 20:47:27 +02:00
|
|
|
browser_view_->BrowserCreated(browser, GetBoundsChangedCallback());
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::NotifyBrowserCreated() {
|
|
|
|
DCHECK(browser_view_);
|
|
|
|
DCHECK(browser_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_view_->delegate()) {
|
2024-10-12 20:52:17 +02:00
|
|
|
browser_view_->delegate()->OnBrowserCreated(browser_view_.get(),
|
|
|
|
browser_.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::NotifyBrowserDestroyed() {
|
|
|
|
DCHECK(browser_);
|
2024-10-12 20:52:17 +02:00
|
|
|
// |browser_view_| may be destroyed before this callback arrives.
|
|
|
|
if (browser_view_ && browser_view_->delegate()) {
|
|
|
|
browser_view_->delegate()->OnBrowserDestroyed(browser_view_.get(),
|
2024-05-11 17:48:38 +02:00
|
|
|
browser_.get());
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::BrowserDestroyed(
|
2020-09-25 03:40:47 +02:00
|
|
|
CefBrowserHostBase* browser) {
|
2020-07-04 20:21:34 +02:00
|
|
|
CefBrowserPlatformDelegateAlloy::BrowserDestroyed(browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-10-12 20:52:17 +02:00
|
|
|
// |browser_view_| may be destroyed before this callback arrives.
|
|
|
|
if (browser_view_) {
|
|
|
|
browser_view_->BrowserDestroyed(browser);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
browser_view_ = nullptr;
|
2020-09-15 17:03:38 +02:00
|
|
|
native_delegate_->BrowserDestroyed(browser);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateViews::CreateHostWindow() {
|
|
|
|
// Nothing to do here.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::CloseHostWindow() {
|
|
|
|
views::Widget* widget = GetWindowWidget();
|
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
|
|
|
}
|
|
|
|
|
|
|
|
CefWindowHandle CefBrowserPlatformDelegateViews::GetHostWindowHandle() const {
|
|
|
|
return view_util::GetWindowHandle(GetWindowWidget());
|
|
|
|
}
|
|
|
|
|
|
|
|
views::Widget* CefBrowserPlatformDelegateViews::GetWindowWidget() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_view_->root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return browser_view_->root_view()->GetWidget();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefRefPtr<CefBrowserView> CefBrowserPlatformDelegateViews::GetBrowserView()
|
|
|
|
const {
|
2016-01-19 21:09:01 +01:00
|
|
|
return browser_view_.get();
|
|
|
|
}
|
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
SkColor CefBrowserPlatformDelegateViews::GetBackgroundColor() const {
|
|
|
|
return native_delegate_->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
2020-01-31 23:54:26 +01:00
|
|
|
void CefBrowserPlatformDelegateViews::WasResized() {
|
|
|
|
native_delegate_->WasResized();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
void CefBrowserPlatformDelegateViews::SendKeyEvent(const CefKeyEvent& event) {
|
|
|
|
native_delegate_->SendKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::SendMouseClickEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) {
|
|
|
|
native_delegate_->SendMouseClickEvent(event, type, mouseUp, clickCount);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2020-01-23 22:58:01 +01:00
|
|
|
void CefBrowserPlatformDelegateViews::SendMouseMoveEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
bool mouseLeave) {
|
|
|
|
native_delegate_->SendMouseMoveEvent(event, mouseLeave);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::SendMouseWheelEvent(
|
2020-01-23 22:58:01 +01:00
|
|
|
const CefMouseEvent& event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) {
|
|
|
|
native_delegate_->SendMouseWheelEvent(event, deltaX, deltaY);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
void CefBrowserPlatformDelegateViews::SendTouchEvent(
|
2020-01-23 22:58:01 +01:00
|
|
|
const CefTouchEvent& event) {
|
|
|
|
native_delegate_->SendTouchEvent(event);
|
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
|
2021-09-27 09:50:07 +02:00
|
|
|
void CefBrowserPlatformDelegateViews::SetFocus(bool setFocus) {
|
2024-11-05 20:58:45 +01:00
|
|
|
if (setFocus && browser_view_) {
|
|
|
|
browser_view_->RequestFocusSync();
|
2021-09-07 16:04:55 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateViews::GetScreenPoint(
|
2022-05-13 13:38:41 +02:00
|
|
|
const gfx::Point& view_pt,
|
|
|
|
bool want_dip_coords) const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_view_->root_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return view_pt;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
gfx::Point screen_point = view_pt;
|
|
|
|
view_util::ConvertPointToScreen(browser_view_->root_view(), &screen_point,
|
2022-05-13 13:38:41 +02:00
|
|
|
/*output_pixel_coords=*/!want_dip_coords);
|
2016-01-19 21:09:01 +01:00
|
|
|
return screen_point;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateViews::ViewText(const std::string& text) {
|
|
|
|
native_delegate_->ViewText(text);
|
|
|
|
}
|
|
|
|
|
2018-11-03 02:15:09 +01:00
|
|
|
bool CefBrowserPlatformDelegateViews::HandleKeyboardEvent(
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) {
|
2017-02-17 00:19:43 +01:00
|
|
|
// The BrowserView will handle accelerators.
|
2018-11-03 02:15:09 +01:00
|
|
|
return browser_view_->HandleKeyboardEvent(event);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefEventHandle CefBrowserPlatformDelegateViews::GetEventHandle(
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) const {
|
2016-01-19 21:09:01 +01:00
|
|
|
return native_delegate_->GetEventHandle(event);
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
std::unique_ptr<CefMenuRunner>
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserPlatformDelegateViews::CreateMenuRunner() {
|
2016-05-25 01:35:43 +02:00
|
|
|
return base::WrapUnique(new CefMenuRunnerViews(browser_view_.get()));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CefBrowserPlatformDelegateViews::IsViewsHosted() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-17 20:47:27 +02:00
|
|
|
gfx::Point CefBrowserPlatformDelegateViews::GetDialogPosition(
|
|
|
|
const gfx::Size& size) {
|
|
|
|
const gfx::Rect& bounds = browser_view_->root_view()->GetBoundsInScreen();
|
|
|
|
|
|
|
|
// Offset relative to the top-level content view.
|
|
|
|
gfx::Point offset = bounds.origin();
|
|
|
|
view_util::ConvertPointFromScreen(
|
|
|
|
browser_view_->root_view()->GetWidget()->GetRootView(), &offset, false);
|
|
|
|
|
|
|
|
return gfx::Point(offset.x() + (bounds.width() - size.width()) / 2,
|
|
|
|
offset.y() + (bounds.height() - size.height()) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size CefBrowserPlatformDelegateViews::GetMaximumDialogSize() {
|
|
|
|
return browser_view_->root_view()->GetBoundsInScreen().size();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateViews::GetParentWindowHandle() const {
|
|
|
|
return GetHostWindowHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateViews::GetParentScreenPoint(
|
2022-05-13 13:38:41 +02:00
|
|
|
const gfx::Point& view,
|
|
|
|
bool want_dip_coords) const {
|
|
|
|
return GetScreenPoint(view, want_dip_coords);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|