Changeset 225288 in webkit


Ignore:
Timestamp:
Nov 29, 2017 12:41:47 PM (6 years ago)
Author:
Simon Fraser
Message:

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.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225283 r225288  
     12017-11-29  Simon Fraser  <simon.fraser@apple.com>
     2
     3        REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
     4        https://bugs.webkit.org/show_bug.cgi?id=180155
     5        rdar://problem/34220827
     6
     7        Reviewed by Zalan Bujtas.
     8       
     9        When content is loaded in a UIWebView or WKWebView via an HTML string, history().currentItem()
     10        is null so itemAllowsScrollRestoration() would return false, preventing scrolling to anchors.
     11
     12        Fix by allowing scroll restoration if the the history item is null.
     13
     14        Tested by WebKit.NoHistoryItemScrollToFragment API test.
     15
     16        * loader/FrameLoader.cpp:
     17        (WebCore::itemAllowsScrollRestoration):
     18
    1192017-11-29  Chris Dumez  <cdumez@apple.com>
    220
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r225144 r225288  
    28902890static bool itemAllowsScrollRestoration(HistoryItem* historyItem)
    28912891{
    2892     return historyItem && historyItem->shouldRestoreScrollPosition();
     2892    return !historyItem || historyItem->shouldRestoreScrollPosition();
    28932893}
    28942894
  • trunk/Tools/ChangeLog

    r225287 r225288  
     12017-11-29  Simon Fraser  <simon.fraser@apple.com>
     2
     3        REGRESSION (r213590): Scrolling to anchors broken in web views when content loaded via HTML string
     4        https://bugs.webkit.org/show_bug.cgi?id=180155
     5        rdar://problem/34220827
     6
     7        Reviewed by Zalan Bujtas.
     8
     9        API test that loads a page with a relative anchor, and simulates a click to scroll to it.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm:
     13        (TestWebKitAPI::TEST):
     14        * TestWebKitAPI/Tests/WebKit/NoHistoryItemScrollToFragment.mm: Added.
     15        (-[DidScrollToFragmentDelegate _webViewDidScroll:]):
     16        (TestWebKitAPI::TEST):
     17        * TestWebKitAPI/Tests/WebKit/scroll-to-anchor.html: Added.
     18
    1192017-11-29  Ryan Haddad  <ryanhaddad@apple.com>
    220
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r225231 r225288  
    3838                0F3B94A71A77267400DE3272 /* WKWebViewEvaluateJavaScript.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F3B94A51A77266C00DE3272 /* WKWebViewEvaluateJavaScript.mm */; };
    3939                0F4FFA9E1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */; };
     40                0F5651F71FCE4DDC00310FBC /* NoHistoryItemScrollToFragment.mm in Sources */ = {isa = PBXBuildFile; fileRef = 0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */; };
     41                0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */; };
    4042                115EB3431EE0BA03003C2C0A /* ViewportSizeForViewportUnits.mm in Sources */ = {isa = PBXBuildFile; fileRef = 115EB3421EE0B720003C2C0A /* ViewportSizeForViewportUnits.mm */; };
    4143                1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1A02C84B125D4A5E00E3F4BD /* find.html */; };
     
    10031005                                A12DDC001E8373E700CF6CAE /* rendered-image-excluding-overflow.html in Copy Resources */,
    10041006                                F46849C01EEF5EF300B937FE /* rich-and-plain-text.html in Copy Resources */,
     1007                                0F5651F91FCE513500310FBC /* scroll-to-anchor.html in Copy Resources */,
    10051008                                F4D65DA81F5E4704009D8C27 /* selected-text-image-link-and-editable.html in Copy Resources */,
    10061009                                7A66BDB81EAF18D500CCC924 /* set-long-title.html in Copy Resources */,
     
    10721075                0F4FFA9D1ED3AA8500F7111F /* SnapshotViaRenderInContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SnapshotViaRenderInContext.mm; sourceTree = "<group>"; };
    10731076                0F4FFAA01ED3D0DE00F7111F /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
     1077                0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NoHistoryItemScrollToFragment.mm; sourceTree = "<group>"; };
     1078                0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "scroll-to-anchor.html"; sourceTree = "<group>"; };
    10741079                0FC6C4CB141027E0005B7F0C /* RedBlackTree.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RedBlackTree.cpp; sourceTree = "<group>"; };
    10751080                0FC6C4CE141034AD005B7F0C /* MetaAllocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MetaAllocator.cpp; sourceTree = "<group>"; };
     
    25202525                                93F7E86B14DC8E4D00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames.cpp */,
    25212526                                93F7E86E14DC8E5B00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp */,
     2527                                0F5651F61FCE4DDB00310FBC /* NoHistoryItemScrollToFragment.mm */,
    25222528                                7CCB4DA71C83AE7300CC6918 /* PageGroup.cpp */,
    25232529                                BC909779125571AB00083756 /* PageLoadBasic.cpp */,
     
    27082714                                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */,
    27092715                                F6FDDDD514241C48004F1729 /* push-state.html */,
     2716                                0F5651F81FCE50E800310FBC /* scroll-to-anchor.html */,
    27102717                                7A66BDB71EAF150100CCC924 /* set-long-title.html */,
    27112718                                CEBABD481B71687C0051210A /* should-open-external-schemes.html */,
     
    34113418                                7CCE7F041A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutForImages.cpp in Sources */,
    34123419                                7CCE7F051A411AE600447C4C /* NewFirstVisuallyNonEmptyLayoutFrames.cpp in Sources */,
     3420                                0F5651F71FCE4DDC00310FBC /* NoHistoryItemScrollToFragment.mm in Sources */,
    34133421                                2ECFF5551D9B12F800B55394 /* NowPlayingControlsTests.mm in Sources */,
    34143422                                A10F047E1E3AD29C00C95E19 /* NSFileManagerExtras.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/MediaStreamTrackDetached.mm

    r221505 r225288  
    8181
    8282    TestWebKitAPI::Util::run(&hasRecievedCorrectCaptureState);
    83 
    84 
    8583}
    8684
Note: See TracChangeset for help on using the changeset viewer.