| 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 19 matching lines...) Expand all Loading... |
| 30 }, | 30 }, |
| 31 | 31 |
| 32 /** @private */ | 32 /** @private */ |
| 33 mouseFocus_: { | 33 mouseFocus_: { |
| 34 type: Boolean, | 34 type: Boolean, |
| 35 reflectToAttribute: true, | 35 reflectToAttribute: true, |
| 36 }, | 36 }, |
| 37 | 37 |
| 38 /** @private */ | 38 /** @private */ |
| 39 isFolder_: Boolean, | 39 isFolder_: Boolean, |
| 40 |
| 41 /** @private */ |
| 42 openItemUrl_: String, |
| 40 }, | 43 }, |
| 41 | 44 |
| 42 observers: [ | 45 observers: [ |
| 43 'updateFavicon_(item_.url)', | 46 'updateFavicon_(item_.url)', |
| 44 ], | 47 ], |
| 45 | 48 |
| 46 listeners: { | 49 listeners: { |
| 47 'mousedown': 'onMousedown_', | 50 'mousedown': 'onMousedown_', |
| 48 'blur': 'onItemBlur_', | 51 'blur': 'onItemBlur_', |
| 49 'click': 'onClick_', | 52 'click': 'onClick_', |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 y: e.clientY, | 86 y: e.clientY, |
| 84 }); | 87 }); |
| 85 }, | 88 }, |
| 86 | 89 |
| 87 /** | 90 /** |
| 88 * @param {Event} e | 91 * @param {Event} e |
| 89 * @private | 92 * @private |
| 90 */ | 93 */ |
| 91 onMenuButtonClick_: function(e) { | 94 onMenuButtonClick_: function(e) { |
| 92 e.stopPropagation(); | 95 e.stopPropagation(); |
| 96 e.preventDefault(); |
| 93 this.dispatch(bookmarks.actions.selectItem( | 97 this.dispatch(bookmarks.actions.selectItem( |
| 94 this.itemId, false, false, this.getState())); | 98 this.itemId, false, false, this.getState())); |
| 95 this.fire('open-item-menu', { | 99 this.fire('open-item-menu', { |
| 96 targetElement: e.target, | 100 targetElement: e.target, |
| 97 }); | 101 }); |
| 98 }, | 102 }, |
| 99 | 103 |
| 100 /** | 104 /** |
| 101 * @param {Event} e | 105 * @param {Event} e |
| 102 * @private | 106 * @private |
| 103 */ | 107 */ |
| 104 onMenuButtonDblClick_: function(e) { | 108 onMenuButtonDblClick_: function(e) { |
| 105 e.stopPropagation(); | 109 e.stopPropagation(); |
| 106 }, | 110 }, |
| 107 | 111 |
| 108 /** @private */ | 112 /** @private */ |
| 109 onItemIdChanged_: function() { | 113 onItemIdChanged_: function() { |
| 110 // TODO(tsergeant): Add a histogram to measure whether this assertion fails | 114 // TODO(tsergeant): Add a histogram to measure whether this assertion fails |
| 111 // for real users. | 115 // for real users. |
| 112 assert(this.getState().nodes[this.itemId]); | 116 assert(this.getState().nodes[this.itemId]); |
| 113 this.updateFromStore(); | 117 this.updateFromStore(); |
| 114 }, | 118 }, |
| 115 | 119 |
| 116 /** @private */ | 120 /** @private */ |
| 117 onItemChanged_: function() { | 121 onItemChanged_: function() { |
| 118 this.isFolder_ = !this.item_.url; | 122 this.isFolder_ = !this.item_.url; |
| 123 if (this.item_.url) |
| 124 this.openItemUrl_ = this.item_.url; |
| 125 else |
| 126 this.openItemUrl_ = 'chrome://bookmarks/?id=' + this.itemId; |
| 119 }, | 127 }, |
| 120 | 128 |
| 121 /** | 129 /** |
| 122 * @private | 130 * @private |
| 123 */ | 131 */ |
| 124 onMousedown_: function() { | 132 onMousedown_: function() { |
| 125 this.mouseFocus_ = true; | 133 this.mouseFocus_ = true; |
| 126 }, | 134 }, |
| 127 | 135 |
| 128 /** | 136 /** |
| 129 * @private | 137 * @private |
| 130 */ | 138 */ |
| 131 onItemBlur_: function() { | 139 onItemBlur_: function() { |
| 132 this.mouseFocus_ = false; | 140 this.mouseFocus_ = false; |
| 133 }, | 141 }, |
| 134 | 142 |
| 135 /** | 143 /** |
| 136 * @param {Event} e | 144 * @param {MouseEvent} e |
| 137 * @private | 145 * @private |
| 138 */ | 146 */ |
| 139 onClick_: function(e) { | 147 onClick_: function(e) { |
| 140 this.dispatch(bookmarks.actions.selectItem( | 148 this.dispatch(bookmarks.actions.selectItem( |
| 141 this.itemId, e.ctrlKey, e.shiftKey, this.getState())); | 149 this.itemId, e.ctrlKey, e.shiftKey, this.getState())); |
| 142 e.stopPropagation(); | 150 e.stopPropagation(); |
| 151 e.preventDefault(); |
| 143 }, | 152 }, |
| 144 | 153 |
| 145 /** | 154 /** |
| 146 * @param {Event} e | 155 * @param {MouseEvent} e |
| 147 * @private | 156 * @private |
| 148 */ | 157 */ |
| 149 onDblClick_: function(e) { | 158 onDblClick_: function(e) { |
| 150 if (!this.item_.url) { | 159 var commandManager = bookmarks.CommandManager.getInstance(); |
| 151 this.dispatch( | 160 var itemSet = this.getState().selection.items; |
| 152 bookmarks.actions.selectFolder(this.item_.id, this.getState().nodes)); | 161 if (commandManager.canExecute(Command.OPEN, itemSet)) |
| 153 } else { | 162 commandManager.handle(Command.OPEN, itemSet); |
| 154 chrome.tabs.create({url: this.item_.url}); | |
| 155 } | |
| 156 }, | 163 }, |
| 157 | 164 |
| 158 /** | 165 /** |
| 159 * @param {string} url | 166 * @param {string} url |
| 160 * @private | 167 * @private |
| 161 */ | 168 */ |
| 162 updateFavicon_: function(url) { | 169 updateFavicon_: function(url) { |
| 163 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); | 170 this.$.icon.style.backgroundImage = cr.icon.getFavicon(url); |
| 164 }, | 171 }, |
| 165 }); | 172 }); |
| OLD | NEW |