https://bugs.webkit.org/show_bug.cgi?id=51328
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Jan 2011 18:55:03 +0000 (18:55 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 3 Jan 2011 18:55:03 +0000 (18:55 +0000)
Reviewed by Simon Fraser.

WebCore:

Printing on a page with body { height: 100% } clips out the overflow contents.  This happened
because the computePageRects function was never correct.  It was using the layer's width and height
for the document's width and height, and the layer no longer includes overflow in its width and
height.  It was also incorrectly assuming the first page would begin at (0,0), and this is an invalid
assumption in RTL or vertical text environments.

Added printing/page-count-percentage-height.html

* page/PrintContext.cpp:
(WebCore::PrintContext::computePageRects):
(WebCore::PrintContext::computePageRectsWithPageSizeInternal):

LayoutTests:

Add layout test for printing clipping bug.

* printing/page-count-percentage-height-expected.txt: Added.
* printing/page-count-percentage-height.html: Added.
* printing/script-tests/page-count-percentage-height.js: Added.
(test):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74908 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/printing/page-count-percentage-height-expected.txt [new file with mode: 0644]
LayoutTests/printing/page-count-percentage-height.html [new file with mode: 0644]
LayoutTests/printing/script-tests/page-count-percentage-height.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/page/PrintContext.cpp

index 7d58e34..f7c7238 100644 (file)
@@ -1,3 +1,16 @@
+2011-01-03  David Hyatt  <hyatt@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        https://bugs.webkit.org/show_bug.cgi?id=51328
+
+        Add layout test for printing clipping bug.
+
+        * printing/page-count-percentage-height-expected.txt: Added.
+        * printing/page-count-percentage-height.html: Added.
+        * printing/script-tests/page-count-percentage-height.js: Added.
+        (test):
+
 2011-01-03  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Unreviewed, rolling out unnecessary r74905.
diff --git a/LayoutTests/printing/page-count-percentage-height-expected.txt b/LayoutTests/printing/page-count-percentage-height-expected.txt
new file mode 100644 (file)
index 0000000..7fde3da
--- /dev/null
@@ -0,0 +1,15 @@
+Test to make sure 2nd page is printed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+PASS: page number of "page1" is 0
+PASS: page number of "page2" is 1
+PASS: number of pages is 2
+All tests passed
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/printing/page-count-percentage-height.html b/LayoutTests/printing/page-count-percentage-height.html
new file mode 100644 (file)
index 0000000..215aecc
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/paged-media-test-utils.js"></script>
+<style>
+body { height: 100% }
+</style>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<div id="sandbox"></div>
+<script src="script-tests/page-count-percentage-height.js"></script>
+<script>runPrintingTest(test);</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/printing/script-tests/page-count-percentage-height.js b/LayoutTests/printing/script-tests/page-count-percentage-height.js
new file mode 100644 (file)
index 0000000..f9ef4f0
--- /dev/null
@@ -0,0 +1,16 @@
+description("Test to make sure 2nd page is printed.");
+
+function test()
+{
+    createBlockWithRatioToPageHeight("page1", 1);
+    createBlockWithRatioToPageHeight("page2", 0.5);
+
+    pageNumberForElementShouldBe("page1", 0);
+    pageNumberForElementShouldBe("page2", 1);
+    
+    numberOfPagesShouldBe(2);
+
+    document.body.removeChild(document.getElementById("sandbox"));
+}
+
+var successfullyParsed = true;
index 9c8b73d..db3efe3 100644 (file)
@@ -1,3 +1,21 @@
+2011-01-03  David Hyatt  <hyatt@apple.com>
+
+        Reviewed by Simon Fraser.
+
+        https://bugs.webkit.org/show_bug.cgi?id=51328
+
+        Printing on a page with body { height: 100% } clips out the overflow contents.  This happened
+        because the computePageRects function was never correct.  It was using the layer's width and height
+        for the document's width and height, and the layer no longer includes overflow in its width and
+        height.  It was also incorrectly assuming the first page would begin at (0,0), and this is an invalid
+        assumption in RTL or vertical text environments.
+
+        Added printing/page-count-percentage-height.html
+
+        * page/PrintContext.cpp:
+        (WebCore::PrintContext::computePageRects):
+        (WebCore::PrintContext::computePageRectsWithPageSizeInternal):
+
 2011-01-03  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [Qt] Unreviewed buildfix for --minimal build after r74895.
index 7acca96..f051ead 100644 (file)
@@ -68,11 +68,11 @@ void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
         return;
     }
 
-    RenderView* root = toRenderView(m_frame->document()->renderer());
+    RenderView* view = toRenderView(m_frame->document()->renderer());
 
     float ratio = printRect.height() / printRect.width();
 
-    float pageWidth  = (float)root->rightLayoutOverflow();
+    float pageWidth  = view->docWidth();
     float pageHeight = pageWidth * ratio;
     outPageHeight = pageHeight; // this is the height of the page adjusted by margins
     pageHeight -= headerHeight + footerHeight;
@@ -96,20 +96,20 @@ void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
     if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer())
         return;
 
-    RenderView* root = toRenderView(m_frame->document()->renderer());
+    RenderView* view = toRenderView(m_frame->document()->renderer());
+
+    IntRect docRect = view->documentRect();
 
-    int docWidth = root->layer()->width();
-    int docHeight = root->layer()->height();
     int pageWidth = pageSizeInPixels.width();
     int pageHeight = pageSizeInPixels.height();
 
-    unsigned pageCount = ceilf((float)docHeight / pageHeight);
+    unsigned pageCount = ceilf((float)docRect.height() / pageHeight);
     for (unsigned i = 0; i < pageCount; ++i) {
         if (allowHorizontalMultiPages) {
-            for (int currWidth = 0; currWidth < docWidth; currWidth += pageWidth)
-                m_pageRects.append(IntRect(currWidth, i * pageHeight, pageWidth, pageHeight));
+            for (int currentX = docRect.x(); currentX < docRect.right(); currentX += pageWidth)
+                m_pageRects.append(IntRect(currentX, docRect.y() + i * pageHeight, pageWidth, pageHeight));
         } else
-            m_pageRects.append(IntRect(0, i * pageHeight, pageWidth, pageHeight));
+            m_pageRects.append(IntRect(docRect.x(), docRect.y() + i * pageHeight, pageWidth, pageHeight));
     }
 }