Skip to content

Commit

Permalink
[UnifiedPDF] Data detection overlays should show on PDFs
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270998
rdar://123761050

Reviewed by Simon Fraser.

Currently, we do not surface any data detection results on
UnifiedPDFPlugin. This patch introduces the plumbing required to
fetch data detection results from PDFKit, the infrastructure to display
data detector overlays, and the requisite event handling/state
management to only display (or act on) a data detection result when the
mouse hovers/clicks over it.

To facilitate this end:

- Introduce two classes WebKit::PDFDataDetectorItem and
  WebKit::PDFDataDetectorOverlayController. The former encapsulates all
  the data we need to represent a data detection scanning result
  obtained from PDFKit, while the latter manages all the state for us to
  be able to indicate data detector results as page overlays.

- Introduce new public helpers on UnifiedPDFPlugin that
  PDFDataDetectorOverlayController can use to delegate work. Notably,
  this is required for us to implement the updated
  DataDetectorHighlightClient interface from 276060@main.

- Modify WebCore::DataDetectorHighlight to understand a new type of
  highlight corresponding to PDF selections.

* Source/WTF/wtf/PlatformEnableCocoa.h:

Add a new PlatformEnable flag so we don't have to litter the codebase
with #if ENABLE(UNIFIED_PDF) && ENABLE(DATA_DETECTION) && PLATFORM(MAC)

* Source/WebCore/PAL/pal/cocoa/DataDetectorsCoreSoftLink.h:
* Source/WebCore/PAL/pal/cocoa/DataDetectorsCoreSoftLink.mm:

DDResultIsPastDate is available (and used) on non-IOS_FAMILY platforms,
so let's move its declaration out from the platform-specific section.

* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/platform/mac/DataDetectorHighlight.h:
* Source/WebCore/platform/mac/DataDetectorHighlight.mm:
(WebCore::DataDetectorHighlight::createForPDFSelection):
(WebCore::DataDetectorHighlight::isRangeSupportingType const):
* Source/WebKit/Platform/spi/Cocoa/PDFKitSPI.h:
* Source/WebKit/Shared/Cocoa/PDFKitSoftLink.h:
* Source/WebKit/Shared/Cocoa/PDFKitSoftLink.mm:
* Source/WebKit/SourcesCocoa.txt:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm:
(WebKit::PDFPluginBase::lastKnownMousePositionInView const):
(WebKit::PDFPluginBase::mousePositionInView const):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorItem.h: Added.
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorItem.mm: Added.
(WebKit::hasActionsForResult):
(WebKit::resultIsPastDate):
(WebKit::PDFDataDetectorItem::create):
(WebKit::PDFDataDetectorItem::PDFDataDetectorItem):
(WebKit::PDFDataDetectorItem::scannerResult const):
(WebKit::PDFDataDetectorItem::hasActions const):
(WebKit::PDFDataDetectorItem::isPastDate const):
(WebKit::PDFDataDetectorItem::selection const):
(WebKit::PDFDataDetectorItem::pageBounds const):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorOverlayController.h: Added.
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorOverlayController.mm: Added.
(WebKit::PDFDataDetectorOverlayController::PDFDataDetectorOverlayController):
(WebKit::PDFDataDetectorOverlayController::protectedPlugin const):
(WebKit::PDFDataDetectorOverlayController::installOverlayIfNeeded):
(WebKit::PDFDataDetectorOverlayController::uninstallOverlay):
(WebKit::PDFDataDetectorOverlayController::teardown):
(WebKit::createPlatformDataDetectorHighlight):
(WebKit::PDFDataDetectorOverlayController::createPlatformDataDetectorHighlight const):
(WebKit::PDFDataDetectorOverlayController::handleMouseEvent):
(WebKit::PDFDataDetectorOverlayController::handleDataDetectorAction):
(WebKit::PDFDataDetectorOverlayController::updateDataDetectorHighlightsIfNeeded):
(WebKit::PDFDataDetectorOverlayController::updatePlatformHighlightData):
(WebKit::PDFDataDetectorOverlayController::didInvalidateHighlightOverlayRects):
(WebKit::PDFDataDetectorOverlayController::willMoveToPage):
(WebKit::PDFDataDetectorOverlayController::scheduleRenderingUpdate):
(WebKit::PDFDataDetectorOverlayController::deviceScaleFactor const):
(WebKit::PDFDataDetectorOverlayController::createGraphicsLayer):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::UnifiedPDFPlugin):
(WebKit::UnifiedPDFPlugin::teardown):
(WebKit::UnifiedPDFPlugin::installPDFDocument):
(WebKit::UnifiedPDFPlugin::enableDataDetection):
(WebKit::UnifiedPDFPlugin::handleClickForDataDetectionResult):
(WebKit::UnifiedPDFPlugin::createGraphicsLayer):

Refactor createGraphicsLayer into three overloads so it isn't
inconvenient to use internally or from the overlay controller.

(WebKit::UnifiedPDFPlugin::scheduleRenderingUpdate):
(WebKit::UnifiedPDFPlugin::pageAtIndex const):

Expose this helper to avoid having to pass the entire PDFDocumentLayout
object to the overlay controller.

(WebKit::UnifiedPDFPlugin::didChangeScrollOffset):

Repaint the data detector overlays to our hearts content on a scroll. To
be optimized!

(WebKit::UnifiedPDFPlugin::handleMouseEvent):
(WebKit::UnifiedPDFPlugin::rectForSelectionInPluginSpace const):
(WebKit::UnifiedPDFPlugin::installDataDetectorOverlay):
(WebKit::UnifiedPDFPlugin::uninstallDataDetectorOverlay):

Canonical link: https://commits.webkit.org/276131@main
  • Loading branch information
aprotyas committed Mar 15, 2024
1 parent 798d178 commit 37723d9
Show file tree
Hide file tree
Showing 20 changed files with 772 additions and 14 deletions.
4 changes: 4 additions & 0 deletions Source/WTF/wtf/PlatformEnableCocoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@
#define ENABLE_PDF_HUD 1
#endif

#if !defined(ENABLE_UNIFIED_PDF_DATA_DETECTION) && ENABLE(UNIFIED_PDF) && ENABLE(DATA_DETECTION) && PLATFORM(MAC)
#define ENABLE_UNIFIED_PDF_DATA_DETECTION 1
#endif

#if !defined(ENABLE_PERIODIC_MEMORY_MONITOR) && PLATFORM(MAC)
#define ENABLE_PERIODIC_MEMORY_MONITOR 1
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/PAL/pal/cocoa/DataDetectorsCoreSoftLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ SOFT_LINK_CONSTANT_FOR_HEADER(PAL, DataDetectorsCore, DDBinderPhoneNumberKey, CF
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDResultGetRange, CFRange, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDResultGetType, CFStringRef, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDResultGetCategory, DDResultCategory, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDResultIsPastDate, Boolean, (DDResultRef result, CFDateRef referenceDate, CFTimeZoneRef referenceTimeZone), (result, referenceDate, referenceTimeZone))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScanQueryAddTextFragment, void, (DDScanQueryRef query, CFStringRef fragment, CFRange range, void *identifier, DDTextFragmentMode mode, DDTextCoalescingType type), (query, fragment, range, identifier, mode, type))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScanQueryAddSeparator, void, (DDScanQueryRef query, DDTextCoalescingType type), (query, type))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScanQueryAddLineBreak, void, (DDScanQueryRef query), (query))
Expand All @@ -65,6 +64,7 @@ SOFT_LINK_POINTER_FOR_HEADER(PAL, DataDetectorsCore, DDBinderSignatureBlockKey,
SOFT_LINK_CONSTANT_FOR_HEADER(PAL, DataDetectorsCore, DDScannerCopyResultsOptionsForPassiveUse, DDScannerCopyResultsOptions)
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScannerEnableOptionalSource, void, (DDScannerRef scanner, DDScannerSource source, Boolean enable), (scanner, source, enable))
#endif // PLATFORM(IOS_FAMILY)
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDResultIsPastDate, Boolean, (DDResultRef result, CFDateRef referenceDate, CFTimeZoneRef referenceTimeZone), (result, referenceDate, referenceTimeZone))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScannerCreate, DDScannerRef, (DDScannerType type, DDScannerOptions options, CFErrorRef * errorRef), (type, options, errorRef))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScannerScanQuery, Boolean, (DDScannerRef scanner, DDScanQueryRef query), (scanner, query))
SOFT_LINK_FUNCTION_FOR_HEADER(PAL, DataDetectorsCore, DDScanQueryCreate, DDScanQueryRef, (CFAllocatorRef allocator), (allocator))
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/PAL/pal/cocoa/DataDetectorsCoreSoftLink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDResultGetRange, CFRange, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDResultGetType, CFStringRef, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDResultGetCategory, DDResultCategory, (DDResultRef result), (result))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDResultIsPastDate, Boolean, (DDResultRef result, CFDateRef referenceDate, CFTimeZoneRef referenceTimeZone), (result, referenceDate, referenceTimeZone))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDScanQueryAddTextFragment, void, (DDScanQueryRef query, CFStringRef fragment, CFRange range, void *identifier, DDTextFragmentMode mode, DDTextCoalescingType type), (query, fragment, range, identifier, mode, type))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDScanQueryAddSeparator, void, (DDScanQueryRef query, DDTextCoalescingType type), (query, type))
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDScanQueryAddLineBreak, void, (DDScanQueryRef query), (query))
Expand All @@ -64,6 +63,7 @@
SOFT_LINK_CONSTANT_FOR_SOURCE(PAL, DataDetectorsCore, DDScannerCopyResultsOptionsForPassiveUse, DDScannerCopyResultsOptions)
SOFT_LINK_FUNCTION_FOR_SOURCE(PAL, DataDetectorsCore, DDScannerEnableOptionalSource, void, (DDScannerRef scanner, DDScannerSource source, Boolean enable), (scanner, source, enable))
#endif // PLATFORM(IOS_FAMILY)
SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, DataDetectorsCore, DDResultIsPastDate, Boolean, (DDResultRef result, CFDateRef referenceDate, CFTimeZoneRef referenceTimeZone), (result, referenceDate, referenceTimeZone), PAL_EXPORT)
SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, DataDetectorsCore, DDScannerCreate, DDScannerRef, (DDScannerType type, DDScannerOptions options, CFErrorRef * errorRef), (type, options, errorRef), PAL_EXPORT)
SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, DataDetectorsCore, DDScannerScanQuery, Boolean, (DDScannerRef scanner, DDScanQueryRef query), (scanner, query), PAL_EXPORT)
SOFT_LINK_FUNCTION_FOR_SOURCE_WITH_EXPORT(PAL, DataDetectorsCore, DDScanQueryCreate, DDScanQueryRef, (CFAllocatorRef allocator), (allocator), PAL_EXPORT)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/PAL/pal/spi/cocoa/DataDetectorsCoreSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ extern CFStringRef const DDBinderParsecSourceKey;
extern CFStringRef const DDBinderSignatureBlockKey;

@interface DDScannerResult : NSObject <NSCoding, NSSecureCoding>
@property (readonly, nonatomic) NSRange urlificationRange;
+ (NSArray *)resultsFromCoreResults:(CFArrayRef)coreResults;
- (DDResultRef)coreResult;
@end
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -6285,7 +6285,7 @@
F4A064C8277E48C900B06A17 /* FontCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = F4A064C6277E48C600B06A17 /* FontCocoa.h */; settings = {ATTRIBUTES = (Private, ); }; };
F4A1C12A2AD05FA400862999 /* WebEventPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = F4A1C1292AD05F8A00862999 /* WebEventPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
F4B0018926E7F21F006EAABE /* HTMLNameCache.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B0018726E7F21F006EAABE /* HTMLNameCache.h */; };
F4B2A909265030BA009E7286 /* DataDetectorHighlight.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */; };
F4B2A909265030BA009E7286 /* DataDetectorHighlight.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B2A90626502BA0009E7286 /* DataDetectorHighlight.h */; settings = {ATTRIBUTES = (Private, ); }; };
F4B422C4220C0568009E1E7D /* DOMPasteAccess.h in Headers */ = {isa = PBXBuildFile; fileRef = F4B422C2220C0000009E1E7D /* DOMPasteAccess.h */; settings = {ATTRIBUTES = (Private, ); }; };
F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; };
F4BFB9861E1DDF9B00862C24 /* EditingHistoryUtil.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */; };
Expand Down
12 changes: 9 additions & 3 deletions Source/WebCore/platform/mac/DataDetectorHighlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class DataDetectorHighlight : public RefCounted<DataDetectorHighlight>, private
static Ref<DataDetectorHighlight> createForSelection(DataDetectorHighlightClient&, RetainPtr<DDHighlightRef>&&, SimpleRange&&);
static Ref<DataDetectorHighlight> createForTelephoneNumber(DataDetectorHighlightClient&, RetainPtr<DDHighlightRef>&&, SimpleRange&&);
static Ref<DataDetectorHighlight> createForImageOverlay(DataDetectorHighlightClient&, RetainPtr<DDHighlightRef>&&, SimpleRange&&);
#if ENABLE(UNIFIED_PDF_DATA_DETECTION)
WEBCORE_EXPORT static Ref<DataDetectorHighlight> createForPDFSelection(DataDetectorHighlightClient&, RetainPtr<DDHighlightRef>&&);
#endif

~DataDetectorHighlight();

Expand All @@ -76,15 +79,18 @@ class DataDetectorHighlight : public RefCounted<DataDetectorHighlight>, private
TelephoneNumber = 1 << 0,
Selection = 1 << 1,
ImageOverlay = 1 << 2,
#if ENABLE(UNIFIED_PDF_DATA_DETECTION)
PDFSelection = 1 << 3,
#endif
};

Type type() const { return m_type; }
bool isRangeSupportingType() const;

void fadeIn();
void fadeOut();
WEBCORE_EXPORT void fadeIn();
WEBCORE_EXPORT void fadeOut();

void setHighlight(DDHighlightRef);
WEBCORE_EXPORT void setHighlight(DDHighlightRef);

private:
DataDetectorHighlight(DataDetectorHighlightClient&, Type, RetainPtr<DDHighlightRef>&&, std::optional<SimpleRange>&&);
Expand Down
10 changes: 10 additions & 0 deletions Source/WebCore/platform/mac/DataDetectorHighlight.mm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
return adoptRef(*new DataDetectorHighlight(client, DataDetectorHighlight::Type::ImageOverlay, WTFMove(ddHighlight), { WTFMove(range) }));
}

#if ENABLE(UNIFIED_PDF_DATA_DETECTION)
Ref<DataDetectorHighlight> DataDetectorHighlight::createForPDFSelection(DataDetectorHighlightClient& client, RetainPtr<DDHighlightRef>&& ddHighlight)
{
return adoptRef(*new DataDetectorHighlight(client, DataDetectorHighlight::Type::PDFSelection, WTFMove(ddHighlight), { }));
}
#endif

DataDetectorHighlight::DataDetectorHighlight(DataDetectorHighlightClient& client, Type type, RetainPtr<DDHighlightRef>&& ddHighlight, std::optional<SimpleRange>&& range)
: m_client(client)
, m_range(WTFMove(range))
Expand Down Expand Up @@ -151,13 +158,16 @@

bool DataDetectorHighlight::isRangeSupportingType() const
{
#if ENABLE(UNIFIED_PDF_DATA_DETECTION)
static constexpr OptionSet rangeSupportingHighlightTypes {
DataDetectorHighlight::Type::TelephoneNumber,
DataDetectorHighlight::Type::Selection,
DataDetectorHighlight::Type::ImageOverlay,
};

return rangeSupportingHighlightTypes.contains(m_type);
#endif
return true;
}

const SimpleRange& DataDetectorHighlight::range() const
Expand Down
16 changes: 16 additions & 0 deletions Source/WebKit/Platform/spi/Cocoa/PDFKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ typedef NS_ENUM(NSUInteger, PDFSelectionGranularity);
@end
#endif

#if ENABLE(UNIFIED_PDF_DATA_DETECTION)

#if HAVE(PDFDOCUMENT_ENABLE_DATA_DETECTORS)
@interface PDFDocument (Staging_123761050)
@property (nonatomic) BOOL enableDataDetectors;
@end
#endif

#if HAVE(PDFPAGE_DATA_DETECTOR_RESULTS)
@interface PDFPage (Staging_123761050)
- (NSArray *)dataDetectorResults;
@end
#endif

#endif

#endif // ENABLE(UNIFIED_PDF)

// FIXME: Move this declaration inside the !USE(APPLE_INTERNAL_SDK) block once rdar://problem/118903435 is in builds.
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/Shared/Cocoa/PDFKitSoftLink.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ SOFT_LINK_CLASS_FOR_HEADER(WebKit, PDFLayerController)
SOFT_LINK_CLASS_FOR_HEADER(WebKit, PDFSelection)
SOFT_LINK_CONSTANT_FOR_HEADER(WebKit, PDFKit, kPDFDestinationUnspecifiedValue, CGFloat)
SOFT_LINK_CONSTANT_FOR_HEADER(WebKit, PDFKit, PDFViewCopyPermissionNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_HEADER(WebKit, PDFKit, PDFDocumentCreationDateAttribute, PDFDocumentAttribute)
ALLOW_DEPRECATED_DECLARATIONS_END

#endif // HAVE(PDFKIT)
2 changes: 2 additions & 0 deletions Source/WebKit/Shared/Cocoa/PDFKitSoftLink.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#if HAVE(PDFKIT)

#import "PDFKitSPI.h"
#import <wtf/SoftLinking.h>

SOFT_LINK_FRAMEWORK_FOR_SOURCE(WebKit, PDFKit)
Expand All @@ -44,6 +45,7 @@
SOFT_LINK_CLASS_FOR_SOURCE(WebKit, PDFKit, PDFSelection)
SOFT_LINK_CONSTANT_FOR_SOURCE(WebKit, PDFKit, kPDFDestinationUnspecifiedValue, CGFloat)
SOFT_LINK_CONSTANT_FOR_SOURCE(WebKit, PDFKit, PDFViewCopyPermissionNotification, NSNotificationName)
SOFT_LINK_CONSTANT_FOR_SOURCE(WebKit, PDFKit, PDFDocumentCreationDateAttribute, PDFDocumentAttribute)
ALLOW_DEPRECATED_DECLARATIONS_END

#endif // HAVE(PDFKIT)
2 changes: 2 additions & 0 deletions Source/WebKit/SourcesCocoa.txt
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,8 @@ WebProcess/Plugins/PDF/PDFPluginTextAnnotation.mm
WebProcess/Plugins/PDF/PDFScriptEvaluator.mm
WebProcess/Plugins/PDF/WKAccessibilityPDFDocumentObject.mm
WebProcess/Plugins/PDF/UnifiedPDF/AsyncPDFRenderer.mm
WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorItem.mm
WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorOverlayController.mm
WebProcess/Plugins/PDF/UnifiedPDF/PDFDocumentLayout.mm
WebProcess/Plugins/PDF/UnifiedPDF/PDFPageCoverage.mm
WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm
Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4950,6 +4950,10 @@
33B5A80D2AFD2B2300A15D40 /* WebExtensionFrameParameters.serialization.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebExtensionFrameParameters.serialization.in; sourceTree = "<group>"; };
33B5A80E2AFD5DE800A15D40 /* WebExtensionContextAPIWebNavigationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebExtensionContextAPIWebNavigationCocoa.mm; sourceTree = "<group>"; };
33D059A42A1EEEDC009AFE71 /* WebEventModifier.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebEventModifier.cpp; sourceTree = "<group>"; };
33DAECEC2B99D052005C596E /* PDFDataDetectorItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFDataDetectorItem.h; sourceTree = "<group>"; };
33DAECED2B99D05A005C596E /* PDFDataDetectorItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PDFDataDetectorItem.mm; sourceTree = "<group>"; };
33DAECEE2B9AAE91005C596E /* PDFDataDetectorOverlayController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PDFDataDetectorOverlayController.h; sourceTree = "<group>"; };
33DAECEF2B9AAE92005C596E /* PDFDataDetectorOverlayController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PDFDataDetectorOverlayController.mm; sourceTree = "<group>"; };
33F68335293FF6F5005C63C0 /* JSWebExtensionAPIWebNavigationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWebExtensionAPIWebNavigationEvent.h; sourceTree = "<group>"; };
33F68336293FF6F5005C63C0 /* JSWebExtensionAPIWebNavigationEvent.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = JSWebExtensionAPIWebNavigationEvent.mm; sourceTree = "<group>"; };
33F6833D293FFA4B005C63C0 /* WebExtensionAPIWebNavigationEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebExtensionAPIWebNavigationEvent.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -8700,6 +8704,10 @@
children = (
0F23ADDE2B7D240B00E6199B /* AsyncPDFRenderer.h */,
0F23ADDF2B7D240C00E6199B /* AsyncPDFRenderer.mm */,
33DAECEC2B99D052005C596E /* PDFDataDetectorItem.h */,
33DAECED2B99D05A005C596E /* PDFDataDetectorItem.mm */,
33DAECEE2B9AAE91005C596E /* PDFDataDetectorOverlayController.h */,
33DAECEF2B9AAE92005C596E /* PDFDataDetectorOverlayController.mm */,
0F3D56732AC651390086D64E /* PDFDocumentLayout.h */,
0F3D56722AC651390086D64E /* PDFDocumentLayout.mm */,
0F9B0BC22B7DB9BF0003E962 /* PDFPageCoverage.h */,
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ class PDFPluginBase : public ThreadSafeRefCountedAndCanMakeThreadSafeWeakPtr<PDF
WebCore::IntRect convertFromPluginToRootView(const WebCore::IntRect&) const;
WebCore::IntRect boundsOnScreen() const;

WebCore::IntPoint mousePositionInView(const WebMouseEvent&) const;

bool showContextMenuAtPoint(const WebCore::IntPoint&);
WebCore::AXObjectCache* axObjectCache() const;

Expand Down
6 changes: 5 additions & 1 deletion Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,14 @@
WebCore::IntPoint PDFPluginBase::lastKnownMousePositionInView() const
{
if (m_lastMouseEvent)
return convertFromRootViewToPlugin(m_lastMouseEvent->position());
return mousePositionInView(*m_lastMouseEvent);
return { };
}

WebCore::IntPoint PDFPluginBase::mousePositionInView(const WebMouseEvent& event) const
{
return convertFromRootViewToPlugin(event.position());
}

void PDFPluginBase::navigateToURL(const URL& url)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (C) 2024 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once

#if ENABLE(UNIFIED_PDF_DATA_DETECTION)

#include <wtf/Noncopyable.h>
#include <wtf/RefCounted.h>
#include <wtf/RetainPtr.h>

OBJC_CLASS DDScannerResult;
OBJC_CLASS PDFPage;
OBJC_CLASS PDFSelection;

namespace WebCore {
class FloatRect;
}

namespace WebKit {

class PDFDataDetectorItem : public RefCounted<PDFDataDetectorItem> {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(PDFDataDetectorItem);
public:
static Ref<PDFDataDetectorItem> create(DDScannerResult *, PDFPage *);

DDScannerResult *scannerResult() const;
bool hasActions() const;
bool isPastDate() const;
RetainPtr<PDFSelection> selection() const;

private:
PDFDataDetectorItem(DDScannerResult *, PDFPage *);

RetainPtr<DDScannerResult> m_result;
RetainPtr<PDFPage> m_page;
bool m_hasActions { false };
bool m_isPastDate { false };
};

} // namespace WebKit

#endif // ENABLE(UNIFIED_PDF_DATA_DETECTION)
Loading

0 comments on commit 37723d9

Please sign in to comment.