Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit a1b29c3

Browse files
Source/WebCore: Fix iframe printing.
https://bugs.webkit.org/show_bug.cgi?id=85118 Patch by Vitaly Buka <[email protected]> on 2012-05-22 Reviewed by Darin Adler, Eric Seidel. Patch fixed two issues by disabling special handling of subframes for printing. 1. Regression. Division by zero when forceLayoutForPagination called for subframes and page sizes set to zero. 2. Old issue. RendererView adjusted layout of subframes for printing and set invalid dimensions. Sometimes it caused missing iframe when printed. Test: printing/iframe-print.html * page/Frame.cpp: (WebCore::Frame::setPrinting): Calls forceLayoutForPagination for root frames only. (WebCore::Frame::resizePageRectsKeepingRatio): Added ASSERTs to catch division by zero. * rendering/RenderView.cpp: Replaced printing() with shouldUsePrintingLayout() for most calls. (WebCore::RenderView::computeLogicalHeight): (WebCore::RenderView::computeLogicalWidth): (WebCore::RenderView::layout): (WebCore::RenderView::shouldUsePrintingLayout): Returns true only if printing enabled and it's a root frame. (WebCore::RenderView::viewRect): (WebCore::RenderView::viewHeight): (WebCore::RenderView::viewWidth): * rendering/RenderView.h: LayoutTests: LayoutTest for iframe printing. https://bugs.webkit.org/show_bug.cgi?id=85118 Patch by Vitaly Buka <[email protected]> on 2012-05-22 Reviewed by Darin Adler, Eric Seidel. * printing/iframe-print-expected.txt: Added. * printing/iframe-print.html: Added. * printing/resources/iframe-subframe-vertical-rl.html: Added. * printing/resources/iframe-subframe.html: Added. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@118039 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent b8f7773 commit a1b29c3

File tree

9 files changed

+127
-9
lines changed

9 files changed

+127
-9
lines changed

LayoutTests/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2012-05-22 Vitaly Buka <[email protected]>
2+
3+
LayoutTest for iframe printing.
4+
https://bugs.webkit.org/show_bug.cgi?id=85118
5+
6+
Reviewed by Darin Adler, Eric Seidel.
7+
8+
* printing/iframe-print-expected.txt: Added.
9+
* printing/iframe-print.html: Added.
10+
* printing/resources/iframe-subframe-vertical-rl.html: Added.
11+
* printing/resources/iframe-subframe.html: Added.
12+
113
2012-05-22 Rafael Brandao <[email protected]>
214

315
[Qt] canvas/philip/tests/2d.path.stroke.overlap.html fails with Qt-4.6.2 or higher
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
layer at (0,0) size 1000x324
2+
RenderView at (0,0) size 1000x324
3+
layer at (0,0) size 1000x324
4+
RenderBlock {HTML} at (0,0) size 1000x324
5+
RenderBody {BODY} at (8,8) size 984x308
6+
RenderPartObject {IFRAME} at (0,200) size 304x104 [border: (2px inset #000000)]
7+
layer at (0,0) size 300x100
8+
RenderView at (0,0) size 300x100
9+
layer at (0,0) size 300x34
10+
RenderBlock {HTML} at (0,0) size 300x34
11+
RenderBody {BODY} at (8,8) size 284x18
12+
RenderText {#text} at (0,0) size 246x18
13+
text run at (0,0) width 246: "You should see this text when printed."
14+
RenderText {#text} at (304,290) size 4x18
15+
text run at (304,290) width 4: " "
16+
RenderPartObject {IFRAME} at (308,0) size 304x304 [border: (2px inset #000000)]
17+
layer at (0,0) size 300x300
18+
RenderView at (0,0) size 300x300
19+
layer at (40,0) size 260x300
20+
RenderBlock {HTML} at (0,0) size 260x300
21+
RenderBody {BODY} at (8,8) size 244x284
22+
RenderText {#text} at (0,0) size 18x250
23+
text run at (0,0) width 250: "You should see this text when printed. "
24+
RenderBR {BR} at (0,249) size 18x1
25+
RenderText {#text} at (18,0) size 18x166
26+
text run at (18,0) width 166: "Vertical text on the right. "
27+
RenderBR {BR} at (18,165) size 18x1
28+
RenderPartObject {IFRAME} at (36,0) size 204x154 [border: (2px inset #000000)]
29+
layer at (0,0) size 200x150
30+
RenderView at (0,0) size 200x150
31+
layer at (0,0) size 200x52
32+
RenderBlock {HTML} at (0,0) size 200x52
33+
RenderBody {BODY} at (8,8) size 184x36
34+
RenderText {#text} at (0,0) size 154x36
35+
text run at (0,0) width 154: "You should see this text"
36+
text run at (0,18) width 88: "when printed."
37+
RenderText {#text} at (0,0) size 0x0
38+
RenderText {#text} at (0,0) size 0x0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<script>
3+
if (window.layoutTestController)
4+
layoutTestController.setPrinting();
5+
</script>
6+
<body>
7+
<iframe src="./resources/iframe-subframe.html" frameborder="1" height="100"></iframe>
8+
<iframe src="./resources/iframe-subframe-vertical-rl.html" frameborder="1" height="300"></iframe>
9+
</body>
10+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html style="-webkit-writing-mode:vertical-rl">
3+
<body>
4+
You should see this text when printed.
5+
<br>
6+
Vertical text on the right.
7+
<br>
8+
<iframe src="./iframe-subframe.html" frameborder="1" width="200"></iframe>
9+
</body>
10+
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
You should see this text when printed.
5+
</body>
6+
</html>

Source/WebCore/ChangeLog

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
2012-05-22 Vitaly Buka <[email protected]>
2+
3+
Fix iframe printing.
4+
https://bugs.webkit.org/show_bug.cgi?id=85118
5+
6+
Reviewed by Darin Adler, Eric Seidel.
7+
8+
Patch fixed two issues by disabling special handling of subframes for printing.
9+
1. Regression. Division by zero when forceLayoutForPagination called for subframes
10+
and page sizes set to zero.
11+
2. Old issue. RendererView adjusted layout of subframes for printing and set invalid
12+
dimensions. Sometimes it caused missing iframe when printed.
13+
14+
Test: printing/iframe-print.html
15+
16+
* page/Frame.cpp:
17+
(WebCore::Frame::setPrinting): Calls forceLayoutForPagination for root frames only.
18+
(WebCore::Frame::resizePageRectsKeepingRatio): Added ASSERTs to catch division by zero.
19+
* rendering/RenderView.cpp: Replaced printing() with shouldUsePrintingLayout() for most calls.
20+
(WebCore::RenderView::computeLogicalHeight):
21+
(WebCore::RenderView::computeLogicalWidth):
22+
(WebCore::RenderView::layout):
23+
(WebCore::RenderView::shouldUsePrintingLayout): Returns true only if printing enabled and it's a root frame.
24+
(WebCore::RenderView::viewRect):
25+
(WebCore::RenderView::viewHeight):
26+
(WebCore::RenderView::viewWidth):
27+
* rendering/RenderView.h:
28+
129
2012-05-22 Rafael Brandao <[email protected]>
230

331
[Qt] canvas/philip/tests/2d.path.stroke.overlap.html fails with Qt-4.6.2 or higher

Source/WebCore/page/Frame.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,10 @@ void Frame::setPrinting(bool printing, const FloatSize& pageSize, const FloatSiz
522522
view()->adjustMediaTypeForPrinting(printing);
523523

524524
m_doc->styleResolverChanged(RecalcStyleImmediately);
525-
if (printing)
525+
if (printing && !tree()->parent()) {
526+
// Only root frame should be fit to page size. Subframes should be constrained by parents only.
526527
view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
527-
else {
528+
} else {
528529
view()->forceLayout();
529530
if (shouldAdjustViewSize == AdjustViewSize)
530531
view()->adjustViewSize();
@@ -542,10 +543,12 @@ FloatSize Frame::resizePageRectsKeepingRatio(const FloatSize& originalSize, cons
542543
return FloatSize();
543544

544545
if (contentRenderer()->style()->isHorizontalWritingMode()) {
546+
ASSERT(fabs(originalSize.width()) > numeric_limits<float>::epsilon());
545547
float ratio = originalSize.height() / originalSize.width();
546548
resultSize.setWidth(floorf(expectedSize.width()));
547549
resultSize.setHeight(floorf(resultSize.width() * ratio));
548550
} else {
551+
ASSERT(fabs(originalSize.height()) > numeric_limits<float>::epsilon());
549552
float ratio = originalSize.width() / originalSize.height();
550553
resultSize.setHeight(floorf(expectedSize.height()));
551554
resultSize.setWidth(floorf(resultSize.height() * ratio));

Source/WebCore/rendering/RenderView.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ bool RenderView::hitTest(const HitTestRequest& request, HitTestResult& result)
8484

8585
void RenderView::computeLogicalHeight()
8686
{
87-
if (!printing() && m_frameView)
87+
if (!shouldUsePrintingLayout() && m_frameView)
8888
setLogicalHeight(viewLogicalHeight());
8989
}
9090

9191
void RenderView::computeLogicalWidth()
9292
{
93-
if (!printing() && m_frameView)
93+
if (!shouldUsePrintingLayout() && m_frameView)
9494
setLogicalWidth(viewLogicalWidth());
9595
}
9696

@@ -111,11 +111,11 @@ void RenderView::layout()
111111
if (!document()->paginated())
112112
setPageLogicalHeight(0);
113113

114-
if (printing())
114+
if (shouldUsePrintingLayout())
115115
m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();
116116

117117
// Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
118-
bool relayoutChildren = !printing() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
118+
bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
119119
if (relayoutChildren) {
120120
setChildNeedsLayout(true, MarkOnlyThis);
121121
for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
@@ -629,6 +629,15 @@ bool RenderView::printing() const
629629
return document()->printing();
630630
}
631631

632+
bool RenderView::shouldUsePrintingLayout() const
633+
{
634+
if (!printing() || !m_frameView)
635+
return false;
636+
Frame* frame = m_frameView->frame();
637+
// Only root frame should have special handling for printing.
638+
return frame && !frame->tree()->parent();
639+
}
640+
632641
size_t RenderView::getRetainedWidgets(Vector<RenderWidget*>& renderWidgets)
633642
{
634643
size_t size = m_widgets.size();
@@ -693,7 +702,7 @@ void RenderView::notifyWidgets(WidgetNotification notification)
693702

694703
LayoutRect RenderView::viewRect() const
695704
{
696-
if (printing())
705+
if (shouldUsePrintingLayout())
697706
return LayoutRect(LayoutPoint(), size());
698707
if (m_frameView)
699708
return m_frameView->visibleContentRect();
@@ -733,7 +742,7 @@ IntRect RenderView::documentRect() const
733742
int RenderView::viewHeight() const
734743
{
735744
int height = 0;
736-
if (!printing() && m_frameView) {
745+
if (!shouldUsePrintingLayout() && m_frameView) {
737746
height = m_frameView->layoutHeight();
738747
height = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(height)) : height;
739748
}
@@ -743,7 +752,7 @@ int RenderView::viewHeight() const
743752
int RenderView::viewWidth() const
744753
{
745754
int width = 0;
746-
if (!printing() && m_frameView) {
755+
if (!shouldUsePrintingLayout() && m_frameView) {
747756
width = m_frameView->layoutWidth();
748757
width = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(width)) : width;
749758
}

Source/WebCore/rendering/RenderView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ class RenderView : public RenderBlock {
266266
OwnPtr<RenderBoxSet> m_fixedPositionedElements;
267267

268268
private:
269+
bool shouldUsePrintingLayout() const;
270+
269271
unsigned m_pageLogicalHeight;
270272
bool m_pageLogicalHeightChanged;
271273
LayoutState* m_layoutState;

0 commit comments

Comments
 (0)