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

Side by Side Diff: chrome/browser/resources/md_bookmarks/store.js

Issue 2668693007: [MD Bookmarks] Double Click (Closed)
Patch Set: renaming Created 3 years, 10 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 var BookmarksStore = Polymer({ 5 var BookmarksStore = Polymer({
6 is: 'bookmarks-store', 6 is: 'bookmarks-store',
7 7
8 properties: { 8 properties: {
9 /** @type {BookmarkTreeNode} */ 9 /** @type {BookmarkTreeNode} */
10 rootNode: { 10 rootNode: {
(...skipping 27 matching lines...) Expand all
38 }, 38 },
39 39
40 /** @type {Object<?string, !BookmarkTreeNode>} */ 40 /** @type {Object<?string, !BookmarkTreeNode>} */
41 idToNodeMap_: Object, 41 idToNodeMap_: Object,
42 42
43 /** @type {?number} */ 43 /** @type {?number} */
44 anchorIndex_: Number, 44 anchorIndex_: Number,
45 45
46 /** @type {Set<string>} */ 46 /** @type {Set<string>} */
47 searchResultSet_: Object, 47 searchResultSet_: Object,
48
49 /** @type {Set<number>} */
50 selectedIndexSet_: Object,
48 }, 51 },
49 52
50 /** @private {Object} */ 53 /** @private {Object} */
51 documentListeners_: null, 54 documentListeners_: null,
52 55
53 /** @override */ 56 /** @override */
54 attached: function() { 57 attached: function() {
55 this.documentListeners_ = { 58 this.documentListeners_ = {
56 'folder-open-changed': this.onFolderOpenChanged_.bind(this), 59 'folder-open-changed': this.onFolderOpenChanged_.bind(this),
60 'open-item': this.onItemOpened_.bind(this),
57 'search-term-changed': this.onSearchTermChanged_.bind(this), 61 'search-term-changed': this.onSearchTermChanged_.bind(this),
58 'select-item': this.onItemSelected_.bind(this), 62 'select-item': this.onItemSelected_.bind(this),
59 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this), 63 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this),
60 }; 64 };
61 for (var event in this.documentListeners_) 65 for (var event in this.documentListeners_)
62 document.addEventListener(event, this.documentListeners_[event]); 66 document.addEventListener(event, this.documentListeners_[event]);
63 }, 67 },
64 68
65 /** @override */ 69 /** @override */
66 detached: function() { 70 detached: function() {
(...skipping 18 matching lines...) Expand all
85 // bookmarks-store, private: 89 // bookmarks-store, private:
86 90
87 /** 91 /**
88 * @param {BookmarkTreeNode} rootNode 92 * @param {BookmarkTreeNode} rootNode
89 * @private 93 * @private
90 */ 94 */
91 setupStore_: function(rootNode) { 95 setupStore_: function(rootNode) {
92 this.rootNode = rootNode; 96 this.rootNode = rootNode;
93 this.idToNodeMap_ = {}; 97 this.idToNodeMap_ = {};
94 this.rootNode.path = 'rootNode'; 98 this.rootNode.path = 'rootNode';
99 this.selectedIndexSet_ = new Set();
95 BookmarksStore.generatePaths(rootNode, 0); 100 BookmarksStore.generatePaths(rootNode, 0);
96 BookmarksStore.initNodes(this.rootNode, this.idToNodeMap_); 101 BookmarksStore.initNodes(this.rootNode, this.idToNodeMap_);
97 102
98 // Initialize the store's fields from the router. 103 // Initialize the store's fields from the router.
99 if (this.$.router.searchTerm) 104 if (this.$.router.searchTerm)
100 this.searchTerm = this.$.router.searchTerm; 105 this.searchTerm = this.$.router.searchTerm;
101 else 106 else
102 this.fire('selected-folder-changed', this.$.router.selectedId); 107 this.fire('selected-folder-changed', this.$.router.selectedId);
103 }, 108 },
104 109
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 }, 185 },
181 186
182 /** 187 /**
183 * Remove all selected items in the list. 188 * Remove all selected items in the list.
184 * @private 189 * @private
185 */ 190 */
186 clearSelectedItems_: function() { 191 clearSelectedItems_: function() {
187 if (!this.displayedList) 192 if (!this.displayedList)
188 return; 193 return;
189 194
195 this.selectedIndexSet_.clear();
196
190 for (var i = 0; i < this.displayedList.length; i++) { 197 for (var i = 0; i < this.displayedList.length; i++) {
191 if (!this.displayedList[i].isSelectedItem) 198 if (!this.displayedList[i].isSelectedItem)
192 continue; 199 continue;
193 200
194 this.set('displayedList.#' + i + '.isSelectedItem', false); 201 this.set('displayedList.#' + i + '.isSelectedItem', false);
195 } 202 }
196 }, 203 },
197 204
198 /** 205 /**
199 * Return the index in the search result of an item. 206 * Return the index in the search result of an item.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 var startIndex, endIndex; 250 var startIndex, endIndex;
244 if (this.anchorIndex_ == null) { 251 if (this.anchorIndex_ == null) {
245 this.anchorIndex_ = this.getIndexInList_(item); 252 this.anchorIndex_ = this.getIndexInList_(item);
246 startIndex = this.anchorIndex_; 253 startIndex = this.anchorIndex_;
247 endIndex = this.anchorIndex_; 254 endIndex = this.anchorIndex_;
248 } else { 255 } else {
249 var selectedIndex = this.getIndexInList_(item); 256 var selectedIndex = this.getIndexInList_(item);
250 startIndex = Math.min(this.anchorIndex_, selectedIndex); 257 startIndex = Math.min(this.anchorIndex_, selectedIndex);
251 endIndex = Math.max(this.anchorIndex_, selectedIndex); 258 endIndex = Math.max(this.anchorIndex_, selectedIndex);
252 } 259 }
253 for (var i = startIndex; i <= endIndex; i++) 260 for (var i = startIndex; i <= endIndex; i++) {
254 this.set('displayedList.#' + i + '.isSelectedItem', true); 261 this.set('displayedList.#' + i + '.isSelectedItem', true);
262 this.selectedIndexSet_.add(i);
263 }
255 }, 264 },
256 265
257 /** 266 /**
258 * Selects a single item in the displayedList. 267 * Selects a single item in the displayedList.
259 * @param {BookmarkTreeNode} item 268 * @param {BookmarkTreeNode} item
260 * @private 269 * @private
261 */ 270 */
262 selectItem_: function(item) { 271 selectItem_: function(item) {
263 this.anchorIndex_ = this.getIndexInList_(item); 272 this.anchorIndex_ = this.getIndexInList_(item);
264 this.set('displayedList.#' + this.anchorIndex_ + '.isSelectedItem', true); 273 this.set('displayedList.#' + this.anchorIndex_ + '.isSelectedItem', true);
274 this.selectedIndexSet_.add(this.anchorIndex_);
265 }, 275 },
266 276
267 ////////////////////////////////////////////////////////////////////////////// 277 //////////////////////////////////////////////////////////////////////////////
268 // bookmarks-store, bookmarks API event listeners: 278 // bookmarks-store, bookmarks API event listeners:
269 279
270 /** 280 /**
271 * Callback for when a bookmark node is removed. 281 * Callback for when a bookmark node is removed.
272 * If a folder is selected or is an ancestor of a selected folder, the parent 282 * If a folder is selected or is an ancestor of a selected folder, the parent
273 * of the removed folder will be selected. 283 * of the removed folder will be selected.
274 * @param {string} id The id of the removed bookmark node. 284 * @param {string} id The id of the removed bookmark node.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // Deselect the old folder if defined. 363 // Deselect the old folder if defined.
354 if (this.selectedId && this.idToNodeMap_[this.selectedId]) 364 if (this.selectedId && this.idToNodeMap_[this.selectedId])
355 this.set( 365 this.set(
356 this.idToNodeMap_[this.selectedId].path + '.isSelectedFolder', false); 366 this.idToNodeMap_[this.selectedId].path + '.isSelectedFolder', false);
357 367
358 // Check if the selected id is that of a defined folder. 368 // Check if the selected id is that of a defined folder.
359 var id = /** @type {string} */ (e.detail); 369 var id = /** @type {string} */ (e.detail);
360 if (!this.idToNodeMap_[id] || this.idToNodeMap_[id].url) 370 if (!this.idToNodeMap_[id] || this.idToNodeMap_[id].url)
361 id = this.rootNode.children[0].id; 371 id = this.rootNode.children[0].id;
362 372
363 var newFolder = this.idToNodeMap_[id]; 373 var folder = this.idToNodeMap_[id];
364 this.set(newFolder.path + '.isSelectedFolder', true); 374 this.set(folder.path + '.isSelectedFolder', true);
365 this.selectedId = id; 375 this.selectedId = id;
376 while (folder.parentId) {
377 folder = this.idToNodeMap_[folder.parentId];
378 if (folder.isOpen)
379 continue;
380
381 this.fire('folder-open-changed', {
382 id: folder.id,
383 open: true,
384 });
385 }
366 }, 386 },
367 387
368 /** 388 /**
369 * Handles events that open and close folders. 389 * Handles events that open and close folders.
370 * @param {CustomEvent} e 390 * @param {CustomEvent} e
371 * @private 391 * @private
372 */ 392 */
373 onFolderOpenChanged_: function(e) { 393 onFolderOpenChanged_: function(e) {
374 var folder = this.idToNodeMap_[e.detail.id]; 394 var folder = this.idToNodeMap_[e.detail.id];
375 this.set(folder.path + '.isOpen', e.detail.open); 395 this.set(folder.path + '.isOpen', e.detail.open);
376 if (!folder.isOpen && this.isAncestorOfSelected_(folder)) 396 if (!folder.isOpen && this.isAncestorOfSelected_(folder))
377 this.fire('selected-folder-changed', folder.id); 397 this.fire('selected-folder-changed', folder.id);
378 }, 398 },
379 399
380 /** 400 /**
381 * Selects items according to keyboard behaviours. 401 * Selects items according to keyboard behaviours.
382 * @param {CustomEvent} e 402 * @param {CustomEvent} e
383 * @private 403 * @private
384 */ 404 */
385 onItemSelected_: function(e) { 405 onItemSelected_: function(e) {
386 if (!e.detail.add) 406 if (!e.detail.add)
387 this.clearSelectedItems_(); 407 this.clearSelectedItems_();
388 408
389 if (e.detail.range) 409 if (e.detail.range)
390 this.selectRange_(e.detail.item); 410 this.selectRange_(e.detail.item);
391 else 411 else
392 this.selectItem_(e.detail.item); 412 this.selectItem_(e.detail.item);
393 }, 413 },
414
415 /**
416 * @param {CustomEvent} e
417 * @private
418 */
419 onItemOpened_: function(e) {
420 if (this.selectedIndexSet_.size == 1) {
421 var item = /** BookmarkTreeNode */ (e.detail);
422 // do the single event here
423 if (!item.url)
424 this.fire('selected-folder-changed', item.id);
425 else
426 chrome.tabs.create({url: item.url});
427 } else {
428 for (let index of this.selectedIndexSet_) {
tsergeant 2017/02/02 02:02:38 Chris and I just tried the old bookmark manager an
jiaxi 2017/02/02 03:07:03 Done.
429 if (!this.displayedList[index].url)
430 continue;
431
432 chrome.tabs.create({url: this.displayedList[index].url});
433 }
434 }
435 },
394 }); 436 });
395 437
396 //////////////////////////////////////////////////////////////////////////////// 438 ////////////////////////////////////////////////////////////////////////////////
397 // bookmarks-store, static methods: 439 // bookmarks-store, static methods:
398 440
399 /** 441 /**
400 * Stores the path from the store to a node inside the node. 442 * Stores the path from the store to a node inside the node.
401 * @param {BookmarkTreeNode} bookmarkNode 443 * @param {BookmarkTreeNode} bookmarkNode
402 * @param {number} startIndex 444 * @param {number} startIndex
403 */ 445 */
(...skipping 21 matching lines...) Expand all
425 idToNodeMap[bookmarkNode.id] = bookmarkNode; 467 idToNodeMap[bookmarkNode.id] = bookmarkNode;
426 468
427 if (bookmarkNode.url) 469 if (bookmarkNode.url)
428 return; 470 return;
429 471
430 bookmarkNode.isSelectedFolder = false; 472 bookmarkNode.isSelectedFolder = false;
431 bookmarkNode.isOpen = true; 473 bookmarkNode.isOpen = true;
432 for (var i = 0; i < bookmarkNode.children.length; i++) 474 for (var i = 0; i < bookmarkNode.children.length; i++)
433 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap); 475 BookmarksStore.initNodes(bookmarkNode.children[i], idToNodeMap);
434 }; 476 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698