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

Unified Diff: chrome/browser/resources/md_bookmarks/item.js

Issue 2872163002: MD Bookmarks: Add 'Open' command, to open in either the BMM or in new tabs (Closed)
Patch Set: Open items with middle-click Created 3 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
Index: chrome/browser/resources/md_bookmarks/item.js
diff --git a/chrome/browser/resources/md_bookmarks/item.js b/chrome/browser/resources/md_bookmarks/item.js
index c0be4847f2849e7449f9dea0103cdba3555ad008..1a0b8bcc2a47e644ff8188d8e26a957126e185c8 100644
--- a/chrome/browser/resources/md_bookmarks/item.js
+++ b/chrome/browser/resources/md_bookmarks/item.js
@@ -37,7 +37,10 @@ Polymer({
listeners: {
'click': 'onClick_',
+ 'auxclick': 'onMiddleClick_',
'dblclick': 'onDblClick_',
+ 'mousedown': 'cancelMiddleMouseBehavior_',
+ 'mouseup': 'cancelMiddleMouseBehavior_',
'contextmenu': 'onContextMenu_',
},
@@ -58,16 +61,23 @@ Polymer({
return this;
},
+ /**
+ * Change selection so that only this item is selected.
+ * @private
+ */
+ selectItem_: function() {
+ this.dispatch(bookmarks.actions.selectItem(
+ this.itemId, false, false, this.getState()));
+ },
+
/**
* @param {Event} e
* @private
*/
onContextMenu_: function(e) {
e.preventDefault();
- if (!this.isSelectedItem_) {
- this.dispatch(bookmarks.actions.selectItem(
- this.itemId, false, false, this.getState()));
- }
+ if (!this.isSelectedItem_)
+ this.selectItem_();
this.fire('open-item-menu', {
x: e.clientX,
y: e.clientY,
@@ -80,8 +90,7 @@ Polymer({
*/
onMenuButtonClick_: function(e) {
e.stopPropagation();
- this.dispatch(bookmarks.actions.selectItem(
- this.itemId, false, false, this.getState()));
+ this.selectItem_();
this.fire('open-item-menu', {
targetElement: e.target,
});
@@ -109,28 +118,63 @@ Polymer({
},
/**
- * @param {Event} e
+ * @param {MouseEvent} e
* @private
*/
onClick_: function(e) {
- this.dispatch(bookmarks.actions.selectItem(
- this.itemId, e.ctrlKey, e.shiftKey, this.getState()));
+ if (e.detail == 1) {
+ this.dispatch(bookmarks.actions.selectItem(
+ this.itemId, e.ctrlKey, e.shiftKey, this.getState()));
+ }
e.stopPropagation();
},
/**
- * @param {Event} e
+ * @param {MouseEvent} e
* @private
*/
- onDblClick_: function(e) {
- if (!this.item_.url) {
- this.dispatch(
- bookmarks.actions.selectFolder(this.item_.id, this.getState().nodes));
+ onMiddleClick_: function(e) {
+ if (e.button != 1)
+ return;
+
+ this.selectItem_();
+ if (this.isFolder_)
+ return;
+
+ var commandManager = bookmarks.CommandManager.getInstance();
+ var itemSet = this.getState().selection.items;
+ if (e.shiftKey) {
+ if (commandManager.canExecute(Command.OPEN, itemSet))
+ commandManager.handle(Command.OPEN, itemSet)
} else {
- chrome.tabs.create({url: this.item_.url});
+ if (commandManager.canExecute(Command.OPEN_NEW_TAB, itemSet))
+ commandManager.handle(Command.OPEN_NEW_TAB, itemSet)
+ }
+ },
+
+ /**
+ * Prevent default middle-mouse behavior. On Windows, this prevents autoscroll
+ * (during mousedown), and on Linux this prevents paste (during mouseup).
+ * @param {MouseEvent} e
+ * @private
+ */
+ cancelMiddleMouseBehavior_: function(e) {
+ if (e.button == 1) {
+ e.preventDefault();
}
},
+ /**
+ * @param {MouseEvent} e
+ * @private
+ */
+ onDblClick_: function(e) {
+ var commandManager = bookmarks.CommandManager.getInstance();
+ var itemSet = this.getState().selection.items;
+ if (commandManager.canExecute(Command.OPEN, itemSet))
+ commandManager.handle(Command.OPEN, itemSet);
+ },
+
/**
* @param {string} url
* @private
« no previous file with comments | « chrome/browser/resources/md_bookmarks/constants.js ('k') | chrome/test/data/webui/md_bookmarks/test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698