[Extra zoom mode] Add a mechanism to zoom to fixed scales when double tapping in...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2018 01:02:53 +0000 (01:02 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 Apr 2018 01:02:53 +0000 (01:02 +0000)
commit3376664b7bab02699f81cc66f013061547ebc410
treeea8b9f9a96d53d7cd9f46b2adf2343639485270a
parent9161bbf081719f4d26c65cecaad03a51da2b2b4f
[Extra zoom mode] Add a mechanism to zoom to fixed scales when double tapping in extra zoom mode
https://bugs.webkit.org/show_bug.cgi?id=184435
<rdar://problem/38726260>

Reviewed by Dean Jackson.

Source/WebCore:

Expose the size of the platform view. By default, in extra zoom mode, this *not* the same as the minimum layout
size, since we lay out at a large width and then shrink down to real device dimensions when computing the
initial scale (see r229063).

ViewGestureGeometryCollector uses this in the process of computing a target zoom scale when double tapping.

* page/ViewportConfiguration.h:
(WebCore::ViewportConfiguration::viewSize const):

Source/WebKit:

Adds support for an alternate codepath when computing a zoom rect when double tapping that doesn't take the hit-
tested node into account, and instead cycles the zoom scale between 2 fixed values (in addition to the initial
scale). In the next patch, these fixed scales will be determined by computing zoom scales needed to make most of
the text on the page legible (i.e. the first text legibility zoom scale), and another to make all of the text on
the page legible, with the exception of outliers (this is the second text legibility zoom scale).

See comments below for more detail.

* UIProcess/Cocoa/ViewGestureController.h:
* UIProcess/Cocoa/ViewGestureController.messages.in:
* UIProcess/ios/SmartMagnificationController.h:
* UIProcess/ios/SmartMagnificationController.messages.in:
* UIProcess/ios/SmartMagnificationController.mm:
(WebKit::SmartMagnificationController::didCollectGeometryForSmartMagnificationGesture):
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::didCollectGeometryForSmartMagnificationGesture):
* WebProcess/WebPage/ViewGestureGeometryCollector.cpp:
(WebKit::ViewGestureGeometryCollector::dispatchDidCollectGeometryForSmartMagnificationGesture):

Rename the boolean `isReplacedElement` argument to `fitEntireRect` instead. The UI process only uses this on iOS
to determine whether or not to fit the entire element rect to the viewport and add padding. This patch renames
this variable because we are not zooming to a replaced element in the case where text legibility on the page
(rather than element geometry) is being used to figure out the zoom scale, but we still want to fit the entire
target rect to the viewport.

(WebKit::ViewGestureGeometryCollector::collectGeometryForSmartMagnificationGesture):

If text legiblity zoom scaling is preferred, then compute first and second-level text legibility zoom scales to
zoom to upon double tap (where the second zoom scale is greater than the first). To choose a target zoom
scale, choose the lowest target zoom scale that is at least a small amount less than the current scale. If
neither of the two scales fulfill this description, then zoom back out to the initial scale. This has the effect
of consistently cycling between all three zoom scales as the user double taps.

(WebKit::ViewGestureGeometryCollector::computeTextLegibilityScales):

Introduce a new helper method that computes and caches target scales to zoom to when double tapping to zoom. If
a cached pair of target scales is already present, it skips this computation and immediately returns it.

(WebKit::ViewGestureGeometryCollector::computeZoomInformationForNode):
(WebKit::ViewGestureGeometryCollector::computeMinimumAndMaximumViewportScales const):

Factor out logic to compute min and max zoom scales into a separate helper, and call it from both
computeZoomInformationForNode and computeTextLegibilityScales.

(WebKit::ViewGestureGeometryCollector::mainFrameDidLayout):

Invalidate cached text legibility scales when layout is triggered.

* WebProcess/WebPage/ViewGestureGeometryCollector.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mainFrameDidLayout):
* WebProcess/WebPage/WebPage.h:
(WebKit::WebPage::viewportConfiguration const):

Expose WebPage's ViewportConfiguration as a const reference.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformPrefersTextLegibilityBasedZoomScaling const):

Adds a platform hook for opting into text-legibility-based zoom scaling instead of regular hit-testing-based
zoom scaling heuristics.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@230506 268f45cc-cd09-0410-ab3c-d52691b4dbfc
14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/ViewportConfiguration.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/ViewGestureController.h
Source/WebKit/UIProcess/Cocoa/ViewGestureController.messages.in
Source/WebKit/UIProcess/ios/SmartMagnificationController.h
Source/WebKit/UIProcess/ios/SmartMagnificationController.messages.in
Source/WebKit/UIProcess/ios/SmartMagnificationController.mm
Source/WebKit/UIProcess/mac/ViewGestureControllerMac.mm
Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.cpp
Source/WebKit/WebProcess/WebPage/ViewGestureGeometryCollector.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKit/WebProcess/WebPage/WebPage.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm