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

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

Issue 2089563002: [Polymer] update polymer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2361 return this.scrollTarget instanceof HTMLElement; 2361 return this.scrollTarget instanceof HTMLElement;
2362 } 2362 }
2363 }; 2363 };
2364 (function() { 2364 (function() {
2365 2365
2366 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/); 2366 var IOS = navigator.userAgent.match(/iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/);
2367 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8; 2367 var IOS_TOUCH_SCROLLING = IOS && IOS[1] >= 8;
2368 var DEFAULT_PHYSICAL_COUNT = 3; 2368 var DEFAULT_PHYSICAL_COUNT = 3;
2369 var HIDDEN_Y = '-10000px'; 2369 var HIDDEN_Y = '-10000px';
2370 var DEFAULT_GRID_SIZE = 200; 2370 var DEFAULT_GRID_SIZE = 200;
2371 var SECRET_TABINDEX = -100;
2371 2372
2372 Polymer({ 2373 Polymer({
2373 2374
2374 is: 'iron-list', 2375 is: 'iron-list',
2375 2376
2376 properties: { 2377 properties: {
2377 2378
2378 /** 2379 /**
2379 * An array containing items determining how many instances of the templat e 2380 * An array containing items determining how many instances of the templat e
2380 * to stamp and that that each template instance should bind to. 2381 * to stamp and that that each template instance should bind to.
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
3192 var dot = path.indexOf('.'); 3193 var dot = path.indexOf('.');
3193 var key = path.substring(0, dot < 0 ? path.length : dot); 3194 var key = path.substring(0, dot < 0 ? path.length : dot);
3194 var idx = this._physicalIndexForKey[key]; 3195 var idx = this._physicalIndexForKey[key];
3195 var offscreenItem = this._offscreenFocusedItem; 3196 var offscreenItem = this._offscreenFocusedItem;
3196 var el = offscreenItem && offscreenItem._templateInstance.__key__ === key ? 3197 var el = offscreenItem && offscreenItem._templateInstance.__key__ === key ?
3197 offscreenItem : this._physicalItems[idx]; 3198 offscreenItem : this._physicalItems[idx];
3198 3199
3199 if (!el || el._templateInstance.__key__ !== key) { 3200 if (!el || el._templateInstance.__key__ !== key) {
3200 return; 3201 return;
3201 } 3202 }
3202
3203 if (dot >= 0) { 3203 if (dot >= 0) {
3204 path = this.as + '.' + path.substring(dot+1); 3204 path = this.as + '.' + path.substring(dot+1);
3205 el._templateInstance.notifyPath(path, value, true); 3205 el._templateInstance.notifyPath(path, value, true);
3206 } else { 3206 } else {
3207 // Update selection if needed
3208 var currentItem = el._templateInstance[this.as];
3209 if (Array.isArray(this.selectedItems)) {
3210 for (var i = 0; i < this.selectedItems.length; i++) {
3211 if (this.selectedItems[i] === currentItem) {
3212 this.set('selectedItems.' + i, value);
3213 break;
3214 }
3215 }
3216 } else if (this.selectedItem === currentItem) {
3217 this.set('selectedItem', value);
3218 }
3207 el._templateInstance[this.as] = value; 3219 el._templateInstance[this.as] = value;
3208 } 3220 }
3209
3210 }, 3221 },
3211 3222
3212 /** 3223 /**
3213 * Called when the items have changed. That is, ressignments 3224 * Called when the items have changed. That is, ressignments
3214 * to `items`, splices or updates to a single item. 3225 * to `items`, splices or updates to a single item.
3215 */ 3226 */
3216 _itemsChanged: function(change) { 3227 _itemsChanged: function(change) {
3217 if (change.path === 'items') { 3228 if (change.path === 'items') {
3218 // reset items 3229 // reset items
3219 this._virtualStart = 0; 3230 this._virtualStart = 0;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 3398
3388 // update the average if we measured something 3399 // update the average if we measured something
3389 if (this._physicalAverageCount !== prevAvgCount) { 3400 if (this._physicalAverageCount !== prevAvgCount) {
3390 this._physicalAverage = Math.round( 3401 this._physicalAverage = Math.round(
3391 ((prevPhysicalAvg * prevAvgCount) + newPhysicalSize) / 3402 ((prevPhysicalAvg * prevAvgCount) + newPhysicalSize) /
3392 this._physicalAverageCount); 3403 this._physicalAverageCount);
3393 } 3404 }
3394 }, 3405 },
3395 3406
3396 _updateGridMetrics: function() { 3407 _updateGridMetrics: function() {
3397 this._viewportWidth = this._scrollTargetWidth; 3408 this._viewportWidth = this.$.items.offsetWidth;
3398 // Set item width to the value of the _physicalItems offsetWidth 3409 // Set item width to the value of the _physicalItems offsetWidth
3399 this._itemWidth = this._physicalCount > 0 ? this._physicalItems[0].offsetW idth : DEFAULT_GRID_SIZE; 3410 this._itemWidth = this._physicalCount > 0 ? this._physicalItems[0].getBoun dingClientRect().width : DEFAULT_GRID_SIZE;
3400 // Set row height to the value of the _physicalItems offsetHeight 3411 // Set row height to the value of the _physicalItems offsetHeight
3401 this._rowHeight = this._physicalCount > 0 ? this._physicalItems[0].offsetH eight : DEFAULT_GRID_SIZE; 3412 this._rowHeight = this._physicalCount > 0 ? this._physicalItems[0].offsetH eight : DEFAULT_GRID_SIZE;
3402 // If in grid mode compute how many items with exist in each row 3413 // If in grid mode compute how many items with exist in each row
3403 this._itemsPerRow = this._itemWidth ? Math.floor(this._viewportWidth / thi s._itemWidth) : this._itemsPerRow; 3414 this._itemsPerRow = this._itemWidth ? Math.floor(this._viewportWidth / thi s._itemWidth) : this._itemsPerRow;
3404 }, 3415 },
3405 3416
3406 /** 3417 /**
3407 * Updates the position of the physical items. 3418 * Updates the position of the physical items.
3408 */ 3419 */
3409 _positionItems: function() { 3420 _positionItems: function() {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
3716 */ 3727 */
3717 _selectionEnabledChanged: function(selectionEnabled) { 3728 _selectionEnabledChanged: function(selectionEnabled) {
3718 var handler = selectionEnabled ? this.listen : this.unlisten; 3729 var handler = selectionEnabled ? this.listen : this.unlisten;
3719 handler.call(this, this, 'tap', '_selectionHandler'); 3730 handler.call(this, this, 'tap', '_selectionHandler');
3720 }, 3731 },
3721 3732
3722 /** 3733 /**
3723 * Select an item from an event object. 3734 * Select an item from an event object.
3724 */ 3735 */
3725 _selectionHandler: function(e) { 3736 _selectionHandler: function(e) {
3726 if (this.selectionEnabled) { 3737 var model = this.modelForElement(e.target);
3727 var model = this.modelForElement(e.target); 3738 if (!model) {
3728 if (model) { 3739 return;
3729 this.toggleSelectionForItem(model[this.as]);
3730 }
3731 } 3740 }
3741 var modelTabIndex, activeElTabIndex;
3742 var target = Polymer.dom(e).path[0];
3743 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac tiveElement;
3744 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i ndexAs])];
3745 // Safari does not focus certain form controls via mouse
3746 // https://bugs.webkit.org/show_bug.cgi?id=118043
3747 if (target.localName === 'input' ||
3748 target.localName === 'button' ||
3749 target.localName === 'select') {
3750 return;
3751 }
3752 // Set a temporary tabindex
3753 modelTabIndex = model.tabIndex;
3754 model.tabIndex = SECRET_TABINDEX;
3755 activeElTabIndex = activeEl ? activeEl.tabIndex : -1;
3756 model.tabIndex = modelTabIndex;
3757 // Only select the item if the tap wasn't on a focusable child
3758 // or the element bound to `tabIndex`
3759 if (activeEl && physicalItem.contains(activeEl) && activeElTabIndex !== SE CRET_TABINDEX) {
3760 return;
3761 }
3762 this.toggleSelectionForItem(model[this.as]);
3732 }, 3763 },
3733 3764
3734 _multiSelectionChanged: function(multiSelection) { 3765 _multiSelectionChanged: function(multiSelection) {
3735 this.clearSelection(); 3766 this.clearSelection();
3736 this.$.selector.multi = multiSelection; 3767 this.$.selector.multi = multiSelection;
3737 }, 3768 },
3738 3769
3739 /** 3770 /**
3740 * Updates the size of an item. 3771 * Updates the size of an item.
3741 * 3772 *
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3794 if (idx < 0 || idx >= this._virtualCount) { 3825 if (idx < 0 || idx >= this._virtualCount) {
3795 return; 3826 return;
3796 } 3827 }
3797 this._restoreFocusedItem(); 3828 this._restoreFocusedItem();
3798 // scroll to index to make sure it's rendered 3829 // scroll to index to make sure it's rendered
3799 if (!this._isIndexRendered(idx)) { 3830 if (!this._isIndexRendered(idx)) {
3800 this.scrollToIndex(idx); 3831 this.scrollToIndex(idx);
3801 } 3832 }
3802 3833
3803 var physicalItem = this._physicalItems[this._getPhysicalIndex(idx)]; 3834 var physicalItem = this._physicalItems[this._getPhysicalIndex(idx)];
3804 var SECRET = ~(Math.random() * 100);
3805 var model = physicalItem._templateInstance; 3835 var model = physicalItem._templateInstance;
3806 var focusable; 3836 var focusable;
3807 3837
3808 // set a secret tab index 3838 // set a secret tab index
3809 model.tabIndex = SECRET; 3839 model.tabIndex = SECRET_TABINDEX;
3810 // check if focusable element is the physical item 3840 // check if focusable element is the physical item
3811 if (physicalItem.tabIndex === SECRET) { 3841 if (physicalItem.tabIndex === SECRET_TABINDEX) {
3812 focusable = physicalItem; 3842 focusable = physicalItem;
3813 } 3843 }
3814 // search for the element which tabindex is bound to the secret tab index 3844 // search for the element which tabindex is bound to the secret tab index
3815 if (!focusable) { 3845 if (!focusable) {
3816 focusable = Polymer.dom(physicalItem).querySelector('[tabindex="' + SECR ET + '"]'); 3846 focusable = Polymer.dom(physicalItem).querySelector('[tabindex="' + SECR ET_TABINDEX + '"]');
3817 } 3847 }
3818 // restore the tab index 3848 // restore the tab index
3819 model.tabIndex = 0; 3849 model.tabIndex = 0;
3820 // focus the focusable element 3850 // focus the focusable element
3821 this._focusedIndex = idx; 3851 this._focusedIndex = idx;
3822 focusable && focusable.focus(); 3852 focusable && focusable.focus();
3823 }, 3853 },
3824 3854
3825 _removeFocusedItem: function() { 3855 _removeFocusedItem: function() {
3826 if (this._offscreenFocusedItem) { 3856 if (this._offscreenFocusedItem) {
(...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after
5283 5313
5284 _boundAnimate: { 5314 _boundAnimate: {
5285 type: Function, 5315 type: Function,
5286 value: function() { 5316 value: function() {
5287 return this.animate.bind(this); 5317 return this.animate.bind(this);
5288 } 5318 }
5289 } 5319 }
5290 }, 5320 },
5291 5321
5292 get target () { 5322 get target () {
5293 var ownerRoot = Polymer.dom(this).getOwnerRoot(); 5323 return this.keyEventTarget;
5294 var target;
5295
5296 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE
5297 target = ownerRoot.host;
5298 } else {
5299 target = this.parentNode;
5300 }
5301
5302 return target;
5303 }, 5324 },
5304 5325
5305 keyBindings: { 5326 keyBindings: {
5306 'enter:keydown': '_onEnterKeydown', 5327 'enter:keydown': '_onEnterKeydown',
5307 'space:keydown': '_onSpaceKeydown', 5328 'space:keydown': '_onSpaceKeydown',
5308 'space:keyup': '_onSpaceKeyup' 5329 'space:keyup': '_onSpaceKeyup'
5309 }, 5330 },
5310 5331
5311 attached: function() { 5332 attached: function() {
5312 // Set up a11yKeysBehavior to listen to key events on the target, 5333 // Set up a11yKeysBehavior to listen to key events on the target,
5313 // so that space and enter activate the ripple even if the target doesn' t 5334 // so that space and enter activate the ripple even if the target doesn' t
5314 // handle key events. The key handlers deal with `noink` themselves. 5335 // handle key events. The key handlers deal with `noink` themselves.
5315 this.keyEventTarget = this.target; 5336 if (this.parentNode.nodeType == 11) { // DOCUMENT_FRAGMENT_NODE
5316 this.listen(this.target, 'up', 'uiUpAction'); 5337 this.keyEventTarget = Polymer.dom(this).getOwnerRoot().host;
5317 this.listen(this.target, 'down', 'uiDownAction'); 5338 } else {
5339 this.keyEventTarget = this.parentNode;
5340 }
5341 this.listen(this.keyEventTarget, 'up', 'uiUpAction');
5342 this.listen(this.keyEventTarget, 'down', 'uiDownAction');
5318 }, 5343 },
5319 5344
5320 detached: function() { 5345 detached: function() {
5321 this.unlisten(this.target, 'up', 'uiUpAction'); 5346 this.unlisten(this.keyEventTarget, 'up', 'uiUpAction');
5322 this.unlisten(this.target, 'down', 'uiDownAction'); 5347 this.unlisten(this.keyEventTarget, 'down', 'uiDownAction');
5348 this.keyEventTarget = null;
5323 }, 5349 },
5324 5350
5325 get shouldKeepAnimating () { 5351 get shouldKeepAnimating () {
5326 for (var index = 0; index < this.ripples.length; ++index) { 5352 for (var index = 0; index < this.ripples.length; ++index) {
5327 if (!this.ripples[index].isAnimationComplete) { 5353 if (!this.ripples[index].isAnimationComplete) {
5328 return true; 5354 return true;
5329 } 5355 }
5330 } 5356 }
5331 5357
5332 return false; 5358 return false;
(...skipping 27 matching lines...) Expand all
5360 downAction: function(event) { 5386 downAction: function(event) {
5361 if (this.holdDown && this.ripples.length > 0) { 5387 if (this.holdDown && this.ripples.length > 0) {
5362 return; 5388 return;
5363 } 5389 }
5364 5390
5365 var ripple = this.addRipple(); 5391 var ripple = this.addRipple();
5366 5392
5367 ripple.downAction(event); 5393 ripple.downAction(event);
5368 5394
5369 if (!this._animating) { 5395 if (!this._animating) {
5396 this._animating = true;
5370 this.animate(); 5397 this.animate();
5371 } 5398 }
5372 }, 5399 },
5373 5400
5374 /** 5401 /**
5375 * Provokes a ripple up effect via a UI event, 5402 * Provokes a ripple up effect via a UI event,
5376 * respecting the `noink` property. 5403 * respecting the `noink` property.
5377 * @param {Event=} event 5404 * @param {Event=} event
5378 */ 5405 */
5379 uiUpAction: function(event) { 5406 uiUpAction: function(event) {
5380 if (!this.noink) { 5407 if (!this.noink) {
5381 this.upAction(event); 5408 this.upAction(event);
5382 } 5409 }
5383 }, 5410 },
5384 5411
5385 /** 5412 /**
5386 * Provokes a ripple up effect via a UI event, 5413 * Provokes a ripple up effect via a UI event,
5387 * *not* respecting the `noink` property. 5414 * *not* respecting the `noink` property.
5388 * @param {Event=} event 5415 * @param {Event=} event
5389 */ 5416 */
5390 upAction: function(event) { 5417 upAction: function(event) {
5391 if (this.holdDown) { 5418 if (this.holdDown) {
5392 return; 5419 return;
5393 } 5420 }
5394 5421
5395 this.ripples.forEach(function(ripple) { 5422 this.ripples.forEach(function(ripple) {
5396 ripple.upAction(event); 5423 ripple.upAction(event);
5397 }); 5424 });
5398 5425
5426 this._animating = true;
5399 this.animate(); 5427 this.animate();
5400 }, 5428 },
5401 5429
5402 onAnimationComplete: function() { 5430 onAnimationComplete: function() {
5403 this._animating = false; 5431 this._animating = false;
5404 this.$.background.style.backgroundColor = null; 5432 this.$.background.style.backgroundColor = null;
5405 this.fire('transitionend'); 5433 this.fire('transitionend');
5406 }, 5434 },
5407 5435
5408 addRipple: function() { 5436 addRipple: function() {
(...skipping 18 matching lines...) Expand all
5427 this.ripples.splice(rippleIndex, 1); 5455 this.ripples.splice(rippleIndex, 1);
5428 5456
5429 ripple.remove(); 5457 ripple.remove();
5430 5458
5431 if (!this.ripples.length) { 5459 if (!this.ripples.length) {
5432 this._setAnimating(false); 5460 this._setAnimating(false);
5433 } 5461 }
5434 }, 5462 },
5435 5463
5436 animate: function() { 5464 animate: function() {
5465 if (!this._animating) {
5466 return;
5467 }
5437 var index; 5468 var index;
5438 var ripple; 5469 var ripple;
5439 5470
5440 this._animating = true;
5441
5442 for (index = 0; index < this.ripples.length; ++index) { 5471 for (index = 0; index < this.ripples.length; ++index) {
5443 ripple = this.ripples[index]; 5472 ripple = this.ripples[index];
5444 5473
5445 ripple.draw(); 5474 ripple.draw();
5446 5475
5447 this.$.background.style.opacity = ripple.outerOpacity; 5476 this.$.background.style.opacity = ripple.outerOpacity;
5448 5477
5449 if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) { 5478 if (ripple.isOpacityFullyDecayed && !ripple.isRestingAtMaxRadius) {
5450 this.removeRipple(ripple); 5479 this.removeRipple(ripple);
5451 } 5480 }
(...skipping 24 matching lines...) Expand all
5476 _holdDownChanged: function(newVal, oldVal) { 5505 _holdDownChanged: function(newVal, oldVal) {
5477 if (oldVal === undefined) { 5506 if (oldVal === undefined) {
5478 return; 5507 return;
5479 } 5508 }
5480 if (newVal) { 5509 if (newVal) {
5481 this.downAction(); 5510 this.downAction();
5482 } else { 5511 } else {
5483 this.upAction(); 5512 this.upAction();
5484 } 5513 }
5485 } 5514 }
5515
5516 /**
5517 Fired when the animation finishes.
5518 This is useful if you want to wait until
5519 the ripple animation finishes to perform some action.
5520
5521 @event transitionend
5522 @param {{node: Object}} detail Contains the animated node.
5523 */
5486 }); 5524 });
5487 })(); 5525 })();
5488 /** 5526 /**
5489 * `Polymer.PaperRippleBehavior` dynamically implements a ripple 5527 * `Polymer.PaperRippleBehavior` dynamically implements a ripple
5490 * when the element has focus via pointer or keyboard. 5528 * when the element has focus via pointer or keyboard.
5491 * 5529 *
5492 * NOTE: This behavior is intended to be used in conjunction with and after 5530 * NOTE: This behavior is intended to be used in conjunction with and after
5493 * `Polymer.IronButtonState` and `Polymer.IronControlState`. 5531 * `Polymer.IronButtonState` and `Polymer.IronControlState`.
5494 * 5532 *
5495 * @polymerBehavior Polymer.PaperRippleBehavior 5533 * @polymerBehavior Polymer.PaperRippleBehavior
(...skipping 5996 matching lines...) Expand 10 before | Expand all | Expand 10 after
11492 Manager.get().updateItem_(index, data); 11530 Manager.get().updateItem_(index, data);
11493 }; 11531 };
11494 11532
11495 return {Manager: Manager}; 11533 return {Manager: Manager};
11496 }); 11534 });
11497 // Copyright 2015 The Chromium Authors. All rights reserved. 11535 // Copyright 2015 The Chromium Authors. All rights reserved.
11498 // Use of this source code is governed by a BSD-style license that can be 11536 // Use of this source code is governed by a BSD-style license that can be
11499 // found in the LICENSE file. 11537 // found in the LICENSE file.
11500 11538
11501 window.addEventListener('load', downloads.Manager.onLoad); 11539 window.addEventListener('load', downloads.Manager.onLoad);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698