1 // Copyright 2020 The Chromium Embedded Framework Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
6
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #include "ui/display/screen.h"
10 #include "ui/gfx/geometry/point.h"
11
CefBrowserPlatformDelegateChrome(std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)12 CefBrowserPlatformDelegateChrome::CefBrowserPlatformDelegateChrome(
13 std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate)
14 : native_delegate_(std::move(native_delegate)) {
15 native_delegate_->set_windowless_handler(this);
16 }
17
WebContentsCreated(content::WebContents * web_contents,bool owned)18 void CefBrowserPlatformDelegateChrome::WebContentsCreated(
19 content::WebContents* web_contents,
20 bool owned) {
21 CefBrowserPlatformDelegate::WebContentsCreated(web_contents, owned);
22 native_delegate_->WebContentsCreated(web_contents, /*owned=*/false);
23 }
24
WebContentsDestroyed(content::WebContents * web_contents)25 void CefBrowserPlatformDelegateChrome::WebContentsDestroyed(
26 content::WebContents* web_contents) {
27 CefBrowserPlatformDelegate::WebContentsDestroyed(web_contents);
28 native_delegate_->WebContentsDestroyed(web_contents);
29 }
30
BrowserCreated(CefBrowserHostBase * browser)31 void CefBrowserPlatformDelegateChrome::BrowserCreated(
32 CefBrowserHostBase* browser) {
33 CefBrowserPlatformDelegate::BrowserCreated(browser);
34 native_delegate_->BrowserCreated(browser);
35 }
36
BrowserDestroyed(CefBrowserHostBase * browser)37 void CefBrowserPlatformDelegateChrome::BrowserDestroyed(
38 CefBrowserHostBase* browser) {
39 CefBrowserPlatformDelegate::BrowserDestroyed(browser);
40 native_delegate_->BrowserDestroyed(browser);
41 }
42
GetBackgroundColor() const43 SkColor CefBrowserPlatformDelegateChrome::GetBackgroundColor() const {
44 return native_delegate_->GetBackgroundColor();
45 }
46
SendKeyEvent(const CefKeyEvent & event)47 void CefBrowserPlatformDelegateChrome::SendKeyEvent(const CefKeyEvent& event) {
48 native_delegate_->SendKeyEvent(event);
49 }
50
SendMouseClickEvent(const CefMouseEvent & event,CefBrowserHost::MouseButtonType type,bool mouseUp,int clickCount)51 void CefBrowserPlatformDelegateChrome::SendMouseClickEvent(
52 const CefMouseEvent& event,
53 CefBrowserHost::MouseButtonType type,
54 bool mouseUp,
55 int clickCount) {
56 native_delegate_->SendMouseClickEvent(event, type, mouseUp, clickCount);
57 }
58
SendMouseMoveEvent(const CefMouseEvent & event,bool mouseLeave)59 void CefBrowserPlatformDelegateChrome::SendMouseMoveEvent(
60 const CefMouseEvent& event,
61 bool mouseLeave) {
62 native_delegate_->SendMouseMoveEvent(event, mouseLeave);
63 }
64
SendMouseWheelEvent(const CefMouseEvent & event,int deltaX,int deltaY)65 void CefBrowserPlatformDelegateChrome::SendMouseWheelEvent(
66 const CefMouseEvent& event,
67 int deltaX,
68 int deltaY) {
69 native_delegate_->SendMouseWheelEvent(event, deltaX, deltaY);
70 }
71
GetScreenPoint(const gfx::Point & view) const72 gfx::Point CefBrowserPlatformDelegateChrome::GetScreenPoint(
73 const gfx::Point& view) const {
74 auto screen = display::Screen::GetScreen();
75
76 gfx::NativeWindow native_window =
77 chrome_browser_ ? chrome_browser_->window()->GetNativeWindow() : nullptr;
78
79 // Returns screen pixel coordinates.
80 auto screen_rect = screen->DIPToScreenRectInWindow(
81 native_window, gfx::Rect(view, gfx::Size(0, 0)));
82 return screen_rect.origin();
83 }
84
ViewText(const std::string & text)85 void CefBrowserPlatformDelegateChrome::ViewText(const std::string& text) {
86 native_delegate_->ViewText(text);
87 }
88
GetEventHandle(const content::NativeWebKeyboardEvent & event) const89 CefEventHandle CefBrowserPlatformDelegateChrome::GetEventHandle(
90 const content::NativeWebKeyboardEvent& event) const {
91 return native_delegate_->GetEventHandle(event);
92 }
93
GetParentWindowHandle() const94 CefWindowHandle CefBrowserPlatformDelegateChrome::GetParentWindowHandle()
95 const {
96 return GetHostWindowHandle();
97 }
98
GetParentScreenPoint(const gfx::Point & view) const99 gfx::Point CefBrowserPlatformDelegateChrome::GetParentScreenPoint(
100 const gfx::Point& view) const {
101 return GetScreenPoint(view);
102 }
103
set_chrome_browser(Browser * browser)104 void CefBrowserPlatformDelegateChrome::set_chrome_browser(Browser* browser) {
105 chrome_browser_ = browser;
106 }
107