| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // TODO(arv): Now that this is driven by a data model, implement a data model | 5 // TODO(arv): Now that this is driven by a data model, implement a data model |
| 6 // that handles the loading and the events from the bookmark backend. | 6 // that handles the loading and the events from the bookmark backend. |
| 7 | 7 |
| 8 cr.define('bmm', function() { | 8 cr.define('bmm', function() { |
| 9 const List = cr.ui.List; | 9 const List = cr.ui.List; |
| 10 const ListItem = cr.ui.ListItem; | 10 const ListItem = cr.ui.ListItem; |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 } | 189 } |
| 190 }, | 190 }, |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * Handles the clicks on the list so that we can check if the user clicked | 193 * Handles the clicks on the list so that we can check if the user clicked |
| 194 * on a link or a folder. | 194 * on a link or a folder. |
| 195 * @private | 195 * @private |
| 196 * @param {!Event} e The click event object. | 196 * @param {!Event} e The click event object. |
| 197 */ | 197 */ |
| 198 handleClick_: function(e) { | 198 handleClick_: function(e) { |
| 199 var self = this; | |
| 200 | |
| 201 function dispatch(url) { | |
| 202 var event = new cr.Event('urlClicked', true, false); | |
| 203 event.url = url; | |
| 204 event.originalEvent = e; | |
| 205 self.dispatchEvent(event); | |
| 206 } | |
| 207 | |
| 208 var el = e.target; | |
| 209 | |
| 210 // Handle clicks on the links to URLs. | |
| 211 if (el.href) { | |
| 212 dispatch(el.href); | |
| 213 | |
| 214 // Handle middle click to open bookmark in a new tab. | 199 // Handle middle click to open bookmark in a new tab. |
| 215 } else if (e.button == 1) { | 200 if (e.button == 1) { |
| 201 var el = e.target; |
| 216 while (el.parentNode != this) { | 202 while (el.parentNode != this) { |
| 217 el = el.parentNode; | 203 el = el.parentNode; |
| 218 } | 204 } |
| 219 var node = el.bookmarkNode; | 205 var node = el.bookmarkNode; |
| 220 if (!bmm.isFolder(node)) | 206 if (!bmm.isFolder(node)) { |
| 221 dispatch(node.url); | 207 var event = new cr.Event('urlClicked', true, false); |
| 208 event.url = url; |
| 209 event.originalEvent = e; |
| 210 this.dispatchEvent(event); |
| 211 } |
| 222 } | 212 } |
| 223 }, | 213 }, |
| 224 | 214 |
| 225 /** | 215 /** |
| 226 * Handles mousedown events so that we can prevent the auto scroll as | 216 * Handles mousedown events so that we can prevent the auto scroll as |
| 227 * necessary. | 217 * necessary. |
| 228 * @private | 218 * @private |
| 229 * @param {!Event} e The mousedown event object. | 219 * @param {!Event} e The mousedown event object. |
| 230 */ | 220 */ |
| 231 handleMouseDown_: function(e) { | 221 handleMouseDown_: function(e) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 var labelEl = this.ownerDocument.createElement('span'); | 375 var labelEl = this.ownerDocument.createElement('span'); |
| 386 labelEl.className = 'label'; | 376 labelEl.className = 'label'; |
| 387 labelEl.textContent = bookmarkNode.title; | 377 labelEl.textContent = bookmarkNode.title; |
| 388 | 378 |
| 389 var urlEl = this.ownerDocument.createElement('span'); | 379 var urlEl = this.ownerDocument.createElement('span'); |
| 390 urlEl.className = 'url'; | 380 urlEl.className = 'url'; |
| 391 urlEl.dir = 'ltr'; | 381 urlEl.dir = 'ltr'; |
| 392 | 382 |
| 393 if (bmm.isFolder(bookmarkNode)) { | 383 if (bmm.isFolder(bookmarkNode)) { |
| 394 this.className = 'folder'; | 384 this.className = 'folder'; |
| 395 labelEl.href = '#' + bookmarkNode.id; | |
| 396 } else { | 385 } else { |
| 397 labelEl.style.backgroundImage = url('chrome://favicon/' + | 386 labelEl.style.backgroundImage = url('chrome://favicon/' + |
| 398 bookmarkNode.url); | 387 bookmarkNode.url); |
| 399 labelEl.href = urlEl.textContent = bookmarkNode.url; | 388 urlEl.textContent = bookmarkNode.url; |
| 400 } | 389 } |
| 401 | 390 |
| 402 this.appendChild(labelEl); | 391 this.appendChild(labelEl); |
| 403 this.appendChild(urlEl); | 392 this.appendChild(urlEl); |
| 404 | 393 |
| 405 // Initially the ContextMenuButton was added here but it slowed down | 394 // Initially the ContextMenuButton was added here but it slowed down |
| 406 // rendering a lot so it is now added using mouseover. | 395 // rendering a lot so it is now added using mouseover. |
| 407 }, | 396 }, |
| 408 | 397 |
| 409 /** | 398 /** |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 cr.dispatchSimpleEvent(this, 'edit', true); | 553 cr.dispatchSimpleEvent(this, 'edit', true); |
| 565 } | 554 } |
| 566 } | 555 } |
| 567 } | 556 } |
| 568 }; | 557 }; |
| 569 | 558 |
| 570 return { | 559 return { |
| 571 BookmarkList: BookmarkList | 560 BookmarkList: BookmarkList |
| 572 }; | 561 }; |
| 573 }); | 562 }); |
| OLD | NEW |