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

Side by Side Diff: ui/webui/resources/js/cr/ui/list.js

Issue 618133002: All changes to ui/webui/ from bookmarks CL that block other CLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@true_master
Patch Set: add var Created 6 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // require: array_data_model.js 5 // require: array_data_model.js
6 // require: list_selection_model.js 6 // require: list_selection_model.js
7 // require: list_selection_controller.js 7 // require: list_selection_controller.js
8 // require: list_item.js 8 // require: list_item.js
9 9
10 /** 10 /**
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 }, 149 },
150 150
151 get dataModel() { 151 get dataModel() {
152 return this.dataModel_; 152 return this.dataModel_;
153 }, 153 },
154 154
155 155
156 /** 156 /**
157 * Cached item for measuring the default item size by measureItem(). 157 * Cached item for measuring the default item size by measureItem().
158 * @type {ListItem} 158 * @type {cr.ui.ListItem}
159 */ 159 */
160 cachedMeasuredItem_: null, 160 cachedMeasuredItem_: null,
161 161
162 /** 162 /**
163 * The selection model to use. 163 * The selection model to use.
164 * @type {cr.ui.ListSelectionModel} 164 * @type {cr.ui.ListSelectionModel}
165 */ 165 */
166 get selectionModel() { 166 get selectionModel() {
167 return this.selectionModel_; 167 return this.selectionModel_;
168 }, 168 },
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 }, 516 },
517 517
518 /** 518 /**
519 * Called when an element in the list is blurred. If focus moves outside 519 * Called when an element in the list is blurred. If focus moves outside
520 * the list, marks the list as no longer having focus and dispatches an 520 * the list, marks the list as no longer having focus and dispatches an
521 * event. 521 * event.
522 * @param {Event} e The blur event. 522 * @param {Event} e The blur event.
523 * @private 523 * @private
524 */ 524 */
525 handleElementBlur_: function(e) { 525 handleElementBlur_: function(e) {
526 if (!this.contains(e.relatedTarget)) 526 this.hasElementFocus = false;
527 this.hasElementFocus = false;
528 }, 527 },
529 528
530 /** 529 /**
531 * Returns the list item element containing the given element, or null if 530 * Returns the list item element containing the given element, or null if
532 * it doesn't belong to any list item element. 531 * it doesn't belong to any list item element.
533 * @param {HTMLElement} element The element. 532 * @param {HTMLElement} element The element.
534 * @return {HTMLLIElement} The list item containing |element|, or null. 533 * @return {HTMLLIElement} The list item containing |element|, or null.
535 */ 534 */
536 getListItemAncestor: function(element) { 535 getListItemAncestor: function(element) {
537 var container = element; 536 var container = element;
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 var el = this.getListItemByIndex(index); 761 var el = this.getListItemByIndex(index);
763 if (el) 762 if (el)
764 return el.getBoundingClientRect(); 763 return el.getBoundingClientRect();
765 return this.getBoundingClientRect(); 764 return this.getBoundingClientRect();
766 }, 765 },
767 766
768 /** 767 /**
769 * Takes a value from the data model and finds the associated list item. 768 * Takes a value from the data model and finds the associated list item.
770 * @param {*} value The value in the data model that we want to get the list 769 * @param {*} value The value in the data model that we want to get the list
771 * item for. 770 * item for.
772 * @return {ListItem} The first found list item or null if not found. 771 * @return {cr.ui.ListItem} The first found list item or null if not found.
773 */ 772 */
774 getListItem: function(value) { 773 getListItem: function(value) {
775 var dataModel = this.dataModel; 774 var dataModel = this.dataModel;
776 if (dataModel) { 775 if (dataModel) {
777 var index = dataModel.indexOf(value); 776 var index = dataModel.indexOf(value);
778 return this.getListItemByIndex(index); 777 return this.getListItemByIndex(index);
779 } 778 }
780 return null; 779 return null;
781 }, 780 },
782 781
783 /** 782 /**
784 * Find the list item element at the given index. 783 * Find the list item element at the given index.
785 * @param {number} index The index of the list item to get. 784 * @param {number} index The index of the list item to get.
786 * @return {ListItem} The found list item or null if not found. 785 * @return {cr.ui.ListItem} The found list item or null if not found.
787 */ 786 */
788 getListItemByIndex: function(index) { 787 getListItemByIndex: function(index) {
789 return this.cachedItems_[index] || null; 788 return this.cachedItems_[index] || null;
790 }, 789 },
791 790
792 /** 791 /**
793 * Find the index of the given list item element. 792 * Find the index of the given list item element.
794 * @param {ListItem} item The list item to get the index of. 793 * @param {HTMLLIElement} item The list item to get the index of.
795 * @return {number} The index of the list item, or -1 if not found. 794 * @return {number} The index of the list item, or -1 if not found.
796 */ 795 */
797 getIndexOfListItem: function(item) { 796 getIndexOfListItem: function(item) {
798 var index = item.listIndex; 797 var index = item.listIndex;
799 if (this.cachedItems_[index] == item) { 798 if (this.cachedItems_[index] == item) {
800 return index; 799 return index;
801 } 800 }
802 return -1; 801 return -1;
803 }, 802 },
804 803
805 /** 804 /**
806 * Creates a new list item. 805 * Creates a new list item.
807 * @param {*} value The value to use for the item. 806 * @param {*} value The value to use for the item.
808 * @return {!ListItem} The newly created list item. 807 * @return {!cr.ui.ListItem} The newly created list item.
809 */ 808 */
810 createItem: function(value) { 809 createItem: function(value) {
811 var item = new this.itemConstructor_(value); 810 var item = new this.itemConstructor_(value);
812 item.label = value; 811 item.label = value;
813 item.id = this.uniqueIdPrefix_ + '-' + this.nextUniqueIdSuffix_++; 812 item.id = this.uniqueIdPrefix_ + '-' + this.nextUniqueIdSuffix_++;
814 if (typeof item.decorate == 'function') 813 if (typeof item.decorate == 'function')
815 item.decorate(); 814 item.decorate();
816 return item; 815 return item;
817 }, 816 },
818 817
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1152 }, 1151 },
1153 1152
1154 /** 1153 /**
1155 * Restore the lead item that is present in the list but may be updated 1154 * Restore the lead item that is present in the list but may be updated
1156 * in the data model (supposed to be used inside a batch update). Usually 1155 * in the data model (supposed to be used inside a batch update). Usually
1157 * such an item would be recreated in the redraw method. If reinsertion 1156 * such an item would be recreated in the redraw method. If reinsertion
1158 * is undesirable (for instance to prevent losing focus) the item may be 1157 * is undesirable (for instance to prevent losing focus) the item may be
1159 * updated and restored. Assumed the listItem relates to the same data item 1158 * updated and restored. Assumed the listItem relates to the same data item
1160 * as the lead item in the begin of the batch update. 1159 * as the lead item in the begin of the batch update.
1161 * 1160 *
1162 * @param {ListItem} leadItem Already existing lead item. 1161 * @param {cr.ui.ListItem} leadItem Already existing lead item.
1163 */ 1162 */
1164 restoreLeadItem: function(leadItem) { 1163 restoreLeadItem: function(leadItem) {
1165 delete this.cachedItems_[leadItem.listIndex]; 1164 delete this.cachedItems_[leadItem.listIndex];
1166 1165
1167 leadItem.listIndex = this.selectionModel.leadIndex; 1166 leadItem.listIndex = this.selectionModel.leadIndex;
1168 this.pinnedItem_ = this.cachedItems_[leadItem.listIndex] = leadItem; 1167 this.pinnedItem_ = this.cachedItems_[leadItem.listIndex] = leadItem;
1169 }, 1168 },
1170 1169
1171 /** 1170 /**
1172 * Invalidates list by removing cached items. 1171 * Invalidates list by removing cached items.
(...skipping 22 matching lines...) Expand all
1195 */ 1194 */
1196 activateItemAtIndex: function(index) { 1195 activateItemAtIndex: function(index) {
1197 }, 1196 },
1198 1197
1199 /** 1198 /**
1200 * Returns a ListItem for the leadIndex. If the item isn't present in the 1199 * Returns a ListItem for the leadIndex. If the item isn't present in the
1201 * list creates it and inserts to the list (may be invisible if it's out of 1200 * list creates it and inserts to the list (may be invisible if it's out of
1202 * the visible range). 1201 * the visible range).
1203 * 1202 *
1204 * Item returned from this method won't be removed until it remains a lead 1203 * Item returned from this method won't be removed until it remains a lead
1205 * item or til the data model changes (unlike other items that could be 1204 * item or till the data model changes (unlike other items that could be
1206 * removed when they go out of the visible range). 1205 * removed when they go out of the visible range).
1207 * 1206 *
1208 * @return {cr.ui.ListItem} The lead item for the list. 1207 * @return {cr.ui.ListItem} The lead item for the list.
1209 */ 1208 */
1210 ensureLeadItemExists: function() { 1209 ensureLeadItemExists: function() {
1211 var index = this.selectionModel.leadIndex; 1210 var index = this.selectionModel.leadIndex;
1212 if (index < 0) 1211 if (index < 0)
1213 return null; 1212 return null;
1214 var cachedItems = this.cachedItems_ || {}; 1213 var cachedItems = this.cachedItems_ || {};
1215 1214
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 if (element.tabIndex >= 0 && !element.disabled) 1346 if (element.tabIndex >= 0 && !element.disabled)
1348 return true; 1347 return true;
1349 } 1348 }
1350 return false; 1349 return false;
1351 } 1350 }
1352 1351
1353 return { 1352 return {
1354 List: List 1353 List: List
1355 }; 1354 };
1356 }); 1355 });
OLDNEW
« no previous file with comments | « ui/webui/resources/js/cr/ui/context_menu_handler.js ('k') | ui/webui/resources/js/cr/ui/splitter.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698