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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 * @extends {HTMLButtonElement} | 61 * @extends {HTMLButtonElement} |
62 */ | 62 */ |
63 var BookmarkList = cr.ui.define('list'); | 63 var BookmarkList = cr.ui.define('list'); |
64 | 64 |
65 BookmarkList.prototype = { | 65 BookmarkList.prototype = { |
66 __proto__: List.prototype, | 66 __proto__: List.prototype, |
67 | 67 |
68 /** @inheritDoc */ | 68 /** @inheritDoc */ |
69 decorate: function() { | 69 decorate: function() { |
70 List.prototype.decorate.call(this); | 70 List.prototype.decorate.call(this); |
71 this.addEventListener('click', this.handleClick_); | |
72 this.addEventListener('mousedown', this.handleMouseDown_); | 71 this.addEventListener('mousedown', this.handleMouseDown_); |
73 | 72 |
74 // HACK(arv): http://crbug.com/40902 | 73 // HACK(arv): http://crbug.com/40902 |
75 window.addEventListener('resize', this.redraw.bind(this)); | 74 window.addEventListener('resize', this.redraw.bind(this)); |
76 | 75 |
77 // We could add the ContextMenuButton in the BookmarkListItem but it slows | 76 // We could add the ContextMenuButton in the BookmarkListItem but it slows |
78 // down redraws a lot so we do this on mouseovers instead. | 77 // down redraws a lot so we do this on mouseovers instead. |
79 this.addEventListener('mouseover', this.handleMouseOver_.bind(this)); | 78 this.addEventListener('mouseover', this.handleMouseOver_.bind(this)); |
80 }, | 79 }, |
81 | 80 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 el = el.parentNode; | 182 el = el.parentNode; |
184 } | 183 } |
185 | 184 |
186 if (el && el.parentNode == this && | 185 if (el && el.parentNode == this && |
187 !(el.lastChild instanceof ContextMenuButton)) { | 186 !(el.lastChild instanceof ContextMenuButton)) { |
188 el.appendChild(new ContextMenuButton); | 187 el.appendChild(new ContextMenuButton); |
189 } | 188 } |
190 }, | 189 }, |
191 | 190 |
192 /** | 191 /** |
193 * Handles the clicks on the list so that we can check if the user clicked | 192 * Dispatches an urlClicked event which is used to open URLs in new |
194 * on a link or a folder. | 193 * tabs etc. |
195 * @private | 194 * @private |
196 * @param {!Event} e The click event object. | 195 * @param {string} url The URL that was clicked. |
| 196 * @param {!Event} originalEvent The original click event object. |
197 */ | 197 */ |
198 handleClick_: function(e) { | 198 dispatchUrlClickedEvent_: function(url, originalEvent) { |
199 // Handle middle click to open bookmark in a new tab. | 199 var event = new cr.Event('urlClicked', true, false); |
200 if (e.button == 1) { | 200 event.url = url; |
201 var el = e.target; | 201 event.originalEvent = originalEvent; |
202 while (el.parentNode != this) { | 202 this.dispatchEvent(event); |
203 el = el.parentNode; | |
204 } | |
205 var node = el.bookmarkNode; | |
206 if (!bmm.isFolder(node)) { | |
207 var event = new cr.Event('urlClicked', true, false); | |
208 event.url = node.url; | |
209 event.originalEvent = e; | |
210 this.dispatchEvent(event); | |
211 } | |
212 } | |
213 }, | 203 }, |
214 | 204 |
215 /** | 205 /** |
216 * Handles mousedown events so that we can prevent the auto scroll as | 206 * Handles mousedown events so that we can prevent the auto scroll as |
217 * necessary. | 207 * necessary. |
218 * @private | 208 * @private |
219 * @param {!MouseEvent} e The mousedown event object. | 209 * @param {!MouseEvent} e The mousedown event object. |
220 */ | 210 */ |
221 handleMouseDown_: function(e) { | 211 handleMouseDown_: function(e) { |
222 if (e.button == 1) { | 212 if (e.button == 1) { |
(...skipping 13 matching lines...) Expand all Loading... |
236 | 226 |
237 /** | 227 /** |
238 * WebKit no longer dispatches click events for middle clicks so we need | 228 * WebKit no longer dispatches click events for middle clicks so we need |
239 * to emulate it. | 229 * to emulate it. |
240 * @private | 230 * @private |
241 * @param {!MouseEvent} e The mouse up event object. | 231 * @param {!MouseEvent} e The mouse up event object. |
242 */ | 232 */ |
243 handleMiddleMouseUp_: function(e) { | 233 handleMiddleMouseUp_: function(e) { |
244 this.removeEventListener('mouseup', this.handleMiddleMouseUp_); | 234 this.removeEventListener('mouseup', this.handleMiddleMouseUp_); |
245 if (e.button == 1) { | 235 if (e.button == 1) { |
246 var clickEvent = document.createEvent('MouseEvent'); | 236 var el = e.target; |
247 clickEvent.initMouseEvent('click', | 237 while (el.parentNode != this) { |
248 true, // canBubble | 238 el = el.parentNode; |
249 true, // cancelable, | 239 } |
250 e.view, e.detail, | 240 var node = el.bookmarkNode; |
251 e.screenX, e.screenY, e.clientX, e.clientY, | 241 if (node && !bmm.isFolder(node)) |
252 e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, | 242 this.dispatchUrlClickedEvent_(node.url, e); |
253 e.button, e.relatedTarget); | |
254 e.target.dispatchEvent(clickEvent); | |
255 } | 243 } |
256 }, | 244 }, |
257 | 245 |
258 // Bookmark model update callbacks | 246 // Bookmark model update callbacks |
259 handleBookmarkChanged: function(id, changeInfo) { | 247 handleBookmarkChanged: function(id, changeInfo) { |
260 var dataModel = this.dataModel; | 248 var dataModel = this.dataModel; |
261 var index = dataModel.findIndexById(id); | 249 var index = dataModel.findIndexById(id); |
262 if (index != -1) { | 250 if (index != -1) { |
263 var bookmarkNode = this.dataModel.item(index); | 251 var bookmarkNode = this.dataModel.item(index); |
264 bookmarkNode.title = changeInfo.title; | 252 bookmarkNode.title = changeInfo.title; |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 cr.dispatchSimpleEvent(this, 'edit', true); | 578 cr.dispatchSimpleEvent(this, 'edit', true); |
591 } | 579 } |
592 } | 580 } |
593 } | 581 } |
594 }; | 582 }; |
595 | 583 |
596 return { | 584 return { |
597 BookmarkList: BookmarkList | 585 BookmarkList: BookmarkList |
598 }; | 586 }; |
599 }); | 587 }); |
OLD | NEW |