WebKit currently fires click event even on a node that was removed or once removed from its document during mouseup event. However, both Firefox and Internet Explorer do NOT fire click event in such cases. We should match WebKit's behavior to those two browsers to be consistent.
See discussions on http://lists.w3.org/Archives/Public/www-dom/2011AprJun/0058.html
Created attachment 93063 [details] fixes the bug
Comment on attachment 93063 [details] fixes the bug View in context: https://bugs.webkit.org/attachment.cgi?id=93063&action=review > Source/WebCore/page/EventHandler.cpp:263 > + if (nodeToBeRemoved->contains(m_clickNode.get())) contains is O(depth). Will this cause all removeChild to have to walk up the dom tree?
(In reply to comment #3) > (From update of attachment 93063 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=93063&action=review > > > Source/WebCore/page/EventHandler.cpp:263 > > + if (nodeToBeRemoved->contains(m_clickNode.get())) > > contains is O(depth). Will this cause all removeChild to have to walk up the dom tree? Yes but I don't think this is a big deal. There are many O(n) operations in call sites of this function already.
(In reply to comment #4) > (In reply to comment #3) > > contains is O(depth). Will this cause all removeChild to have to walk up the dom tree? > > Yes but I don't think this is a big deal. There are many O(n) operations in call sites of this function already. An alternative is to wait until the node is actually removed and check inDocument() but that's tricky to get right because there doesn't seem to be any precedents set by other classes and the node can be inserted back or moved to a different node during mutation events, etc...
Created attachment 93064 [details] Added instructions for manual testing
Created attachment 93104 [details] benchmark I made a benchmark for this patch. So there seems to be some performance impact in very specific case where selection isn't where m_clickNode is and m_clickNode is really deep. On my MacBookPro, WebKit ToT Mac port runs the benchmark in 2ms without the patch but takes 7ms with the patch. However, when selection isn't moved manually by removeAllRanges(), the selection's nodeWillBeRemoved will dwarfs the effect of this patch making the benchmark to take ~170ms. In practice, however, I don't think it's common for websites to have such a deep DOM structure, and put selection away from where user clicked and remove thousands of nodes between mousedown & mouseup events.
Can anyone review this patch?
Yay! Thanks for the review, Darin!
Comment on attachment 93064 [details] Added instructions for manual testing Clearing flags on attachment: 93064 Committed r86461: <http://trac.webkit.org/changeset/86461>
All reviewed patches have been landed. Closing bug.
New behavior is spec'ed in http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-mouseevent-event-order See "Example" part at the end of the section.