Bug 209715

Summary: scrollIntoView() erroneously scrolls non-containing block scrollers
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: ScrollingAssignee: Simon Fraser (smfr) <simon.fraser>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, esprehn+autocc, ews-watchlist, fred.wang, glenn, kondapallykalyan, pdr, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Testcase
none
Patch
none
Patch
none
Patch
none
Patch
zalan: review+
Patch none

Description Simon Fraser (smfr) 2020-03-28 20:41:28 PDT
Created attachment 394857 [details]
Testcase

RenderLayer::scrollRectToVisible() walks the parent chain and calls scrollIntoView() on each enclosing layer. But this is wrong, because not all parent layers are in the containing block chain.

Attached testcase shows the bug.
Comment 1 Simon Fraser (smfr) 2020-03-28 20:43:28 PDT
Needs to share code with scroll latching ancestor finding.
Comment 2 Simon Fraser (smfr) 2020-03-30 11:46:33 PDT
Created attachment 394941 [details]
Patch
Comment 3 Darin Adler 2020-03-30 13:47:32 PDT
Comment on attachment 394941 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=394941&action=review

> Source/WebCore/rendering/RenderLayer.cpp:1922
> +    for (RenderLayer* nextLayer = enclosingContainingBlockLayer(*this, crossFrameBoundaries);nextLayer; nextLayer = enclosingContainingBlockLayer(*nextLayer, crossFrameBoundaries)) {

Missing space after semicolon. Also, why not use auto instead of type name here?

> Source/WebCore/rendering/RenderLayer.cpp:2896
> +                    auto* enclosingLayer = ownerElement->renderer()->enclosingLayer();
> +                    if (enclosingLayer)

Why not put this inside the if?
Comment 4 Simon Fraser (smfr) 2020-03-30 14:36:25 PDT
Created attachment 394963 [details]
Patch
Comment 5 Simon Fraser (smfr) 2020-03-30 14:38:49 PDT
Created attachment 394964 [details]
Patch
Comment 6 Simon Fraser (smfr) 2020-03-30 14:45:35 PDT
Created attachment 394966 [details]
Patch
Comment 7 Darin Adler 2020-03-30 14:50:47 PDT
Comment on attachment 394966 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=394966&action=review

> Source/WebKitLegacy/win/WebView.cpp:2041
> +        if (m_gestureTargetNode && m_gestureTargetNode->renderer() && m_gestureTargetNode->renderer()->enclosingLayer()) {
> +            if (auto* layer = m_gestureTargetNode->renderer()->enclosingLayer())

Seems like a double null check on enclosingLayer.
Comment 8 Simon Fraser (smfr) 2020-03-30 14:59:46 PDT
(In reply to Darin Adler from comment #7)
> Comment on attachment 394966 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=394966&action=review
> 
> > Source/WebKitLegacy/win/WebView.cpp:2041
> > +        if (m_gestureTargetNode && m_gestureTargetNode->renderer() && m_gestureTargetNode->renderer()->enclosingLayer()) {
> > +            if (auto* layer = m_gestureTargetNode->renderer()->enclosingLayer())
> 
> Seems like a double null check on enclosingLayer.

Oops yeah. Will fix.
Comment 9 Simon Fraser (smfr) 2020-03-30 15:04:43 PDT
Created attachment 394971 [details]
Patch
Comment 10 EWS 2020-03-30 17:03:30 PDT
Committed r259248: <https://trac.webkit.org/changeset/259248>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 394971 [details].
Comment 11 Radar WebKit Bug Importer 2020-03-30 17:08:33 PDT
<rdar://problem/61081100>