<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>179735</bug_id>
          
          <creation_ts>2017-11-15 10:30:10 -0800</creation_ts>
          <short_desc>window.scrollTo is initially unclamped on iOS</short_desc>
          <delta_ts>2020-10-30 14:39:47 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=184297</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ali Juma">ajuma</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>cdumez</cc>
    
    <cc>danyao</cc>
    
    <cc>fred.wang</cc>
    
    <cc>rbuis</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>thorton</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1372011</commentid>
    <comment_count>0</comment_count>
    <who name="Ali Juma">ajuma</who>
    <bug_when>2017-11-15 10:30:10 -0800</bug_when>
    <thetext>The inputs to window.scrollTo aren&apos;t clamped to the min/max scroll positions by WebCore when ScrollView::delegatesScrolling is true, so window.scrollX and window.scrollY return possibly out-of-bounds values until WebCore receives adjusted values from the UI process. For example:

window.scrollTo(0, 1000000);
var scrollPos = window.scrollY;
// scrollPos is 1000000 even if the page is much smaller than that

window.scrollTo(-100, 0);
scrollPos = window.scrollX;
// scrollPos is -100 even though that&apos;s not a valid scroll offset

This behavior comes from the patch for bug 132879, which stopped clamping in ScrollView::setScrollPosition with the justification that the Web process shouldn&apos;t be clamping since it might have stale information.

I wonder if a better approach might be to continue sending an unclamped scroll offset to the UI process, but in the meanwhile use a clamped scroll offset to update FrameView&apos;s scroll position. That would mean changing AsyncScrollingCoordinator::requestScrollPositionUpdate to take both a clamped and an unclamped offset, so that it can use the clamped version for the call to updateScrollPositionAfterAsyncScroll (which is what updates FrameView&apos;s scroll offset).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1372023</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2017-11-15 10:48:45 -0800</bug_when>
    <thetext>Can you attach a testcase that shows the incorrect behavior?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1372057</commentid>
    <comment_count>2</comment_count>
      <attachid>327004</attachid>
    <who name="Ali Juma">ajuma</who>
    <bug_when>2017-11-15 11:48:09 -0800</bug_when>
    <thetext>Created attachment 327004
Test case

Here&apos;s a test page that tries to scroll to an out-of-bounds offset and then outputs the values of scrollX and scrollY.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1398980</commentid>
    <comment_count>3</comment_count>
    <who name="Frédéric Wang Nélar">fred.wang</who>
    <bug_when>2018-02-13 23:07:26 -0800</bug_when>
    <thetext>(In reply to Ali Juma from comment #0)
&gt; I wonder if a better approach might be to continue sending an unclamped
&gt; scroll offset to the UI process, but in the meanwhile use a clamped scroll
&gt; offset to update FrameView&apos;s scroll position. That would mean changing
&gt; AsyncScrollingCoordinator::requestScrollPositionUpdate to take both a
&gt; clamped and an unclamped offset, so that it can use the clamped version for
&gt; the call to updateScrollPositionAfterAsyncScroll (which is what updates
&gt; FrameView&apos;s scroll offset).

@Ali: How about just putting back the clamping for programmatic scroll? i.e.

-    ScrollPosition newScrollPosition = !delegatesScrolling() ? adjustScrollPositionWithinRange(scrollPosition) : scrollPosition;
+    ScrollPosition newScrollPosition = (!delegatesScrolling() || inProgrammaticScroll()) ? adjustScrollPositionWithinRange(scrollPosition) : scrollPosition;

What would be the problem if programmatically-set position overrides the one in the UI process?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1399045</commentid>
    <comment_count>4</comment_count>
    <who name="Ali Juma">ajuma</who>
    <bug_when>2018-02-14 06:28:53 -0800</bug_when>
    <thetext>(In reply to Frédéric Wang (:fredw) from comment #3)
&gt; (In reply to Ali Juma from comment #0)
&gt; &gt; I wonder if a better approach might be to continue sending an unclamped
&gt; &gt; scroll offset to the UI process, but in the meanwhile use a clamped scroll
&gt; &gt; offset to update FrameView&apos;s scroll position. That would mean changing
&gt; &gt; AsyncScrollingCoordinator::requestScrollPositionUpdate to take both a
&gt; &gt; clamped and an unclamped offset, so that it can use the clamped version for
&gt; &gt; the call to updateScrollPositionAfterAsyncScroll (which is what updates
&gt; &gt; FrameView&apos;s scroll offset).
&gt; 
&gt; @Ali: How about just putting back the clamping for programmatic scroll? i.e.
&gt; 
&gt; -    ScrollPosition newScrollPosition = !delegatesScrolling() ?
&gt; adjustScrollPositionWithinRange(scrollPosition) : scrollPosition;
&gt; +    ScrollPosition newScrollPosition = (!delegatesScrolling() ||
&gt; inProgrammaticScroll()) ? adjustScrollPositionWithinRange(scrollPosition) :
&gt; scrollPosition;
&gt; 
&gt; What would be the problem if programmatically-set position overrides the one
&gt; in the UI process?

The problem would be that the WebProcess may not have up-to-date information about the size of the view, so we might clamp incorrectly. For example, the view might have shrunk, increasing the maximum scroll offset. I think you&apos;re right that for JS-driven scroll, we&apos;re fine to clamp since JS can&apos;t make assumptions about when resize happens in the UI, but I&apos;m not sure that extends to all programmatic scrolls, since inProgrammticScroll() seems to be broader than just JS-driven scroll. The use case in the bug that removed the clamping (bug 132879) sounds like a programmatic scroll.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1703213</commentid>
    <comment_count>5</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-10-30 14:39:47 -0700</bug_when>
    <thetext>&lt;rdar://problem/70897654&gt;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>327004</attachid>
            <date>2017-11-15 11:48:09 -0800</date>
            <delta_ts>2017-11-15 11:48:09 -0800</delta_ts>
            <desc>Test case</desc>
            <filename>test-scroll-to.html</filename>
            <type>text/html</type>
            <size>337</size>
            <attacher name="Ali Juma">ajuma</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxzY3JpcHQ+CiAgICB3aW5kb3cub25sb2FkID0gZnVuY3Rpb24oKSB7
CiAgICAgICAgd2luZG93LnNjcm9sbFRvKC0xMDAsIDk5OTk5OSk7CiAgICAgICAgZG9jdW1lbnQu
Z2V0RWxlbWVudEJ5SWQoIm91dHB1dCIpLmlubmVySFRNTCA9CiAgICAgICAgICAgICJ3aW5kb3cu
c2Nyb2xsWDogIiArIHdpbmRvdy5zY3JvbGxYICsKICAgICAgICAgICAgIiwgd2luZG93LnNjcm9s
bFk6ICIgKyB3aW5kb3cuc2Nyb2xsWTsKICAgIH0KPC9zY3JpcHQ+CkFmdGVyIGNhbGxpbmcgd2lu
ZG93LnNjcm9sbFRvKC0xMDAsIDk5OTk5OSksCjxkaXYgaWQ9Im91dHB1dCI+PC9kaXY+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>