OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 | 6 |
7 var middleButtonMouseDownTarget = null; | 7 var middleButtonMouseDownTarget = null; |
8 | 8 |
9 document.addEventListener('mousedown', function(e) { | 9 document.addEventListener('mousedown', function(e) { |
10 if (e.button == 1) | 10 if (e.button == 1) |
11 middleButtonMouseDownTarget = e.path[0]; | 11 middleButtonMouseDownTarget = e.path[0]; |
12 }, true); | 12 }, true); |
13 | 13 |
14 document.addEventListener('mouseup', function(e) { | 14 document.addEventListener('mouseup', function(e) { |
15 if (e.button != 1) | 15 if (e.button != 1) |
16 return; | 16 return; |
17 | 17 |
18 if (e.path.length > 0 && e.path[0] == middleButtonMouseDownTarget) | 18 if (e.path.length > 0 && e.path[0] == middleButtonMouseDownTarget) |
19 middleButtonMouseDownTarget.dispatchEvent(new MouseEvent('click', e)); | 19 middleButtonMouseDownTarget.dispatchEvent(new MouseEvent('click', e)); |
20 | 20 |
21 middleButtonMouseDownTarget = null; | 21 middleButtonMouseDownTarget = null; |
22 }, true); | 22 }, true); |
23 | 23 |
24 // Prevent the synthetic click to open a new tab as the new tab will | |
25 // open if the click happened on a link regardless of this synthetic | |
26 // event. | |
Dan Beam
2016/05/31 21:34:32
i don't understand what this comment means. can y
Navid Zolghadr
2016/06/01 18:46:16
How about this?
| |
27 window.addEventListener('click', function(e) { | |
28 if (e.button == 1 && !e.isTrusted) | |
Dan Beam
2016/05/31 21:34:32
don't we control the code that's doing this? why
Navid Zolghadr
2016/06/01 18:46:16
Maybe the new comment explains this a little bette
| |
29 e.preventDefault(); | |
30 }); | |
31 | |
24 })(); | 32 })(); |
OLD | NEW |