-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UnifiedPDF] Data detection overlays should show on PDFs
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
Showing
20 changed files
with
772 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/PDFDataDetectorItem.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.