2020-09-25 03:40:47 +02:00
|
|
|
// Copyright 2020 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/chrome/browser_platform_delegate_chrome.h"
|
2022-04-19 19:45:03 +02:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/views/view_util.h"
|
2022-10-12 23:53:06 +02:00
|
|
|
#include "chrome/browser/profiles/profile.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "chrome/browser/ui/browser.h"
|
|
|
|
#include "chrome/browser/ui/browser_window.h"
|
2022-06-02 11:49:50 +02:00
|
|
|
#include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
|
2022-10-12 23:53:06 +02:00
|
|
|
#include "chrome/common/pref_names.h"
|
2022-05-13 13:38:41 +02:00
|
|
|
#include "ui/display/display.h"
|
2020-09-25 03:40:47 +02:00
|
|
|
#include "ui/display/screen.h"
|
|
|
|
#include "ui/gfx/geometry/point.h"
|
|
|
|
|
|
|
|
CefBrowserPlatformDelegateChrome::CefBrowserPlatformDelegateChrome(
|
|
|
|
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
|
|
|
|
: native_delegate_(std::move(native_delegate)) {
|
|
|
|
native_delegate_->set_windowless_handler(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::WebContentsCreated(
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
bool owned) {
|
|
|
|
CefBrowserPlatformDelegate::WebContentsCreated(web_contents, owned);
|
|
|
|
native_delegate_->WebContentsCreated(web_contents, /*owned=*/false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::WebContentsDestroyed(
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
CefBrowserPlatformDelegate::WebContentsDestroyed(web_contents);
|
|
|
|
native_delegate_->WebContentsDestroyed(web_contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::BrowserCreated(
|
|
|
|
CefBrowserHostBase* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserCreated(browser);
|
|
|
|
native_delegate_->BrowserCreated(browser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::BrowserDestroyed(
|
|
|
|
CefBrowserHostBase* browser) {
|
|
|
|
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
|
|
|
native_delegate_->BrowserDestroyed(browser);
|
|
|
|
}
|
|
|
|
|
2022-04-19 19:45:03 +02:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateChrome::GetHostWindowHandle() const {
|
|
|
|
return view_util::GetWindowHandle(GetNativeWindow());
|
|
|
|
}
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
web_modal::WebContentsModalDialogHost*
|
|
|
|
CefBrowserPlatformDelegateChrome::GetWebContentsModalDialogHost() const {
|
|
|
|
if (chrome_browser_) {
|
|
|
|
ChromeWebModalDialogManagerDelegate* manager = chrome_browser_;
|
|
|
|
return manager->GetWebContentsModalDialogHost();
|
|
|
|
}
|
2023-05-08 17:07:57 +02:00
|
|
|
DCHECK(false);
|
2022-06-02 11:49:50 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
SkColor CefBrowserPlatformDelegateChrome::GetBackgroundColor() const {
|
|
|
|
return native_delegate_->GetBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::SendKeyEvent(const CefKeyEvent& event) {
|
|
|
|
native_delegate_->SendKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::SendMouseClickEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
CefBrowserHost::MouseButtonType type,
|
|
|
|
bool mouseUp,
|
|
|
|
int clickCount) {
|
|
|
|
native_delegate_->SendMouseClickEvent(event, type, mouseUp, clickCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::SendMouseMoveEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
bool mouseLeave) {
|
|
|
|
native_delegate_->SendMouseMoveEvent(event, mouseLeave);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::SendMouseWheelEvent(
|
|
|
|
const CefMouseEvent& event,
|
|
|
|
int deltaX,
|
|
|
|
int deltaY) {
|
|
|
|
native_delegate_->SendMouseWheelEvent(event, deltaX, deltaY);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateChrome::GetScreenPoint(
|
2022-05-13 13:38:41 +02:00
|
|
|
const gfx::Point& view,
|
|
|
|
bool want_dip_coords) const {
|
2020-09-25 03:40:47 +02:00
|
|
|
auto screen = display::Screen::GetScreen();
|
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
// Get device (pixel) coordinates.
|
2020-09-25 03:40:47 +02:00
|
|
|
auto screen_rect = screen->DIPToScreenRectInWindow(
|
2022-04-19 19:45:03 +02:00
|
|
|
GetNativeWindow(), gfx::Rect(view, gfx::Size(0, 0)));
|
2022-05-13 13:38:41 +02:00
|
|
|
auto screen_point = screen_rect.origin();
|
|
|
|
|
|
|
|
if (want_dip_coords) {
|
|
|
|
// Convert to DIP coordinates.
|
|
|
|
const auto& display = view_util::GetDisplayNearestPoint(
|
|
|
|
screen_point, /*input_pixel_coords=*/true);
|
|
|
|
view_util::ConvertPointFromPixels(&screen_point,
|
|
|
|
display.device_scale_factor());
|
|
|
|
}
|
|
|
|
|
|
|
|
return screen_point;
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::ViewText(const std::string& text) {
|
|
|
|
native_delegate_->ViewText(text);
|
|
|
|
}
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
CefEventHandle CefBrowserPlatformDelegateChrome::GetEventHandle(
|
2024-06-14 19:01:45 +02:00
|
|
|
const input::NativeWebKeyboardEvent& event) const {
|
2021-02-18 02:58:25 +01:00
|
|
|
return native_delegate_->GetEventHandle(event);
|
|
|
|
}
|
|
|
|
|
2020-09-25 03:40:47 +02:00
|
|
|
CefWindowHandle CefBrowserPlatformDelegateChrome::GetParentWindowHandle()
|
|
|
|
const {
|
|
|
|
return GetHostWindowHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Point CefBrowserPlatformDelegateChrome::GetParentScreenPoint(
|
2022-05-13 13:38:41 +02:00
|
|
|
const gfx::Point& view,
|
|
|
|
bool want_dip_coords) const {
|
|
|
|
return GetScreenPoint(view, want_dip_coords);
|
2020-09-25 03:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefBrowserPlatformDelegateChrome::set_chrome_browser(Browser* browser) {
|
|
|
|
chrome_browser_ = browser;
|
|
|
|
}
|
2022-04-19 19:45:03 +02:00
|
|
|
|
|
|
|
gfx::NativeWindow CefBrowserPlatformDelegateChrome::GetNativeWindow() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (chrome_browser_ && chrome_browser_->window()) {
|
2022-04-19 19:45:03 +02:00
|
|
|
return chrome_browser_->window()->GetNativeWindow();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2024-04-17 18:01:26 +02:00
|
|
|
if (web_contents_) {
|
|
|
|
return web_contents_->GetTopLevelNativeWindow();
|
|
|
|
}
|
|
|
|
NOTIMPLEMENTED();
|
2022-04-19 19:45:03 +02:00
|
|
|
return gfx::NativeWindow();
|
|
|
|
}
|