REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded...
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 20:41:47 +0000 (20:41 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 20:41:47 +0000 (20:41 +0000)
commit921940d8a79dd2a3ad6cacbec65cc95dd10ebe1f
tree6f5e31fc9abe8f92baf5f251b1cd9e40660da02e
parente7969ee013a68418df992686481974d3559a0b9c
REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
https://bugs.webkit.org/show_bug.cgi?id=180155
rdar://problem/34220827

Reviewed by Zalan Bujtas.
Source/WebCore:

When content is loaded in a UIWebView or WKWebView via an HTML string, history().currentItem()
is null so itemAllowsScrollRestoration() would return false, preventing scrolling to anchors.

Fix by allowing scroll restoration if the the history item is null.

Tested by WebKit.NoHistoryItemScrollToFragment API test.

* loader/FrameLoader.cpp:
(WebCore::itemAllowsScrollRestoration):

Tools:

API test that loads a page with a relative anchor, and simulates a click to scroll to it.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm: Added.
(-[DidScrollToFragmentDelegate _webViewDidScroll:]):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225288 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/loader/FrameLoader.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm
Tools/TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html [new file with mode: 0644]