Skip to content

Commit

Permalink
Add TextStream dumping for WebKit::RepaintRequirements
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=274189
rdar://128097770

Reviewed by Simon Fraser and Sammy Gill.

This patch typedefs OptionSet<RepaintRequirement> to RepaintRequirements
for easier reference, and adds a TextStream operator<< overload for said
type to aid with debugging.

* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::updateTrackedAnnotation):
(WebKit::UnifiedPDFPlugin::handlePDFActionForAnnotation):
(WebKit::AnnotationTrackingState::startAnnotationTracking):
(WebKit::UnifiedPDFPlugin::setDisplayModeAndUpdateLayout):
(WebKit::operator<<):

Canonical link: https://commits.webkit.org/278798@main
  • Loading branch information
aprotyas committed May 15, 2024
1 parent 6939c8d commit f54cee4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
21 changes: 14 additions & 7 deletions Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ OBJC_CLASS PDFDestination;
OBJC_CLASS PDFPage;
OBJC_CLASS WKPDFFormMutationObserver;

namespace WTF {
class TextStream;
}

namespace WebCore {
class FrameView;
class KeyboardScrollingAnimator;
Expand Down Expand Up @@ -74,11 +78,12 @@ enum class RepaintRequirement : uint8_t {
Selection = 1 << 1,
HoverOverlay = 1 << 2
};
using RepaintRequirements = OptionSet<RepaintRequirement>;

class AnnotationTrackingState {
public:
OptionSet<RepaintRequirement> startAnnotationTracking(RetainPtr<PDFAnnotation>&&, WebEventType, WebMouseEventButton);
OptionSet<RepaintRequirement> finishAnnotationTracking(PDFAnnotation* annotationUnderMouse, WebEventType, WebMouseEventButton);
RepaintRequirements startAnnotationTracking(RetainPtr<PDFAnnotation>&&, WebEventType, WebMouseEventButton);
RepaintRequirements finishAnnotationTracking(PDFAnnotation* annotationUnderMouse, WebEventType, WebMouseEventButton);

PDFAnnotation *trackedAnnotation() const { return m_trackedAnnotation.get(); }
bool isBeingHovered() const;
Expand Down Expand Up @@ -128,7 +133,7 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay
void handlePDFActionForAnnotation(PDFAnnotation *, unsigned currentPageIndex);
#endif
enum class IsAnnotationCommit : bool { No, Yes };
static OptionSet<RepaintRequirement> repaintRequirementsForAnnotation(PDFAnnotation *, IsAnnotationCommit = IsAnnotationCommit::No);
static RepaintRequirements repaintRequirementsForAnnotation(PDFAnnotation *, IsAnnotationCommit = IsAnnotationCommit::No);
void repaintAnnotationsForFormField(NSString *fieldName);

Vector<WebCore::FloatRect> annotationRectsForTesting() const final;
Expand Down Expand Up @@ -505,16 +510,16 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay

void startTrackingAnnotation(RetainPtr<PDFAnnotation>&&, WebEventType, WebMouseEventButton);
void updateTrackedAnnotation(PDFAnnotation *annotationUnderMouse);
void finishTrackingAnnotation(PDFAnnotation *annotationUnderMouse, WebEventType, WebMouseEventButton, OptionSet<RepaintRequirement> = { });
void finishTrackingAnnotation(PDFAnnotation *annotationUnderMouse, WebEventType, WebMouseEventButton, RepaintRequirements = { });

void revealAnnotation(PDFAnnotation *);

RefPtr<WebCore::GraphicsLayer> createGraphicsLayer(GraphicsLayerClient&, WebCore::GraphicsLayer::Type);
RefPtr<WebCore::GraphicsLayer> createGraphicsLayer(const String& name, WebCore::GraphicsLayer::Type);

void setNeedsRepaintForAnnotation(PDFAnnotation *, OptionSet<RepaintRequirement>);
void setNeedsRepaintInDocumentRect(OptionSet<RepaintRequirement>, const WebCore::FloatRect&);
void setNeedsRepaintInDocumentRects(OptionSet<RepaintRequirement>, const Vector<WebCore::FloatRect>&);
void setNeedsRepaintForAnnotation(PDFAnnotation *, RepaintRequirements);
void setNeedsRepaintInDocumentRect(RepaintRequirements, const WebCore::FloatRect&);
void setNeedsRepaintInDocumentRects(RepaintRequirements, const Vector<WebCore::FloatRect>&);

// "Up" is inside-out.
template <typename T>
Expand Down Expand Up @@ -630,6 +635,8 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay
#endif
};

WTF::TextStream& operator<<(WTF::TextStream&, RepaintRequirement);

} // namespace WebKit

SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::UnifiedPDFPlugin)
Expand Down
37 changes: 27 additions & 10 deletions Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
#include <wtf/Algorithms.h>
#include <wtf/Scope.h>
#include <wtf/text/StringToIntegerConversion.h>
#include <wtf/text/TextStream.h>

#include "PDFKitSoftLink.h"

Expand Down Expand Up @@ -396,7 +397,7 @@ static String mutationObserverNotificationString()
return graphicsLayer;
}

void UnifiedPDFPlugin::setNeedsRepaintForAnnotation(PDFAnnotation *annotation, OptionSet<RepaintRequirement> repaintRequirements)
void UnifiedPDFPlugin::setNeedsRepaintForAnnotation(PDFAnnotation *annotation, RepaintRequirements repaintRequirements)
{
if (!repaintRequirements)
return;
Expand All @@ -409,7 +410,7 @@ static String mutationObserverNotificationString()
setNeedsRepaintInDocumentRect(repaintRequirements, annotationBounds);
}

void UnifiedPDFPlugin::setNeedsRepaintInDocumentRect(OptionSet<RepaintRequirement> repaintRequirements, const FloatRect& rectInDocumentCoordinates)
void UnifiedPDFPlugin::setNeedsRepaintInDocumentRect(RepaintRequirements repaintRequirements, const FloatRect& rectInDocumentCoordinates)
{
if (!repaintRequirements)
return;
Expand All @@ -431,7 +432,7 @@ static String mutationObserverNotificationString()
RefPtr { m_contentsLayer }->setNeedsDisplayInRect(contentsRect);
}

void UnifiedPDFPlugin::setNeedsRepaintInDocumentRects(OptionSet<RepaintRequirement> repaintRequirements, const Vector<FloatRect>& rectsInDocumentCoordinates)
void UnifiedPDFPlugin::setNeedsRepaintInDocumentRects(RepaintRequirements repaintRequirements, const Vector<FloatRect>& rectsInDocumentCoordinates)
{
for (auto& rectInDocumentCoordinates : rectsInDocumentCoordinates)
setNeedsRepaintInDocumentRect(repaintRequirements, rectInDocumentCoordinates);
Expand Down Expand Up @@ -2565,7 +2566,7 @@ static bool isContextMenuEvent(const WebMouseEvent& event)
scrollToPDFDestination(destination);
}

OptionSet<RepaintRequirement> UnifiedPDFPlugin::repaintRequirementsForAnnotation(PDFAnnotation *annotation, IsAnnotationCommit isAnnotationCommit)
RepaintRequirements UnifiedPDFPlugin::repaintRequirementsForAnnotation(PDFAnnotation *annotation, IsAnnotationCommit isAnnotationCommit)
{
if ([annotation isKindOfClass:getPDFAnnotationButtonWidgetClass()])
return RepaintRequirement::PDFContent;
Expand Down Expand Up @@ -2604,7 +2605,7 @@ static bool isContextMenuEvent(const WebMouseEvent& event)
{
RetainPtr currentTrackedAnnotation = m_annotationTrackingState.trackedAnnotation();
bool isHighlighted = [currentTrackedAnnotation isHighlighted];
OptionSet<RepaintRequirement> repaintRequirements;
RepaintRequirements repaintRequirements;

if (isHighlighted && currentTrackedAnnotation != annotationUnderMouse) {
[currentTrackedAnnotation setHighlighted:NO];
Expand All @@ -2617,7 +2618,7 @@ static bool isContextMenuEvent(const WebMouseEvent& event)
setNeedsRepaintForAnnotation(currentTrackedAnnotation.get(), repaintRequirements);
}

void UnifiedPDFPlugin::finishTrackingAnnotation(PDFAnnotation* annotationUnderMouse, WebEventType mouseEventType, WebMouseEventButton mouseEventButton, OptionSet<RepaintRequirement> repaintRequirements)
void UnifiedPDFPlugin::finishTrackingAnnotation(PDFAnnotation* annotationUnderMouse, WebEventType mouseEventType, WebMouseEventButton mouseEventButton, RepaintRequirements repaintRequirements)
{
RetainPtr trackedAnnotation = m_annotationTrackingState.trackedAnnotation();
repaintRequirements.add(m_annotationTrackingState.finishAnnotationTracking(annotationUnderMouse, mouseEventType, mouseEventButton));
Expand Down Expand Up @@ -4000,12 +4001,12 @@ static NSStringCompareOptions compareOptionsForFindOptions(WebCore::FindOptions
}
#endif

OptionSet<RepaintRequirement> AnnotationTrackingState::startAnnotationTracking(RetainPtr<PDFAnnotation>&& annotation, WebEventType mouseEventType, WebMouseEventButton mouseEventButton)
RepaintRequirements AnnotationTrackingState::startAnnotationTracking(RetainPtr<PDFAnnotation>&& annotation, WebEventType mouseEventType, WebMouseEventButton mouseEventButton)
{
ASSERT(!m_trackedAnnotation);
m_trackedAnnotation = WTFMove(annotation);

auto repaintRequirements = OptionSet<RepaintRequirement> { };
auto repaintRequirements = RepaintRequirements { };

if ([m_trackedAnnotation isKindOfClass:getPDFAnnotationButtonWidgetClass()]) {
[m_trackedAnnotation setHighlighted:YES];
Expand All @@ -4022,10 +4023,10 @@ static NSStringCompareOptions compareOptionsForFindOptions(WebCore::FindOptions
return repaintRequirements;
}

OptionSet<RepaintRequirement> AnnotationTrackingState::finishAnnotationTracking(PDFAnnotation* annotationUnderMouse, WebEventType mouseEventType, WebMouseEventButton mouseEventButton)
RepaintRequirements AnnotationTrackingState::finishAnnotationTracking(PDFAnnotation* annotationUnderMouse, WebEventType mouseEventType, WebMouseEventButton mouseEventButton)
{
ASSERT(m_trackedAnnotation);
auto repaintRequirements = OptionSet<RepaintRequirement> { };
auto repaintRequirements = RepaintRequirements { };

if (annotationUnderMouse == m_trackedAnnotation && mouseEventType == WebEventType::MouseUp && mouseEventButton == WebMouseEventButton::Left) {
if ([m_trackedAnnotation isHighlighted]) {
Expand Down Expand Up @@ -4158,6 +4159,22 @@ static NSStringCompareOptions compareOptionsForFindOptions(WebCore::FindOptions
}
}

TextStream& operator<<(TextStream& ts, RepaintRequirement requirement)
{
switch (requirement) {
case RepaintRequirement::PDFContent:
ts << "PDFContent";
break;
case RepaintRequirement::Selection:
ts << "Selection";
break;
case RepaintRequirement::HoverOverlay:
ts << "HoverOverlay";
break;
}
return ts;
}

} // namespace WebKit

#endif // ENABLE(UNIFIED_PDF)

0 comments on commit f54cee4

Please sign in to comment.