Add @page margin support
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 23:33:41 +0000 (23:33 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 23:33:41 +0000 (23:33 +0000)
commite336831a141b71c02e5f786c452ca40813d36002
treedf61841c8717a6e68703562221c7bf8fc3eb1463
parented4f216bd64b867d09fa3c6ee8159b1804244f30
Add @page margin support
https://bugs.webkit.org/show_bug.cgi?id=196680
<rdar://problem/45217707>

Reviewed by Tim Horton.

Source/WebCore:

This patch adds support for @page margin. This feature is currently behind a runtime flag and is off by default.
We resolve the @page margin values in the WebProcess (currently no pseudo class is supported) and transfer them to the UIProcess through computedPagesCallback.
UIProcess is responsible for applying these new values on the printer. We also re-compute the available width/height for the current printing context
in the WebProcess if needed (see PrintInfo for current printer margins).

Tests: printing/page-with-10mm-left-margin.html
       printing/page-with-zero-margin.html

* page/PrintContext.cpp:
(WebCore::PrintContext::computedPageMargin):
(WebCore::PrintContext::computedPageSize):
* page/PrintContext.h:
* page/RuntimeEnabledFeatures.h:
(WebCore::RuntimeEnabledFeatures::pageAtRuleSupportEnabled const):
(WebCore::RuntimeEnabledFeatures::setPageAtRuleSupportEnabled):

Source/WebKit:

* Shared/PrintInfo.cpp:
(WebKit::PrintInfo::encode const):
(WebKit::PrintInfo::decode):
* Shared/PrintInfo.h:
* Shared/WebPreferences.yaml:
* Shared/gtk/PrintInfoGtk.cpp:
(WebKit::PrintInfo::PrintInfo):
* Shared/mac/PrintInfoMac.mm:
(WebKit::PrintInfo::PrintInfo):
* UIProcess/API/C/WKPage.cpp:
(WKPageComputePagesForPrinting):
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetPageAtRuleSupportEnabled):
(WKPreferencesGetPageAtRuleSupportEnabled):
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* UIProcess/GenericCallback.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::computedPagesCallback):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/WKPrintingView.mm:
(pageDidComputePageRects):
(-[WKPrintingView _askPageToComputePageRects]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::beginPrinting):
(WebKit::WebPage::computePagesForPrinting):
(WebKit::WebPage::computePagesForPrintingImpl):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::computePagesForPrintingAndDrawToPDF):

LayoutTests:

* printing/page-with-10mm-left-margin-expected.pdf: Added.
* printing/page-with-10mm-left-margin.html: Added.
* printing/page-with-zero-margin-expected.pdf: Added.
* printing/page-with-zero-margin.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244202 268f45cc-cd09-0410-ab3c-d52691b4dbfc
26 files changed:
LayoutTests/ChangeLog
LayoutTests/printing/page-with-10mm-left-margin-expected.pdf [new file with mode: 0644]
LayoutTests/printing/page-with-10mm-left-margin-expected.txt [new file with mode: 0644]
LayoutTests/printing/page-with-10mm-left-margin.html [new file with mode: 0644]
LayoutTests/printing/page-with-zero-margin-expected.pdf [new file with mode: 0644]
LayoutTests/printing/page-with-zero-margin-expected.txt [new file with mode: 0644]
LayoutTests/printing/page-with-zero-margin.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/PrintContext.cpp
Source/WebCore/page/PrintContext.h
Source/WebCore/page/RuntimeEnabledFeatures.h
Source/WebKit/ChangeLog
Source/WebKit/Shared/PrintInfo.cpp
Source/WebKit/Shared/PrintInfo.h
Source/WebKit/Shared/WebPreferences.yaml
Source/WebKit/Shared/gtk/PrintInfoGtk.cpp
Source/WebKit/Shared/mac/PrintInfoMac.mm
Source/WebKit/UIProcess/API/C/WKPage.cpp
Source/WebKit/UIProcess/GenericCallback.h
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/UIProcess/WebPageProxy.messages.in
Source/WebKit/UIProcess/mac/WKPrintingView.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm