electron/patches/chromium/refactor_expose_cursor_chan...

96 lines
4.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Andy Locascio <andy@slack-corp.com>
Date: Wed, 13 May 2020 14:54:39 -0700
Subject: refactor: expose cursor changes to the WebContentsObserver
Chrome moved the SetCursor IPC message to mojo, which we use to tell OSR about `cursor-changed`.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2172779
diff --git a/content/browser/renderer_host/render_widget_host_delegate.h b/content/browser/renderer_host/render_widget_host_delegate.h
index a3f999654e191d925936c6dd9f041340c1d5cd30..db8a4efd188509f126962e240e9bc1f356962533 100644
--- a/content/browser/renderer_host/render_widget_host_delegate.h
+++ b/content/browser/renderer_host/render_widget_host_delegate.h
@@ -24,6 +24,7 @@
#include "third_party/blink/public/mojom/input/input_handler.mojom-shared.h"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
#include "ui/base/ui_base_types.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/gfx/native_widget_types.h"
namespace blink {
@@ -271,6 +272,9 @@ class CONTENT_EXPORT RenderWidgetHostDelegate {
// Returns the associated RenderViewHostDelegateView*, if possible.
virtual RenderViewHostDelegateView* GetDelegateView();
+ // Notify the delegate of the RenderWidget's changing cursor.
+ virtual void OnCursorChanged(const ui::Cursor& cursor) {}
+
// Returns true if the provided RenderWidgetHostImpl matches the current
// RenderWidgetHost on the primary main frame, and false otherwise.
virtual bool IsWidgetForPrimaryMainFrame(RenderWidgetHostImpl*);
diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc
index d067f0ba15c1898707bd039c19996c8850c7aa72..6801f228e67d7931919b7eb32f20a933a673ed8b 100644
--- a/content/browser/renderer_host/render_widget_host_impl.cc
+++ b/content/browser/renderer_host/render_widget_host_impl.cc
@@ -2038,6 +2038,9 @@ void RenderWidgetHostImpl::SetCursor(const ui::Cursor& cursor) {
if (view_) {
view_->UpdateCursor(cursor);
}
+ if (delegate_) {
+ delegate_->OnCursorChanged(cursor);
+ }
}
void RenderWidgetHostImpl::ShowContextMenuAtPoint(
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index ab6a5a975cc9b88ea9ea48d213d5fc49a4efe6a9..330d6900e5e43a22ce554f7ceaa61d986a3c001e 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -5296,6 +5296,11 @@ TextInputManager* WebContentsImpl::GetTextInputManager() {
return text_input_manager_.get();
}
+void WebContentsImpl::OnCursorChanged(const ui::Cursor& cursor) {
+ observers_.NotifyObservers(&WebContentsObserver::OnCursorChanged,
+ cursor);
+}
+
bool WebContentsImpl::IsWidgetForPrimaryMainFrame(
RenderWidgetHostImpl* render_widget_host) {
return render_widget_host == GetPrimaryMainFrame()->GetRenderWidgetHost();
diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h
index 6e8e83088b54ffe6c509faaca1fd61b16cb5874e..cf64872c2070ef511c8b06f2884fb7866061fa8e 100644
--- a/content/browser/web_contents/web_contents_impl.h
+++ b/content/browser/web_contents/web_contents_impl.h
@@ -1056,6 +1056,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
void SendScreenRects() override;
void SendActiveState(bool active) override;
TextInputManager* GetTextInputManager() override;
+ void OnCursorChanged(const ui::Cursor& cursor) override;
bool IsWidgetForPrimaryMainFrame(
RenderWidgetHostImpl* render_widget_host) override;
bool IsShowingContextMenuOnPage() const override;
diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h
index f21a4be4f0c3dec07c33549f34002188f715ad4e..f0c2a990a0580c33f24f7918293e88f7cf2e0d86 100644
--- a/content/public/browser/web_contents_observer.h
+++ b/content/public/browser/web_contents_observer.h
@@ -33,6 +33,7 @@
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-forward.h"
#include "third_party/blink/public/mojom/media/capture_handle_config.mojom-forward.h"
#include "third_party/skia/include/core/SkColor.h"
+#include "ui/base/cursor/cursor.h"
#include "ui/base/page_transition_types.h"
#include "ui/base/window_open_disposition.h"
@@ -584,6 +585,9 @@ class CONTENT_EXPORT WebContentsObserver : public base::CheckedObserver {
// Invoked when the primary main frame changes size.
virtual void PrimaryMainFrameWasResized(bool width_changed) {}
+ // Invoked every time the RenderWidget's cursor changes.
+ virtual void OnCursorChanged(const ui::Cursor& cursor) {}
+
// Invoked when the given frame changes its window.name property.
virtual void FrameNameChanged(RenderFrameHost* render_frame_host,
const std::string& name) {}