Skip to content

Commit

Permalink
[UnifiedPDF] De-hoist "PDFView" coordinate conversion functions back …
Browse files Browse the repository at this point in the history
…to PDFPlugin

https://bugs.webkit.org/show_bug.cgi?id=265490
rdar://118906205

Reviewed by Wenson Hsieh and Simon Fraser.

When I hoisted these, I left a FIXME to make sure they make sense.
They don't. We don't have any Y flip in UnifiedPDFPlugin.
Move them back to PDFPlugin and add the "PluginToRootView" methods that we really needed.
Also rename frameForHUD to be clear about the coordinate space.

* Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::convertFromPluginToPDFView const):
(WebKit::PDFPlugin::convertFromPDFViewToRootView const):
(WebKit::PDFPlugin::convertFromRootViewToPDFView const):
(WebKit::PDFPlugin::convertFromPDFViewToScreen const):
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm:
(WebKit::PDFPluginBase::visibilityDidChange):
(WebKit::PDFPluginBase::convertFromRootViewToPlugin const):
(WebKit::PDFPluginBase::convertFromPluginToRootView const):
(WebKit::PDFPluginBase::updatePDFHUDLocation):
(WebKit::PDFPluginBase::frameForHUDInRootViewCoordinates const):
(WebKit::PDFPluginBase::convertFromPluginToPDFView const): Deleted.
(WebKit::PDFPluginBase::convertFromPDFViewToRootView const): Deleted.
(WebKit::PDFPluginBase::convertFromRootViewToPDFView const): Deleted.
(WebKit::PDFPluginBase::convertFromPDFViewToScreen const): Deleted.
(WebKit::PDFPluginBase::frameForHUD const): Deleted.

Canonical link: https://commits.webkit.org/271253@main
  • Loading branch information
hortont424 committed Nov 29, 2023
1 parent 49e6e87 commit 47696ba
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
6 changes: 6 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class PDFPlugin final : public PDFPluginBase {
size_t decrementThreadsWaitingOnCallback() { return --m_threadsWaitingOnCallback; }
#endif

WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
WebCore::IntRect convertFromPDFViewToRootView(const WebCore::IntRect&) const;
WebCore::IntPoint convertFromRootViewToPDFView(const WebCore::IntPoint&) const;
WebCore::FloatRect convertFromPDFViewToScreen(const WebCore::FloatRect&) const;

private:
explicit PDFPlugin(WebCore::HTMLPlugInElement&);
bool isLegacyPDFPlugin() const override { return true; }
Expand Down
35 changes: 35 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,41 @@ static void jsPDFDocFinalize(JSObjectRef object)
[CATransaction commit];
}

IntPoint PDFPlugin::convertFromPluginToPDFView(const IntPoint& point) const
{
return IntPoint(point.x(), size().height() - point.y());
}

IntPoint PDFPlugin::convertFromPDFViewToRootView(const IntPoint& point) const
{
IntPoint pointInPluginCoordinates(point.x(), size().height() - point.y());
return valueOrDefault(m_rootViewToPluginTransform.inverse()).mapPoint(pointInPluginCoordinates);
}

IntRect PDFPlugin::convertFromPDFViewToRootView(const IntRect& rect) const
{
IntRect rectInPluginCoordinates(rect.x(), rect.y(), rect.width(), rect.height());
return valueOrDefault(m_rootViewToPluginTransform.inverse()).mapRect(rectInPluginCoordinates);
}

IntPoint PDFPlugin::convertFromRootViewToPDFView(const IntPoint& point) const
{
IntPoint pointInPluginCoordinates = m_rootViewToPluginTransform.mapPoint(point);
return IntPoint(pointInPluginCoordinates.x(), size().height() - pointInPluginCoordinates.y());
}

FloatRect PDFPlugin::convertFromPDFViewToScreen(const FloatRect& rect) const
{
return WebCore::Accessibility::retrieveValueFromMainThread<WebCore::FloatRect>([&] () -> WebCore::FloatRect {
FloatRect updatedRect = rect;
updatedRect.setLocation(convertFromPDFViewToRootView(IntPoint(updatedRect.location())));
CheckedPtr page = this->page();
if (!page)
return { };
return page->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
});
}

static NSUInteger modifierFlagsFromWebEvent(const WebEvent& event)
{
return (event.shiftKey() ? NSEventModifierFlagShift : 0)
Expand Down
11 changes: 4 additions & 7 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,10 @@ class PDFPluginBase : public ThreadSafeRefCounted<PDFPluginBase>, public WebCore
void streamDidFinishLoading();
void streamDidFail();

// FIXME: Rationalize these (both names and behavior).
WebCore::IntPoint convertFromRootViewToPlugin(const WebCore::IntPoint&) const;
WebCore::IntPoint convertFromPluginToPDFView(const WebCore::IntPoint&) const;
WebCore::IntPoint convertFromPDFViewToRootView(const WebCore::IntPoint&) const;
WebCore::IntRect convertFromPDFViewToRootView(const WebCore::IntRect&) const;
WebCore::IntPoint convertFromRootViewToPDFView(const WebCore::IntPoint&) const;
WebCore::FloatRect convertFromPDFViewToScreen(const WebCore::FloatRect&) const;
WebCore::IntRect convertFromRootViewToPlugin(const WebCore::IntRect&) const;
WebCore::IntPoint convertFromPluginToRootView(const WebCore::IntPoint&) const;
WebCore::IntRect convertFromPluginToRootView(const WebCore::IntRect&) const;
WebCore::IntRect boundsOnScreen() const;

WebCore::ScrollPosition scrollPositionForTesting() const { return scrollPosition(); }
Expand Down Expand Up @@ -227,7 +224,7 @@ class PDFPluginBase : public ThreadSafeRefCounted<PDFPluginBase>, public WebCore
// HUD.
#if ENABLE(PDF_HUD)
void updatePDFHUDLocation();
WebCore::IntRect frameForHUD() const;
WebCore::IntRect frameForHUDInRootViewCoordinates() const;
bool hudEnabled() const;
#endif

Expand Down
40 changes: 10 additions & 30 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
if (!m_frame || !hudEnabled())
return;
if (visible)
m_frame->page()->createPDFHUD(*this, frameForHUD());
m_frame->page()->createPDFHUD(*this, frameForHUDInRootViewCoordinates());
else
m_frame->page()->removePDFHUD(*this);
#endif
Expand All @@ -263,39 +263,19 @@
return m_rootViewToPluginTransform.mapPoint(point);
}

IntPoint PDFPluginBase::convertFromPluginToPDFView(const IntPoint& point) const
IntRect PDFPluginBase::convertFromRootViewToPlugin(const IntRect& rect) const
{
return IntPoint(point.x(), size().height() - point.y());
return m_rootViewToPluginTransform.mapRect(rect);
}

IntPoint PDFPluginBase::convertFromPDFViewToRootView(const IntPoint& point) const
IntPoint PDFPluginBase::convertFromPluginToRootView(const IntPoint& point) const
{
IntPoint pointInPluginCoordinates(point.x(), size().height() - point.y());
return valueOrDefault(m_rootViewToPluginTransform.inverse()).mapPoint(pointInPluginCoordinates);
return m_rootViewToPluginTransform.inverse()->mapPoint(point);
}

IntRect PDFPluginBase::convertFromPDFViewToRootView(const IntRect& rect) const
IntRect PDFPluginBase::convertFromPluginToRootView(const IntRect& rect) const
{
IntRect rectInPluginCoordinates(rect.x(), rect.y(), rect.width(), rect.height());
return valueOrDefault(m_rootViewToPluginTransform.inverse()).mapRect(rectInPluginCoordinates);
}

IntPoint PDFPluginBase::convertFromRootViewToPDFView(const IntPoint& point) const
{
IntPoint pointInPluginCoordinates = m_rootViewToPluginTransform.mapPoint(point);
return IntPoint(pointInPluginCoordinates.x(), size().height() - pointInPluginCoordinates.y());
}

FloatRect PDFPluginBase::convertFromPDFViewToScreen(const FloatRect& rect) const
{
return WebCore::Accessibility::retrieveValueFromMainThread<WebCore::FloatRect>([&] () -> WebCore::FloatRect {
FloatRect updatedRect = rect;
updatedRect.setLocation(convertFromPDFViewToRootView(IntPoint(updatedRect.location())));
CheckedPtr page = this->page();
if (!page)
return { };
return page->chrome().rootViewToScreen(enclosingIntRect(updatedRect));
});
return m_rootViewToPluginTransform.inverse()->mapRect(rect);
}

IntRect PDFPluginBase::boundsOnScreen() const
Expand Down Expand Up @@ -545,12 +525,12 @@
{
if (isLocked() || !m_frame || !m_frame->page())
return;
m_frame->protectedPage()->updatePDFHUDLocation(*this, frameForHUD());
m_frame->protectedPage()->updatePDFHUDLocation(*this, frameForHUDInRootViewCoordinates());
}

IntRect PDFPluginBase::frameForHUD() const
IntRect PDFPluginBase::frameForHUDInRootViewCoordinates() const
{
return convertFromPDFViewToRootView(IntRect(IntPoint(), size()));
return convertFromPluginToRootView(IntRect(IntPoint(), size()));
}

bool PDFPluginBase::hudEnabled() const
Expand Down

0 comments on commit 47696ba

Please sign in to comment.