<?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>261786</bug_id>
          
          <creation_ts>2023-09-19 17:36:32 -0700</creation_ts>
          <short_desc>requestPointerLock does not cancel existing pointer capture</short_desc>
          <delta_ts>2023-09-21 13:37:02 -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>UI Events</component>
          <version>Safari 17</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 13</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="James Howard">jameshoward</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>a_protyasha</cc>
    
    <cc>jameshoward</cc>
    
    <cc>karlcow</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1978492</commentid>
    <comment_count>0</comment_count>
      <attachid>467769</attachid>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-19 17:36:32 -0700</bug_when>
    <thetext>Created attachment 467769
Fixed version of pointerevent_pointerlock_after_pointercapture.html

See attached test page, which is an adaptation of this wpt: https://github.com/WebKit/WebKit/blob/main/LayoutTests/imported/w3c/web-platform-tests/pointerevents/pointerlock/pointerevent_pointerlock_after_pointercapture.html

The wpt passes because it only verifies that &apos;lostpointercapture&apos; occurs after sending pointerUp({button: actions.ButtonType.LEFT}) to the test driver. But the spec[^1] says that we&apos;re supposed to get lostpointercapture after &apos;pointerlockchange&apos;.

In my modified test, the expected console output is as follows (taken from Chrome 116.0.5845.179):

lostcapture.html:24 setPointerCapture
lostcapture.html:45 got_capture = true
lostcapture.html:38 requestPointerLock
lostcapture.html:55 Pointer lock element:  div1
lostcapture.html:49 lost_capture = true
lostcapture.html:30 pointerup

In STP 176 (Safari 17.0, WebKit 18617.1.3.2), as well as ToT WebKit as of this writing, the output is as follows:

[Log] setPointerCapture (lostcapture.html, line 24)
[Log] got_capture = true (lostcapture.html, line 45)
[Log] requestPointerLock (lostcapture.html, line 38)
[Log] Pointer lock element:  – &quot;div1&quot; (lostcapture.html, line 55)
[Log] pointerup (lostcapture.html, line 30)
[Log] lost_capture = true (lostcapture.html, line 49)

Note that the last two lines are swapped comparing Chromium to WebKit. This is because Chromium is correctly cancelling pointer capture when pointer lock is engaged, but WebKit is only doing it after I lifted the left mouse button, which is unrelated to pointer lock.

[^1]: https://w3c.github.io/pointerevents/#implicit-release-of-pointer-capture</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978499</commentid>
    <comment_count>1</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-19 17:46:03 -0700</bug_when>
    <thetext>Out of curiosity; are other browser engines passing this modified layout test?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978500</commentid>
    <comment_count>2</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-19 17:47:06 -0700</bug_when>
    <thetext>(In reply to Abrar Rahman Protyasha from comment #1)
&gt; Out of curiosity; are other browser engines passing this modified layout
&gt; test?

(it seems like Chromium is; and Gecko?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1978501</commentid>
    <comment_count>3</comment_count>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-19 17:48:42 -0700</bug_when>
    <thetext>Yeah, Gecko passes too (117.0). WebKit is the only one that fails.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979087</commentid>
    <comment_count>4</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-21 11:57:51 -0700</bug_when>
    <thetext>I believe this is a real bug, but without investigating too far, I can say that simply adding a call to `PointerCaptureController::pointerLockWasApplied()` in `PointerLockController::didAcquirePointerLock()` does not fix things. We should look into all possible ways to acquire pointer lock and unify the codepaths where we need to disengage pointer capture.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979094</commentid>
    <comment_count>5</comment_count>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-21 12:16:39 -0700</bug_when>
    <thetext>Yeah I tried the same thing as well.

I don’t think pointerLockWasApplied is doing what it needs to do.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979098</commentid>
    <comment_count>6</comment_count>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-21 12:26:35 -0700</bug_when>
    <thetext>I should note that this bug isn’t a big issue for me personally. I simply found it by code inspection.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979112</commentid>
    <comment_count>7</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-21 13:28:03 -0700</bug_when>
    <thetext>Sure! But is a real bug (and a potential WPT failure) nonetheless, if someone were to change the WPT to be more in-line with the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979115</commentid>
    <comment_count>8</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-21 13:32:11 -0700</bug_when>
    <thetext>(Thanks for catching this, btw!)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979116</commentid>
    <comment_count>9</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-09-21 13:32:42 -0700</bug_when>
    <thetext>&lt;rdar://problem/115857922&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979117</commentid>
    <comment_count>10</comment_count>
    <who name="Abrar Rahman Protyasha">a_protyasha</who>
    <bug_when>2023-09-21 13:33:14 -0700</bug_when>
    <thetext>I&apos;m importing this into our internal bug tracker, but feel free to work on this as you see fit. Just let me know if you&apos;re about to submit a patch so that we don&apos;t duplicate efforts.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979118</commentid>
    <comment_count>11</comment_count>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-21 13:36:40 -0700</bug_when>
    <thetext>Sure if you want to take this I&apos;d appreciate it. I can help review since I&apos;m not familiar with the surrounding code and tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1979119</commentid>
    <comment_count>12</comment_count>
    <who name="James Howard">jameshoward</who>
    <bug_when>2023-09-21 13:37:02 -0700</bug_when>
    <thetext>(In reply to James Howard from comment #11)
&gt; Sure if you want to take this I&apos;d appreciate it. I can help review since I&apos;m
&gt; not familiar with the surrounding code and tests.

err, I am *now* familiar with the surrounding code and tests. :)</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>467769</attachid>
            <date>2023-09-19 17:36:32 -0700</date>
            <delta_ts>2023-09-19 17:36:32 -0700</delta_ts>
            <desc>Fixed version of pointerevent_pointerlock_after_pointercapture.html</desc>
            <filename>lostcapture.html</filename>
            <type>text/html</type>
            <size>3353</size>
            <attacher name="James Howard">jameshoward</attacher>
            
              <data encoding="base64">PCFkb2N0eXBlIGh0bWw+CjxodG1sPgogICAgPGhlYWQ+CiAgICAgICAgPHRpdGxlPlBvaW50ZXIg
RXZlbnRzIHBvaW50ZXIgbG9jayB0ZXN0PC90aXRsZT4KICAgICAgICA8bWV0YSBuYW1lPSJ2aWV3
cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdpZHRoIj4KICAgICAgICA8c2NyaXB0PgogICAg
ICAgICAgICB2YXIgZ290X2NhcHR1cmUgPSBmYWxzZTsKICAgICAgICAgICAgdmFyIGxvc3RfY2Fw
dHVyZSA9IGZhbHNlOwogICAgICAgICAgICB2YXIgbG9ja19yZXF1ZXN0ZWQgPSBmYWxzZTsKCiAg
ICAgICAgICAgIGZ1bmN0aW9uIHJlc2V0VGVzdFN0YXRlKCkgewogICAgICAgICAgICB9CiAgICAg
ICAgICAgIAogICAgICAgICAgICBmdW5jdGlvbiBvbl9ldmVudCh0YXJnZXQsIGV2dCwgY2FsbGJh
Y2spIHsKICAgICAgICAgICAgICAgIHRhcmdldC5hZGRFdmVudExpc3RlbmVyKGV2dCwgY2FsbGJh
Y2spOwogICAgICAgICAgICB9CgogICAgICAgICAgICBmdW5jdGlvbiBydW4oKSB7CiAgICAgICAg
ICAgICAgICB2YXIgZGl2MSA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJkaXYxIik7CiAgICAg
ICAgICAgICAgICB2YXIgZGl2MiA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKCJkaXYyIik7Cgog
ICAgICAgICAgICAgICAgb25fZXZlbnQoZGl2MSwgJ3BvaW50ZXJkb3duJywgZnVuY3Rpb24oZXZl
bnQpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoZXZlbnQuYnV0dG9uID09IDApIHsKICAgICAg
ICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coInNldFBvaW50ZXJDYXB0dXJlIik7CiAgICAg
ICAgICAgICAgICAgICAgICAgIGRpdjIuc2V0UG9pbnRlckNhcHR1cmUoZXZlbnQucG9pbnRlcklk
KTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAg
ICAgIG9uX2V2ZW50KGRpdjEsICdwb2ludGVydXAnLCBmdW5jdGlvbihldmVudCkgewogICAgICAg
ICAgICAgICAgICAgIGlmIChldmVudC5idXR0b24gPT0gMCkgewogICAgICAgICAgICAgICAgICAg
ICAgICBjb25zb2xlLmxvZygicG9pbnRlcnVwIik7CiAgICAgICAgICAgICAgICAgICAgfQogICAg
ICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBvbl9ldmVudChkb2N1bWVudCwgJ2NvbnRl
eHRtZW51JywgZnVuY3Rpb24oZXZlbnQpIHsKICAgICAgICAgICAgICAgICAgICBldmVudC5wcmV2
ZW50RGVmYXVsdCgpOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBvbl9ldmVu
dChkaXYyLCAncG9pbnRlcm1vdmUnLCBmdW5jdGlvbihldmVudCkgewogICAgICAgICAgICAgICAg
ICAgIGlmIChldmVudC5idXR0b24gPT0gMiAmJiBnb3RfY2FwdHVyZSAmJiAhbG9ja19yZXF1ZXN0
ZWQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgY29uc29sZS5sb2coInJlcXVlc3RQb2ludGVy
TG9jayIpOwogICAgICAgICAgICAgICAgICAgICAgICBkaXYxLnJlcXVlc3RQb2ludGVyTG9jaygp
OwogICAgICAgICAgICAgICAgICAgICAgICBsb2NrX3JlcXVlc3RlZCA9IHRydWU7CiAgICAgICAg
ICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgICBvbl9ldmVu
dChkaXYyLCAnZ290cG9pbnRlcmNhcHR1cmUnLCBmdW5jdGlvbihldmVudCkgewogICAgICAgICAg
ICAgICAgICAgIGdvdF9jYXB0dXJlID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICBjb25zb2xl
LmxvZygiZ290X2NhcHR1cmUgPSB0cnVlIik7CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAg
ICAgICAgIG9uX2V2ZW50KGRpdjIsICdsb3N0cG9pbnRlcmNhcHR1cmUnLCBmdW5jdGlvbihldmVu
dCkgewogICAgICAgICAgICAgICAgICAgIGxvc3RfY2FwdHVyZSA9IHRydWU7CiAgICAgICAgICAg
ICAgICAgICAgY29uc29sZS5sb2coImxvc3RfY2FwdHVyZSA9IHRydWUiKTsKICAgICAgICAgICAg
ICAgIH0pOwogICAgICAgICAgICA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