| OLD | NEW |
| 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 function PromiseResolver() { | 4 function PromiseResolver() { |
| 5 this.resolve_; | 5 this.resolve_; |
| 6 this.reject_; | 6 this.reject_; |
| 7 this.promise_ = new Promise(function(resolve, reject) { | 7 this.promise_ = new Promise(function(resolve, reject) { |
| 8 this.resolve_ = resolve; | 8 this.resolve_ = resolve; |
| 9 this.reject_ = reject; | 9 this.reject_ = reject; |
| 10 }.bind(this)); | 10 }.bind(this)); |
| (...skipping 3345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3356 break; | 3356 break; |
| 3357 } | 3357 } |
| 3358 } | 3358 } |
| 3359 }, | 3359 }, |
| 3360 _focusPrevious: function() { | 3360 _focusPrevious: function() { |
| 3361 var length = this.items.length; | 3361 var length = this.items.length; |
| 3362 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 3362 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 3363 for (var i = 1; i < length + 1; i++) { | 3363 for (var i = 1; i < length + 1; i++) { |
| 3364 var item = this.items[(curFocusIndex - i + length) % length]; | 3364 var item = this.items[(curFocusIndex - i + length) % length]; |
| 3365 if (!item.hasAttribute('disabled')) { | 3365 if (!item.hasAttribute('disabled')) { |
| 3366 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 3366 this._setFocusedItem(item); | 3367 this._setFocusedItem(item); |
| 3367 return; | 3368 if (Polymer.dom(owner).activeElement == item) { |
| 3369 return; |
| 3370 } |
| 3368 } | 3371 } |
| 3369 } | 3372 } |
| 3370 }, | 3373 }, |
| 3371 _focusNext: function() { | 3374 _focusNext: function() { |
| 3372 var length = this.items.length; | 3375 var length = this.items.length; |
| 3373 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 3376 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 3374 for (var i = 1; i < length + 1; i++) { | 3377 for (var i = 1; i < length + 1; i++) { |
| 3375 var item = this.items[(curFocusIndex + i) % length]; | 3378 var item = this.items[(curFocusIndex + i) % length]; |
| 3376 if (!item.hasAttribute('disabled')) { | 3379 if (!item.hasAttribute('disabled')) { |
| 3380 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 3377 this._setFocusedItem(item); | 3381 this._setFocusedItem(item); |
| 3378 return; | 3382 if (Polymer.dom(owner).activeElement == item) { |
| 3383 return; |
| 3384 } |
| 3379 } | 3385 } |
| 3380 } | 3386 } |
| 3381 }, | 3387 }, |
| 3382 _applySelection: function(item, isSelected) { | 3388 _applySelection: function(item, isSelected) { |
| 3383 if (isSelected) { | 3389 if (isSelected) { |
| 3384 item.setAttribute('aria-selected', 'true'); | 3390 item.setAttribute('aria-selected', 'true'); |
| 3385 } else { | 3391 } else { |
| 3386 item.removeAttribute('aria-selected'); | 3392 item.removeAttribute('aria-selected'); |
| 3387 } | 3393 } |
| 3388 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments); | 3394 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments); |
| (...skipping 2611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6000 return Polymer.dom(this.$.content).getDistributedNodes()[0]; | 6006 return Polymer.dom(this.$.content).getDistributedNodes()[0]; |
| 6001 }, | 6007 }, |
| 6002 get _focusTarget() { | 6008 get _focusTarget() { |
| 6003 return this.focusTarget || this.containedElement; | 6009 return this.focusTarget || this.containedElement; |
| 6004 }, | 6010 }, |
| 6005 ready: function() { | 6011 ready: function() { |
| 6006 this._scrollTop = 0; | 6012 this._scrollTop = 0; |
| 6007 this._scrollLeft = 0; | 6013 this._scrollLeft = 0; |
| 6008 this._refitOnScrollRAF = null; | 6014 this._refitOnScrollRAF = null; |
| 6009 }, | 6015 }, |
| 6016 attached: function() { |
| 6017 if (!this.sizingTarget || this.sizingTarget === this) { |
| 6018 this.sizingTarget = this.containedElement; |
| 6019 } |
| 6020 }, |
| 6010 detached: function() { | 6021 detached: function() { |
| 6011 this.cancelAnimation(); | 6022 this.cancelAnimation(); |
| 6023 document.removeEventListener('scroll', this._boundOnCaptureScroll); |
| 6012 Polymer.IronDropdownScrollManager.removeScrollLock(this); | 6024 Polymer.IronDropdownScrollManager.removeScrollLock(this); |
| 6013 }, | 6025 }, |
| 6014 _openedChanged: function() { | 6026 _openedChanged: function() { |
| 6015 if (this.opened && this.disabled) { | 6027 if (this.opened && this.disabled) { |
| 6016 this.cancel(); | 6028 this.cancel(); |
| 6017 } else { | 6029 } else { |
| 6018 this.cancelAnimation(); | 6030 this.cancelAnimation(); |
| 6019 this.sizingTarget = this.containedElement || this.sizingTarget; | |
| 6020 this._updateAnimationConfig(); | 6031 this._updateAnimationConfig(); |
| 6021 this._saveScrollPosition(); | 6032 this._saveScrollPosition(); |
| 6022 if (this.opened) { | 6033 if (this.opened) { |
| 6023 document.addEventListener('scroll', this._boundOnCaptureScroll); | 6034 document.addEventListener('scroll', this._boundOnCaptureScroll); |
| 6024 !this.allowOutsideScroll && Polymer.IronDropdownScrollManager.pushScro
llLock(this); | 6035 !this.allowOutsideScroll && Polymer.IronDropdownScrollManager.pushScro
llLock(this); |
| 6025 } else { | 6036 } else { |
| 6026 document.removeEventListener('scroll', this._boundOnCaptureScroll); | 6037 document.removeEventListener('scroll', this._boundOnCaptureScroll); |
| 6027 Polymer.IronDropdownScrollManager.removeScrollLock(this); | 6038 Polymer.IronDropdownScrollManager.removeScrollLock(this); |
| 6028 } | 6039 } |
| 6029 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); | 6040 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6417 observer: '_horizontalChanged' | 6428 observer: '_horizontalChanged' |
| 6418 }, | 6429 }, |
| 6419 opened: { | 6430 opened: { |
| 6420 type: Boolean, | 6431 type: Boolean, |
| 6421 value: false, | 6432 value: false, |
| 6422 notify: true, | 6433 notify: true, |
| 6423 observer: '_openedChanged' | 6434 observer: '_openedChanged' |
| 6424 }, | 6435 }, |
| 6425 noAnimation: { | 6436 noAnimation: { |
| 6426 type: Boolean | 6437 type: Boolean |
| 6438 }, |
| 6439 _desiredSize: { |
| 6440 type: String, |
| 6441 value: '' |
| 6427 } | 6442 } |
| 6428 }, | 6443 }, |
| 6429 get dimension() { | 6444 get dimension() { |
| 6430 return this.horizontal ? 'width' : 'height'; | 6445 return this.horizontal ? 'width' : 'height'; |
| 6431 }, | 6446 }, |
| 6432 get _dimensionMax() { | 6447 get _dimensionMax() { |
| 6433 return this.horizontal ? 'maxWidth' : 'maxHeight'; | 6448 return this.horizontal ? 'maxWidth' : 'maxHeight'; |
| 6434 }, | 6449 }, |
| 6435 get _dimensionMaxCss() { | 6450 get _dimensionMaxCss() { |
| 6436 return this.horizontal ? 'max-width' : 'max-height'; | 6451 return this.horizontal ? 'max-width' : 'max-height'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6449 toggle: function() { | 6464 toggle: function() { |
| 6450 this.opened = !this.opened; | 6465 this.opened = !this.opened; |
| 6451 }, | 6466 }, |
| 6452 show: function() { | 6467 show: function() { |
| 6453 this.opened = true; | 6468 this.opened = true; |
| 6454 }, | 6469 }, |
| 6455 hide: function() { | 6470 hide: function() { |
| 6456 this.opened = false; | 6471 this.opened = false; |
| 6457 }, | 6472 }, |
| 6458 updateSize: function(size, animated) { | 6473 updateSize: function(size, animated) { |
| 6459 var curSize = this.style[this._dimensionMax]; | 6474 size = size === 'auto' ? '' : size; |
| 6460 if (curSize === size || size === 'auto' && !curSize) { | 6475 if (this._desiredSize === size) { |
| 6461 return; | 6476 return; |
| 6462 } | 6477 } |
| 6478 this._desiredSize = size; |
| 6463 this._updateTransition(false); | 6479 this._updateTransition(false); |
| 6464 if (animated && !this.noAnimation && this._isDisplayed) { | 6480 var willAnimate = animated && !this.noAnimation && this._isDisplayed; |
| 6481 if (willAnimate) { |
| 6465 var startSize = this._calcSize(); | 6482 var startSize = this._calcSize(); |
| 6466 if (size === 'auto') { | 6483 if (size === '') { |
| 6467 this.style[this._dimensionMax] = ''; | 6484 this.style[this._dimensionMax] = ''; |
| 6468 size = this._calcSize(); | 6485 size = this._calcSize(); |
| 6469 } | 6486 } |
| 6470 this.style[this._dimensionMax] = startSize; | 6487 this.style[this._dimensionMax] = startSize; |
| 6471 this.scrollTop = this.scrollTop; | 6488 this.scrollTop = this.scrollTop; |
| 6472 this._updateTransition(true); | 6489 this._updateTransition(true); |
| 6490 willAnimate = size !== startSize; |
| 6473 } | 6491 } |
| 6474 if (size === 'auto') { | 6492 this.style[this._dimensionMax] = size; |
| 6475 this.style[this._dimensionMax] = ''; | 6493 if (!willAnimate) { |
| 6476 } else { | 6494 this._transitionEnd(); |
| 6477 this.style[this._dimensionMax] = size; | |
| 6478 } | 6495 } |
| 6479 }, | 6496 }, |
| 6480 enableTransition: function(enabled) { | 6497 enableTransition: function(enabled) { |
| 6481 Polymer.Base._warn('`enableTransition()` is deprecated, use `noAnimation` in
stead.'); | 6498 Polymer.Base._warn('`enableTransition()` is deprecated, use `noAnimation` in
stead.'); |
| 6482 this.noAnimation = !enabled; | 6499 this.noAnimation = !enabled; |
| 6483 }, | 6500 }, |
| 6484 _updateTransition: function(enabled) { | 6501 _updateTransition: function(enabled) { |
| 6485 this.style.transitionDuration = enabled && !this.noAnimation ? '' : '0s'; | 6502 this.style.transitionDuration = enabled && !this.noAnimation ? '' : '0s'; |
| 6486 }, | 6503 }, |
| 6487 _horizontalChanged: function() { | 6504 _horizontalChanged: function() { |
| 6488 this.style.transitionProperty = this._dimensionMaxCss; | 6505 this.style.transitionProperty = this._dimensionMaxCss; |
| 6489 var otherDimension = this._dimensionMax === 'maxWidth' ? 'maxHeight' : 'maxW
idth'; | 6506 var otherDimension = this._dimensionMax === 'maxWidth' ? 'maxHeight' : 'maxW
idth'; |
| 6490 this.style[otherDimension] = ''; | 6507 this.style[otherDimension] = ''; |
| 6491 this.updateSize(this.opened ? 'auto' : '0px', false); | 6508 this.updateSize(this.opened ? 'auto' : '0px', false); |
| 6492 }, | 6509 }, |
| 6493 _openedChanged: function() { | 6510 _openedChanged: function() { |
| 6494 this.setAttribute('aria-expanded', this.opened); | 6511 this.setAttribute('aria-expanded', this.opened); |
| 6495 this.setAttribute('aria-hidden', !this.opened); | 6512 this.setAttribute('aria-hidden', !this.opened); |
| 6496 this.toggleClass('iron-collapse-closed', false); | 6513 this.toggleClass('iron-collapse-closed', false); |
| 6497 this.toggleClass('iron-collapse-opened', false); | 6514 this.toggleClass('iron-collapse-opened', false); |
| 6498 this.updateSize(this.opened ? 'auto' : '0px', true); | 6515 this.updateSize(this.opened ? 'auto' : '0px', true); |
| 6499 if (this.opened) { | 6516 if (this.opened) { |
| 6500 this.focus(); | 6517 this.focus(); |
| 6501 } | 6518 } |
| 6502 if (this.noAnimation) { | |
| 6503 this._transitionEnd(); | |
| 6504 } | |
| 6505 }, | 6519 }, |
| 6506 _transitionEnd: function() { | 6520 _transitionEnd: function() { |
| 6507 if (this.opened) { | 6521 this.style[this._dimensionMax] = this._desiredSize; |
| 6508 this.style[this._dimensionMax] = ''; | |
| 6509 } | |
| 6510 this.toggleClass('iron-collapse-closed', !this.opened); | 6522 this.toggleClass('iron-collapse-closed', !this.opened); |
| 6511 this.toggleClass('iron-collapse-opened', this.opened); | 6523 this.toggleClass('iron-collapse-opened', this.opened); |
| 6512 this._updateTransition(false); | 6524 this._updateTransition(false); |
| 6513 this.notifyResize(); | 6525 this.notifyResize(); |
| 6514 }, | 6526 }, |
| 6515 get _isDisplayed() { | 6527 get _isDisplayed() { |
| 6516 var rect = this.getBoundingClientRect(); | 6528 var rect = this.getBoundingClientRect(); |
| 6517 for (var prop in rect) { | 6529 for (var prop in rect) { |
| 6518 if (rect[prop] !== 0) return true; | 6530 if (rect[prop] !== 0) return true; |
| 6519 } | 6531 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6631 role: 'checkbox', | 6643 role: 'checkbox', |
| 6632 'aria-checked': false, | 6644 'aria-checked': false, |
| 6633 tabindex: 0 | 6645 tabindex: 0 |
| 6634 }, | 6646 }, |
| 6635 properties: { | 6647 properties: { |
| 6636 ariaActiveAttribute: { | 6648 ariaActiveAttribute: { |
| 6637 type: String, | 6649 type: String, |
| 6638 value: 'aria-checked' | 6650 value: 'aria-checked' |
| 6639 } | 6651 } |
| 6640 }, | 6652 }, |
| 6653 attached: function() { |
| 6654 var inkSize = this.getComputedStyleValue('--calculated-paper-checkbox-ink-si
ze'); |
| 6655 if (inkSize === '-1px') { |
| 6656 var checkboxSize = parseFloat(this.getComputedStyleValue('--calculated-pap
er-checkbox-size')); |
| 6657 var defaultInkSize = Math.floor(8 / 3 * checkboxSize); |
| 6658 if (defaultInkSize % 2 !== checkboxSize % 2) { |
| 6659 defaultInkSize++; |
| 6660 } |
| 6661 this.customStyle['--paper-checkbox-ink-size'] = defaultInkSize + 'px'; |
| 6662 this.updateStyles(); |
| 6663 } |
| 6664 }, |
| 6641 _computeCheckboxClass: function(checked, invalid) { | 6665 _computeCheckboxClass: function(checked, invalid) { |
| 6642 var className = ''; | 6666 var className = ''; |
| 6643 if (checked) { | 6667 if (checked) { |
| 6644 className += 'checked '; | 6668 className += 'checked '; |
| 6645 } | 6669 } |
| 6646 if (invalid) { | 6670 if (invalid) { |
| 6647 className += 'invalid'; | 6671 className += 'invalid'; |
| 6648 } | 6672 } |
| 6649 return className; | 6673 return className; |
| 6650 }, | 6674 }, |
| (...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7699 } | 7723 } |
| 7700 }, | 7724 }, |
| 7701 scrollToItem: function(item) { | 7725 scrollToItem: function(item) { |
| 7702 return this.scrollToIndex(this.items.indexOf(item)); | 7726 return this.scrollToIndex(this.items.indexOf(item)); |
| 7703 }, | 7727 }, |
| 7704 scrollToIndex: function(idx) { | 7728 scrollToIndex: function(idx) { |
| 7705 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { | 7729 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { |
| 7706 return; | 7730 return; |
| 7707 } | 7731 } |
| 7708 Polymer.dom.flush(); | 7732 Polymer.dom.flush(); |
| 7733 if (!this._itemsRendered) { |
| 7734 return; |
| 7735 } |
| 7709 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); | 7736 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); |
| 7710 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { | 7737 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { |
| 7711 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; | 7738 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; |
| 7712 } | 7739 } |
| 7713 this._manageFocus(); | 7740 this._manageFocus(); |
| 7714 this._assignModels(); | 7741 this._assignModels(); |
| 7715 this._updateMetrics(); | 7742 this._updateMetrics(); |
| 7716 var estPhysicalTop = Math.floor(this._virtualStart / this._itemsPerRow) *
this._physicalAverage; | 7743 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * t
his._physicalAverage; |
| 7717 this._physicalTop = estPhysicalTop; | |
| 7718 var currentTopItem = this._physicalStart; | 7744 var currentTopItem = this._physicalStart; |
| 7719 var currentVirtualItem = this._virtualStart; | 7745 var currentVirtualItem = this._virtualStart; |
| 7720 var targetOffsetTop = 0; | 7746 var targetOffsetTop = 0; |
| 7721 var hiddenContentSize = this._hiddenContentSize; | 7747 var hiddenContentSize = this._hiddenContentSize; |
| 7722 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { | 7748 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { |
| 7723 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); | 7749 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); |
| 7724 currentTopItem = (currentTopItem + 1) % this._physicalCount; | 7750 currentTopItem = (currentTopItem + 1) % this._physicalCount; |
| 7725 currentVirtualItem++; | 7751 currentVirtualItem++; |
| 7726 } | 7752 } |
| 7727 this._updateScrollerSize(true); | 7753 this._updateScrollerSize(true); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7825 var target = Polymer.dom(e).path[0]; | 7851 var target = Polymer.dom(e).path[0]; |
| 7826 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac
tiveElement; | 7852 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac
tiveElement; |
| 7827 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i
ndexAs])]; | 7853 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i
ndexAs])]; |
| 7828 if (target.localName === 'input' || target.localName === 'button' || targe
t.localName === 'select') { | 7854 if (target.localName === 'input' || target.localName === 'button' || targe
t.localName === 'select') { |
| 7829 return; | 7855 return; |
| 7830 } | 7856 } |
| 7831 modelTabIndex = model.tabIndex; | 7857 modelTabIndex = model.tabIndex; |
| 7832 model.tabIndex = SECRET_TABINDEX; | 7858 model.tabIndex = SECRET_TABINDEX; |
| 7833 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; | 7859 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; |
| 7834 model.tabIndex = modelTabIndex; | 7860 model.tabIndex = modelTabIndex; |
| 7835 if (activeEl && physicalItem.contains(activeEl) && activeElTabIndex !== SE
CRET_TABINDEX) { | 7861 if (activeEl && physicalItem !== activeEl && physicalItem.contains(activeE
l) && activeElTabIndex !== SECRET_TABINDEX) { |
| 7836 return; | 7862 return; |
| 7837 } | 7863 } |
| 7838 this.toggleSelectionForItem(model[this.as]); | 7864 this.toggleSelectionForItem(model[this.as]); |
| 7839 }, | 7865 }, |
| 7840 _multiSelectionChanged: function(multiSelection) { | 7866 _multiSelectionChanged: function(multiSelection) { |
| 7841 this.clearSelection(); | 7867 this.clearSelection(); |
| 7842 this.$.selector.multi = multiSelection; | 7868 this.$.selector.multi = multiSelection; |
| 7843 }, | 7869 }, |
| 7844 updateSizeForItem: function(item) { | 7870 updateSizeForItem: function(item) { |
| 7845 item = this._getNormalizedItem(item); | 7871 item = this._getNormalizedItem(item); |
| (...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8794 | 8820 |
| 8795 case HistoryRange.MONTH: | 8821 case HistoryRange.MONTH: |
| 8796 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; | 8822 histogramValue = HistoryPageViewHistogram.GROUPED_MONTH; |
| 8797 break; | 8823 break; |
| 8798 } | 8824 } |
| 8799 break; | 8825 break; |
| 8800 } | 8826 } |
| 8801 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); | 8827 md_history.BrowserService.getInstance().recordHistogram('History.HistoryPage
View', histogramValue, HistoryPageViewHistogram.END); |
| 8802 } | 8828 } |
| 8803 }); | 8829 }); |
| OLD | NEW |