Add a persistent, fixed scale factor to make it easy to scale down WK(Web)Views
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 00:27:39 +0000 (00:27 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 00:27:39 +0000 (00:27 +0000)
commit0f2e8419f0e0b1e8a9b0c33f8d2695a3bbcd8a90
tree7bdc02dfce51f66dbc3bf137f3ae0e6f946415f9
parentf5c5c2bca265a929cd7f3d0b453be043369c9929
Add a persistent, fixed scale factor to make it easy to scale down WK(Web)Views
https://bugs.webkit.org/show_bug.cgi?id=143560
<rdar://problem/16302047>

Reviewed by Darin Adler.

Add a new "view" scale factor to WKView and WKWebView.

Unlike page scale (or "magnification" in the API), view scale:
    - persists between page loads
    - persists between Web process crashes
    - is not user adjustable
    - can reliably be < 1

The page scale and view scale are multiplied together whenever we push
a new page scale down into WebCore, so the implementation of view scale
is transparent to WebCore, and acts effectively as a constant multiplier
for the (user-adjustable) page scale factor.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::scaleView):
Add scaleView, which updates our cached viewScaleFactor and pushes it to the Web process.

(WebKit::WebPageProxy::creationParameters):
Plumb viewScaleFactor through the page creation parameters.

* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::viewScaleFactor): Added.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::WebPage):
If the viewScaleFactor is not 1 at creation time, call scalePage with a page scale of 1.
Internally, scalePage will multiply in the viewScaleFactor and push it all to the Web process.

(WebKit::WebPage::scalePage):
Multiply the page scale factor by the view scale factor before passing it to WebCore.

(WebKit::WebPage::scalePageInViewCoordinates):
Early returns need to check the total scale, not just the new page scale.

(WebKit::WebPage::totalScaleFactor):
The scale that we get back from WebCore::Page::pageScaleFactor is the product
of WebKit2's view and page scales. So, here we'll call that the totalScaleFactor.
(Might need a different name because it seems like "total" should include deviceScale too).

(WebKit::WebPage::pageScaleFactor):
WebKit2's notion of the pageScaleFactor does not include the view scale, so
divide it out of WebCore's page scale.

(WebKit::WebPage::scaleView):
Apply a new view scale, maintaining the current scroll position.

* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::viewScaleFactor):
* WebProcess/WebPage/WebPage.messages.in:

* Shared/WebPageCreationParameters.cpp:
(WebKit::WebPageCreationParameters::encode):
(WebKit::WebPageCreationParameters::decode):
* Shared/WebPageCreationParameters.h:
Plumb viewScaleFactor through the page creation parameters.

* UIProcess/API/Cocoa/WKViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _viewScale]):
(-[WKWebView _setViewScale:]):
* UIProcess/API/mac/WKView.mm:
(-[WKView _viewScale]):
(-[WKView _setViewScale:]):
Push the new view scale to WebPage.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _setAutomaticallyComputesFixedLayoutSizeFromViewScale:]):
(-[WKWebView _automaticallyComputesFixedLayoutSizeFromViewScale]):
* UIProcess/API/mac/WKView.mm:
(-[WKView setFrameSize:]):
(-[WKView _updateAutomaticallyComputedFixedLayoutSize]):
(-[WKView _setAutomaticallyComputesFixedLayoutSizeFromViewScale:]):
(-[WKView _automaticallyComputesFixedLayoutSizeFromViewScale]):
* UIProcess/API/mac/WKViewInternal.h:
Add a new layout mode, "DynamicSizeComputedFromViewScale",
which turns on fixed layout size mode, and sets the fixed layout size
based on the view's frame and view scale. The fixed layout size is maintained
as the frame of the view scaled by the inverse of the view scale. This
makes it very easy to maintain a WK(Web)View that is scaled down by
a constant amount, but is laid out as if it were not.

* WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm:
(WebKit::TiledCoreAnimationDrawingArea::adjustTransientZoom):
(WebKit::TiledCoreAnimationDrawingArea::commitTransientZoom):
(WebKit::TiledCoreAnimationDrawingArea::applyTransientZoomToPage):
Because the transient zoom mechanism touches layers that WebCore owns,
it mostly need to operate with totalScaleFactor, because that is what WebCore sees.

* MiniBrowser/mac/BrowserWindowController.h:
* MiniBrowser/mac/MainMenu.xib:
* MiniBrowser/mac/WK1BrowserWindowController.m:
(-[WK1BrowserWindowController setScale:]):
* MiniBrowser/mac/WK2BrowserWindowController.m:
(viewScaleForMenuItemTag):
(-[WK2BrowserWindowController setScale:]):
(-[WK2BrowserWindowController validateMenuItem:]):
Add a submenu with four view scale options: 100%, 75%, 50%, and 25%.
When in use, we resize the window so that the view fits correctly, and
use automaticallyComputesFixedlayoutSizeFromViewScale so that the page's
layout size will not change when scaling down (but will update appropriately
when the view is resized).

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182772 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPageCreationParameters.cpp
Source/WebKit2/Shared/WebPageCreationParameters.h
Source/WebKit2/UIProcess/API/C/WKLayoutMode.h
Source/WebKit2/UIProcess/API/Cocoa/WKViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/_WKLayoutMode.h
Source/WebKit2/UIProcess/API/mac/WKView.mm
Source/WebKit2/UIProcess/API/mac/WKViewInternal.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/mac/TiledCoreAnimationDrawingArea.mm
Tools/ChangeLog
Tools/MiniBrowser/mac/BrowserWindowController.h
Tools/MiniBrowser/mac/MainMenu.xib
Tools/MiniBrowser/mac/WK1BrowserWindowController.m
Tools/MiniBrowser/mac/WK2BrowserWindowController.m