Skip to content

Commit

Permalink
[UnifiedPDF] PDF in style embed renders in the wrong place
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=266750
rdar://119969233

Reviewed by Alan Baradlay.

The UnifiedPDFPlugin's root layer has to be positioned relative to the compositing
layer of the RenderEmbeddedObject, which can be inflated by borders, outlines, padding
and shadows.

RenderLayerBacking knows best how to compute the right offset, so let it position
the plugin's root layer.

* LayoutTests/compositing/plugins/pdf/pdf-in-styled-embed-expected.txt: Added.
* LayoutTests/compositing/plugins/pdf/pdf-in-styled-embed.html: Added.
* Source/WebCore/rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateAfterWidgetResize):
* Source/WebKit/WebProcess/Plugins/PDF/UnifiedPDF/UnifiedPDFPlugin.mm:
(WebKit::UnifiedPDFPlugin::updateLayerHierarchy):

Canonical link: https://commits.webkit.org/272443@main
  • Loading branch information
smfr committed Dec 22, 2023
1 parent 4acf76c commit e353e4f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

(GraphicsLayer
(anchor 0.00 0.00)
(bounds 788.00 805.00)
(children 1
(GraphicsLayer
(bounds 788.00 805.00)
(contentsOpaque 1)
(children 1
(GraphicsLayer
(offsetFromRenderer width=-28 height=-28)
(position 180.00 180.00)
(bounds 436.00 436.00)
(drawsContent 1)
)
)
)
)
)

34 changes: 34 additions & 0 deletions LayoutTests/compositing/plugins/pdf/pdf-in-styled-embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html> <!-- webkit-test-runner [ UnifiedPDFEnabled=true PDFPluginHUDEnabled=false ] -->
<html>
<head>
<style>
embed {
margin: 200px;
width: 300px;
height: 300px;
border: 20px solid silver;
padding: 20px;
box-shadow: 0 0 20px black;
}
</style>
<script src="../../../resources/ui-helper.js"></script>
<script>
if (window.testRunner) {
testRunner.waitUntilDone();
testRunner.dumpAsText();
}
window.addEventListener('load', async () => {
await UIHelper.renderingUpdate();

const layers = document.getElementById('layers');
layers.textContent = internals.layerTreeAsText(document);

testRunner.notifyDone();
}, false);
</script>
</head>
<body>
<embed src="../../../fast/images/resources/green_rectangle.pdf">
<pre id="layers"></pre>
</body>
</html>
5 changes: 3 additions & 2 deletions Source/WebCore/rendering/RenderLayerBacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "GraphicsLayer.h"
#include "HTMLBodyElement.h"
#include "HTMLCanvasElement.h"
#include "HTMLIFrameElement.h"
#include "HTMLModelElement.h"
#include "HTMLNames.h"
#include "HTMLPlugInElement.h"
Expand All @@ -65,7 +64,6 @@
#include "RenderFragmentContainer.h"
#include "RenderFragmentedFlow.h"
#include "RenderHTMLCanvas.h"
#include "RenderIFrame.h"
#include "RenderImage.h"
#include "RenderLayerCompositor.h"
#include "RenderLayerInlines.h"
Expand Down Expand Up @@ -981,6 +979,9 @@ void RenderLayerBacking::updateAfterWidgetResize()
innerCompositor->frameViewDidChangeSize();
innerCompositor->frameViewDidChangeLocation(flooredIntPoint(contentsBox().location()));
}

if (auto* contentsLayer = layerForContents())
contentsLayer->setPosition(flooredIntPoint(contentsBox().location()));
}

void RenderLayerBacking::updateAfterLayout(bool needsClippingUpdate, bool needsFullRepaint)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
{
ensureLayers();

// The m_rootLayer's position is set in RenderLayerBacking::updateAfterWidgetResize().
m_rootLayer->setSize(size());
m_overflowControlsContainer->setSize(size());

Expand Down

0 comments on commit e353e4f

Please sign in to comment.