mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Support JavaScript window.moveTo/By() and resizeTo/By() (fixes #698)
Adds new CefDisplayHandler::OnContentsBoundsChange and CefDisplayHandler::GetRootWindowScreenRect callbacks. cefclient: Implement the above callbacks and call CefBrowserHost::NotifyScreenInfoChanged when the root window bounds change. cefclient: osr: Use real screen bounds by default. Pass `--fake-screen-bounds` for the old default behavior. Load https://tests/window in cefclient for additional implementation details and usage examples.
This commit is contained in:
@ -5,6 +5,7 @@
|
||||
#include "cef/libcef/browser/native/browser_platform_delegate_native.h"
|
||||
|
||||
#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
#include "content/public/browser/render_widget_host.h"
|
||||
#include "third_party/blink/public/common/input/web_mouse_event.h"
|
||||
@ -24,3 +25,25 @@ void CefBrowserPlatformDelegateNative::WasResized() {
|
||||
host->GetWidget()->SynchronizeVisualProperties();
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateNative::NotifyScreenInfoChanged() {
|
||||
content::RenderWidgetHostImpl* render_widget_host = nullptr;
|
||||
if (web_contents_) {
|
||||
if (auto* rvh = web_contents_->GetRenderViewHost()) {
|
||||
render_widget_host =
|
||||
content::RenderWidgetHostImpl::From(rvh->GetWidget());
|
||||
}
|
||||
}
|
||||
if (!render_widget_host) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send updated screen bounds information to the renderer process.
|
||||
if (render_widget_host->delegate()) {
|
||||
render_widget_host->delegate()->SendScreenRects();
|
||||
} else {
|
||||
render_widget_host->SendScreenRects();
|
||||
}
|
||||
|
||||
render_widget_host->NotifyScreenInfoChanged();
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class CefBrowserPlatformDelegateNative
|
||||
// CefBrowserPlatformDelegate methods:
|
||||
SkColor GetBackgroundColor() const override;
|
||||
void WasResized() override;
|
||||
void NotifyScreenInfoChanged() override;
|
||||
|
||||
// Translate CEF events to Chromium/Blink Web events.
|
||||
virtual input::NativeWebKeyboardEvent TranslateWebKeyEvent(
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "cef/libcef/browser/native/browser_platform_delegate_native_aura.h"
|
||||
|
||||
#include "cef/libcef/browser/browser_host_base.h"
|
||||
#include "cef/libcef/browser/native/menu_runner_views_aura.h"
|
||||
#include "cef/libcef/browser/views/view_util.h"
|
||||
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
|
||||
@ -19,6 +20,42 @@ CefBrowserPlatformDelegateNativeAura::CefBrowserPlatformDelegateNativeAura(
|
||||
SkColor background_color)
|
||||
: CefBrowserPlatformDelegateNative(window_info, background_color) {}
|
||||
|
||||
void CefBrowserPlatformDelegateNativeAura::InstallRootWindowBoundsCallback() {
|
||||
auto* host_view = GetHostView();
|
||||
CHECK(host_view);
|
||||
|
||||
host_view->SetRootWindowBoundsCallback(base::BindRepeating(
|
||||
[](base::WeakPtr<CefBrowserPlatformDelegateNativeAura> self) {
|
||||
return self->RootWindowBoundsCallback();
|
||||
},
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
}
|
||||
|
||||
std::optional<gfx::Rect>
|
||||
CefBrowserPlatformDelegateNativeAura::RootWindowBoundsCallback() {
|
||||
if (browser_) {
|
||||
if (auto client = browser_->client()) {
|
||||
if (auto handler = client->GetDisplayHandler()) {
|
||||
CefRect rect;
|
||||
if (handler->GetRootWindowScreenRect(browser_.get(), rect) &&
|
||||
!rect.IsEmpty()) {
|
||||
return gfx::Rect(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call the default platform implementation, if any.
|
||||
return GetRootWindowBounds();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateNativeAura::RenderViewReady() {
|
||||
CefBrowserPlatformDelegateNative::RenderViewReady();
|
||||
|
||||
// The RWHV should now exist for Alloy style browsers.
|
||||
InstallRootWindowBoundsCallback();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateNativeAura::SendKeyEvent(
|
||||
const CefKeyEvent& event) {
|
||||
auto view = GetHostView();
|
||||
|
@ -5,19 +5,19 @@
|
||||
#ifndef CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_AURA_H_
|
||||
#define CEF_LIBCEF_BROWSER_NATIVE_BROWSER_PLATFORM_DELEGATE_NATIVE_AURA_H_
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "cef/libcef/browser/native/browser_platform_delegate_native.h"
|
||||
#include "ui/events/event.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
#include "ui/gfx/geometry/vector2d.h"
|
||||
|
||||
namespace content {
|
||||
class RenderWidgetHostViewAura;
|
||||
}
|
||||
|
||||
namespace gfx {
|
||||
class Vector2d;
|
||||
}
|
||||
|
||||
// Windowed browser implementation for Aura platforms.
|
||||
class CefBrowserPlatformDelegateNativeAura
|
||||
: public CefBrowserPlatformDelegateNative {
|
||||
@ -25,7 +25,10 @@ class CefBrowserPlatformDelegateNativeAura
|
||||
CefBrowserPlatformDelegateNativeAura(const CefWindowInfo& window_info,
|
||||
SkColor background_color);
|
||||
|
||||
void InstallRootWindowBoundsCallback();
|
||||
|
||||
// CefBrowserPlatformDelegate methods:
|
||||
void RenderViewReady() override;
|
||||
void SendKeyEvent(const CefKeyEvent& event) override;
|
||||
void SendMouseClickEvent(const CefMouseEvent& event,
|
||||
CefBrowserHost::MouseButtonType type,
|
||||
@ -71,9 +74,16 @@ class CefBrowserPlatformDelegateNativeAura
|
||||
int deltaY) const;
|
||||
virtual gfx::Vector2d GetUiWheelEventOffset(int deltaX, int deltaY) const;
|
||||
|
||||
// Returns the root window bounds in screen DIP coordinates.
|
||||
virtual std::optional<gfx::Rect> GetRootWindowBounds() {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
protected:
|
||||
base::OnceClosure GetWidgetDeleteCallback();
|
||||
|
||||
std::optional<gfx::Rect> RootWindowBoundsCallback();
|
||||
|
||||
static base::TimeTicks GetEventTimeStamp();
|
||||
static int TranslateUiEventModifiers(uint32_t cef_modifiers);
|
||||
static int TranslateUiChangedButtonFlags(uint32_t cef_modifiers);
|
||||
|
@ -427,6 +427,27 @@ CefEventHandle CefBrowserPlatformDelegateNativeWin::GetEventHandle(
|
||||
const_cast<CHROME_MSG*>(&event.os_event->native_event()));
|
||||
}
|
||||
|
||||
std::optional<gfx::Rect>
|
||||
CefBrowserPlatformDelegateNativeWin::GetRootWindowBounds() {
|
||||
if (window_widget_) {
|
||||
if (HWND hwnd = GetHostWindowHandle()) {
|
||||
if (HWND root_hwnd = ::GetAncestor(hwnd, GA_ROOT)) {
|
||||
RECT root_rect = {};
|
||||
if (::GetWindowRect(root_hwnd, &root_rect)) {
|
||||
auto* top_level =
|
||||
window_widget_->GetNativeWindow()->GetToplevelWindow();
|
||||
gfx::Rect bounds(root_rect);
|
||||
bounds = display::Screen::GetScreen()->ScreenToDIPRectInWindow(
|
||||
top_level, bounds);
|
||||
return bounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
ui::KeyEvent CefBrowserPlatformDelegateNativeWin::TranslateUiKeyEvent(
|
||||
const CefKeyEvent& key_event) const {
|
||||
int flags = TranslateUiEventModifiers(key_event.modifiers);
|
||||
@ -596,8 +617,8 @@ LRESULT CALLBACK CefBrowserPlatformDelegateNativeWin::WndProc(HWND hwnd,
|
||||
|
||||
case WM_MOVING:
|
||||
case WM_MOVE:
|
||||
if (browser) {
|
||||
browser->NotifyMoveOrResizeStarted();
|
||||
if (platform_delegate) {
|
||||
platform_delegate->NotifyMoveOrResizeStarted();
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
@ -32,6 +32,7 @@ class CefBrowserPlatformDelegateNativeWin
|
||||
bool HandleKeyboardEvent(const input::NativeWebKeyboardEvent& event) override;
|
||||
CefEventHandle GetEventHandle(
|
||||
const input::NativeWebKeyboardEvent& event) const override;
|
||||
std::optional<gfx::Rect> GetRootWindowBounds() override;
|
||||
|
||||
// CefBrowserPlatformDelegateNativeAura methods:
|
||||
ui::KeyEvent TranslateUiKeyEvent(const CefKeyEvent& key_event) const override;
|
||||
|
Reference in New Issue
Block a user