From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Andy Locascio 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 f3875c216b5f4169a3beb9ae3aeb73c9f4df23f1..5e471024655e1b9ee224ed8ba7fc416e8be10aaa 100644 --- a/content/browser/renderer_host/render_widget_host_delegate.h +++ b/content/browser/renderer_host/render_widget_host_delegate.h @@ -14,6 +14,7 @@ #include "build/build_config.h" #include "components/viz/common/vertical_scroll_direction.h" #include "content/common/content_export.h" +#include "content/common/cursors/webcursor.h" #include "content/public/common/drop_data.h" #include "services/metrics/public/cpp/ukm_recorder.h" #include "third_party/blink/public/common/input/web_input_event.h" @@ -266,6 +267,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 WebCursor& cursor) {} + // Returns true if the provided RenderWidgetHostImpl matches the current // RenderWidgetHost on the main frame, and false otherwise. virtual bool IsWidgetForMainFrame(RenderWidgetHostImpl*); diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index 3122722665f1e2e4796e9628486c8bea8fdf283e..a5d58e950b91431639fb14b0e6a9bd430759bd00 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -1912,6 +1912,8 @@ void RenderWidgetHostImpl::FilterDropData(DropData* drop_data) { void RenderWidgetHostImpl::SetCursor(const ui::Cursor& cursor) { if (view_) view_->UpdateCursor(WebCursor(cursor)); + if (delegate_) + delegate_->OnCursorChanged(WebCursor(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 bc54b385d792eaad00c13fe43e9be1536397c5d7..a2bce274bdd70c0481a1bc75d449bfadf7b91618 100644 --- a/content/browser/web_contents/web_contents_impl.cc +++ b/content/browser/web_contents/web_contents_impl.cc @@ -4119,6 +4119,12 @@ TextInputManager* WebContentsImpl::GetTextInputManager() { return text_input_manager_.get(); } +void WebContentsImpl::OnCursorChanged(const WebCursor& cursor) { + observers_.ForEachObserver([&](WebContentsObserver* observer) { + observer->OnCursorChanged(cursor); + }); +} + bool WebContentsImpl::IsWidgetForMainFrame( RenderWidgetHostImpl* render_widget_host) { return render_widget_host == GetMainFrame()->GetRenderWidgetHost(); diff --git a/content/browser/web_contents/web_contents_impl.h b/content/browser/web_contents/web_contents_impl.h index 84ecccc204ee33820b8a059219244a841d6d642f..357ba07b83577392a902203cd7ee50e0ba3d27dd 100644 --- a/content/browser/web_contents/web_contents_impl.h +++ b/content/browser/web_contents/web_contents_impl.h @@ -965,6 +965,7 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents, blink::mojom::FrameVisibility visibility) override; void SendScreenRects() override; TextInputManager* GetTextInputManager() override; + void OnCursorChanged(const WebCursor& cursor) override; bool IsWidgetForMainFrame(RenderWidgetHostImpl* render_widget_host) override; bool AddDomainInfoToRapporSample(rappor::Sample* sample) override; bool IsShowingContextMenuOnPage() const override; diff --git a/content/public/browser/web_contents_observer.h b/content/public/browser/web_contents_observer.h index 9ab0a264e9ec660950e17cc608c375bf6366ac4a..45f56a4ea05e40b0b8287cea77810b7c9bdd1020 100644 --- a/content/public/browser/web_contents_observer.h +++ b/content/public/browser/web_contents_observer.h @@ -14,6 +14,7 @@ #include "base/threading/thread_restrictions.h" #include "components/viz/common/vertical_scroll_direction.h" #include "content/common/content_export.h" +#include "content/common/cursors/webcursor.h" #include "content/public/browser/allow_service_worker_result.h" #include "content/public/browser/cookie_access_details.h" #include "content/public/browser/navigation_controller.h" @@ -367,6 +368,9 @@ class CONTENT_EXPORT WebContentsObserver : public IPC::Listener { // Invoked every time the WebContents changes visibility. virtual void OnVisibilityChanged(Visibility visibility) {} + // Invoked every time the RenderWidget's cursor changes. + virtual void OnCursorChanged(const WebCursor& cursor) {} + // Invoked when the main frame changes size. virtual void MainFrameWasResized(bool width_changed) {}