Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 (function() { | |
| 6 | |
| 7 var middleButtonMouseDownTarget = null; | |
| 8 | |
| 9 document.addEventListener('mousedown', function(e) { | |
| 10 if (e.button == 1) | |
| 11 middleButtonMouseDownTarget = e.path[0]; | |
| 12 }, true); | |
| 13 | |
| 14 document.addEventListener('mouseup', function(e) { | |
| 15 if (e.button != 1) | |
| 16 return; | |
| 17 | |
| 18 if (e.path.length > 0 && e.path[0] == middleButtonMouseDownTarget) | |
| 19 middleButtonMouseDownTarget.dispatchEvent(new MouseEvent('click', e)); | |
| 20 | |
| 21 middleButtonMouseDownTarget = null; | |
| 22 }, true); | |
| 23 | |
| 24 // If js sends a synthetic click event to an element like what we do | |
| 25 // here the default handler runs for that event. Now if user middle | |
| 26 // clicks on an element Chrome by default runs the default behavior | |
| 27 // (i.e. opening the link in a new tab) with firing no click event. | |
| 28 // See crbug.com/255. This file does send that synthetic click for | |
| 29 // middle click to temporary fix the expected behavours in some | |
| 30 // click handlers. However, this will cause yet another tab to open | |
| 31 // if the target is a link as the default handler runs for this synthetic | |
| 32 // as well if the event is not prevented. | |
|
Dan Beam
2016/06/02 19:18:33
yeah, sorry, this still doesn't make much sense to
| |
| 33 window.addEventListener('click', function(e) { | |
| 34 if (e.button == 1 && !e.isTrusted) | |
| 35 e.preventDefault(); | |
| 36 }); | |
| 37 | |
| 38 })(); | |
| OLD | NEW |