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

Side by Side Diff: chrome/browser/resources/shared/js/cr/ui/list.js

Issue 11280253: Fixing column widths in tables. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review fixes. Created 8 years 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 | Annotate | Revision Log
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 this.nextUniqueIdSuffix_ = 0; 339 this.nextUniqueIdSuffix_ = 0;
340 }, 340 },
341 341
342 /** 342 /**
343 * @param {ListItem=} item The list item to measure. 343 * @param {ListItem=} item The list item to measure.
344 * @return {number} The height of the given item. If the fixed height on CSS 344 * @return {number} The height of the given item. If the fixed height on CSS
345 * is set by 'px', uses that value as height. Otherwise, measures the size. 345 * is set by 'px', uses that value as height. Otherwise, measures the size.
346 * @private 346 * @private
347 */ 347 */
348 measureItemHeight_: function(item) { 348 measureItemHeight_: function(item) {
349 var height = item.style.height;
350 // Use the fixed height if set it on CSS, to save a time of layout
351 // calculation.
352 if (height && height.substr(-2) == 'px')
353 return parseInt(height.substr(0, height.length - 2));
354
355 return this.measureItem(item).height; 349 return this.measureItem(item).height;
356 }, 350 },
357 351
358 /** 352 /**
359 * @return {number} The height of default item, measuring it if necessary. 353 * @return {number} The height of default item, measuring it if necessary.
360 * @private 354 * @private
361 */ 355 */
362 getDefaultItemHeight_: function() { 356 getDefaultItemHeight_: function() {
363 return this.getDefaultItemSize_().height; 357 return this.getDefaultItemSize_().height;
364 }, 358 },
365 359
366 /** 360 /**
367 * @param {number} index The index of the item. 361 * @param {number} index The index of the item.
368 * @return {number} The height of the item, measuring it if necessary. 362 * @return {number} The height of the item, measuring it if necessary.
369 */ 363 */
370 getItemHeightByIndex_: function(index) { 364 getItemHeightByIndex_: function(index) {
371 // If |this.fixedHeight_| is true, all the rows have same default height. 365 // If |this.fixedHeight_| is true, all the rows have same default height.
372 if (this.fixedHeight_) 366 if (this.fixedHeight_)
373 return this.getDefaultItemHeight_(); 367 return this.getDefaultItemHeight_();
374 368
375 if (this.cachedItemHeights_[index]) 369 if (this.cachedItemHeights_[index])
376 return this.cachedItemHeights_[index]; 370 return this.cachedItemHeights_[index];
377 371
378 var item = this.getListItemByIndex(index); 372 var item = this.getListItemByIndex(index);
379 if (item) 373 if (item) {
380 return this.measureItemHeight_(item); 374 var h = this.measureItemHeight_(item);
381 375 this.cachedItemHeights_[index] = h;
376 return h;
377 }
382 return this.getDefaultItemHeight_(); 378 return this.getDefaultItemHeight_();
383 }, 379 },
384 380
385 /** 381 /**
386 * @return {{height: number, width: number}} The height and width 382 * @return {{height: number, width: number}} The height and width
387 * of default item, measuring it if necessary. 383 * of default item, measuring it if necessary.
388 * @private 384 * @private
389 */ 385 */
390 getDefaultItemSize_: function() { 386 getDefaultItemSize_: function() {
391 if (!this.measured_ || !this.measured_.height) { 387 if (!this.measured_ || !this.measured_.height) {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 677
682 /** 678 /**
683 * @param {number} index The index of the item. 679 * @param {number} index The index of the item.
684 * @return {number} The top position of the item inside the list. 680 * @return {number} The top position of the item inside the list.
685 */ 681 */
686 getItemTop: function(index) { 682 getItemTop: function(index) {
687 if (this.fixedHeight_) { 683 if (this.fixedHeight_) {
688 var itemHeight = this.getDefaultItemHeight_(); 684 var itemHeight = this.getDefaultItemHeight_();
689 return index * itemHeight; 685 return index * itemHeight;
690 } else { 686 } else {
687 this.ensureAllItemSizesInCache();
691 var top = 0; 688 var top = 0;
692 for (var i = 0; i < index; i++) { 689 for (var i = 0; i < index; i++) {
693 top += this.getItemHeightByIndex_(i); 690 top += this.getItemHeightByIndex_(i);
694 } 691 }
695 return top; 692 return top;
696 } 693 }
697 }, 694 },
698 695
699 /** 696 /**
700 * @param {number} index The index of the item. 697 * @param {number} index The index of the item.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 for (var y = 0; y < measuringIndexes.length; y++) { 1043 for (var y = 0; y < measuringIndexes.length; y++) {
1047 // If the list item has been appended above, removes it. 1044 // If the list item has been appended above, removes it.
1048 if (isElementAppended[y]) 1045 if (isElementAppended[y])
1049 this.removeChild(measuringItems[y]); 1046 this.removeChild(measuringItems[y]);
1050 } 1047 }
1051 }, 1048 },
1052 1049
1053 /** 1050 /**
1054 * Returns the height of after filler in the list. 1051 * Returns the height of after filler in the list.
1055 * @param {number} lastIndex The index of item past the last in viewport. 1052 * @param {number} lastIndex The index of item past the last in viewport.
1056 * @param {number} itemHeight The height of the item.
1057 * @return {number} The height of after filler. 1053 * @return {number} The height of after filler.
1058 */ 1054 */
1059 getAfterFillerHeight: function(lastIndex) { 1055 getAfterFillerHeight: function(lastIndex) {
1060 if (this.fixedHeight_) { 1056 if (this.fixedHeight_) {
1061 var itemHeight = this.getDefaultItemHeight_(); 1057 var itemHeight = this.getDefaultItemHeight_();
1062 return (this.dataModel.length - lastIndex) * itemHeight; 1058 return (this.dataModel.length - lastIndex) * itemHeight;
1063 } 1059 }
1064 1060
1065 var height = 0; 1061 var height = 0;
1066 for (var i = lastIndex; i < this.dataModel.length; i++) 1062 for (var i = lastIndex; i < this.dataModel.length; i++)
1067 height += this.getItemHeightByIndex_(i); 1063 height += this.getItemHeightByIndex_(i);
1068 return height; 1064 return height;
1069 }, 1065 },
1070 1066
1071 /** 1067 /**
1072 * Redraws the viewport. 1068 * Redraws the viewport.
1073 */ 1069 */
1074 redraw: function() { 1070 redraw: function() {
1075 if (this.batchCount_ != 0) 1071 if (this.batchCount_ != 0)
1076 return; 1072 return;
1077 1073
1078 var dataModel = this.dataModel; 1074 var dataModel = this.dataModel;
1079 if (!dataModel || !this.autoExpands_ && this.clientHeight == 0) { 1075 if (!dataModel || !this.autoExpands_ && this.clientHeight == 0) {
1080 this.cachedItems_ = {}; 1076 this.cachedItems_ = {};
1081 this.firstIndex_ = 0; 1077 this.firstIndex_ = 0;
1082 this.lastIndex_ = 0; 1078 this.lastIndex_ = 0;
1083 this.remainingSpace_ = true; 1079 this.remainingSpace_ = this.clientHeight != 0;
1084 this.mergeItems(0, 0, {}, {}); 1080 this.mergeItems(0, 0, {}, {});
1085 return; 1081 return;
1086 } 1082 }
1087 1083
1088 // Save the previous positions before any manipulation of elements. 1084 // Save the previous positions before any manipulation of elements.
1089 var scrollTop = this.scrollTop; 1085 var scrollTop = this.scrollTop;
1090 var clientHeight = this.clientHeight; 1086 var clientHeight = this.clientHeight;
1091 1087
1092 // Store all the item sizes into the cache in advance, to prevent 1088 // Store all the item sizes into the cache in advance, to prevent
1093 // interleave measuring with mutating dom. 1089 // interleave measuring with mutating dom.
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 * because list items can contain controls that can be focused, and for some 1268 * because list items can contain controls that can be focused, and for some
1273 * purposes (e.g., styling), the list can still be conceptually focused at 1269 * purposes (e.g., styling), the list can still be conceptually focused at
1274 * that point even though it doesn't actually have the page focus. 1270 * that point even though it doesn't actually have the page focus.
1275 */ 1271 */
1276 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR); 1272 cr.defineProperty(List, 'hasElementFocus', cr.PropertyKind.BOOL_ATTR);
1277 1273
1278 return { 1274 return {
1279 List: List 1275 List: List
1280 }; 1276 };
1281 }); 1277 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/shared/css/table.css ('k') | chrome/browser/resources/shared/js/cr/ui/table.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698