Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2600)

Unified Diff: chrome/browser/resources/synthetic_middleclick.js

Issue 2018943003: Fix history page middle click action (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/ntp4/synthetic_middleclick.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/synthetic_middleclick.js
diff --git a/chrome/browser/resources/synthetic_middleclick.js b/chrome/browser/resources/synthetic_middleclick.js
new file mode 100644
index 0000000000000000000000000000000000000000..b784d100e7bc97937ee36dbf28daaf2611110121
--- /dev/null
+++ b/chrome/browser/resources/synthetic_middleclick.js
@@ -0,0 +1,38 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+(function() {
+
+var middleButtonMouseDownTarget = null;
+
+document.addEventListener('mousedown', function(e) {
+ if (e.button == 1)
+ middleButtonMouseDownTarget = e.path[0];
+}, true);
+
+document.addEventListener('mouseup', function(e) {
+ if (e.button != 1)
+ return;
+
+ if (e.path.length > 0 && e.path[0] == middleButtonMouseDownTarget)
+ middleButtonMouseDownTarget.dispatchEvent(new MouseEvent('click', e));
+
+ middleButtonMouseDownTarget = null;
+}, true);
+
+// If js sends a synthetic click event to an element like what we do
+// here the default handler runs for that event. Now if user middle
+// clicks on an element Chrome by default runs the default behavior
+// (i.e. opening the link in a new tab) with firing no click event.
+// See crbug.com/255. This file does send that synthetic click for
+// middle click to temporary fix the expected behavours in some
+// click handlers. However, this will cause yet another tab to open
+// if the target is a link as the default handler runs for this synthetic
+// 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
+window.addEventListener('click', function(e) {
+ if (e.button == 1 && !e.isTrusted)
+ e.preventDefault();
+});
+
+})();
« no previous file with comments | « chrome/browser/resources/ntp4/synthetic_middleclick.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698