Skip to content

Commit

Permalink
[UnifiedPDF] PDFPluginBase should send cursor updates to the web page
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264913
rdar://118483364

Reviewed by Tim Horton.

In preparation to get cursor updates working for `UnifiedPDFPlugin`, we
should move `PDFPlugin::notifyCursorChanged` up into the `PDFPluginBase`
structure. We should be doing the same (trivial) amount of work for both
PDF plugin types to send cursor updates to the web page.

* Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm:
(toWebCoreCursorType):
(-[WKPDFLayerControllerDelegate setMouseCursor:]):
(WebKit::PDFPlugin::notifySelectionChanged):
(WebKit::coreCursor): Deleted.
(WebKit::PDFPlugin::notifyCursorChanged): Deleted.
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm:
(WebKit::PDFPluginBase::notifyCursorChanged):

Canonical link: https://commits.webkit.org/270863@main
  • Loading branch information
aprotyas committed Nov 17, 2023
1 parent 7bce33d commit ce5a85a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
1 change: 0 additions & 1 deletion Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class PDFPlugin final : public PDFPluginBase {
void notifyDisplayModeChanged(int);

void notifySelectionChanged(PDFSelection *);
void notifyCursorChanged(uint64_t /* PDFLayerControllerCursorType */);

// HUD Actions.
#if ENABLE(PDF_HUD)
Expand Down
35 changes: 13 additions & 22 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,18 @@ - (id)initWithPDFPlugin:(WebKit::PDFPlugin *)plugin;

@end

static WebCore::Cursor::Type toWebCoreCursorType(PDFLayerControllerCursorType cursorType)
{
switch (cursorType) {
case kPDFLayerControllerCursorTypePointer: return WebCore::Cursor::Type::Pointer;
case kPDFLayerControllerCursorTypeHand: return WebCore::Cursor::Type::Hand;
case kPDFLayerControllerCursorTypeIBeam: return WebCore::Cursor::Type::IBeam;
}

RELEASE_ASSERT_NOT_REACHED();
return WebCore::Cursor::Type::Pointer;
}

@implementation WKPDFLayerControllerDelegate

@synthesize pdfPlugin = _pdfPlugin;
Expand Down Expand Up @@ -519,7 +531,7 @@ - (void)pdfLayerController:(PDFLayerController *)pdfLayerController didUpdateLay

- (void)setMouseCursor:(PDFLayerControllerCursorType)cursorType
{
_pdfPlugin->notifyCursorChanged(cursorType);
_pdfPlugin->notifyCursorChanged(toWebCoreCursorType(cursorType));
}

- (void)didChangeAnnotationState
Expand Down Expand Up @@ -2292,27 +2304,6 @@ static bool getEventTypeFromWebEvent(const WebEvent& event, NSEventType& eventTy
m_frame->page()->didChangeSelection(*m_frame->coreLocalFrame());
}

static const WebCore::Cursor& coreCursor(PDFLayerControllerCursorType type)
{
switch (type) {
case kPDFLayerControllerCursorTypeHand:
return WebCore::handCursor();
case kPDFLayerControllerCursorTypeIBeam:
return WebCore::iBeamCursor();
case kPDFLayerControllerCursorTypePointer:
default:
return WebCore::pointerCursor();
}
}

void PDFPlugin::notifyCursorChanged(uint64_t type)
{
if (!m_frame || !m_frame->page())
return;

m_frame->page()->send(Messages::WebPageProxy::SetCursor(coreCursor(static_cast<PDFLayerControllerCursorType>(type))));
}

String PDFPlugin::getSelectionString() const
{
return [[m_pdfLayerController currentSelection] string];
Expand Down
3 changes: 3 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class HTMLPlugInElement;
class ResourceResponse;
class Scrollbar;
class SharedBuffer;
enum class PlatformCursorType : uint8_t;
}

namespace WebKit {
Expand Down Expand Up @@ -167,6 +168,8 @@ class PDFPluginBase : public ThreadSafeRefCounted<PDFPluginBase>, public WebCore
virtual void openWithPreview(CompletionHandler<void(const String&, FrameInfoData&&, const IPC::DataReference&, const String&)>&&) = 0;
#endif

void notifyCursorChanged(WebCore::PlatformCursorType);

protected:
explicit PDFPluginBase(WebCore::HTMLPlugInElement&);

Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@

#if ENABLE(PDF_PLUGIN)

#import "MessageSenderInlines.h"
#import "PluginView.h"
#import "WebEventConversion.h"
#import "WebFrame.h"
#import "WebPage.h"
#import "WebPageProxyMessages.h"
#import <CoreFoundation/CoreFoundation.h>
#import <WebCore/AXObjectCache.h>
#import <WebCore/ArchiveResource.h>
#import <WebCore/Chrome.h>
#import <WebCore/Cursor.h>
#import <WebCore/Document.h>
#import <WebCore/FocusController.h>
#import <WebCore/Frame.h>
Expand Down Expand Up @@ -558,6 +561,14 @@

#endif // ENABLE(PDF_HUD)

void PDFPluginBase::notifyCursorChanged(WebCore::PlatformCursorType cursorType)
{
if (!m_frame || !m_frame->page())
return;

m_frame->protectedPage()->send(Messages::WebPageProxy::SetCursor(WebCore::Cursor::fromType(cursorType)));
}

} // namespace WebKit

#endif // ENABLE(PDF_PLUGIN)

0 comments on commit ce5a85a

Please sign in to comment.