Title: [118039] trunk
Revision
118039
Author
[email protected]
Date
2012-05-22 13:26:16 -0700 (Tue, 22 May 2012)

Log Message

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (118038 => 118039)


--- trunk/LayoutTests/ChangeLog	2012-05-22 20:23:44 UTC (rev 118038)
+++ trunk/LayoutTests/ChangeLog	2012-05-22 20:26:16 UTC (rev 118039)
@@ -1,3 +1,15 @@
+2012-05-22  Vitaly Buka  <[email protected]>
+
+        LayoutTest for iframe printing.
+        https://bugs.webkit.org/show_bug.cgi?id=85118
+
+        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.
+
 2012-05-22  Rafael Brandao  <[email protected]>
 
         [Qt] canvas/philip/tests/2d.path.stroke.overlap.html fails with Qt-4.6.2 or higher

Added: trunk/LayoutTests/printing/iframe-print-expected.txt (0 => 118039)


--- trunk/LayoutTests/printing/iframe-print-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/printing/iframe-print-expected.txt	2012-05-22 20:26:16 UTC (rev 118039)
@@ -0,0 +1,38 @@
+layer at (0,0) size 1000x324
+  RenderView at (0,0) size 1000x324
+layer at (0,0) size 1000x324
+  RenderBlock {HTML} at (0,0) size 1000x324
+    RenderBody {BODY} at (8,8) size 984x308
+      RenderPartObject {IFRAME} at (0,200) size 304x104 [border: (2px inset #000000)]
+        layer at (0,0) size 300x100
+          RenderView at (0,0) size 300x100
+        layer at (0,0) size 300x34
+          RenderBlock {HTML} at (0,0) size 300x34
+            RenderBody {BODY} at (8,8) size 284x18
+              RenderText {#text} at (0,0) size 246x18
+                text run at (0,0) width 246: "You should see this text when printed."
+      RenderText {#text} at (304,290) size 4x18
+        text run at (304,290) width 4: " "
+      RenderPartObject {IFRAME} at (308,0) size 304x304 [border: (2px inset #000000)]
+        layer at (0,0) size 300x300
+          RenderView at (0,0) size 300x300
+        layer at (40,0) size 260x300
+          RenderBlock {HTML} at (0,0) size 260x300
+            RenderBody {BODY} at (8,8) size 244x284
+              RenderText {#text} at (0,0) size 18x250
+                text run at (0,0) width 250: "You should see this text when printed. "
+              RenderBR {BR} at (0,249) size 18x1
+              RenderText {#text} at (18,0) size 18x166
+                text run at (18,0) width 166: "Vertical text on the right. "
+              RenderBR {BR} at (18,165) size 18x1
+              RenderPartObject {IFRAME} at (36,0) size 204x154 [border: (2px inset #000000)]
+                layer at (0,0) size 200x150
+                  RenderView at (0,0) size 200x150
+                layer at (0,0) size 200x52
+                  RenderBlock {HTML} at (0,0) size 200x52
+                    RenderBody {BODY} at (8,8) size 184x36
+                      RenderText {#text} at (0,0) size 154x36
+                        text run at (0,0) width 154: "You should see this text"
+                        text run at (0,18) width 88: "when printed."
+              RenderText {#text} at (0,0) size 0x0
+      RenderText {#text} at (0,0) size 0x0

Added: trunk/LayoutTests/printing/iframe-print.html (0 => 118039)


--- trunk/LayoutTests/printing/iframe-print.html	                        (rev 0)
+++ trunk/LayoutTests/printing/iframe-print.html	2012-05-22 20:26:16 UTC (rev 118039)
@@ -0,0 +1,10 @@
+<html>
+<script>
+  if (window.layoutTestController)
+    layoutTestController.setPrinting();
+</script>
+<body>
+  <iframe src="" frameborder="1" height="100"></iframe>
+  <iframe src="" frameborder="1" height="300"></iframe>
+</body>
+</html>

Added: trunk/LayoutTests/printing/resources/iframe-subframe-vertical-rl.html (0 => 118039)


--- trunk/LayoutTests/printing/resources/iframe-subframe-vertical-rl.html	                        (rev 0)
+++ trunk/LayoutTests/printing/resources/iframe-subframe-vertical-rl.html	2012-05-22 20:26:16 UTC (rev 118039)
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html style="-webkit-writing-mode:vertical-rl">
+<body>
+You should see this text when printed.
+<br>
+Vertical text on the right.
+<br>
+<iframe src="" frameborder="1" width="200"></iframe>
+</body>
+</html>

Added: trunk/LayoutTests/printing/resources/iframe-subframe.html (0 => 118039)


--- trunk/LayoutTests/printing/resources/iframe-subframe.html	                        (rev 0)
+++ trunk/LayoutTests/printing/resources/iframe-subframe.html	2012-05-22 20:26:16 UTC (rev 118039)
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+<body>
+You should see this text when printed.
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (118038 => 118039)


--- trunk/Source/WebCore/ChangeLog	2012-05-22 20:23:44 UTC (rev 118038)
+++ trunk/Source/WebCore/ChangeLog	2012-05-22 20:26:16 UTC (rev 118039)
@@ -1,3 +1,31 @@
+2012-05-22  Vitaly Buka  <[email protected]>
+
+        Fix iframe printing.
+        https://bugs.webkit.org/show_bug.cgi?id=85118
+
+        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:
+
 2012-05-22  Rafael Brandao  <[email protected]>
 
         [Qt] canvas/philip/tests/2d.path.stroke.overlap.html fails with Qt-4.6.2 or higher

Modified: trunk/Source/WebCore/page/Frame.cpp (118038 => 118039)


--- trunk/Source/WebCore/page/Frame.cpp	2012-05-22 20:23:44 UTC (rev 118038)
+++ trunk/Source/WebCore/page/Frame.cpp	2012-05-22 20:26:16 UTC (rev 118039)
@@ -522,9 +522,10 @@
     view()->adjustMediaTypeForPrinting(printing);
 
     m_doc->styleResolverChanged(RecalcStyleImmediately);
-    if (printing)
+    if (printing && !tree()->parent()) {
+        // Only root frame should be fit to page size. Subframes should be constrained by parents only.
         view()->forceLayoutForPagination(pageSize, originalPageSize, maximumShrinkRatio, shouldAdjustViewSize);
-    else {
+    } else {
         view()->forceLayout();
         if (shouldAdjustViewSize == AdjustViewSize)
             view()->adjustViewSize();
@@ -542,10 +543,12 @@
         return FloatSize();
 
     if (contentRenderer()->style()->isHorizontalWritingMode()) {
+        ASSERT(fabs(originalSize.width()) > numeric_limits<float>::epsilon());
         float ratio = originalSize.height() / originalSize.width();
         resultSize.setWidth(floorf(expectedSize.width()));
         resultSize.setHeight(floorf(resultSize.width() * ratio));
     } else {
+        ASSERT(fabs(originalSize.height()) > numeric_limits<float>::epsilon());
         float ratio = originalSize.width() / originalSize.height();
         resultSize.setHeight(floorf(expectedSize.height()));
         resultSize.setWidth(floorf(resultSize.height() * ratio));

Modified: trunk/Source/WebCore/rendering/RenderView.cpp (118038 => 118039)


--- trunk/Source/WebCore/rendering/RenderView.cpp	2012-05-22 20:23:44 UTC (rev 118038)
+++ trunk/Source/WebCore/rendering/RenderView.cpp	2012-05-22 20:26:16 UTC (rev 118039)
@@ -84,13 +84,13 @@
 
 void RenderView::computeLogicalHeight()
 {
-    if (!printing() && m_frameView)
+    if (!shouldUsePrintingLayout() && m_frameView)
         setLogicalHeight(viewLogicalHeight());
 }
 
 void RenderView::computeLogicalWidth()
 {
-    if (!printing() && m_frameView)
+    if (!shouldUsePrintingLayout() && m_frameView)
         setLogicalWidth(viewLogicalWidth());
 }
 
@@ -111,11 +111,11 @@
     if (!document()->paginated())
         setPageLogicalHeight(0);
 
-    if (printing())
+    if (shouldUsePrintingLayout())
         m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = logicalWidth();
 
     // Use calcWidth/Height to get the new width/height, since this will take the full page zoom factor into account.
-    bool relayoutChildren = !printing() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
+    bool relayoutChildren = !shouldUsePrintingLayout() && (!m_frameView || width() != viewWidth() || height() != viewHeight());
     if (relayoutChildren) {
         setChildNeedsLayout(true, MarkOnlyThis);
         for (RenderObject* child = firstChild(); child; child = child->nextSibling()) {
@@ -629,6 +629,15 @@
     return document()->printing();
 }
 
+bool RenderView::shouldUsePrintingLayout() const
+{
+    if (!printing() || !m_frameView)
+        return false;
+    Frame* frame = m_frameView->frame();
+    // Only root frame should have special handling for printing.
+    return frame && !frame->tree()->parent();
+}
+
 size_t RenderView::getRetainedWidgets(Vector<RenderWidget*>& renderWidgets)
 {
     size_t size = m_widgets.size();
@@ -693,7 +702,7 @@
 
 LayoutRect RenderView::viewRect() const
 {
-    if (printing())
+    if (shouldUsePrintingLayout())
         return LayoutRect(LayoutPoint(), size());
     if (m_frameView)
         return m_frameView->visibleContentRect();
@@ -733,7 +742,7 @@
 int RenderView::viewHeight() const
 {
     int height = 0;
-    if (!printing() && m_frameView) {
+    if (!shouldUsePrintingLayout() && m_frameView) {
         height = m_frameView->layoutHeight();
         height = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(height)) : height;
     }
@@ -743,7 +752,7 @@
 int RenderView::viewWidth() const
 {
     int width = 0;
-    if (!printing() && m_frameView) {
+    if (!shouldUsePrintingLayout() && m_frameView) {
         width = m_frameView->layoutWidth();
         width = m_frameView->useFixedLayout() ? ceilf(style()->effectiveZoom() * float(width)) : width;
     }

Modified: trunk/Source/WebCore/rendering/RenderView.h (118038 => 118039)


--- trunk/Source/WebCore/rendering/RenderView.h	2012-05-22 20:23:44 UTC (rev 118038)
+++ trunk/Source/WebCore/rendering/RenderView.h	2012-05-22 20:26:16 UTC (rev 118039)
@@ -266,6 +266,8 @@
     OwnPtr<RenderBoxSet> m_fixedPositionedElements;
 
 private:
+    bool shouldUsePrintingLayout() const;
+
     unsigned m_pageLogicalHeight;
     bool m_pageLogicalHeightChanged;
     LayoutState* m_layoutState;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to