[iOS WK2] Presenting an action sheet on an image map prevents selection UI from updating
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Jul 2017 04:01:30 +0000 (04:01 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 16 Jul 2017 04:01:30 +0000 (04:01 +0000)
commit396cf6979786e74f0404d5bba4721b8e265354da
tree2d5a262c065f9c98da77b18d66711155ce221f14
parente180c539be18e0c12ab84661a195ed542fa11612
[iOS WK2] Presenting an action sheet on an image map prevents selection UI from updating
https://bugs.webkit.org/show_bug.cgi?id=174539
<rdar://problem/33307395>

Reviewed by Darin Adler.

Source/WebCore:

Currently, if TextIndicator fails to take a snapshot in TextIndicator::createWithRange, we will enter an
inconsistent state in the web process where Editor will continue to ignore selection changes until the next time
Editor::setIgnoreSelectionChanges(false) is called. This causes us to indefinitely defer EditorState updates to
the UI process, which leads to selection UI appearing unresponsive.

To fix this, we introduce a new TemporarySelectionChange object to simplify selection changes and/or
EditorState-update-ignoring behaviors within the scope of a single function. The constructor applies these
temporary changes, and the destructor reverts them as needed to their prior values.

This patch only adopts TemporarySelectionChange in order to fix this bug, but future patches will replace the
remaining places where we temporarily change selection and/or ignore selection with this helper.

Test: ActionSheetTests.ImageMapDoesNotDestroySelection.

* editing/Editor.cpp:
(WebCore::TemporarySelectionChange::TemporarySelectionChange):
(WebCore::TemporarySelectionChange::~TemporarySelectionChange):
* editing/Editor.h:
* editing/FrameSelection.h:
(WebCore::FrameSelection::isUpdateAppearanceEnabled):
* page/TextIndicator.cpp:
(WebCore::TextIndicator::createWithRange):

Source/WebKit:

Small tweak to avoid presenting at the element rect or text rect if the interaction information failed to
capture valid bounds for the element. We instead fall back to presenting at the touch location. This addresses
problems when presenting the action sheet popover on image maps on iPad, where GetPositionInformation fails to
capture correct data about for the <area>.

* UIProcess/ios/WKActionSheetAssistant.mm:
(presentationStyleForView):

Tools:

Adds a new unit test suite to cover action sheet popover presentation.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/image-map.html: Added.
* TestWebKitAPI/Tests/ios/ActionSheetTests.mm: Added.
(-[ActionSheetObserver waitForActionSheetAfterBlock:]):

Runs the given block and waits until the UI process has indicated that it will present an action sheet.

(-[ActionSheetObserver _webView:actionsForElement:defaultActions:]):
(TestWebKitAPI::IPadUserInterfaceSwizzler::IPadUserInterfaceSwizzler):

Helper class to alter the behavior of [[UIDevice currentDevice] userInterfaceIdiom] for testing.

(TestWebKitAPI::IPadUserInterfaceSwizzler::padUserInterfaceIdiom):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219541 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/editing/Editor.h
Source/WebCore/editing/FrameSelection.h
Source/WebCore/page/TextIndicator.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/WKActionSheetAssistant.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/image-map.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/ios/ActionSheetTests.mm [new file with mode: 0644]