2010-02-26 10:40:17 +00:00
|
|
|
// The buffer to store the results. We output the results after all
|
|
|
|
// tests finish. Note that we cannot have a DOM element where the
|
|
|
|
// results are stored in HTMLs because the DOM element to store
|
|
|
|
// results may change the number of pages.
|
|
|
|
var _results = '';
|
|
|
|
var _errored = false;
|
|
|
|
|
|
|
|
function appendResult(result)
|
|
|
|
{
|
|
|
|
_results += '<br>' + result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function pageNumberForElementShouldBe(id, expectedPageNumber)
|
2010-02-09 09:39:16 +00:00
|
|
|
{
|
2012-07-26 07:06:57 +00:00
|
|
|
var actualPageNumber = internals.pageNumber(document.getElementById(id));
|
2010-02-09 09:39:16 +00:00
|
|
|
if (actualPageNumber == expectedPageNumber)
|
2010-02-26 10:40:17 +00:00
|
|
|
appendResult('PASS: page number of "' + id + '" is ' + actualPageNumber);
|
|
|
|
else {
|
|
|
|
appendResult('FAIL: expected page number of "' + id + '" is ' + expectedPageNumber + '. Was ' + actualPageNumber);
|
|
|
|
_errored = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 06:59:49 +00:00
|
|
|
function numberOfPagesShouldBe(expectedNumberOfPages, pageWidthInPixels, pageHeightInPixels)
|
2010-02-26 10:40:17 +00:00
|
|
|
{
|
2010-06-17 06:59:49 +00:00
|
|
|
// pageWidthInPixels and pageHeightInPixels can be omitted. If omitted, 800x600 is used.
|
|
|
|
var actualNumberOfPages;
|
|
|
|
if (pageWidthInPixels && pageHeightInPixels)
|
2012-09-05 11:36:03 +00:00
|
|
|
actualNumberOfPages = internals.numberOfPages(pageWidthInPixels, pageHeightInPixels);
|
2010-06-17 06:59:49 +00:00
|
|
|
else
|
2012-09-05 11:36:03 +00:00
|
|
|
actualNumberOfPages = internals.numberOfPages();
|
2010-06-17 06:59:49 +00:00
|
|
|
|
2010-02-26 10:40:17 +00:00
|
|
|
if (actualNumberOfPages == expectedNumberOfPages)
|
|
|
|
appendResult('PASS: number of pages is ' + actualNumberOfPages);
|
|
|
|
else {
|
|
|
|
appendResult('FAIL: expected number of pages is ' + expectedNumberOfPages + '. Was ' + actualNumberOfPages);
|
|
|
|
_errored = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runPrintingTest(testFunction)
|
|
|
|
{
|
2012-06-15 07:38:37 +00:00
|
|
|
if (window.testRunner) {
|
2010-02-26 10:40:17 +00:00
|
|
|
try {
|
|
|
|
testFunction();
|
|
|
|
} catch (err) {
|
|
|
|
_results += '<p>Exception: ' + err.toString();
|
|
|
|
_errored = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_errored)
|
|
|
|
_results += '<br>All tests passed';
|
|
|
|
} else {
|
2012-06-15 07:38:37 +00:00
|
|
|
_results += 'This test requires testRunner. You can test this manually with the above description.';
|
2010-02-26 10:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var resultElement = document.createElement('p');
|
|
|
|
resultElement.innerHTML = _results;
|
2010-06-17 06:59:49 +00:00
|
|
|
var output = document.getElementById("console") || document.body;
|
|
|
|
output.appendChild(resultElement);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ratioToPageHeightToPixels(heightInRatioToPageHeight)
|
|
|
|
{
|
<rdar://problem/8257783> Short documents may print a second blank page
https://bugs.webkit.org/show_bug.cgi?id=43271
Reviewed by Darin Adler.
WebCore:
Test: printing/stretch-to-view-height.html
* WebCore.exp.in: Export Frame::forceLayoutForPagination(), replacing forceLayoutWithPageWidthRange().
* page/Frame.cpp:
(WebCore::Frame::setPrinting): Now takes a page width and height and a maximum shrink factor and passes
them down to forceLayoutForPagination().
* page/Frame.h:
(WebCore::Frame::):
* page/FrameView.cpp:
(WebCore::FrameView::reset): Initialize m_pageHeight.
(WebCore::FrameView::forceLayoutForPagination): Renamed forceLayoutWithPageWidthRange() to this and
changed it to take a page width and height and a maximum shrink factor. Sets m_pageHeight, which is
queried by RenderBox::calcHeight() during layout. If the given pageHeight is 0, m_pageHeight is set
to the visible height, retaining the behavior before this change.
* page/FrameView.h:
(WebCore::FrameView::pageHeight): Added this accessor.
* page/PrintContext.cpp:
(WebCore::PrintContext::begin): Added a height parameter, used when calling setPrinting().
(WebCore::PrintContext::end): Updated for setPrinting() changes.
(WebCore::PrintContext::pageNumberForElement): Account for shrink-to-fit.
(WebCore::PrintContext::pageProperty): Pass 0 for the height, retaining current behavior.
(WebCore::PrintContext::numberOfPages): Account for shrink-to-fit.
(WebCore::PrintContext::spoolAllPagesWithBoundaries): Pass the page width to begin().
* page/PrintContext.h:
* rendering/RenderBox.cpp:
(WebCore::RenderBox::calcHeight): When printing, use FrameView::pageHeight() as the basis for
viewport-relative heights.
WebKit/mac:
* WebView/WebHTMLView.mm:
(-[WebHTMLView _web_setPrintingModeRecursive]): Updated for additional height parameter
to _setPrinting:minimumPageWidth:height:maximumPageWidth:adjustViewSize:.
(-[WebHTMLView _web_clearPrintingModeRecursive]): Ditto.
(-[WebHTMLView _web_setPrintingModeRecursiveAndAdjustViewSize]): Ditto.
(-[WebHTMLView _beginPrintModeWithPageWidth:height:shrinkToFit:]): Added height parameter,
which is scaled and passed on to _setPrinting:minimumPageWidth:height:maximumPageWidth:adjustViewSize:.
(-[WebHTMLView _endPrintMode]): Updated for additional height parameter to
_setPrinting:minimumPageWidth:height:maximumPageWidth:adjustViewSize:.
(-[WebHTMLView layoutToMinimumPageWidth:height:maximumPageWidth:adjustingViewSize:]): Added
height parameter, which is passed on to FrameView::forceLayoutForPagination().
(-[WebHTMLView layout]): Updated for additional height parameter.
(-[WebHTMLView _setPrinting:minimumPageWidth:height:maximumPageWidth:adjustViewSize:]): Added height
parameter, which is passed on to -layoutToMinimumPageWidth:height:maximumPageWidth:adjustViewSize:.
(-[WebHTMLView adjustPageHeightNew:top:bottom:limit:]): Updated for additional height
parameter.
(-[WebHTMLView setPageWidthForPrinting:]): Ditto.
(-[WebHTMLView knowsPageRange:]): Pass the available height on the page on to
_setPrinting:minimumPageWidth:height:maximumPageWidth:adjustViewSize.
* WebView/WebHTMLViewPrivate.h:
WebKit/win:
* WebFrame.cpp:
(WebFrame::setPrinting): Updated for changes to Frame::setPrinting(). Passing 0 for the
page height, which maintains existing behavior.
LayoutTests:
* platform/mac/printing/media-queries-print-expected.txt:
* printing/page-break-margin-collapsed-expected.txt:
* printing/resources/paged-media-test-utils.js:
(ratioToPageHeightToPixels): Changed to reflect the default shrink factor of 1.25.
* printing/script-tests/stretch-to-view-height.js: Added.
(test):
* printing/stretch-to-view-height-expected.txt: Added.
* printing/stretch-to-view-height.html: Added.
Canonical link: https://commits.webkit.org/55231@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@64409 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2010-07-31 05:59:02 +00:00
|
|
|
var pageHeightInPixels = 600 * 1.25;
|
2010-06-17 06:59:49 +00:00
|
|
|
return Math.floor(pageHeightInPixels * heightInRatioToPageHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBlockWithRatioToPageHeight(id, heightInRatioToPageHeight)
|
|
|
|
{
|
|
|
|
var element = document.createElement("div");
|
|
|
|
element.id = id;
|
|
|
|
element.style.height = ratioToPageHeightToPixels(heightInRatioToPageHeight) + "px";
|
|
|
|
document.getElementById("sandbox").appendChild(element);
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createBlockWithNumberOfLines(id, childLines)
|
|
|
|
{
|
|
|
|
var element = document.createElement("div");
|
|
|
|
element.id = id;
|
|
|
|
for (var i = 0; i < childLines; ++i) {
|
|
|
|
element.appendChild(document.createTextNode("line" + i));
|
|
|
|
element.appendChild(document.createElement("br"));
|
|
|
|
}
|
|
|
|
// Make sure that one page has about 20 lines.
|
|
|
|
element.style.lineHeight = ratioToPageHeightToPixels(0.05) + "px";
|
|
|
|
document.getElementById("sandbox").appendChild(element);
|
|
|
|
return element;
|
2010-02-09 09:39:16 +00:00
|
|
|
}
|