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

Side by Side 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 unified diff | Download patch
OLDNEW
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 Polymer({ 5 Polymer({
6 is: 'bookmarks-item', 6 is: 'bookmarks-item',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.StoreClient, 9 bookmarks.StoreClient,
10 ], 10 ],
(...skipping 19 matching lines...) Expand all
30 /** @private */ 30 /** @private */
31 isFolder_: Boolean, 31 isFolder_: Boolean,
32 }, 32 },
33 33
34 observers: [ 34 observers: [
35 'updateFavicon_(item_.url)', 35 'updateFavicon_(item_.url)',
36 ], 36 ],
37 37
38 listeners: { 38 listeners: {
39 'click': 'onClick_', 39 'click': 'onClick_',
40 'auxclick': 'onMiddleClick_',
40 'dblclick': 'onDblClick_', 41 'dblclick': 'onDblClick_',
42 'mousedown': 'cancelMiddleMouseBehavior_',
43 'mouseup': 'cancelMiddleMouseBehavior_',
41 'contextmenu': 'onContextMenu_', 44 'contextmenu': 'onContextMenu_',
42 }, 45 },
43 46
44 /** @override */ 47 /** @override */
45 attached: function() { 48 attached: function() {
46 this.watch('item_', function(store) { 49 this.watch('item_', function(store) {
47 return store.nodes[this.itemId]; 50 return store.nodes[this.itemId];
48 }.bind(this)); 51 }.bind(this));
49 this.watch('isSelectedItem_', function(store) { 52 this.watch('isSelectedItem_', function(store) {
50 return !!store.selection.items.has(this.itemId); 53 return !!store.selection.items.has(this.itemId);
51 }.bind(this)); 54 }.bind(this));
52 55
53 this.updateFromStore(); 56 this.updateFromStore();
54 }, 57 },
55 58
56 /** @return {BookmarksItemElement} */ 59 /** @return {BookmarksItemElement} */
57 getDropTarget: function() { 60 getDropTarget: function() {
58 return this; 61 return this;
59 }, 62 },
60 63
61 /** 64 /**
65 * Change selection so that only this item is selected.
66 * @private
67 */
68 selectItem_: function() {
69 this.dispatch(bookmarks.actions.selectItem(
70 this.itemId, false, false, this.getState()));
71 },
72
73 /**
62 * @param {Event} e 74 * @param {Event} e
63 * @private 75 * @private
64 */ 76 */
65 onContextMenu_: function(e) { 77 onContextMenu_: function(e) {
66 e.preventDefault(); 78 e.preventDefault();
67 if (!this.isSelectedItem_) { 79 if (!this.isSelectedItem_)
68 this.dispatch(bookmarks.actions.selectItem( 80 this.selectItem_();
69 this.itemId, false, false, this.getState()));
70 }
71 this.fire('open-item-menu', { 81 this.fire('open-item-menu', {
72 x: e.clientX, 82 x: e.clientX,
73 y: e.clientY, 83 y: e.clientY,
74 }); 84 });
75 }, 85 },
76 86
77 /** 87 /**
78 * @param {Event} e 88 * @param {Event} e
79 * @private 89 * @private
80 */ 90 */
81 onMenuButtonClick_: function(e) { 91 onMenuButtonClick_: function(e) {
82 e.stopPropagation(); 92 e.stopPropagation();
83 this.dispatch(bookmarks.actions.selectItem( 93 this.selectItem_();
84 this.itemId, false, false, this.getState()));
85 this.fire('open-item-menu', { 94 this.fire('open-item-menu', {
86 targetElement: e.target, 95 targetElement: e.target,
87 }); 96 });
88 }, 97 },
89 98
90 /** 99 /**
91 * @param {Event} e 100 * @param {Event} e
92 * @private 101 * @private
93 */ 102 */
94 onMenuButtonDblClick_: function(e) { 103 onMenuButtonDblClick_: function(e) {
95 e.stopPropagation(); 104 e.stopPropagation();
96 }, 105 },
97 106
98 /** @private */ 107 /** @private */
99 onItemIdChanged_: function() { 108 onItemIdChanged_: function() {
100 // TODO(tsergeant): Add a histogram to measure whether this assertion fails 109 // TODO(tsergeant): Add a histogram to measure whether this assertion fails
101 // for real users. 110 // for real users.
102 assert(this.getState().nodes[this.itemId]); 111 assert(this.getState().nodes[this.itemId]);
103 this.updateFromStore(); 112 this.updateFromStore();
104 }, 113 },
105 114
106 /** @private */ 115 /** @private */
107 onItemChanged_: function() { 116 onItemChanged_: function() {
108 this.isFolder_ = !this.item_.url; 117 this.isFolder_ = !this.item_.url;
109 }, 118 },
110 119
111 /** 120 /**
112 * @param {Event} e 121 * @param {MouseEvent} e
113 * @private 122 * @private
114 */ 123 */
115 onClick_: function(e) { 124 onClick_: function(e) {
116 this.dispatch(bookmarks.actions.selectItem( 125 if (e.detail == 1) {
117 this.itemId, e.ctrlKey, e.shiftKey, this.getState())); 126 this.dispatch(bookmarks.actions.selectItem(
127 this.itemId, e.ctrlKey, e.shiftKey, this.getState()));
128 }
118 e.stopPropagation(); 129 e.stopPropagation();
119 }, 130 },
120 131
121 /** 132 /**
122 * @param {Event} e 133 * @param {MouseEvent} e
134 * @private
135 */
136 onMiddleClick_: function(e) {
137 if (e.button != 1)
138 return;
139
140 this.selectItem_();
141 if (this.isFolder_)
142 return;
143
144 var commandManager = bookmarks.CommandManager.getInstance();
145 var itemSet = this.getState().selection.items;
146 if (e.shiftKey) {
147 if (commandManager.canExecute(Command.OPEN, itemSet))
148 commandManager.handle(Command.OPEN, itemSet)
149 } else {
150 if (commandManager.canExecute(Command.OPEN_NEW_TAB, itemSet))
151 commandManager.handle(Command.OPEN_NEW_TAB, itemSet)
152 }
153 },
154
155 /**
156 * Prevent default middle-mouse behavior. On Windows, this prevents autoscroll
157 * (during mousedown), and on Linux this prevents paste (during mouseup).
158 * @param {MouseEvent} e
159 * @private
160 */
161 cancelMiddleMouseBehavior_: function(e) {
162 if (e.button == 1) {
163 e.preventDefault();
164 }
165 },
166
167 /**
168 * @param {MouseEvent} e
123 * @private 169 * @private
124 */ 170 */
125 onDblClick_: function(e) { 171 onDblClick_: function(e) {
126 if (!this.item_.url) { 172 var commandManager = bookmarks.CommandManager.getInstance();
127 this.dispatch( 173 var itemSet = this.getState().selection.items;
128 bookmarks.actions.selectFolder(this.item_.id, this.getState().nodes)); 174 if (commandManager.canExecute(Command.OPEN, itemSet))
129 } else { 175 commandManager.handle(Command.OPEN, itemSet);
130 chrome.tabs.create({url: this.item_.url});
131 }
132 }, 176 },
133 177
134 /** 178 /**
135 * @param {string} url 179 * @param {string} url
136 * @private 180 * @private
137 */ 181 */
138 updateFavicon_: function(url) { 182 updateFavicon_: function(url) {
139 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); 183 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url);
140 }, 184 },
141 }); 185 });
OLDNEW
« 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