| 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 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 getDropTarget: function() { | 70 getDropTarget: function() { |
| 71 return this; | 71 return this; |
| 72 }, | 72 }, |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {Event} e | 75 * @param {Event} e |
| 76 * @private | 76 * @private |
| 77 */ | 77 */ |
| 78 onContextMenu_: function(e) { | 78 onContextMenu_: function(e) { |
| 79 e.preventDefault(); | 79 e.preventDefault(); |
| 80 if (!this.isSelectedItem_) { | 80 if (!this.isSelectedItem_) |
| 81 this.dispatch(bookmarks.actions.selectItem( | 81 this.selectThisItem_(); |
| 82 this.itemId, false, false, this.getState())); | 82 |
| 83 } | |
| 84 this.fire('open-item-menu', { | 83 this.fire('open-item-menu', { |
| 85 x: e.clientX, | 84 x: e.clientX, |
| 86 y: e.clientY, | 85 y: e.clientY, |
| 87 }); | 86 }); |
| 88 }, | 87 }, |
| 89 | 88 |
| 90 /** | 89 /** |
| 91 * @param {Event} e | 90 * @param {Event} e |
| 92 * @private | 91 * @private |
| 93 */ | 92 */ |
| 94 onMenuButtonClick_: function(e) { | 93 onMenuButtonClick_: function(e) { |
| 95 e.stopPropagation(); | 94 e.stopPropagation(); |
| 96 e.preventDefault(); | 95 e.preventDefault(); |
| 97 this.dispatch(bookmarks.actions.selectItem( | 96 this.selectThisItem_(); |
| 98 this.itemId, false, false, this.getState())); | |
| 99 this.fire('open-item-menu', { | 97 this.fire('open-item-menu', { |
| 100 targetElement: e.target, | 98 targetElement: e.target, |
| 101 }); | 99 }); |
| 102 }, | 100 }, |
| 103 | 101 |
| 104 /** | 102 /** |
| 105 * @param {Event} e | 103 * @param {Event} e |
| 106 * @private | 104 * @private |
| 107 */ | 105 */ |
| 108 onMenuButtonDblClick_: function(e) { | 106 onMenuButtonDblClick_: function(e) { |
| 109 e.stopPropagation(); | 107 e.stopPropagation(); |
| 110 }, | 108 }, |
| 111 | 109 |
| 112 /** @private */ | 110 /** @private */ |
| 111 selectThisItem_: function() { |
| 112 this.dispatch(bookmarks.actions.selectItem(this.itemId, this.getState(), { |
| 113 clear: true, |
| 114 range: false, |
| 115 toggle: false, |
| 116 })); |
| 117 }, |
| 118 |
| 119 /** @private */ |
| 113 onItemIdChanged_: function() { | 120 onItemIdChanged_: function() { |
| 114 // TODO(tsergeant): Add a histogram to measure whether this assertion fails | 121 // TODO(tsergeant): Add a histogram to measure whether this assertion fails |
| 115 // for real users. | 122 // for real users. |
| 116 assert(this.getState().nodes[this.itemId]); | 123 assert(this.getState().nodes[this.itemId]); |
| 117 this.updateFromStore(); | 124 this.updateFromStore(); |
| 118 }, | 125 }, |
| 119 | 126 |
| 120 /** @private */ | 127 /** @private */ |
| 121 onItemChanged_: function() { | 128 onItemChanged_: function() { |
| 122 this.isFolder_ = !this.item_.url; | 129 this.isFolder_ = !this.item_.url; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 138 */ | 145 */ |
| 139 onItemBlur_: function() { | 146 onItemBlur_: function() { |
| 140 this.mouseFocus_ = false; | 147 this.mouseFocus_ = false; |
| 141 }, | 148 }, |
| 142 | 149 |
| 143 /** | 150 /** |
| 144 * @param {MouseEvent} e | 151 * @param {MouseEvent} e |
| 145 * @private | 152 * @private |
| 146 */ | 153 */ |
| 147 onClick_: function(e) { | 154 onClick_: function(e) { |
| 148 this.dispatch(bookmarks.actions.selectItem( | 155 // Ignore double clicks so that Ctrl double-clicking an item won't deselect |
| 149 this.itemId, e.ctrlKey, e.shiftKey, this.getState())); | 156 // the item before opening. |
| 157 if (e.detail != 2) { |
| 158 this.dispatch(bookmarks.actions.selectItem(this.itemId, this.getState(), { |
| 159 clear: !e.ctrlKey, |
| 160 range: e.shiftKey, |
| 161 toggle: e.ctrlKey && !e.shiftKey, |
| 162 })); |
| 163 } |
| 150 e.stopPropagation(); | 164 e.stopPropagation(); |
| 151 e.preventDefault(); | 165 e.preventDefault(); |
| 152 }, | 166 }, |
| 153 | 167 |
| 154 /** | 168 /** |
| 155 * @param {MouseEvent} e | 169 * @param {MouseEvent} e |
| 156 * @private | 170 * @private |
| 157 */ | 171 */ |
| 158 onDblClick_: function(e) { | 172 onDblClick_: function(e) { |
| 159 var commandManager = bookmarks.CommandManager.getInstance(); | 173 var commandManager = bookmarks.CommandManager.getInstance(); |
| 160 var itemSet = this.getState().selection.items; | 174 var itemSet = this.getState().selection.items; |
| 161 if (commandManager.canExecute(Command.OPEN, itemSet)) | 175 if (commandManager.canExecute(Command.OPEN, itemSet)) |
| 162 commandManager.handle(Command.OPEN, itemSet); | 176 commandManager.handle(Command.OPEN, itemSet); |
| 163 }, | 177 }, |
| 164 | 178 |
| 165 /** | 179 /** |
| 166 * @param {string} url | 180 * @param {string} url |
| 167 * @private | 181 * @private |
| 168 */ | 182 */ |
| 169 updateFavicon_: function(url) { | 183 updateFavicon_: function(url) { |
| 170 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); | 184 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); |
| 171 }, | 185 }, |
| 172 }); | 186 }); |
| OLD | NEW |