Skip to content

Commit

Permalink
[UnifiedPDF] [visionOS] PDF opening as thumbnail and pushed to the co…
Browse files Browse the repository at this point in the history
…rner of Safari

https://bugs.webkit.org/show_bug.cgi?id=284479
rdar://140186673

Reviewed by Wenson Hsieh.

Safari on visionOS applies a minimum effective device width (mEDW) on
the web view. This makes for a very odd layout size, which results in
the PDF plugin being displayed in a tiny rect.

Unlike regular web content, PDF content does not reflow, and hence does
not require laying out a page at a given minimum width. As such, this
patch chooses to disregard the mEDW when the viewport is configured for
a plugin document.

We do so by adding `shouldHonorMinimumEffectiveDeviceWidthFromClient` to
ViewportConfigration::Parameters, and only setting that to false for
plugin document parameters. This option is consulted when we consider
the new effective width when the view layout size is updated (as part of
mEDW application), and is also consulted during regular viewport
configuration updates where we reset mEDW to 0 if the option is set.

* Source/WebCore/page/ViewportConfiguration.cpp:
(WebCore::ViewportConfiguration::setViewLayoutSize):
(WebCore::ViewportConfiguration::pluginDocumentParameters):
(WebCore::ViewportConfiguration::updateConfiguration):
(WebCore::operator<<):

Add a couple of missing flags in text stream dumping output.

* Source/WebCore/page/ViewportConfiguration.h:

Canonical link: https://commits.webkit.org/287797@main
  • Loading branch information
aprotyas committed Dec 13, 2024
1 parent c660b3c commit a8debe6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Source/WebCore/page/ViewportConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,17 @@ bool ViewportConfiguration::setContentsSize(const IntSize& contentSize)
bool ViewportConfiguration::setViewLayoutSize(const FloatSize& viewLayoutSize, std::optional<double>&& scaleFactor, std::optional<double>&& minimumEffectiveDeviceWidthFromClient)
{
double newScaleFactor = scaleFactor.value_or(m_layoutSizeScaleFactor);
double newEffectiveWidth = minimumEffectiveDeviceWidthFromClient.value_or(m_minimumEffectiveDeviceWidthForView);
double newEffectiveWidth = [&] {
if (!m_configuration.shouldHonorMinimumEffectiveDeviceWidthFromClient)
return m_minimumEffectiveDeviceWidthForView;

if (!minimumEffectiveDeviceWidthFromClient)
return m_minimumEffectiveDeviceWidthForView;

m_minimumEffectiveDeviceWidthWasSetByClient = true;
return *minimumEffectiveDeviceWidthFromClient;
}();

if (m_viewLayoutSize == viewLayoutSize && m_layoutSizeScaleFactor == newScaleFactor && newEffectiveWidth == m_minimumEffectiveDeviceWidthForView)
return false;

Expand Down Expand Up @@ -427,6 +437,7 @@ ViewportConfiguration::Parameters ViewportConfiguration::pluginDocumentParameter
parameters.initialScale = 1;
parameters.initialScaleIgnoringLayoutScaleFactor = 1;
parameters.initialScaleIsSet = true;
parameters.shouldHonorMinimumEffectiveDeviceWidthFromClient = false;
return parameters;
}
#endif
Expand Down Expand Up @@ -537,6 +548,9 @@ void ViewportConfiguration::updateConfiguration()
m_configuration.heightIsSet = viewportArgumentsOverridesHeight;
}

if (!m_configuration.shouldHonorMinimumEffectiveDeviceWidthFromClient && std::exchange(m_minimumEffectiveDeviceWidthWasSetByClient, false))
m_minimumEffectiveDeviceWidthForView = 0;

if (m_configuration.initialScaleIsSet && m_minimumEffectiveDeviceWidthForView > m_viewLayoutSize.width())
m_configuration.ignoreInitialScaleForLayoutWidth = true;

Expand Down Expand Up @@ -717,6 +731,8 @@ TextStream& operator<<(TextStream& ts, const ViewportConfiguration::Parameters&
ts.dumpProperty("allowsUserScaling", parameters.allowsUserScaling);
ts.dumpProperty("allowsShrinkToFit", parameters.allowsShrinkToFit);
ts.dumpProperty("avoidsUnsafeArea", parameters.avoidsUnsafeArea);
ts.dumpProperty("ignoreInitialScaleForLayoutWidth", parameters.ignoreInitialScaleForLayoutWidth);
ts.dumpProperty("shouldHonorMinimumEffectiveDeviceWidthFromClient", parameters.shouldHonorMinimumEffectiveDeviceWidthFromClient);

return ts;
}
Expand Down
3 changes: 3 additions & 0 deletions Source/WebCore/page/ViewportConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class ViewportConfiguration {

bool ignoreInitialScaleForLayoutWidth { false };

bool shouldHonorMinimumEffectiveDeviceWidthFromClient { true };

friend bool operator==(const Parameters&, const Parameters&) = default;
};

Expand Down Expand Up @@ -215,6 +217,7 @@ class ViewportConfiguration {
bool m_isKnownToLayOutWiderThanViewport { false };
bool m_prefersHorizontalScrollingBelowDesktopViewportWidths { false };
bool m_canIgnoreViewportArgumentsToAvoidExcessiveZoom { false };
bool m_minimumEffectiveDeviceWidthWasSetByClient { false };
};

WTF::TextStream& operator<<(WTF::TextStream&, const ViewportConfiguration::Parameters&);
Expand Down

0 comments on commit a8debe6

Please sign in to comment.