Skip to content

Commit

Permalink
[UnifiedPDF] After resizing the window, PDF content is not centered a…
Browse files Browse the repository at this point in the history
…nd hit testing is offset

https://bugs.webkit.org/show_bug.cgi?id=269549
rdar://123066513

Reviewed by Tim Horton.

The PDF content is centered in the window via a transform on the m_contentsLayer layer.
We need to update this transform both when the scale factor changes, but also when
layout is updated.

This is a small change to fix the issue. A larger refactoring of the "update" functions
is needed.

* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::updateLayerPositions):
(WebKit::UnifiedPDFPlugin::setPageScaleFactor):
(WebKit::UnifiedPDFPlugin::updateLayout):

Canonical link: https://commits.webkit.org/274859@main
  • Loading branch information
smfr committed Feb 16, 2024
1 parent 55b0517 commit 0626093
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay
void ensureLayers();
void updatePageBackgroundLayers();
void updateLayerHierarchy();
void updateLayerPositions();

void didChangeScrollOffset() override;
void didChangeIsInWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,16 @@ static String mutationObserverNotificationString()
didChangeIsInWindow();
}

void UnifiedPDFPlugin::updateLayerPositions()
{
TransformationMatrix transform;
transform.scale(m_scaleFactor);
auto padding = centeringOffset();
transform.translate(padding.width(), padding.height());

m_contentsLayer->setTransform(transform);
m_pageBackgroundsContainerLayer->setTransform(transform);
}

std::pair<bool, bool> UnifiedPDFPlugin::shouldShowDebugIndicators() const
{
Expand Down Expand Up @@ -849,14 +859,7 @@ static String mutationObserverNotificationString()
if (!m_inMagnificationGesture)
m_rootLayer->noteDeviceOrPageScaleFactorChangedIncludingDescendants();

TransformationMatrix transform;
transform.scale(m_scaleFactor);
auto padding = centeringOffset();
transform.translate(padding.width(), padding.height());

m_contentsLayer->setTransform(transform);
m_pageBackgroundsContainerLayer->setTransform(transform);

updateLayerPositions();
updatePageBackgroundLayers();
updateSnapOffsets();

Expand Down Expand Up @@ -929,6 +932,7 @@ static String mutationObserverNotificationString()
}

updateLayerHierarchy();
updateLayerPositions();
updateScrollingExtents();

if (shouldAdjustScale == AdjustScaleAfterLayout::Yes && m_view) {
Expand Down

0 comments on commit 0626093

Please sign in to comment.