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

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>24923</bug_id>
          
          <creation_ts>2014-03-04 21:58:53 +0000</creation_ts>
          <short_desc>What should happen to the mouse events if pointer event listener removes the target from document or hides it?</short_desc>
          <delta_ts>2014-06-04 02:34:13 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>PointerEventsWG</product>
          <component>Pointer Events specification</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Olli Pettay">bugs</reporter>
          <assigned_to name="Jacob Rossi [MSFT]">jrossi</assigned_to>
          <cc>public-pointer-events</cc>
    
    <cc>rbyers</cc>
    
    <cc>redux</cc>
    
    <cc>scott.gonzalez</cc>
          
          <qa_contact name="Pointer Events Bugzilla list">public-pointer-events-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>101858</commentid>
    <comment_count>0</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-04 21:58:53 +0000</bug_when>
    <thetext>Per spec mouse events should be fired after pointer events, but it doesn&apos;t
talk about the target.
Should mouse events be targeted based on coordinates, or should they
use the same target as what the relevant pointer event had?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101860</commentid>
    <comment_count>1</comment_count>
      <attachid>1447</attachid>
    <who name="Patrick H. Lauke">redux</who>
    <bug_when>2014-03-04 22:06:09 +0000</bug_when>
    <thetext>Created attachment 1447
pointerdown removes e.target, mousedown never gets called</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101862</commentid>
    <comment_count>2</comment_count>
      <attachid>1448</attachid>
    <who name="Patrick H. Lauke">redux</who>
    <bug_when>2014-03-04 22:15:04 +0000</bug_when>
    <thetext>Created attachment 1448
pointerdown removes e.target, what about mousedown?

added little test file. in IE11, once the button is removed following pointerdown, the mousedown event is still being fired at the parent div and bubbles up to window.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101863</commentid>
    <comment_count>3</comment_count>
    <who name="Patrick H. Lauke">redux</who>
    <bug_when>2014-03-04 22:16:54 +0000</bug_when>
    <thetext>i would have actually expected that the compatibility mouse event silently vanishes into thin air in the case where the target of the pointer event suddenly disappears...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101895</commentid>
    <comment_count>4</comment_count>
    <who name="Scott González">scott.gonzalez</who>
    <bug_when>2014-03-05 13:17:59 +0000</bug_when>
    <thetext>If the compatibility mouse event silently vanished, it could break a pretty common pattern. Because mouse events don&apos;t have pointer capture, it&apos;s common to implement dragging behaviors by binding a mousedown handler on a specific element, but then binding mousemove and mouseup handlers on the document and removing them on mouseup. This pattern already breaks if you move your mouse out of the window before the mouseup, but I don&apos;t think we want to introduce another scenario where this can break.

I haven&apos;t spent enough time thinking about how such code would be interacting with newer code that&apos;s leveraging pointer events, but I&apos;m sure the mixture is going to happen quite a bit over the next few years.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101906</commentid>
    <comment_count>5</comment_count>
    <who name="Rick Byers">rbyers</who>
    <bug_when>2014-03-05 16:37:45 +0000</bug_when>
    <thetext>Interesting, I assumed we wouldn&apos;t repeat the hit test (and so use the same target as the pointer event).  Even if the element isn&apos;t removed the difference is still observable - eg. what if you pointerdown on something while it&apos;s animating, and by the time the pointerdown handler finishes (and mousedown is dispatched) there&apos;s a new element under the cursor?  If we do a new hit test then it might cause surprises (code seeing only pointer or mouse events when you&apos;d normally see both).

Scott, doesn&apos;t the scenario you describe also come up with mouse-only events when an element is removed while a mousemove is being dispatched to it?  That mousemove will never bubble up to the document, but in most cases you&apos;ll get another mousemove shortly.  Personally I think UAs should be dispatching a fake mousemove when the DOM element under the mouse cursor changes (we&apos;ve got a bug for this in blink - I don&apos;t think we do it reliably today but I&apos;m planning on getting it improved). Anyway, I don&apos;t think the compat mouse event issue with pointer events necessarily makes things any worse.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101911</commentid>
    <comment_count>6</comment_count>
    <who name="Scott González">scott.gonzalez</who>
    <bug_when>2014-03-05 18:29:24 +0000</bug_when>
    <thetext>Rick: Yes, the same issue would occur if the element was removed during a mousemove, but that&apos;s not going to be nearly as common. Elements will generally be removed at the end of an interaction sequence (during the release of the button). Developers quickly understand if you say that removing an element in the middle of an interaction is going to break something, but it&apos;s harder to explain if it occurs after they&apos;ve finished the interaction.

Regarding firing of fake mousemove events when the DOM changes, here&apos;s a test page I created a year ago: http://dev-test.nemikor.com/behavior/mouseover-when-element-is-shown.html. I discussed this with Jacob and Olli back then, but if we&apos;re going to address it at this level, I think we should try to get this into the mouse events spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101913</commentid>
    <comment_count>7</comment_count>
    <who name="Rick Byers">rbyers</who>
    <bug_when>2014-03-05 19:26:06 +0000</bug_when>
    <thetext>Ah, so you&apos;re mainly worried about removal during a pointerdown event breaking someone that&apos;s waiting for the mousedown event?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101914</commentid>
    <comment_count>8</comment_count>
    <who name="Scott González">scott.gonzalez</who>
    <bug_when>2014-03-05 19:38:14 +0000</bug_when>
    <thetext>My biggest concern is removal during a pointerup event breaking someone that&apos;s waiting for the mouseup event (which was likely bound to the document during the mousedown event). I would expect the target to be the same for the mouse event and the pointer event, but IE&apos;s behavior is better than Patrick&apos;s expectation of the event just vanishing because it would break less code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102169</commentid>
    <comment_count>9</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-10 22:01:55 +0000</bug_when>
    <thetext>(In reply to Scott González from comment #6)
&gt; but if we&apos;re going to address
&gt; it at this level, I think we should try to get this into the mouse events
&gt; spec.

This is a pointer events spec issue, about how legacy mouse events should
be dispatched and when.
I don&apos;t see a reason to handle this is mouse events spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102170</commentid>
    <comment_count>10</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-10 22:03:31 +0000</bug_when>
    <thetext>(In reply to Scott González from comment #6)
&gt; Rick: Yes, the same issue would occur if the element was removed during a
&gt; mousemove,
What is the issue there? Event target chain is created before
event dispatch.

This bug is about what should happen to the legacy mouse event.
Where should it be dispatched and when.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102190</commentid>
    <comment_count>11</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-03-11 05:39:40 +0000</bug_when>
    <thetext>I strongly want to avoid hit testing again for compatibility mouse events. Primarily for perf reasons, but also because we saw developer confusion when pointer* and mouse* didn&apos;t go to the same element (an early preview of IE10 behaved this way).

This behavior is defined at the top of the section:

&quot;Unless otherwise noted, the target of any mapped mouse event MAY be the same as the target for the pointer event from which it was mapped.&quot;

(MAY is used here as the entire section is optional)

Now, in the case of node removal, IE will fix up the target to its parent in the propagation path of the event.  This works well with most coding patterns similar to what Scott describes. In the case that the mouseup handler is on the node removed...we&apos;ll, I think you shot yourself in the foot. :-)

Do we want spec text to describe this fix up behavior?  I apologize that this nuance was left out of our spec proposal (this scenario doesn&apos;t come up often).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102198</commentid>
    <comment_count>12</comment_count>
    <who name="Patrick H. Lauke">redux</who>
    <bug_when>2014-03-11 10:07:01 +0000</bug_when>
    <thetext>JR: &quot;Do we want spec text to describe this fix up behavior?&quot;

I&apos;m all for making the spec as explicit as possible to avoid surprises and possible implementation divergence...so I&apos;d favor something in the spec. I&apos;d propose something like:

- add a break in the first paragraph of section 11, so that &quot;Unless otherwise...&quot; beings a new paragraph.
- at the end of the &quot;Unless...&quot; sentence, add something along the lines of &quot;If the target of the pointer event is removed from the document before the relevant compatibility mouse event is fired, the compatibility mouse event MAY be fired on the parent of the original target.&quot;

Admittedly a mouthful and a bit awkward, but hopefully clear enough?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102202</commentid>
    <comment_count>13</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-11 12:48:16 +0000</bug_when>
    <thetext>(In reply to Jacob Rossi [MSFT] from comment #11)
&gt; &quot;Unless otherwise noted, the target of any mapped mouse event MAY be the
&gt; same as the target for the pointer event from which it was mapped.&quot;
We have to remove such MAY then. If the section is implemented, it should
be implemented in MUST-way


&gt; Now, in the case of node removal, IE will fix up the target to its parent in
&gt; the propagation path of the event. 
So IE actually stores the event target chain for pointer event are reuses
(part of) it for mouse events? What if target, and its parent are removed?
What if target or its parent are moved to another document?


&gt; Do we want spec text to describe this fix up behavior? 
I think not doing hit testing is ok (since it is indeed odd if pointer event
happens on a different element than mouse event), but we need explain
exactly also what the target of the mouse event should be when the target
(or any of its ancestors) of the pointer event is removed from the tree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102497</commentid>
    <comment_count>14</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-17 20:00:54 +0000</bug_when>
    <thetext>Has anyone had time to test this some more on IE11?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102506</commentid>
    <comment_count>15</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-03-17 21:16:42 +0000</bug_when>
    <thetext>I just looked more into this. The initial event path is built from the target node. If the target node is removed (whether by itself or as a part of a larger sub-tree removal, whether removed or simply moved elsewhere in the document or to another document), then the corresponding compatibility mouse event path is built from the nearest ancestor in the initial event path that is still in the tree.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102507</commentid>
    <comment_count>16</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-03-17 21:22:28 +0000</bug_when>
    <thetext>Being a little more algorithmic in the description:

1. Hit test to determine target for pointer event. Store this as the &quot;Hit Node&quot;.
2. Build (and lock) an event path, based on Hit Node.
3. Dispatch pointer event.
4. Build (and lock) an event path for the compat mouse event, based on Hit Node.
5. Dispatch the mouse event.

Then, in our code path for elements leaving the tree, if the element leaving the tree is Hit Node then Hit Node is updated (at the time of removal) to the nearest in-tree ancestor (which is the same as nearest in-tree ancestor from the event path in step 2).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102510</commentid>
    <comment_count>17</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-17 21:33:40 +0000</bug_when>
    <thetext>So it can go all the way up to Document object if document.documentElement is removed from document or something?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102512</commentid>
    <comment_count>18</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-03-17 21:42:52 +0000</bug_when>
    <thetext>Yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102513</commentid>
    <comment_count>19</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2014-03-17 21:51:06 +0000</bug_when>
    <thetext>Also, what happens if the element to which pointerevent was dispatched
changed style to display: none before mouse event dispatch?



(I think using the nearest non-moved ancestor should be fine, and just not care
about layout. )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102514</commentid>
    <comment_count>20</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-03-17 21:54:51 +0000</bug_when>
    <thetext>Style changes do not affect the event path. The mouse event is still dispatched to the original target.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107176</commentid>
    <comment_count>21</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-06-03 05:37:53 +0000</bug_when>
    <thetext>As asked in Action-98, I think this is the simplest change to describe this behavior:

https://dvcs.w3.org/hg/pointerevents/rev/f07f819eaf5e

Feedback welcomed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107178</commentid>
    <comment_count>22</comment_count>
    <who name="Patrick H. Lauke">redux</who>
    <bug_when>2014-06-03 06:40:40 +0000</bug_when>
    <thetext>combining my suggestions from the mailing list - and some additional note about the event path thing - here, I&apos;d suggest changing the second line from

&lt;p&gt;Unless otherwise noted, the target of any mapped mouse event SHOULD be the same target as the respective pointer event unless the target is no longer participating in its &lt;code&gt;ownerDocument&lt;/code&gt;&apos;s tree. In this case, the mouse event should be fired at the original target&apos;s parent node at the time it left the tree (meaning, a new even path is built for the mouse event).&lt;/p&gt;

to

&lt;p&gt;Unless otherwise noted, the target of any mapped mouse event SHOULD be the same target as the respective pointer event, unless the target is no longer participating in its &lt;code&gt;ownerDocument&lt;/code&gt;&apos;s tree. In this case, the mouse event should be fired at the original target&apos;s nearest ancestor node (at the time it was removed from the tree), meaning that a new event path (based on the original path) is built for the mouse event.&lt;/p&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107200</commentid>
    <comment_count>23</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-06-03 13:13:03 +0000</bug_when>
    <thetext>I agree with your suggestion. In particular, the change to &quot;nearest ancestor node&quot; to cover the subtree removal case. However, I would change &quot;(based on the original path)&quot; to &quot;(based on the new target node)&quot;.  The former sounds like the original path is to be used as an input into the event path creation algorithm in some special way. Really you&apos;re just building a brand new path using the newly found target node.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>107231</commentid>
    <comment_count>24</comment_count>
    <who name="Jacob Rossi [MSFT]">jrossi</who>
    <bug_when>2014-06-04 02:34:13 +0000</bug_when>
    <thetext>Updated in this change: https://dvcs.w3.org/hg/pointerevents/rev/5b06a2e374b7

&quot;In this case, the mouse event should be fired at the original target&apos;s nearest ancestor node (at the time it was removed from the tree) that still participates in its ownerDocument&apos;s tree, meaning that a new event path (based on the new target node) is built for the mouse event.&quot;</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1447</attachid>
            <date>2014-03-04 22:06:09 +0000</date>
            <delta_ts>2014-03-04 22:11:09 +0000</delta_ts>
            <desc>pointerdown removes e.target, mousedown never gets called</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>379</size>
            <attacher name="Patrick H. Lauke">redux</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+DQo8dGl0bGU+QnVnIDI0OTIzIHRlc3Q8L3RpdGxlPg0KPGJ1dHRvbj5U
ZXN0PC9idXR0b24+DQo8c2NyaXB0Pg0KdmFyIGIgPSBkb2N1bWVudC5nZXRFbGVtZW50c0J5VGFn
TmFtZSgnYnV0dG9uJylbMF07DQpiLmFkZEV2ZW50TGlzdGVuZXIoJ3BvaW50ZXJkb3duJywgZnVu
Y3Rpb24oZSkgew0KCWNvbnNvbGUubG9nKCdwb2ludGVyZG93biBmaXJlZCcpOw0KCS8vIGUudGFy
Z2V0LnBhcmVudE5vZGUucmVtb3ZlQ2hpbGQoZS50YXJnZXQpOw0KfSwgdHJ1ZSk7DQpiLmFkZEV2
ZW50TGlzdGVuZXIoJ21vdXNlZG93bicsIGZ1bmN0aW9uKGUpIHsNCgljb25zb2xlLmxvZygnbW91
c2Vkb3duIGZpcmVkJyk7DQp9LCB0cnVlKTsNCjwvc2NyaXB0Pg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>1448</attachid>
            <date>2014-03-04 22:15:04 +0000</date>
            <delta_ts>2014-03-04 22:15:04 +0000</delta_ts>
            <desc>pointerdown removes e.target, what about mousedown?</desc>
            <filename>test.html</filename>
            <type>text/html</type>
            <size>672</size>
            <attacher name="Patrick H. Lauke">redux</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+DQo8dGl0bGU+QnVnIDI0OTIzIHRlc3Q8L3RpdGxlPg0KPGRpdj48YnV0
dG9uPlRlc3Q8L2J1dHRvbj48L2Rpdj4NCjxzY3JpcHQ+DQp2YXIgYiA9IGRvY3VtZW50LmdldEVs
ZW1lbnRzQnlUYWdOYW1lKCdidXR0b24nKVswXTsNCnZhciBkID0gZG9jdW1lbnQuZ2V0RWxlbWVu
dHNCeVRhZ05hbWUoJ2RpdicpWzBdOw0KYi5hZGRFdmVudExpc3RlbmVyKCdwb2ludGVyZG93bics
IGZ1bmN0aW9uKGUpIHsNCgljb25zb2xlLmxvZygncG9pbnRlcmRvd24gZmlyZWQnKTsNCgllLnRh
cmdldC5wYXJlbnROb2RlLnJlbW92ZUNoaWxkKGUudGFyZ2V0KTsNCn0sIGZhbHNlKTsNCmIuYWRk
RXZlbnRMaXN0ZW5lcignbW91c2Vkb3duJywgZnVuY3Rpb24oZSkgew0KCWNvbnNvbGUubG9nKCdt
b3VzZWRvd24gZmlyZWQnKTsNCn0sIGZhbHNlKTsNCmQuYWRkRXZlbnRMaXN0ZW5lcignbW91c2Vk
b3duJywgZnVuY3Rpb24oZSkgew0KCWNvbnNvbGUubG9nKCdtb3VzZWRvd24gb24gcGFyZW50IGRp
diBmaXJlZCcpOw0KfSwgZmFsc2UpOw0Kd2luZG93LmFkZEV2ZW50TGlzdGVuZXIoJ21vdXNlZG93
bicsIGZ1bmN0aW9uKGUpIHsNCgljb25zb2xlLmxvZygnbW91c2Vkb3duIG9uIHdpbmRvdyBmaXJl
ZCcpOw0KCWNvbnNvbGUuZGlyKGUpOw0KfSwgZmFsc2UpOw0KPC9zY3JpcHQ+
</data>

          </attachment>
      

    </bug>

</bugzilla>