REGRESSION (r242801): [iOS] preventDefault() on touchstart in a subframe does not...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 22:07:07 +0000 (22:07 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 22:07:07 +0000 (22:07 +0000)
commit6f4cc39671c5dafc0eb8fbe2e7c83d57e122fe01
treea9be44d0e3cb75751329b5f1007b8bc1f25bb6c6
parente05971f6fc0df574298f228e390239bb9b5c1598
REGRESSION (r242801): [iOS] preventDefault() on touchstart in a subframe does not prevent focusing the subframe
https://bugs.webkit.org/show_bug.cgi?id=195749
<rdar://problem/48892367>

Reviewed by Tim Horton.

Source/WebKit:

r242801 added logic to fetch interaction information at the touch location upon touch start. However this,
combined with an existing behavior where the process of computing InteractionInformationAtPosition in WebPage
moves focus into the frame of the hit-tested node below the touch location, means that we'll always trigger a
blur event on the window and move focus into the subframe when performing a touch inside a subframe, even if the
page prevents default on touchstart.

To fix this, add a "readonly" flag to InteractionInformationRequest, and only change focus when requesting
position information in the case where the request is not readonly. For now, this readonly flag is false by
default; in a future patch, we should identify the (hopefully few) places that rely on position information
requests to move focus, explicitly turn this bit off in those places, and otherwise send readonly position
information requests by default.

* Shared/ios/InteractionInformationRequest.cpp:
(WebKit::InteractionInformationRequest::encode const):
(WebKit::InteractionInformationRequest::decode):
(WebKit::InteractionInformationRequest::isValidForRequest):
(WebKit::InteractionInformationRequest::isApproximatelyValidForRequest):

Ensure that a readonly request is not valid for a non-readonly request.

* Shared/ios/InteractionInformationRequest.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _requestActivatedElementAtPosition:completionBlock:]):

Send a readonly position information request in the case where a WebKit SPI client is querying for element
information at the given location.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _webTouchEventsRecognized:]):

Send a readonly position information request on touchstart.

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

LayoutTests:

Add a test to verify that tapping a subframe doesn't move focus into it subframe if the page prevents default
on touchstart.

* fast/events/touch/ios/no-focus-change-when-preventing-default-on-touchstart-expected.txt: Added.
* fast/events/touch/ios/no-focus-change-when-preventing-default-on-touchstart.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242968 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/fast/events/touch/ios/no-focus-change-when-preventing-default-on-touchstart-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/touch/ios/no-focus-change-when-preventing-default-on-touchstart.html [new file with mode: 0644]
Source/WebKit/ChangeLog
Source/WebKit/Shared/ios/InteractionInformationRequest.cpp
Source/WebKit/Shared/ios/InteractionInformationRequest.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm