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

Side by Side Diff: chrome/browser/resources/md_downloads/crisper.js

Issue 2074813002: Roll Polymer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: chromium.patch Created 4 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/vulcanized.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 /** 5 /**
6 * @fileoverview Assertion support. 6 * @fileoverview Assertion support.
7 */ 7 */
8 8
9 /** 9 /**
10 * Verify |condition| is truthy and return |condition| if so. 10 * Verify |condition| is truthy and return |condition| if so.
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 * keyEvent.key = @ 1858 * keyEvent.key = @
1859 * To get 2 returned, set noSpecialChars = true 1859 * To get 2 returned, set noSpecialChars = true
1860 * To get @ returned, set noSpecialChars = false 1860 * To get @ returned, set noSpecialChars = false
1861 */ 1861 */
1862 function normalizedKeyForEvent(keyEvent, noSpecialChars) { 1862 function normalizedKeyForEvent(keyEvent, noSpecialChars) {
1863 // Fall back from .key, to .keyIdentifier, to .keyCode, and then to 1863 // Fall back from .key, to .keyIdentifier, to .keyCode, and then to
1864 // .detail.key to support artificial keyboard events. 1864 // .detail.key to support artificial keyboard events.
1865 return transformKey(keyEvent.key, noSpecialChars) || 1865 return transformKey(keyEvent.key, noSpecialChars) ||
1866 transformKeyIdentifier(keyEvent.keyIdentifier) || 1866 transformKeyIdentifier(keyEvent.keyIdentifier) ||
1867 transformKeyCode(keyEvent.keyCode) || 1867 transformKeyCode(keyEvent.keyCode) ||
1868 transformKey(keyEvent.detail.key, noSpecialChars) || ''; 1868 transformKey(keyEvent.detail ? keyEvent.detail.key : keyEvent.detail, no SpecialChars) || '';
1869 } 1869 }
1870 1870
1871 function keyComboMatchesEvent(keyCombo, event) { 1871 function keyComboMatchesEvent(keyCombo, event) {
1872 // For combos with modifiers we support only alpha-numeric keys 1872 // For combos with modifiers we support only alpha-numeric keys
1873 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); 1873 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers);
1874 return keyEvent === keyCombo.key && 1874 return keyEvent === keyCombo.key &&
1875 (!keyCombo.hasModifiers || ( 1875 (!keyCombo.hasModifiers || (
1876 !!event.shiftKey === !!keyCombo.shiftKey && 1876 !!event.shiftKey === !!keyCombo.shiftKey &&
1877 !!event.ctrlKey === !!keyCombo.ctrlKey && 1877 !!event.ctrlKey === !!keyCombo.ctrlKey &&
1878 !!event.altKey === !!keyCombo.altKey && 1878 !!event.altKey === !!keyCombo.altKey &&
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 * This value is the same as `scrollTop`. 2511 * This value is the same as `scrollTop`.
2512 */ 2512 */
2513 _scrollPosition: 0, 2513 _scrollPosition: 0,
2514 2514
2515 /** 2515 /**
2516 * The sum of the heights of all the tiles in the DOM. 2516 * The sum of the heights of all the tiles in the DOM.
2517 */ 2517 */
2518 _physicalSize: 0, 2518 _physicalSize: 0,
2519 2519
2520 /** 2520 /**
2521 * The average `F` of the tiles observed till now. 2521 * The average `offsetHeight` of the tiles observed till now.
2522 */ 2522 */
2523 _physicalAverage: 0, 2523 _physicalAverage: 0,
2524 2524
2525 /** 2525 /**
2526 * The number of tiles which `offsetHeight` > 0 observed until now. 2526 * The number of tiles which `offsetHeight` > 0 observed until now.
2527 */ 2527 */
2528 _physicalAverageCount: 0, 2528 _physicalAverageCount: 0,
2529 2529
2530 /** 2530 /**
2531 * The Y position of the item rendered in the `_physicalStart` 2531 * The Y position of the item rendered in the `_physicalStart`
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 if (this._firstVisibleIndexVal === null) { 2779 if (this._firstVisibleIndexVal === null) {
2780 var physicalOffset = Math.floor(this._physicalTop + this._scrollerPaddin gTop); 2780 var physicalOffset = Math.floor(this._physicalTop + this._scrollerPaddin gTop);
2781 2781
2782 this._firstVisibleIndexVal = this._iterateItems( 2782 this._firstVisibleIndexVal = this._iterateItems(
2783 function(pidx, vidx) { 2783 function(pidx, vidx) {
2784 physicalOffset += this._getPhysicalSizeIncrement(pidx); 2784 physicalOffset += this._getPhysicalSizeIncrement(pidx);
2785 2785
2786 if (physicalOffset > this._scrollPosition) { 2786 if (physicalOffset > this._scrollPosition) {
2787 return this.grid ? vidx - (vidx % this._itemsPerRow) : vidx; 2787 return this.grid ? vidx - (vidx % this._itemsPerRow) : vidx;
2788 } 2788 }
2789
2790 // Handle a partially rendered final row in grid mode 2789 // Handle a partially rendered final row in grid mode
2791 if (this.grid && this._virtualCount - 1 === vidx) { 2790 if (this.grid && this._virtualCount - 1 === vidx) {
2792 return vidx - (vidx % this._itemsPerRow); 2791 return vidx - (vidx % this._itemsPerRow);
2793 } 2792 }
2794 }) || 0; 2793 }) || 0;
2795 } 2794 }
2796 return this._firstVisibleIndexVal; 2795 return this._firstVisibleIndexVal;
2797 }, 2796 },
2798 2797
2799 /** 2798 /**
2800 * Gets the index of the last visible item in the viewport. 2799 * Gets the index of the last visible item in the viewport.
2801 * 2800 *
2802 * @type {number} 2801 * @type {number}
2803 */ 2802 */
2804 get lastVisibleIndex() { 2803 get lastVisibleIndex() {
2805 if (this._lastVisibleIndexVal === null) { 2804 if (this._lastVisibleIndexVal === null) {
2806 if (this.grid) { 2805 if (this.grid) {
2807 var lastIndex = this.firstVisibleIndex + this._estRowsInView * this._i temsPerRow - 1; 2806 var lastIndex = this.firstVisibleIndex + this._estRowsInView * this._i temsPerRow - 1;
2808 this._lastVisibleIndexVal = lastIndex > this._virtualCount ? this._vir tualCount : lastIndex; 2807 this._lastVisibleIndexVal = Math.min(this._virtualCount, lastIndex);
2809 } else { 2808 } else {
2810 var physicalOffset = this._physicalTop; 2809 var physicalOffset = this._physicalTop;
2811
2812 this._iterateItems(function(pidx, vidx) { 2810 this._iterateItems(function(pidx, vidx) {
2811 if (physicalOffset < this._scrollBottom) {
2812 this._lastVisibleIndexVal = vidx;
2813 } else {
2814 // Break _iterateItems
2815 return true;
2816 }
2813 physicalOffset += this._getPhysicalSizeIncrement(pidx); 2817 physicalOffset += this._getPhysicalSizeIncrement(pidx);
2814
2815 if(physicalOffset <= this._scrollBottom) {
2816 if (this.grid) {
2817 var lastIndex = vidx - vidx % this._itemsPerRow + this._itemsPer Row - 1;
2818 this._lastVisibleIndexVal = lastIndex > this._virtualCount ? thi s._virtualCount : lastIndex;
2819 } else {
2820 this._lastVisibleIndexVal = vidx;
2821 }
2822 }
2823 }); 2818 });
2824 } 2819 }
2825 } 2820 }
2826 return this._lastVisibleIndexVal; 2821 return this._lastVisibleIndexVal;
2827 }, 2822 },
2828 2823
2829 get _defaultScrollTarget() { 2824 get _defaultScrollTarget() {
2830 return this; 2825 return this;
2831 }, 2826 },
2832 get _virtualRowCount() { 2827 get _virtualRowCount() {
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
3187 }, 3182 },
3188 3183
3189 /** 3184 /**
3190 * Called as a side effect of a host items.<key>.<path> path change, 3185 * Called as a side effect of a host items.<key>.<path> path change,
3191 * responsible for notifying item.<path> changes. 3186 * responsible for notifying item.<path> changes.
3192 */ 3187 */
3193 _forwardItemPath: function(path, value) { 3188 _forwardItemPath: function(path, value) {
3194 if (!this._physicalIndexForKey) { 3189 if (!this._physicalIndexForKey) {
3195 return; 3190 return;
3196 } 3191 }
3197 var inst;
3198 var dot = path.indexOf('.'); 3192 var dot = path.indexOf('.');
3199 var key = path.substring(0, dot < 0 ? path.length : dot); 3193 var key = path.substring(0, dot < 0 ? path.length : dot);
3200 var idx = this._physicalIndexForKey[key]; 3194 var idx = this._physicalIndexForKey[key];
3201 var el = this._physicalItems[idx]; 3195 var offscreenItem = this._offscreenFocusedItem;
3196 var el = offscreenItem && offscreenItem._templateInstance.__key__ === key ?
3197 offscreenItem : this._physicalItems[idx];
3202 3198
3203 3199 if (!el || el._templateInstance.__key__ !== key) {
3204 if (idx === this._focusedIndex && this._offscreenFocusedItem) {
3205 el = this._offscreenFocusedItem;
3206 }
3207 if (!el) {
3208 return; 3200 return;
3209 } 3201 }
3210 3202
3211 inst = el._templateInstance;
3212
3213 if (inst.__key__ !== key) {
3214 return;
3215 }
3216 if (dot >= 0) { 3203 if (dot >= 0) {
3217 path = this.as + '.' + path.substring(dot+1); 3204 path = this.as + '.' + path.substring(dot+1);
3218 inst.notifyPath(path, value, true); 3205 el._templateInstance.notifyPath(path, value, true);
3219 } else { 3206 } else {
3220 inst[this.as] = value; 3207 el._templateInstance[this.as] = value;
3221 } 3208 }
3209
3222 }, 3210 },
3223 3211
3224 /** 3212 /**
3225 * Called when the items have changed. That is, ressignments 3213 * Called when the items have changed. That is, ressignments
3226 * to `items`, splices or updates to a single item. 3214 * to `items`, splices or updates to a single item.
3227 */ 3215 */
3228 _itemsChanged: function(change) { 3216 _itemsChanged: function(change) {
3229 if (change.path === 'items') { 3217 if (change.path === 'items') {
3230 // reset items 3218 // reset items
3231 this._virtualStart = 0; 3219 this._virtualStart = 0;
3232 this._physicalTop = 0; 3220 this._physicalTop = 0;
3233 this._virtualCount = this.items ? this.items.length : 0; 3221 this._virtualCount = this.items ? this.items.length : 0;
3234 this._collection = this.items ? Polymer.Collection.get(this.items) : nul l; 3222 this._collection = this.items ? Polymer.Collection.get(this.items) : nul l;
3235 this._physicalIndexForKey = {}; 3223 this._physicalIndexForKey = {};
3224 this._firstVisibleIndexVal = null;
3225 this._lastVisibleIndexVal = null;
3236 3226
3237 this._resetScrollPosition(0); 3227 this._resetScrollPosition(0);
3238 this._removeFocusedItem(); 3228 this._removeFocusedItem();
3239
3240 // create the initial physical items 3229 // create the initial physical items
3241 if (!this._physicalItems) { 3230 if (!this._physicalItems) {
3242 this._physicalCount = Math.max(1, Math.min(DEFAULT_PHYSICAL_COUNT, thi s._virtualCount)); 3231 this._physicalCount = Math.max(1, Math.min(DEFAULT_PHYSICAL_COUNT, thi s._virtualCount));
3243 this._physicalItems = this._createPool(this._physicalCount); 3232 this._physicalItems = this._createPool(this._physicalCount);
3244 this._physicalSizes = new Array(this._physicalCount); 3233 this._physicalSizes = new Array(this._physicalCount);
3245 } 3234 }
3246 3235
3247 this._physicalStart = 0; 3236 this._physicalStart = 0;
3248 3237
3249 } else if (change.path === 'items.splices') { 3238 } else if (change.path === 'items.splices') {
3239
3250 this._adjustVirtualIndex(change.value.indexSplices); 3240 this._adjustVirtualIndex(change.value.indexSplices);
3251 this._virtualCount = this.items ? this.items.length : 0; 3241 this._virtualCount = this.items ? this.items.length : 0;
3252 3242
3253 } else { 3243 } else {
3254 // update a single item 3244 // update a single item
3255 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change. value); 3245 this._forwardItemPath(change.path.split('.').slice(1).join('.'), change. value);
3256 return; 3246 return;
3257 } 3247 }
3258 3248
3259 this._itemsRendered = false; 3249 this._itemsRendered = false;
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3472 /** 3462 /**
3473 * Adjusts the scroll position when it was overestimated. 3463 * Adjusts the scroll position when it was overestimated.
3474 */ 3464 */
3475 _adjustScrollPosition: function() { 3465 _adjustScrollPosition: function() {
3476 var deltaHeight = this._virtualStart === 0 ? this._physicalTop : 3466 var deltaHeight = this._virtualStart === 0 ? this._physicalTop :
3477 Math.min(this._scrollPosition + this._physicalTop, 0); 3467 Math.min(this._scrollPosition + this._physicalTop, 0);
3478 3468
3479 if (deltaHeight) { 3469 if (deltaHeight) {
3480 this._physicalTop = this._physicalTop - deltaHeight; 3470 this._physicalTop = this._physicalTop - deltaHeight;
3481 // juking scroll position during interial scrolling on iOS is no bueno 3471 // juking scroll position during interial scrolling on iOS is no bueno
3482 if (!IOS_TOUCH_SCROLLING) { 3472 if (!IOS_TOUCH_SCROLLING && this._physicalTop !== 0) {
3483 this._resetScrollPosition(this._scrollTop - deltaHeight); 3473 this._resetScrollPosition(this._scrollTop - deltaHeight);
3484 } 3474 }
3485 } 3475 }
3486 }, 3476 },
3487 3477
3488 /** 3478 /**
3489 * Sets the position of the scroll. 3479 * Sets the position of the scroll.
3490 */ 3480 */
3491 _resetScrollPosition: function(pos) { 3481 _resetScrollPosition: function(pos) {
3492 if (this.scrollTarget) { 3482 if (this.scrollTarget) {
(...skipping 18 matching lines...) Expand all
3511 forceUpdate = forceUpdate || this._scrollHeight === 0; 3501 forceUpdate = forceUpdate || this._scrollHeight === 0;
3512 forceUpdate = forceUpdate || this._scrollPosition >= this._estScrollHeight - this._physicalSize; 3502 forceUpdate = forceUpdate || this._scrollPosition >= this._estScrollHeight - this._physicalSize;
3513 forceUpdate = forceUpdate || this.grid && this.$.items.style.height < this ._estScrollHeight; 3503 forceUpdate = forceUpdate || this.grid && this.$.items.style.height < this ._estScrollHeight;
3514 3504
3515 // amortize height adjustment, so it won't trigger repaints very often 3505 // amortize height adjustment, so it won't trigger repaints very often
3516 if (forceUpdate || Math.abs(this._estScrollHeight - this._scrollHeight) >= this._optPhysicalSize) { 3506 if (forceUpdate || Math.abs(this._estScrollHeight - this._scrollHeight) >= this._optPhysicalSize) {
3517 this.$.items.style.height = this._estScrollHeight + 'px'; 3507 this.$.items.style.height = this._estScrollHeight + 'px';
3518 this._scrollHeight = this._estScrollHeight; 3508 this._scrollHeight = this._estScrollHeight;
3519 } 3509 }
3520 }, 3510 },
3511
3521 /** 3512 /**
3522 * Scroll to a specific item in the virtual list regardless 3513 * Scroll to a specific item in the virtual list regardless
3523 * of the physical items in the DOM tree. 3514 * of the physical items in the DOM tree.
3524 * 3515 *
3516 * @method scrollToItem
3517 * @param {(Object)} item The item to be scrolled to
3518 */
3519 scrollToItem: function(item){
3520 return this.scrollToIndex(this.items.indexOf(item));
3521 },
3522
3523 /**
3524 * Scroll to a specific index in the virtual list regardless
3525 * of the physical items in the DOM tree.
3526 *
3525 * @method scrollToIndex 3527 * @method scrollToIndex
3526 * @param {number} idx The index of the item 3528 * @param {number} idx The index of the item
3527 */ 3529 */
3528 scrollToIndex: function(idx) { 3530 scrollToIndex: function(idx) {
3529 if (typeof idx !== 'number') { 3531 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) {
3530 return; 3532 return;
3531 } 3533 }
3532 3534
3533 Polymer.dom.flush(); 3535 Polymer.dom.flush();
3534 3536
3535 idx = Math.min(Math.max(idx, 0), this._virtualCount-1); 3537 idx = Math.min(Math.max(idx, 0), this._virtualCount-1);
3536 // update the virtual start only when needed 3538 // update the virtual start only when needed
3537 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { 3539 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) {
3538 this._virtualStart = this.grid ? (idx - this._itemsPerRow * 2) : (idx - 1); 3540 this._virtualStart = this.grid ? (idx - this._itemsPerRow * 2) : (idx - 1);
3539 } 3541 }
(...skipping 6832 matching lines...) Expand 10 before | Expand all | Expand 10 after
10372 }, 10374 },
10373 10375
10374 /** 10376 /**
10375 * @return {string} The value of the search field. 10377 * @return {string} The value of the search field.
10376 */ 10378 */
10377 getValue: function() { 10379 getValue: function() {
10378 return this.$.searchInput.value; 10380 return this.$.searchInput.value;
10379 }, 10381 },
10380 10382
10381 /** 10383 /**
10382 * Sets the value of the search field, if it exists. 10384 * Sets the value of the search field.
10383 * @param {string} value 10385 * @param {string} value
10384 */ 10386 */
10385 setValue: function(value) { 10387 setValue: function(value) {
10386 // Use bindValue when setting the input value so that changes propagate 10388 // Use bindValue when setting the input value so that changes propagate
10387 // correctly. 10389 // correctly.
10388 this.$.searchInput.bindValue = value; 10390 this.$.searchInput.bindValue = value;
10389 this.hasSearchText = value != ''; 10391 this.onValueChanged_(value);
10390 }, 10392 },
10391 10393
10392 showAndFocus: function() { 10394 showAndFocus: function() {
10393 this.showingSearch = true; 10395 this.showingSearch = true;
10394 this.focus_(); 10396 this.focus_();
10395 }, 10397 },
10396 10398
10397 /** @private */ 10399 /** @private */
10398 focus_: function() { 10400 focus_: function() {
10399 this.$.searchInput.focus(); 10401 this.$.searchInput.focus();
10400 }, 10402 },
10401 10403
10402 onSearchTermSearch: function() { 10404 onSearchTermSearch: function() {
10403 var newValue = this.getValue(); 10405 this.onValueChanged_(this.getValue());
10406 },
10407
10408 /**
10409 * Updates the internal state of the search field based on a change that has
10410 * already happened.
10411 * @param {string} newValue
10412 * @private
10413 */
10414 onValueChanged_: function(newValue) {
10404 if (newValue == this.lastValue_) 10415 if (newValue == this.lastValue_)
10405 return; 10416 return;
10406 10417
10407 this.hasSearchText = newValue != ''; 10418 this.hasSearchText = newValue != '';
10408 this.fire('search-changed', newValue); 10419 this.fire('search-changed', newValue);
10409 this.lastValue_ = newValue; 10420 this.lastValue_ = newValue;
10410 }, 10421 },
10411 10422
10412 onSearchTermKeydown: function(e) { 10423 onSearchTermKeydown: function(e) {
10413 if (e.key == 'Escape') 10424 if (e.key == 'Escape')
10414 this.showingSearch = false; 10425 this.showingSearch = false;
10415 }, 10426 },
10416 10427
10417 /** @private */ 10428 /** @private */
10418 showingSearchChanged_: function() { 10429 showingSearchChanged_: function() {
10419 if (this.showingSearch) { 10430 if (this.showingSearch) {
10420 this.focus_(); 10431 this.focus_();
10421 return; 10432 return;
10422 } 10433 }
10423 10434
10424 this.setValue(''); 10435 this.setValue('');
10425 this.$.searchInput.blur(); 10436 this.$.searchInput.blur();
10426 this.onSearchTermSearch();
10427 }, 10437 },
10428 10438
10429 /** @private */ 10439 /** @private */
10430 toggleShowingSearch_: function() { 10440 toggleShowingSearch_: function() {
10431 this.showingSearch = !this.showingSearch; 10441 this.showingSearch = !this.showingSearch;
10432 }, 10442 },
10433 }; 10443 };
10434 (function() { 10444 (function() {
10435 'use strict'; 10445 'use strict';
10436 10446
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after
11482 Manager.get().updateItem_(index, data); 11492 Manager.get().updateItem_(index, data);
11483 }; 11493 };
11484 11494
11485 return {Manager: Manager}; 11495 return {Manager: Manager};
11486 }); 11496 });
11487 // Copyright 2015 The Chromium Authors. All rights reserved. 11497 // Copyright 2015 The Chromium Authors. All rights reserved.
11488 // Use of this source code is governed by a BSD-style license that can be 11498 // Use of this source code is governed by a BSD-style license that can be
11489 // found in the LICENSE file. 11499 // found in the LICENSE file.
11490 11500
11491 window.addEventListener('load', downloads.Manager.onLoad); 11501 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_downloads/vulcanized.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698