Skip to content

Commit

Permalink
[UnifiedPDF] Adjust automatically resize logic.
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271264
rdar://123417338

Reviewed by Simon Fraser and Abrar Rahman Protyasha.

This patch aims to make the "Automatically Resize," context menu item
logic a little more intuitive. The way that this setting works now
with this patch is as follows:

1. Defaults to off
- PDFDocumentLayout has m_autoSizeState initialized to
ShouldUpdateAutoSizeScale::Yes, but the plugin will set it to No after
the first layout. This is so that the document gets fitted according to
our existing logic on initial load. Any sort of window resizing at this
point will not resize the document.

2. Turning it on rescales the PDF to the window width
- This is done by adjusting the logic that we have when we handle the
associated context menu event. Instead of setting the plugin's scale
factor to its initial scale that was computed on load, we will set it
to 1.0.

3. Any type of zooming turns it off
- This is already handled already in UnifiedPDFPlugin::setPageScaleFactor.
This includes HUD, pinch, and keyboard zooming.

4. The setting can also be toggleable
- Expanded the associated context menu action handling to include this.
When the setting is toggled off the scales will remain the same even
during window resizing. Toggling it back on will reset the plugin's
scale factor and adjust the document fitting scale so that the document
once again fits the available width.

* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::updateLayout):
(WebKit::UnifiedPDFPlugin::performContextMenuAction):

Canonical link: https://commits.webkit.org/276371@main
  • Loading branch information
sammygill committed Mar 19, 2024
1 parent 4a5699e commit 088d359
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,8 @@ static String mutationObserverNotificationString()
auto initialScaleFactor = initialScale();
LOG_WITH_STREAM(PDF, stream << "UnifiedPDFPlugin::updateLayout - on first layout, chose scale for actual size " << initialScaleFactor);
setScaleFactor(initialScaleFactor);

m_documentLayout.setShouldUpdateAutoSizeScale(PDFDocumentLayout::ShouldUpdateAutoSizeScale::No);
}
}

Expand Down Expand Up @@ -2430,9 +2432,10 @@ static bool isContextMenuEvent(const WebMouseEvent& event)
case ContextMenuItemTag::AutoSize:
if (m_documentLayout.shouldUpdateAutoSizeScale() == PDFDocumentLayout::ShouldUpdateAutoSizeScale::No) {
m_documentLayout.setShouldUpdateAutoSizeScale(PDFDocumentLayout::ShouldUpdateAutoSizeScale::Yes);
resetZoom();
setScaleFactor(1.0);
updateLayout();
}
} else
m_documentLayout.setShouldUpdateAutoSizeScale(PDFDocumentLayout::ShouldUpdateAutoSizeScale::No);
break;
case ContextMenuItemTag::WebSearch:
performWebSearch(selectionString());
Expand Down

0 comments on commit 088d359

Please sign in to comment.