mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-29 18:49:52 +01:00
chrome: Implement GetWindowHandle() for --multi-threaded-message-loop (see issue #3294)
This commit is contained in:
parent
2ea7459a89
commit
c04895b222
@ -4,6 +4,8 @@
|
||||
|
||||
#include "libcef/browser/chrome/browser_platform_delegate_chrome.h"
|
||||
|
||||
#include "libcef/browser/views/view_util.h"
|
||||
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "ui/display/screen.h"
|
||||
@ -40,6 +42,10 @@ void CefBrowserPlatformDelegateChrome::BrowserDestroyed(
|
||||
native_delegate_->BrowserDestroyed(browser);
|
||||
}
|
||||
|
||||
CefWindowHandle CefBrowserPlatformDelegateChrome::GetHostWindowHandle() const {
|
||||
return view_util::GetWindowHandle(GetNativeWindow());
|
||||
}
|
||||
|
||||
SkColor CefBrowserPlatformDelegateChrome::GetBackgroundColor() const {
|
||||
return native_delegate_->GetBackgroundColor();
|
||||
}
|
||||
@ -73,12 +79,9 @@ gfx::Point CefBrowserPlatformDelegateChrome::GetScreenPoint(
|
||||
const gfx::Point& view) const {
|
||||
auto screen = display::Screen::GetScreen();
|
||||
|
||||
gfx::NativeWindow native_window =
|
||||
chrome_browser_ ? chrome_browser_->window()->GetNativeWindow() : nullptr;
|
||||
|
||||
// Returns screen pixel coordinates.
|
||||
auto screen_rect = screen->DIPToScreenRectInWindow(
|
||||
native_window, gfx::Rect(view, gfx::Size(0, 0)));
|
||||
GetNativeWindow(), gfx::Rect(view, gfx::Size(0, 0)));
|
||||
return screen_rect.origin();
|
||||
}
|
||||
|
||||
@ -104,3 +107,9 @@ gfx::Point CefBrowserPlatformDelegateChrome::GetParentScreenPoint(
|
||||
void CefBrowserPlatformDelegateChrome::set_chrome_browser(Browser* browser) {
|
||||
chrome_browser_ = browser;
|
||||
}
|
||||
|
||||
gfx::NativeWindow CefBrowserPlatformDelegateChrome::GetNativeWindow() const {
|
||||
if (chrome_browser_ && chrome_browser_->window())
|
||||
return chrome_browser_->window()->GetNativeWindow();
|
||||
return gfx::NativeWindow();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ class CefBrowserPlatformDelegateChrome
|
||||
void WebContentsDestroyed(content::WebContents* web_contents) override;
|
||||
void BrowserCreated(CefBrowserHostBase* browser) override;
|
||||
void BrowserDestroyed(CefBrowserHostBase* browser) override;
|
||||
CefWindowHandle GetHostWindowHandle() const override;
|
||||
SkColor GetBackgroundColor() const override;
|
||||
void SendKeyEvent(const CefKeyEvent& event) override;
|
||||
void SendMouseClickEvent(const CefMouseEvent& event,
|
||||
@ -50,6 +51,8 @@ class CefBrowserPlatformDelegateChrome
|
||||
}
|
||||
|
||||
protected:
|
||||
gfx::NativeWindow GetNativeWindow() const;
|
||||
|
||||
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate_;
|
||||
|
||||
Browser* chrome_browser_ = nullptr;
|
||||
|
@ -168,8 +168,7 @@ CefWindowHandle ChromeBrowserHostImpl::GetWindowHandle() {
|
||||
if (platform_delegate_)
|
||||
return platform_delegate_->GetHostWindowHandle();
|
||||
}
|
||||
NOTIMPLEMENTED();
|
||||
return kNullWindowHandle;
|
||||
return host_window_handle_;
|
||||
}
|
||||
|
||||
CefWindowHandle ChromeBrowserHostImpl::GetOpenerWindowHandle() {
|
||||
@ -524,6 +523,8 @@ void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
|
||||
browser_ = browser;
|
||||
static_cast<CefBrowserPlatformDelegateChrome*>(platform_delegate_.get())
|
||||
->set_chrome_browser(browser);
|
||||
if (browser_)
|
||||
host_window_handle_ = platform_delegate_->GetHostWindowHandle();
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::WindowDestroyed() {
|
||||
|
@ -159,6 +159,7 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase {
|
||||
int GetCurrentTabIndex() const;
|
||||
|
||||
Browser* browser_ = nullptr;
|
||||
CefWindowHandle host_window_handle_ = kNullWindowHandle;
|
||||
};
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_CHROME_CHROME_BROWSER_HOST_IMPL_H_
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "include/views/cef_view.h"
|
||||
#include "include/views/cef_window.h"
|
||||
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace display {
|
||||
@ -123,6 +124,9 @@ gfx::NativeView GetNativeView(views::Widget* widget);
|
||||
// Returns the platform window handle for |widget|. May return nullptr.
|
||||
CefWindowHandle GetWindowHandle(views::Widget* widget);
|
||||
|
||||
// Returns the platform window handle for |window|. May return nullptr.
|
||||
CefWindowHandle GetWindowHandle(gfx::NativeWindow window);
|
||||
|
||||
} // namespace view_util
|
||||
|
||||
#endif // CEF_LIBCEF_BROWSER_VIEWS_VIEW_UTIL_H_
|
||||
|
@ -26,9 +26,15 @@ gfx::NativeView GetNativeView(views::Widget* widget) {
|
||||
CefWindowHandle GetWindowHandle(views::Widget* widget) {
|
||||
// Same implementation as views::HWNDForView() but cross-platform.
|
||||
if (widget) {
|
||||
aura::Window* window = widget->GetNativeWindow();
|
||||
if (window && window->GetRootWindow())
|
||||
return window->GetHost()->GetAcceleratedWidget();
|
||||
return GetWindowHandle(widget->GetNativeWindow());
|
||||
}
|
||||
return kNullWindowHandle;
|
||||
}
|
||||
|
||||
CefWindowHandle GetWindowHandle(gfx::NativeWindow window) {
|
||||
// |window| is an aura::Window*.
|
||||
if (window && window->GetRootWindow()) {
|
||||
return window->GetHost()->GetAcceleratedWidget();
|
||||
}
|
||||
return kNullWindowHandle;
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "libcef/browser/views/view_util.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "include/internal/cef_types_mac.h"
|
||||
|
||||
#include "ui/views/widget/widget.h"
|
||||
@ -23,10 +25,20 @@ gfx::NativeView GetNativeView(views::Widget* widget) {
|
||||
}
|
||||
|
||||
CefWindowHandle GetWindowHandle(views::Widget* widget) {
|
||||
// |view| is a wrapper type from native_widget_types.h.
|
||||
auto view = GetNativeView(widget);
|
||||
if (view)
|
||||
return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE(view.GetNativeNSView());
|
||||
return kNullWindowHandle;
|
||||
}
|
||||
|
||||
CefWindowHandle GetWindowHandle(gfx::NativeWindow window) {
|
||||
// |window| is a wrapper type from native_widget_types.h.
|
||||
if (window) {
|
||||
NSWindow* nswindow = window.GetNativeNSWindow();
|
||||
return CAST_NSVIEW_TO_CEF_WINDOW_HANDLE([nswindow contentView]);
|
||||
}
|
||||
return kNullWindowHandle;
|
||||
}
|
||||
|
||||
} // namespace view_util
|
||||
|
Loading…
x
Reference in New Issue
Block a user