Skip to content

Commit

Permalink
[UnifiedPDF] PDFs in <embed> and <object> do not clip
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264622
<rdar://problem/118155018>

Reviewed by Simon Fraser.

* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::updateLayerHierarchy):
Add explicit clipping and scrolling layers.

(WebKit::UnifiedPDFPlugin::didChangeSettings):
Propagate layer border and repaint counter settings when changed.

(WebKit::UnifiedPDFPlugin::didChangeScrollOffset):
Scroll the scrolling layer.

* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
(WebKit::PDFPluginBase::didChangeSettings):
* Source/WebKit/WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::didChangeSettings):
* Source/WebKit/WebProcess/Plugins/PluginView.h:
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
Propagate preference changes to PDFPlugin.

Canonical link: https://commits.webkit.org/270573@main
  • Loading branch information
hortont424 committed Nov 10, 2023
1 parent 42d74b7 commit bd2dbde
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class PDFPluginBase : public ThreadSafeRefCounted<PDFPluginBase>, public WebCore
WebCore::Scrollbar* horizontalScrollbar() const override { return m_horizontalScrollbar.get(); }
WebCore::Scrollbar* verticalScrollbar() const override { return m_verticalScrollbar.get(); }

virtual void didChangeSettings() { }

// HUD Actions.
#if ENABLE(PDF_HUD)
virtual void zoomIn() = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay
void didChangeScrollOffset() override;
void didChangeIsInWindow();

void didChangeSettings() override;

void invalidateScrollbarRect(WebCore::Scrollbar&, const WebCore::IntRect&) override;
void invalidateScrollCornerRect(const WebCore::IntRect&) override;

Expand All @@ -113,7 +115,9 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay

PDFDocumentLayout m_documentLayout;
RefPtr<WebCore::GraphicsLayer> m_rootLayer;
RefPtr<WebCore::GraphicsLayer> m_contentsLayer; // FIXME: Temporary, this will be replaced with a TiledBacking.
RefPtr<WebCore::GraphicsLayer> m_clippingLayer;
RefPtr<WebCore::GraphicsLayer> m_scrollingLayer;
RefPtr<WebCore::GraphicsLayer> m_contentsLayer;
};

} // namespace WebKit
Expand Down
55 changes: 43 additions & 12 deletions Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,55 @@
void UnifiedPDFPlugin::updateLayerHierarchy()
{
if (!m_rootLayer) {
auto rootLayer = createGraphicsLayer("UnifiedPDFPlugin root"_s, GraphicsLayer::Type::Normal);
m_rootLayer = rootLayer.copyRef();
rootLayer->setAnchorPoint({ });
m_rootLayer = createGraphicsLayer("UnifiedPDFPlugin root"_s, GraphicsLayer::Type::Normal);
m_rootLayer->setAnchorPoint({ });
}

if (!m_clippingLayer) {
m_clippingLayer = createGraphicsLayer("UnifiedPDFPlugin clipping"_s, GraphicsLayer::Type::Normal);
m_clippingLayer->setAnchorPoint({ });
m_clippingLayer->setMasksToBounds(true);
m_rootLayer->addChild(*m_clippingLayer);
}

if (!m_scrollingLayer) {
m_scrollingLayer = createGraphicsLayer("UnifiedPDFPlugin scrolling"_s, GraphicsLayer::Type::Normal);
m_scrollingLayer->setAnchorPoint({ });
m_clippingLayer->addChild(*m_scrollingLayer);
}

if (!m_contentsLayer) {
auto contentsLayer = createGraphicsLayer("UnifiedPDFPlugin contents"_s, GraphicsLayer::Type::TiledBacking);
m_contentsLayer = contentsLayer.copyRef();
contentsLayer->setAnchorPoint({ });
contentsLayer->setDrawsContent(true);
didChangeIsInWindow();
m_rootLayer->addChild(*contentsLayer);
m_contentsLayer = createGraphicsLayer("UnifiedPDFPlugin contents"_s, GraphicsLayer::Type::TiledBacking);
m_contentsLayer->setAnchorPoint({ });
m_contentsLayer->setDrawsContent(true);
m_scrollingLayer->addChild(*m_contentsLayer);
}

m_clippingLayer->setSize(size());

m_contentsLayer->setSize(contentsSize());
m_contentsLayer->setNeedsDisplay();

didChangeSettings();
didChangeIsInWindow();
}

void UnifiedPDFPlugin::didChangeSettings()
{
CheckedPtr page = this->page();
if (!page)
return;
Settings& settings = page->settings();
bool showDebugBorders = settings.showDebugBorders();
bool showRepaintCounter = settings.showRepaintCounter();
auto propagateSettingsToLayer = [&] (GraphicsLayer& layer) {
layer.setShowDebugBorder(showDebugBorders);
layer.setShowRepaintCounter(showRepaintCounter);
};
propagateSettingsToLayer(*m_rootLayer);
propagateSettingsToLayer(*m_clippingLayer);
propagateSettingsToLayer(*m_scrollingLayer);
propagateSettingsToLayer(*m_contentsLayer);
}

void UnifiedPDFPlugin::notifyFlushRequired(const GraphicsLayer*)
Expand Down Expand Up @@ -262,9 +295,7 @@

void UnifiedPDFPlugin::didChangeScrollOffset()
{
// FIXME: Build up a layer hierarchy more like that of the root of web content
// instead of randomly moving the contents layer around.
m_contentsLayer->setPosition({ -static_cast<float>(m_scrollOffset.width()), -static_cast<float>(m_scrollOffset.height()) });
m_scrollingLayer->setPosition({ -static_cast<float>(m_scrollOffset.width()), -static_cast<float>(m_scrollOffset.height()) });
scheduleRenderingUpdate();
}

Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PluginView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,11 @@ bool PluginView::isUsingUISideCompositing() const
return m_webPage->isUsingUISideCompositing();
}

void PluginView::didChangeSettings()
{
m_plugin->didChangeSettings();
}

} // namespace WebKit

#endif
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/Plugins/PluginView.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class PluginView final : public WebCore::PluginViewBase {

void invalidateRect(const WebCore::IntRect&) final;

void didChangeSettings();

private:
PluginView(WebCore::HTMLPlugInElement&, const URL&, const String& contentType, bool shouldUseManualLoader, WebPage&);
virtual ~PluginView();
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4624,6 +4624,11 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
#include <WebKitAdditions/WebPageUpdatePreferencesAdditions.cpp>
#endif

#if ENABLE(PDF_PLUGIN)
for (auto& pluginView : m_pluginViews)
pluginView.didChangeSettings();
#endif

m_page->settingsDidChange();
}

Expand Down

0 comments on commit bd2dbde

Please sign in to comment.