Skip to content

Commit

Permalink
[UnifiedPDF] Revert back to the fixed-size plugin
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=262831
rdar://116609170

Reviewed by Tim Horton and Chris Dumez.

Undo some of 268697@main so that the UnifiedPDFPlugin once again is a fixed size; in future, it will
scroll internally as the PDFPlugin does.

So simplify the style in `PluginDocumentParser::createStyleElement()` to have the html, body and
embed all be width and height 100%, and make the document non-scrollable. Remove
`pluginFillsViewport()`. Resize the layers when we get `geometryDidChange()`.

Also ensure that the layer tree is updated when the plugin loads the PDF via a call to
`invalidateStyleAndLayerComposition()` in `PluginView::manualLoadDidFinishLoading()`.

Fix a spelling error in "udpateLayerHierarchy".

* Source/WebCore/html/PluginDocument.cpp:
(WebCore::PluginDocumentParser::createStyleElement):
* Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h:
(WebKit::PDFPluginBase::pluginFillsViewport const): Deleted.
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.h:
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::installPDFDocument):
(WebKit::UnifiedPDFPlugin::updateLayerHierarchy):
(WebKit::UnifiedPDFPlugin::deviceScaleFactor const):
(WebKit::UnifiedPDFPlugin::geometryDidChange):
(WebKit::UnifiedPDFPlugin::sizeToFitContents): Deleted.
(WebKit::UnifiedPDFPlugin::udpateLayerHierarchy): Deleted.
* Source/WebKit/WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::PluginView):
(WebKit::PluginView::manualLoadDidFinishLoading):
(WebKit::PluginView::updateDocumentForPluginSizingBehavior): Deleted.

Canonical link: https://commits.webkit.org/269048@main
  • Loading branch information
smfr committed Oct 7, 2023
1 parent c8357fd commit b4ec9b5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 46 deletions.
8 changes: 1 addition & 7 deletions Source/WebCore/html/PluginDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ Ref<HTMLStyleElement> PluginDocumentParser::createStyleElement(Document& documen
{
auto styleElement = HTMLStyleElement::create(document);

constexpr auto styleSheetContents = R"CONTENTS(
html.plugin-fills-viewport, html.plugin-fills-viewport body, html.plugin-fills-viewport embed { width: 100%; height: 100%; }
html.plugin-fills-viewport body { overflow: hidden; }
body { margin: 0; }
embed { width: 100%; }
)CONTENTS"_s;

constexpr auto styleSheetContents = "html, body, embed { width: 100%; height: 100%; }\nbody { margin: 0; overflow: hidden; }\n"_s;
#if PLATFORM(IOS_FAMILY)
constexpr auto bodyBackgroundColorStyle = "body { background-color: rgb(217, 224, 233) }"_s;
#else
Expand Down
2 changes: 0 additions & 2 deletions Source/WebKit/WebProcess/Plugins/PDF/PDFPluginBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class PDFPluginBase : public ThreadSafeRefCounted<PDFPluginBase> {
virtual PlatformLayer* platformLayer() const { return nullptr; }
virtual WebCore::GraphicsLayer* graphicsLayer() const { return nullptr; }

virtual bool pluginFillsViewport() const { return true; }

virtual void setView(PluginView&);

virtual void willDetachRenderer() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay
WebCore::PluginLayerHostingStrategy layerHostingStrategy() const override { return WebCore::PluginLayerHostingStrategy::GraphicsLayer; }
WebCore::GraphicsLayer* graphicsLayer() const override;

bool pluginFillsViewport() const override { return false; }

void teardown() override;

void createPDFDocument() override;
Expand Down Expand Up @@ -87,9 +85,9 @@ class UnifiedPDFPlugin final : public PDFPluginBase, public WebCore::GraphicsLay

// GraphicsLayerClient
void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::FloatRect&, OptionSet<WebCore::GraphicsLayerPaintBehavior>) override;
float deviceScaleFactor() const override;

void sizeToFitContents();
void udpateLayerHierarchy();
void updateLayerHierarchy();

RefPtr<WebCore::GraphicsLayer> createGraphicsLayer(const String& name, GraphicsLayer::Type);

Expand Down
48 changes: 27 additions & 21 deletions Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,7 @@
return;

m_documentLayout.updateLayout(size());
udpateLayerHierarchy();
sizeToFitContents();

m_contentsLayer->setNeedsDisplay();
}

void UnifiedPDFPlugin::sizeToFitContents()
{
auto contentsSize = expandedIntSize(m_documentLayout.scaledContentsSize());

auto& pluginElement = m_view->pluginElement();
pluginElement.setInlineStyleProperty(CSSPropertyHeight, contentsSize.height(), CSSUnitType::CSS_PX);
updateLayerHierarchy();
}

RefPtr<GraphicsLayer> UnifiedPDFPlugin::createGraphicsLayer(const String& name, GraphicsLayer::Type layerType)
Expand All @@ -113,17 +102,24 @@
return graphicsLayer;
}

void UnifiedPDFPlugin::udpateLayerHierarchy()
void UnifiedPDFPlugin::updateLayerHierarchy()
{
m_rootLayer = createGraphicsLayer("UnifiedPDFPlugin root"_s, GraphicsLayer::Type::Normal);
m_rootLayer->setAnchorPoint({ });
if (!m_rootLayer) {
auto rootLayer = createGraphicsLayer("UnifiedPDFPlugin root"_s, GraphicsLayer::Type::Normal);
m_rootLayer = rootLayer.copyRef();
rootLayer->setAnchorPoint({ });
}

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

m_rootLayer->addChild(*m_contentsLayer);
m_contentsLayer->setSize(size());
m_contentsLayer->setNeedsDisplay();
}

void UnifiedPDFPlugin::paintContents(const GraphicsLayer* layer, GraphicsContext& context, const FloatRect& clipRect, OptionSet<GraphicsLayerPaintBehavior>)
Expand Down Expand Up @@ -188,6 +184,16 @@
return 1;
}

float UnifiedPDFPlugin::deviceScaleFactor() const
{
RefPtr frame = m_view->frame();
auto* page = frame->page();
if (!page)
return 1;

return page->deviceScaleFactor();
}

void UnifiedPDFPlugin::geometryDidChange(const IntSize& pluginSize, const AffineTransform& pluginToRootViewTransform)
{
if (size() == pluginSize)
Expand All @@ -196,7 +202,7 @@
PDFPluginBase::geometryDidChange(pluginSize, pluginToRootViewTransform);

m_documentLayout.updateLayout(size());
sizeToFitContents();
updateLayerHierarchy();
}

RetainPtr<PDFDocument> UnifiedPDFPlugin::pdfDocumentForPrinting() const
Expand Down
18 changes: 6 additions & 12 deletions Source/WebKit/WebProcess/Plugins/PluginView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ PluginView::PluginView(HTMLPlugInElement& element, const URL& mainResourceURL, c
, m_pendingResourceRequestTimer(RunLoop::main(), this, &PluginView::pendingResourceRequestTimerFired)
{
m_webPage->addPluginView(*this);
updateDocumentForPluginSizingBehavior();
}

PluginView::~PluginView()
Expand All @@ -256,16 +255,6 @@ LocalFrame* PluginView::frame() const
return m_pluginElement->document().frame();
}

void PluginView::updateDocumentForPluginSizingBehavior()
{
if (!m_plugin->pluginFillsViewport())
return;

RefPtr documentElement = m_pluginElement->document().documentElement();
// The styles in PluginDocumentParser are constructed to respond to this class.
documentElement->setAttributeWithoutSynchronization(HTMLNames::classAttr, "plugin-fills-viewport"_s);
}

void PluginView::manualLoadDidReceiveResponse(const ResourceResponse& response)
{
if (!m_isInitialized) {
Expand Down Expand Up @@ -298,6 +287,11 @@ void PluginView::manualLoadDidFinishLoading()
}

m_plugin->streamDidFinishLoading();

if (layerHostingStrategy() != PluginLayerHostingStrategy::None) {
// This ensures that we update RenderLayers and compositing when the result of RenderEmbeddedObject::requiresLayer() changes.
Ref { m_pluginElement }->invalidateStyleAndLayerComposition();
}
}

void PluginView::manualLoadDidFail()
Expand Down Expand Up @@ -384,7 +378,7 @@ void PluginView::initializePlugin()
#if PLATFORM(COCOA)
if (m_plugin->isComposited() && frame()) {
frame()->view()->enterCompositingMode();
m_pluginElement->invalidateStyleAndLayerComposition();
Ref { m_pluginElement }->invalidateStyleAndLayerComposition();
}
m_plugin->visibilityDidChange(isVisible());
#endif
Expand Down

0 comments on commit b4ec9b5

Please sign in to comment.