Skip to content

Commit

Permalink
[UnifiedPDF] Cursor updates are incorrect over text/image elements fo…
Browse files Browse the repository at this point in the history
…r untagged PDFs.

https://bugs.webkit.org/show_bug.cgi?id=265908
rdar://119217538

Reviewed by Tim Horton.

The CGPDFPageLayoutGetAreaOfInterestAtPoint interface does not correctly
identify text/image elements on Untagged PDF files. This made our hit
test results incomplete on said PDF files. To address this issue, we
adopt new PDFPage API `areaOfInterestAtPoint`, which not only hit tests
for annotations, but also for text and image on a page, thus subsuming
both -[PDFPage annotationAtPoint:] and CGPDFPageLayoutGetAreaOfInterestAtPoint
while maintaining correctness across tagged and untagged PDFs.

* Source/WebKit/Platform/spi/Cocoa/PDFKitSPI.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::pdfElementTypesForPluginPoint const):

Canonical link: https://commits.webkit.org/275287@main
  • Loading branch information
aprotyas committed Feb 24, 2024
1 parent cb875ef commit bcb2f89
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Source/WebKit/Platform/spi/Cocoa/PDFKitSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
#endif // PLATFORM(IOS_FAMILY)

#import <PDFKit/PDFDocumentPriv.h>
#import <PDFKit/PDFPagePriv.h>
#import <PDFKit/PDFSelectionPriv.h>

#if __has_include(<PDFKit/PDFActionPriv.h>)
#import <PDFKit/PDFActionPriv.h>
#else
Expand Down Expand Up @@ -122,6 +124,23 @@
@end
#endif

#if HAVE(PDFPAGE_AREA_OF_INTEREST_AT_POINT)
#define PDFAreaOfInterest NSInteger

#define kPDFTextArea (1UL << 1)
#define kPDFAnnotationArea (1UL << 2)
#define kPDFLinkArea (1UL << 3)
#define kPDFControlArea (1UL << 4)
#define kPDFTextFieldArea (1UL << 5)
#define kPDFIconArea (1UL << 6)
#define kPDFPopupArea (1UL << 7)
#define kPDFImageArea (1UL << 8)

@interface PDFPage (Staging_119217538)
- (PDFAreaOfInterest)areaOfInterestAtPoint:(PDFPoint)point;
@end
#endif

#if HAVE(PDFDOCUMENT_SELECTION_WITH_GRANULARITY)
typedef NS_ENUM(NSUInteger, PDFSelectionGranularity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,38 @@ static BOOL annotationIsLinkWithDestination(PDFAnnotation *annotation)

PDFElementTypes pdfElementTypes { PDFElementType::Page };

#if HAVE(PDFPAGE_AREA_OF_INTEREST_AT_POINT)
if ([page respondsToSelector:@selector(areaOfInterestAtPoint:)]) {
PDFAreaOfInterest areaOfInterest = [page areaOfInterestAtPoint:pointInPDFPageSpace];

if (areaOfInterest & kPDFTextArea)
pdfElementTypes.add(PDFElementType::Text);

if (areaOfInterest & kPDFAnnotationArea)
pdfElementTypes.add(PDFElementType::Annotation);

if ((areaOfInterest & kPDFLinkArea) && annotationIsLinkWithDestination([page annotationAtPoint:pointInPDFPageSpace]))
pdfElementTypes.add(PDFElementType::Link);

if (areaOfInterest & kPDFControlArea)
pdfElementTypes.add(PDFElementType::Control);

if (areaOfInterest & kPDFTextFieldArea)
pdfElementTypes.add(PDFElementType::TextField);

if (areaOfInterest & kPDFIconArea)
pdfElementTypes.add(PDFElementType::Icon);

if (areaOfInterest & kPDFPopupArea)
pdfElementTypes.add(PDFElementType::Popup);

if (areaOfInterest & kPDFImageArea)
pdfElementTypes.add(PDFElementType::Image);

return pdfElementTypes;
}
#endif

if (auto annotation = [page annotationAtPoint:pointInPDFPageSpace]) {
pdfElementTypes.add(PDFElementType::Annotation);

Expand Down Expand Up @@ -1658,8 +1690,6 @@ static BOOL annotationIsLinkWithDestination(PDFAnnotation *annotation)
}
#endif

// FIXME: <https://webkit.org/b/265908> Cursor updates are incorrect over text/image elements for untagged PDFs.

return pdfElementTypes;
}

Expand Down

0 comments on commit bcb2f89

Please sign in to comment.