| OLD | NEW |
| 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 function assert(condition, opt_message) { | 4 function assert(condition, opt_message) { |
| 5 if (!condition) { | 5 if (!condition) { |
| 6 var message = 'Assertion failed'; | 6 var message = 'Assertion failed'; |
| 7 if (opt_message) message = message + ': ' + opt_message; | 7 if (opt_message) message = message + ': ' + opt_message; |
| 8 var error = new Error(message); | 8 var error = new Error(message); |
| 9 var global = function() { | 9 var global = function() { |
| 10 return this; | 10 return this; |
| (...skipping 1911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1922 } | 1922 } |
| 1923 }, | 1923 }, |
| 1924 scrollToItem: function(item) { | 1924 scrollToItem: function(item) { |
| 1925 return this.scrollToIndex(this.items.indexOf(item)); | 1925 return this.scrollToIndex(this.items.indexOf(item)); |
| 1926 }, | 1926 }, |
| 1927 scrollToIndex: function(idx) { | 1927 scrollToIndex: function(idx) { |
| 1928 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { | 1928 if (typeof idx !== 'number' || idx < 0 || idx > this.items.length - 1) { |
| 1929 return; | 1929 return; |
| 1930 } | 1930 } |
| 1931 Polymer.dom.flush(); | 1931 Polymer.dom.flush(); |
| 1932 if (!this._itemsRendered) { |
| 1933 return; |
| 1934 } |
| 1932 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); | 1935 idx = Math.min(Math.max(idx, 0), this._virtualCount - 1); |
| 1933 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { | 1936 if (!this._isIndexRendered(idx) || idx >= this._maxVirtualStart) { |
| 1934 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; | 1937 this._virtualStart = this.grid ? idx - this._itemsPerRow * 2 : idx - 1; |
| 1935 } | 1938 } |
| 1936 this._manageFocus(); | 1939 this._manageFocus(); |
| 1937 this._assignModels(); | 1940 this._assignModels(); |
| 1938 this._updateMetrics(); | 1941 this._updateMetrics(); |
| 1939 var estPhysicalTop = Math.floor(this._virtualStart / this._itemsPerRow) *
this._physicalAverage; | 1942 this._physicalTop = Math.floor(this._virtualStart / this._itemsPerRow) * t
his._physicalAverage; |
| 1940 this._physicalTop = estPhysicalTop; | |
| 1941 var currentTopItem = this._physicalStart; | 1943 var currentTopItem = this._physicalStart; |
| 1942 var currentVirtualItem = this._virtualStart; | 1944 var currentVirtualItem = this._virtualStart; |
| 1943 var targetOffsetTop = 0; | 1945 var targetOffsetTop = 0; |
| 1944 var hiddenContentSize = this._hiddenContentSize; | 1946 var hiddenContentSize = this._hiddenContentSize; |
| 1945 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { | 1947 while (currentVirtualItem < idx && targetOffsetTop <= hiddenContentSize) { |
| 1946 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); | 1948 targetOffsetTop = targetOffsetTop + this._getPhysicalSizeIncrement(curre
ntTopItem); |
| 1947 currentTopItem = (currentTopItem + 1) % this._physicalCount; | 1949 currentTopItem = (currentTopItem + 1) % this._physicalCount; |
| 1948 currentVirtualItem++; | 1950 currentVirtualItem++; |
| 1949 } | 1951 } |
| 1950 this._updateScrollerSize(true); | 1952 this._updateScrollerSize(true); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 var target = Polymer.dom(e).path[0]; | 2050 var target = Polymer.dom(e).path[0]; |
| 2049 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac
tiveElement; | 2051 var activeEl = Polymer.dom(this.domHost ? this.domHost.root : document).ac
tiveElement; |
| 2050 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i
ndexAs])]; | 2052 var physicalItem = this._physicalItems[this._getPhysicalIndex(model[this.i
ndexAs])]; |
| 2051 if (target.localName === 'input' || target.localName === 'button' || targe
t.localName === 'select') { | 2053 if (target.localName === 'input' || target.localName === 'button' || targe
t.localName === 'select') { |
| 2052 return; | 2054 return; |
| 2053 } | 2055 } |
| 2054 modelTabIndex = model.tabIndex; | 2056 modelTabIndex = model.tabIndex; |
| 2055 model.tabIndex = SECRET_TABINDEX; | 2057 model.tabIndex = SECRET_TABINDEX; |
| 2056 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; | 2058 activeElTabIndex = activeEl ? activeEl.tabIndex : -1; |
| 2057 model.tabIndex = modelTabIndex; | 2059 model.tabIndex = modelTabIndex; |
| 2058 if (activeEl && physicalItem.contains(activeEl) && activeElTabIndex !== SE
CRET_TABINDEX) { | 2060 if (activeEl && physicalItem !== activeEl && physicalItem.contains(activeE
l) && activeElTabIndex !== SECRET_TABINDEX) { |
| 2059 return; | 2061 return; |
| 2060 } | 2062 } |
| 2061 this.toggleSelectionForItem(model[this.as]); | 2063 this.toggleSelectionForItem(model[this.as]); |
| 2062 }, | 2064 }, |
| 2063 _multiSelectionChanged: function(multiSelection) { | 2065 _multiSelectionChanged: function(multiSelection) { |
| 2064 this.clearSelection(); | 2066 this.clearSelection(); |
| 2065 this.$.selector.multi = multiSelection; | 2067 this.$.selector.multi = multiSelection; |
| 2066 }, | 2068 }, |
| 2067 updateSizeForItem: function(item) { | 2069 updateSizeForItem: function(item) { |
| 2068 item = this._getNormalizedItem(item); | 2070 item = this._getNormalizedItem(item); |
| (...skipping 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4116 break; | 4118 break; |
| 4117 } | 4119 } |
| 4118 } | 4120 } |
| 4119 }, | 4121 }, |
| 4120 _focusPrevious: function() { | 4122 _focusPrevious: function() { |
| 4121 var length = this.items.length; | 4123 var length = this.items.length; |
| 4122 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 4124 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 4123 for (var i = 1; i < length + 1; i++) { | 4125 for (var i = 1; i < length + 1; i++) { |
| 4124 var item = this.items[(curFocusIndex - i + length) % length]; | 4126 var item = this.items[(curFocusIndex - i + length) % length]; |
| 4125 if (!item.hasAttribute('disabled')) { | 4127 if (!item.hasAttribute('disabled')) { |
| 4128 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 4126 this._setFocusedItem(item); | 4129 this._setFocusedItem(item); |
| 4127 return; | 4130 if (Polymer.dom(owner).activeElement == item) { |
| 4131 return; |
| 4132 } |
| 4128 } | 4133 } |
| 4129 } | 4134 } |
| 4130 }, | 4135 }, |
| 4131 _focusNext: function() { | 4136 _focusNext: function() { |
| 4132 var length = this.items.length; | 4137 var length = this.items.length; |
| 4133 var curFocusIndex = Number(this.indexOf(this.focusedItem)); | 4138 var curFocusIndex = Number(this.indexOf(this.focusedItem)); |
| 4134 for (var i = 1; i < length + 1; i++) { | 4139 for (var i = 1; i < length + 1; i++) { |
| 4135 var item = this.items[(curFocusIndex + i) % length]; | 4140 var item = this.items[(curFocusIndex + i) % length]; |
| 4136 if (!item.hasAttribute('disabled')) { | 4141 if (!item.hasAttribute('disabled')) { |
| 4142 var owner = Polymer.dom(item).getOwnerRoot() || document; |
| 4137 this._setFocusedItem(item); | 4143 this._setFocusedItem(item); |
| 4138 return; | 4144 if (Polymer.dom(owner).activeElement == item) { |
| 4145 return; |
| 4146 } |
| 4139 } | 4147 } |
| 4140 } | 4148 } |
| 4141 }, | 4149 }, |
| 4142 _applySelection: function(item, isSelected) { | 4150 _applySelection: function(item, isSelected) { |
| 4143 if (isSelected) { | 4151 if (isSelected) { |
| 4144 item.setAttribute('aria-selected', 'true'); | 4152 item.setAttribute('aria-selected', 'true'); |
| 4145 } else { | 4153 } else { |
| 4146 item.removeAttribute('aria-selected'); | 4154 item.removeAttribute('aria-selected'); |
| 4147 } | 4155 } |
| 4148 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments); | 4156 Polymer.IronSelectableBehavior._applySelection.apply(this, arguments); |
| (...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5594 return Polymer.dom(this.$.content).getDistributedNodes()[0]; | 5602 return Polymer.dom(this.$.content).getDistributedNodes()[0]; |
| 5595 }, | 5603 }, |
| 5596 get _focusTarget() { | 5604 get _focusTarget() { |
| 5597 return this.focusTarget || this.containedElement; | 5605 return this.focusTarget || this.containedElement; |
| 5598 }, | 5606 }, |
| 5599 ready: function() { | 5607 ready: function() { |
| 5600 this._scrollTop = 0; | 5608 this._scrollTop = 0; |
| 5601 this._scrollLeft = 0; | 5609 this._scrollLeft = 0; |
| 5602 this._refitOnScrollRAF = null; | 5610 this._refitOnScrollRAF = null; |
| 5603 }, | 5611 }, |
| 5612 attached: function() { |
| 5613 if (!this.sizingTarget || this.sizingTarget === this) { |
| 5614 this.sizingTarget = this.containedElement; |
| 5615 } |
| 5616 }, |
| 5604 detached: function() { | 5617 detached: function() { |
| 5605 this.cancelAnimation(); | 5618 this.cancelAnimation(); |
| 5619 document.removeEventListener('scroll', this._boundOnCaptureScroll); |
| 5606 Polymer.IronDropdownScrollManager.removeScrollLock(this); | 5620 Polymer.IronDropdownScrollManager.removeScrollLock(this); |
| 5607 }, | 5621 }, |
| 5608 _openedChanged: function() { | 5622 _openedChanged: function() { |
| 5609 if (this.opened && this.disabled) { | 5623 if (this.opened && this.disabled) { |
| 5610 this.cancel(); | 5624 this.cancel(); |
| 5611 } else { | 5625 } else { |
| 5612 this.cancelAnimation(); | 5626 this.cancelAnimation(); |
| 5613 this.sizingTarget = this.containedElement || this.sizingTarget; | |
| 5614 this._updateAnimationConfig(); | 5627 this._updateAnimationConfig(); |
| 5615 this._saveScrollPosition(); | 5628 this._saveScrollPosition(); |
| 5616 if (this.opened) { | 5629 if (this.opened) { |
| 5617 document.addEventListener('scroll', this._boundOnCaptureScroll); | 5630 document.addEventListener('scroll', this._boundOnCaptureScroll); |
| 5618 !this.allowOutsideScroll && Polymer.IronDropdownScrollManager.pushScro
llLock(this); | 5631 !this.allowOutsideScroll && Polymer.IronDropdownScrollManager.pushScro
llLock(this); |
| 5619 } else { | 5632 } else { |
| 5620 document.removeEventListener('scroll', this._boundOnCaptureScroll); | 5633 document.removeEventListener('scroll', this._boundOnCaptureScroll); |
| 5621 Polymer.IronDropdownScrollManager.removeScrollLock(this); | 5634 Polymer.IronDropdownScrollManager.removeScrollLock(this); |
| 5622 } | 5635 } |
| 5623 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); | 5636 Polymer.IronOverlayBehaviorImpl._openedChanged.apply(this, arguments); |
| (...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6944 }; | 6957 }; |
| 6945 return { | 6958 return { |
| 6946 Manager: Manager | 6959 Manager: Manager |
| 6947 }; | 6960 }; |
| 6948 }); | 6961 }); |
| 6949 | 6962 |
| 6950 // Copyright 2015 The Chromium Authors. All rights reserved. | 6963 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 6951 // Use of this source code is governed by a BSD-style license that can be | 6964 // Use of this source code is governed by a BSD-style license that can be |
| 6952 // found in the LICENSE file. | 6965 // found in the LICENSE file. |
| 6953 window.addEventListener('load', downloads.Manager.onLoad); | 6966 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |