| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 if (typeof Polymer == 'undefined') | 5 if (typeof Polymer == 'undefined') |
| 6 Polymer = {dom: 'shadow'}; | 6 Polymer = {dom: 'shadow'}; |
| 7 else | 7 else |
| 8 console.error('Polymer is already defined.'); | 8 console.error('Polymer is already defined.'); |
| 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 9 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 10 // Use of this source code is governed by a BSD-style license that can be | 10 // Use of this source code is governed by a BSD-style license that can be |
| (...skipping 11010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11021 * in a KeyboardEvent instance. | 11021 * in a KeyboardEvent instance. |
| 11022 */ | 11022 */ |
| 11023 var MODIFIER_KEYS = { | 11023 var MODIFIER_KEYS = { |
| 11024 'shift': 'shiftKey', | 11024 'shift': 'shiftKey', |
| 11025 'ctrl': 'ctrlKey', | 11025 'ctrl': 'ctrlKey', |
| 11026 'alt': 'altKey', | 11026 'alt': 'altKey', |
| 11027 'meta': 'metaKey' | 11027 'meta': 'metaKey' |
| 11028 }; | 11028 }; |
| 11029 | 11029 |
| 11030 /** | 11030 /** |
| 11031 * KeyboardEvent.key is mostly represented by printable character made by |
| 11032 * the keyboard, with unprintable keys labeled nicely. |
| 11033 * |
| 11034 * However, on OS X, Alt+char can make a Unicode character that follows an |
| 11035 * Apple-specific mapping. In this case, we fall back to .keyCode. |
| 11036 */ |
| 11037 var KEY_CHAR = /[a-z0-9*]/; |
| 11038 |
| 11039 /** |
| 11031 * Matches a keyIdentifier string. | 11040 * Matches a keyIdentifier string. |
| 11032 */ | 11041 */ |
| 11033 var IDENT_CHAR = /U\+/; | 11042 var IDENT_CHAR = /U\+/; |
| 11034 | 11043 |
| 11035 /** | 11044 /** |
| 11036 * Matches arrow keys in Gecko 27.0+ | 11045 * Matches arrow keys in Gecko 27.0+ |
| 11037 */ | 11046 */ |
| 11038 var ARROW_KEY = /^arrow/; | 11047 var ARROW_KEY = /^arrow/; |
| 11039 | 11048 |
| 11040 /** | 11049 /** |
| 11041 * Matches space keys everywhere (notably including IE10's exceptional name | 11050 * Matches space keys everywhere (notably including IE10's exceptional name |
| 11042 * `spacebar`). | 11051 * `spacebar`). |
| 11043 */ | 11052 */ |
| 11044 var SPACE_KEY = /^space(bar)?/; | 11053 var SPACE_KEY = /^space(bar)?/; |
| 11045 | 11054 |
| 11046 function transformKey(key) { | 11055 /** |
| 11056 * Transforms the key. |
| 11057 * @param {string} key The KeyBoardEvent.key |
| 11058 * @param {Boolean} [noSpecialChars] Limits the transformation to |
| 11059 * alpha-numeric characters. |
| 11060 */ |
| 11061 function transformKey(key, noSpecialChars) { |
| 11047 var validKey = ''; | 11062 var validKey = ''; |
| 11048 if (key) { | 11063 if (key) { |
| 11049 var lKey = key.toLowerCase(); | 11064 var lKey = key.toLowerCase(); |
| 11050 if (lKey === ' ' || SPACE_KEY.test(lKey)) { | 11065 if (lKey === ' ' || SPACE_KEY.test(lKey)) { |
| 11051 validKey = 'space'; | 11066 validKey = 'space'; |
| 11052 } else if (lKey.length == 1) { | 11067 } else if (lKey.length == 1) { |
| 11053 validKey = lKey; | 11068 if (!noSpecialChars || KEY_CHAR.test(lKey)) { |
| 11069 validKey = lKey; |
| 11070 } |
| 11054 } else if (ARROW_KEY.test(lKey)) { | 11071 } else if (ARROW_KEY.test(lKey)) { |
| 11055 validKey = lKey.replace('arrow', ''); | 11072 validKey = lKey.replace('arrow', ''); |
| 11056 } else if (lKey == 'multiply') { | 11073 } else if (lKey == 'multiply') { |
| 11057 // numpad '*' can map to Multiply on IE/Windows | 11074 // numpad '*' can map to Multiply on IE/Windows |
| 11058 validKey = '*'; | 11075 validKey = '*'; |
| 11059 } else { | 11076 } else { |
| 11060 validKey = lKey; | 11077 validKey = lKey; |
| 11061 } | 11078 } |
| 11062 } | 11079 } |
| 11063 return validKey; | 11080 return validKey; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 11094 } else if (keyCode >= 96 && keyCode <= 105) { | 11111 } else if (keyCode >= 96 && keyCode <= 105) { |
| 11095 // num pad 0-9 | 11112 // num pad 0-9 |
| 11096 validKey = String(96 - keyCode); | 11113 validKey = String(96 - keyCode); |
| 11097 } else { | 11114 } else { |
| 11098 validKey = KEY_CODE[keyCode]; | 11115 validKey = KEY_CODE[keyCode]; |
| 11099 } | 11116 } |
| 11100 } | 11117 } |
| 11101 return validKey; | 11118 return validKey; |
| 11102 } | 11119 } |
| 11103 | 11120 |
| 11104 function normalizedKeyForEvent(keyEvent) { | 11121 /** |
| 11105 // fall back from .key, to .keyIdentifier, to .keyCode, and then to | 11122 * Calculates the normalized key for a KeyboardEvent. |
| 11106 // .detail.key to support artificial keyboard events | 11123 * @param {KeyboardEvent} keyEvent |
| 11107 return transformKey(keyEvent.key) || | 11124 * @param {Boolean} [noSpecialChars] Set to true to limit keyEvent.key |
| 11125 * transformation to alpha-numeric chars. This is useful with key |
| 11126 * combinations like shift + 2, which on FF for MacOS produces |
| 11127 * keyEvent.key = @ |
| 11128 * To get 2 returned, set noSpecialChars = true |
| 11129 * To get @ returned, set noSpecialChars = false |
| 11130 */ |
| 11131 function normalizedKeyForEvent(keyEvent, noSpecialChars) { |
| 11132 // Fall back from .key, to .keyIdentifier, to .keyCode, and then to |
| 11133 // .detail.key to support artificial keyboard events. |
| 11134 return transformKey(keyEvent.key, noSpecialChars) || |
| 11108 transformKeyIdentifier(keyEvent.keyIdentifier) || | 11135 transformKeyIdentifier(keyEvent.keyIdentifier) || |
| 11109 transformKeyCode(keyEvent.keyCode) || | 11136 transformKeyCode(keyEvent.keyCode) || |
| 11110 transformKey(keyEvent.detail.key) || ''; | 11137 transformKey(keyEvent.detail.key, noSpecialChars) || ''; |
| 11111 } | 11138 } |
| 11112 | 11139 |
| 11113 function keyComboMatchesEvent(keyCombo, event, eventKey) { | 11140 function keyComboMatchesEvent(keyCombo, event) { |
| 11114 return eventKey === keyCombo.key && | 11141 // For combos with modifiers we support only alpha-numeric keys |
| 11142 var keyEvent = normalizedKeyForEvent(event, keyCombo.hasModifiers); |
| 11143 return keyEvent === keyCombo.key && |
| 11115 (!keyCombo.hasModifiers || ( | 11144 (!keyCombo.hasModifiers || ( |
| 11116 !!event.shiftKey === !!keyCombo.shiftKey && | 11145 !!event.shiftKey === !!keyCombo.shiftKey && |
| 11117 !!event.ctrlKey === !!keyCombo.ctrlKey && | 11146 !!event.ctrlKey === !!keyCombo.ctrlKey && |
| 11118 !!event.altKey === !!keyCombo.altKey && | 11147 !!event.altKey === !!keyCombo.altKey && |
| 11119 !!event.metaKey === !!keyCombo.metaKey) | 11148 !!event.metaKey === !!keyCombo.metaKey) |
| 11120 ); | 11149 ); |
| 11121 } | 11150 } |
| 11122 | 11151 |
| 11123 function parseKeyComboString(keyComboString) { | 11152 function parseKeyComboString(keyComboString) { |
| 11124 if (keyComboString.length === 1) { | 11153 if (keyComboString.length === 1) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11241 * When called, will remove all imperatively-added key bindings. | 11270 * When called, will remove all imperatively-added key bindings. |
| 11242 */ | 11271 */ |
| 11243 removeOwnKeyBindings: function() { | 11272 removeOwnKeyBindings: function() { |
| 11244 this._imperativeKeyBindings = {}; | 11273 this._imperativeKeyBindings = {}; |
| 11245 this._prepKeyBindings(); | 11274 this._prepKeyBindings(); |
| 11246 this._resetKeyEventListeners(); | 11275 this._resetKeyEventListeners(); |
| 11247 }, | 11276 }, |
| 11248 | 11277 |
| 11249 keyboardEventMatchesKeys: function(event, eventString) { | 11278 keyboardEventMatchesKeys: function(event, eventString) { |
| 11250 var keyCombos = parseEventString(eventString); | 11279 var keyCombos = parseEventString(eventString); |
| 11251 var eventKey = normalizedKeyForEvent(event); | |
| 11252 for (var i = 0; i < keyCombos.length; ++i) { | 11280 for (var i = 0; i < keyCombos.length; ++i) { |
| 11253 if (keyComboMatchesEvent(keyCombos[i], event, eventKey)) { | 11281 if (keyComboMatchesEvent(keyCombos[i], event)) { |
| 11254 return true; | 11282 return true; |
| 11255 } | 11283 } |
| 11256 } | 11284 } |
| 11257 return false; | 11285 return false; |
| 11258 }, | 11286 }, |
| 11259 | 11287 |
| 11260 _collectKeyBindings: function() { | 11288 _collectKeyBindings: function() { |
| 11261 var keyBindings = this.behaviors.map(function(behavior) { | 11289 var keyBindings = this.behaviors.map(function(behavior) { |
| 11262 return behavior.keyBindings; | 11290 return behavior.keyBindings; |
| 11263 }); | 11291 }); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11343 _onKeyBindingEvent: function(keyBindings, event) { | 11371 _onKeyBindingEvent: function(keyBindings, event) { |
| 11344 if (this.stopKeyboardEventPropagation) { | 11372 if (this.stopKeyboardEventPropagation) { |
| 11345 event.stopPropagation(); | 11373 event.stopPropagation(); |
| 11346 } | 11374 } |
| 11347 | 11375 |
| 11348 // if event has been already prevented, don't do anything | 11376 // if event has been already prevented, don't do anything |
| 11349 if (event.defaultPrevented) { | 11377 if (event.defaultPrevented) { |
| 11350 return; | 11378 return; |
| 11351 } | 11379 } |
| 11352 | 11380 |
| 11353 var eventKey = normalizedKeyForEvent(event); | |
| 11354 for (var i = 0; i < keyBindings.length; i++) { | 11381 for (var i = 0; i < keyBindings.length; i++) { |
| 11355 var keyCombo = keyBindings[i][0]; | 11382 var keyCombo = keyBindings[i][0]; |
| 11356 var handlerName = keyBindings[i][1]; | 11383 var handlerName = keyBindings[i][1]; |
| 11357 if (keyComboMatchesEvent(keyCombo, event, eventKey)) { | 11384 if (keyComboMatchesEvent(keyCombo, event)) { |
| 11358 this._triggerKeyHandler(keyCombo, handlerName, event); | 11385 this._triggerKeyHandler(keyCombo, handlerName, event); |
| 11359 // exit the loop if eventDefault was prevented | 11386 // exit the loop if eventDefault was prevented |
| 11360 if (event.defaultPrevented) { | 11387 if (event.defaultPrevented) { |
| 11361 return; | 11388 return; |
| 11362 } | 11389 } |
| 11363 } | 11390 } |
| 11364 } | 11391 } |
| 11365 }, | 11392 }, |
| 11366 | 11393 |
| 11367 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { | 11394 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12557 raised: { | 12584 raised: { |
| 12558 type: Boolean, | 12585 type: Boolean, |
| 12559 reflectToAttribute: true, | 12586 reflectToAttribute: true, |
| 12560 value: false, | 12587 value: false, |
| 12561 observer: '_calculateElevation' | 12588 observer: '_calculateElevation' |
| 12562 } | 12589 } |
| 12563 }, | 12590 }, |
| 12564 | 12591 |
| 12565 _calculateElevation: function() { | 12592 _calculateElevation: function() { |
| 12566 if (!this.raised) { | 12593 if (!this.raised) { |
| 12567 this.elevation = 0; | 12594 this._setElevation(0); |
| 12568 } else { | 12595 } else { |
| 12569 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this); | 12596 Polymer.PaperButtonBehaviorImpl._calculateElevation.apply(this); |
| 12570 } | 12597 } |
| 12571 } | 12598 } |
| 12572 /** | 12599 /** |
| 12573 | 12600 |
| 12574 Fired when the animation finishes. | 12601 Fired when the animation finishes. |
| 12575 This is useful if you want to wait until | 12602 This is useful if you want to wait until |
| 12576 the ripple animation finishes to perform some action. | 12603 the ripple animation finishes to perform some action. |
| 12577 | 12604 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12670 return this.value !== v; | 12697 return this.value !== v; |
| 12671 }, | 12698 }, |
| 12672 | 12699 |
| 12673 _update: function() { | 12700 _update: function() { |
| 12674 this._validateValue(); | 12701 this._validateValue(); |
| 12675 this._setRatio(this._calcRatio(this.value) * 100); | 12702 this._setRatio(this._calcRatio(this.value) * 100); |
| 12676 } | 12703 } |
| 12677 | 12704 |
| 12678 }; | 12705 }; |
| 12679 Polymer({ | 12706 Polymer({ |
| 12680 | |
| 12681 is: 'paper-progress', | 12707 is: 'paper-progress', |
| 12682 | 12708 |
| 12683 behaviors: [ | 12709 behaviors: [ |
| 12684 Polymer.IronRangeBehavior | 12710 Polymer.IronRangeBehavior |
| 12685 ], | 12711 ], |
| 12686 | 12712 |
| 12687 properties: { | 12713 properties: { |
| 12688 | |
| 12689 /** | 12714 /** |
| 12690 * The number that represents the current secondary progress. | 12715 * The number that represents the current secondary progress. |
| 12691 */ | 12716 */ |
| 12692 secondaryProgress: { | 12717 secondaryProgress: { |
| 12693 type: Number, | 12718 type: Number, |
| 12694 value: 0 | 12719 value: 0 |
| 12695 }, | 12720 }, |
| 12696 | 12721 |
| 12697 /** | 12722 /** |
| 12698 * The secondary ratio | 12723 * The secondary ratio |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12764 this.setAttribute('aria-valuemax', max); | 12789 this.setAttribute('aria-valuemax', max); |
| 12765 }, | 12790 }, |
| 12766 | 12791 |
| 12767 _disabledChanged: function(disabled) { | 12792 _disabledChanged: function(disabled) { |
| 12768 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | 12793 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); |
| 12769 }, | 12794 }, |
| 12770 | 12795 |
| 12771 _hideSecondaryProgress: function(secondaryRatio) { | 12796 _hideSecondaryProgress: function(secondaryRatio) { |
| 12772 return secondaryRatio === 0; | 12797 return secondaryRatio === 0; |
| 12773 } | 12798 } |
| 12774 | |
| 12775 }); | 12799 }); |
| 12776 // Copyright 2015 The Chromium Authors. All rights reserved. | 12800 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 12777 // Use of this source code is governed by a BSD-style license that can be | 12801 // Use of this source code is governed by a BSD-style license that can be |
| 12778 // found in the LICENSE file. | 12802 // found in the LICENSE file. |
| 12779 | 12803 |
| 12780 cr.define('downloads', function() { | 12804 cr.define('downloads', function() { |
| 12781 var InkyTextButton = Polymer({ | 12805 var InkyTextButton = Polymer({ |
| 12782 is: 'inky-text-button', | 12806 is: 'inky-text-button', |
| 12783 | 12807 |
| 12784 behaviors: [ | 12808 behaviors: [ |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13111 /** @polymerBehavior Polymer.PaperItemBehavior */ | 13135 /** @polymerBehavior Polymer.PaperItemBehavior */ |
| 13112 Polymer.PaperItemBehaviorImpl = { | 13136 Polymer.PaperItemBehaviorImpl = { |
| 13113 hostAttributes: { | 13137 hostAttributes: { |
| 13114 role: 'option', | 13138 role: 'option', |
| 13115 tabindex: '0' | 13139 tabindex: '0' |
| 13116 } | 13140 } |
| 13117 }; | 13141 }; |
| 13118 | 13142 |
| 13119 /** @polymerBehavior */ | 13143 /** @polymerBehavior */ |
| 13120 Polymer.PaperItemBehavior = [ | 13144 Polymer.PaperItemBehavior = [ |
| 13145 Polymer.IronButtonState, |
| 13121 Polymer.IronControlState, | 13146 Polymer.IronControlState, |
| 13122 Polymer.IronButtonState, | |
| 13123 Polymer.PaperItemBehaviorImpl | 13147 Polymer.PaperItemBehaviorImpl |
| 13124 ]; | 13148 ]; |
| 13125 Polymer({ | 13149 Polymer({ |
| 13126 is: 'paper-item', | 13150 is: 'paper-item', |
| 13127 | 13151 |
| 13128 behaviors: [ | 13152 behaviors: [ |
| 13129 Polymer.PaperItemBehavior | 13153 Polymer.PaperItemBehavior |
| 13130 ] | 13154 ] |
| 13131 }); | 13155 }); |
| 13132 /** | 13156 /** |
| (...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14484 _boundOnCaptureKeydown: { | 14508 _boundOnCaptureKeydown: { |
| 14485 type: Function, | 14509 type: Function, |
| 14486 value: function() { | 14510 value: function() { |
| 14487 return this._onCaptureKeydown.bind(this); | 14511 return this._onCaptureKeydown.bind(this); |
| 14488 } | 14512 } |
| 14489 } | 14513 } |
| 14490 | 14514 |
| 14491 }, | 14515 }, |
| 14492 | 14516 |
| 14493 listeners: { | 14517 listeners: { |
| 14494 'tap': '_onClick', | |
| 14495 'iron-resize': '_onIronResize' | 14518 'iron-resize': '_onIronResize' |
| 14496 }, | 14519 }, |
| 14497 | 14520 |
| 14498 /** | 14521 /** |
| 14499 * The backdrop element. | 14522 * The backdrop element. |
| 14500 * @type Node | 14523 * @type Node |
| 14501 */ | 14524 */ |
| 14502 get backdropElement() { | 14525 get backdropElement() { |
| 14503 return this._backdrop; | 14526 return this._backdrop; |
| 14504 }, | 14527 }, |
| 14505 | 14528 |
| 14506 get _focusNode() { | 14529 get _focusNode() { |
| 14507 return Polymer.dom(this).querySelector('[autofocus]') || this; | 14530 return Polymer.dom(this).querySelector('[autofocus]') || this; |
| 14508 }, | 14531 }, |
| 14509 | 14532 |
| 14510 registered: function() { | 14533 registered: function() { |
| 14511 this._backdrop = document.createElement('iron-overlay-backdrop'); | 14534 this._backdrop = document.createElement('iron-overlay-backdrop'); |
| 14512 }, | 14535 }, |
| 14513 | 14536 |
| 14514 ready: function() { | 14537 ready: function() { |
| 14515 this._ensureSetup(); | 14538 this._ensureSetup(); |
| 14539 }, |
| 14540 |
| 14541 attached: function() { |
| 14542 // Call _openedChanged here so that position can be computed correctly. |
| 14516 if (this._callOpenedWhenReady) { | 14543 if (this._callOpenedWhenReady) { |
| 14517 this._openedChanged(); | 14544 this._openedChanged(); |
| 14518 } | 14545 } |
| 14519 }, | 14546 }, |
| 14520 | 14547 |
| 14521 detached: function() { | 14548 detached: function() { |
| 14522 this.opened = false; | 14549 this.opened = false; |
| 14523 this._completeBackdrop(); | 14550 this._completeBackdrop(); |
| 14524 this._manager.removeOverlay(this); | 14551 this._manager.removeOverlay(this); |
| 14525 }, | 14552 }, |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14737 if (!this.noAutoFocus) { | 14764 if (!this.noAutoFocus) { |
| 14738 this._focusNode.focus(); | 14765 this._focusNode.focus(); |
| 14739 } | 14766 } |
| 14740 } else { | 14767 } else { |
| 14741 this._focusNode.blur(); | 14768 this._focusNode.blur(); |
| 14742 this._manager.focusOverlay(); | 14769 this._manager.focusOverlay(); |
| 14743 } | 14770 } |
| 14744 }, | 14771 }, |
| 14745 | 14772 |
| 14746 _onCaptureClick: function(event) { | 14773 _onCaptureClick: function(event) { |
| 14747 // attempt to close asynchronously and prevent the close of a tap event is
immediately heard | 14774 if (!this.noCancelOnOutsideClick && |
| 14748 // on target. This is because in shadow dom due to event retargetting even
t.target is not | 14775 this._manager.currentOverlay() === this && |
| 14749 // useful. | 14776 Polymer.dom(event).path.indexOf(this) === -1) { |
| 14750 if (!this.noCancelOnOutsideClick && (this._manager.currentOverlay() == thi
s)) { | 14777 this.cancel(); |
| 14751 this._cancelJob = this.async(function() { | |
| 14752 this.cancel(); | |
| 14753 }, 10); | |
| 14754 } | 14778 } |
| 14755 }, | 14779 }, |
| 14756 | 14780 |
| 14757 _onClick: function(event) { | |
| 14758 if (this._cancelJob) { | |
| 14759 this.cancelAsync(this._cancelJob); | |
| 14760 this._cancelJob = null; | |
| 14761 } | |
| 14762 }, | |
| 14763 | |
| 14764 _onCaptureKeydown: function(event) { | 14781 _onCaptureKeydown: function(event) { |
| 14765 var ESC = 27; | 14782 var ESC = 27; |
| 14766 if (!this.noCancelOnEscKey && (event.keyCode === ESC)) { | 14783 if (!this.noCancelOnEscKey && (event.keyCode === ESC)) { |
| 14767 this.cancel(); | 14784 this.cancel(); |
| 14768 event.stopPropagation(); | 14785 event.stopPropagation(); |
| 14786 event.stopImmediatePropagation(); |
| 14769 } | 14787 } |
| 14770 }, | 14788 }, |
| 14771 | 14789 |
| 14772 _onIronResize: function() { | 14790 _onIronResize: function() { |
| 14773 if (this._squelchNextResize) { | 14791 if (this._squelchNextResize) { |
| 14774 this._squelchNextResize = false; | 14792 this._squelchNextResize = false; |
| 14775 return; | 14793 return; |
| 14776 } | 14794 } |
| 14777 if (this.opened) { | 14795 if (this.opened) { |
| 14778 this.refit(); | 14796 this.refit(); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15012 } | 15030 } |
| 15013 }, | 15031 }, |
| 15014 | 15032 |
| 15015 /** | 15033 /** |
| 15016 * An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this
method to configure | 15034 * An element implementing `Polymer.NeonAnimationRunnerBehavior` calls this
method to configure |
| 15017 * an animation with an optional type. Elements implementing `Polymer.NeonAn
imatableBehavior` | 15035 * an animation with an optional type. Elements implementing `Polymer.NeonAn
imatableBehavior` |
| 15018 * should define the property `animationConfig`, which is either a configura
tion object | 15036 * should define the property `animationConfig`, which is either a configura
tion object |
| 15019 * or a map of animation type to array of configuration objects. | 15037 * or a map of animation type to array of configuration objects. |
| 15020 */ | 15038 */ |
| 15021 getAnimationConfig: function(type) { | 15039 getAnimationConfig: function(type) { |
| 15022 var map = []; | 15040 var map = {}; |
| 15023 var allConfigs = []; | 15041 var allConfigs = []; |
| 15024 this._getAnimationConfigRecursive(type, map, allConfigs); | 15042 this._getAnimationConfigRecursive(type, map, allConfigs); |
| 15025 // append the configurations saved in the map to the array | 15043 // append the configurations saved in the map to the array |
| 15026 for (var key in map) { | 15044 for (var key in map) { |
| 15027 allConfigs.push(map[key]); | 15045 allConfigs.push(map[key]); |
| 15028 } | 15046 } |
| 15029 return allConfigs; | 15047 return allConfigs; |
| 15030 } | 15048 } |
| 15031 | 15049 |
| 15032 }; | 15050 }; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15156 | 15174 |
| 15157 /** | 15175 /** |
| 15158 * Returns true if the provided element is "scroll locked," which is to | 15176 * Returns true if the provided element is "scroll locked," which is to |
| 15159 * say that it cannot be scrolled via pointer or keyboard interactions. | 15177 * say that it cannot be scrolled via pointer or keyboard interactions. |
| 15160 * | 15178 * |
| 15161 * @param {HTMLElement} element An HTML element instance which may or may | 15179 * @param {HTMLElement} element An HTML element instance which may or may |
| 15162 * not be scroll locked. | 15180 * not be scroll locked. |
| 15163 */ | 15181 */ |
| 15164 elementIsScrollLocked: function(element) { | 15182 elementIsScrollLocked: function(element) { |
| 15165 var currentLockingElement = this.currentLockingElement; | 15183 var currentLockingElement = this.currentLockingElement; |
| 15184 |
| 15185 if (currentLockingElement === undefined) |
| 15186 return false; |
| 15187 |
| 15166 var scrollLocked; | 15188 var scrollLocked; |
| 15167 | 15189 |
| 15168 if (this._hasCachedLockedElement(element)) { | 15190 if (this._hasCachedLockedElement(element)) { |
| 15169 return true; | 15191 return true; |
| 15170 } | 15192 } |
| 15171 | 15193 |
| 15172 if (this._hasCachedUnlockedElement(element)) { | 15194 if (this._hasCachedUnlockedElement(element)) { |
| 15173 return false; | 15195 return false; |
| 15174 } | 15196 } |
| 15175 | 15197 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15370 * vertically relative to the dropdown trigger. | 15392 * vertically relative to the dropdown trigger. |
| 15371 */ | 15393 */ |
| 15372 verticalAlign: { | 15394 verticalAlign: { |
| 15373 type: String, | 15395 type: String, |
| 15374 value: 'top', | 15396 value: 'top', |
| 15375 reflectToAttribute: true | 15397 reflectToAttribute: true |
| 15376 }, | 15398 }, |
| 15377 | 15399 |
| 15378 /** | 15400 /** |
| 15379 * A pixel value that will be added to the position calculated for the | 15401 * A pixel value that will be added to the position calculated for the |
| 15380 * given `horizontalAlign`. Use a negative value to offset to the | 15402 * given `horizontalAlign`, in the direction of alignment. You can thi
nk |
| 15381 * left, or a positive value to offset to the right. | 15403 * of it as increasing or decreasing the distance to the side of the |
| 15404 * screen given by `horizontalAlign`. |
| 15405 * |
| 15406 * If `horizontalAlign` is "left", this offset will increase or decrea
se |
| 15407 * the distance to the left side of the screen: a negative offset will |
| 15408 * move the dropdown to the left; a positive one, to the right. |
| 15409 * |
| 15410 * Conversely if `horizontalAlign` is "right", this offset will increa
se |
| 15411 * or decrease the distance to the right side of the screen: a negativ
e |
| 15412 * offset will move the dropdown to the right; a positive one, to the
left. |
| 15382 */ | 15413 */ |
| 15383 horizontalOffset: { | 15414 horizontalOffset: { |
| 15384 type: Number, | 15415 type: Number, |
| 15385 value: 0, | 15416 value: 0, |
| 15386 notify: true | 15417 notify: true |
| 15387 }, | 15418 }, |
| 15388 | 15419 |
| 15389 /** | 15420 /** |
| 15390 * A pixel value that will be added to the position calculated for the | 15421 * A pixel value that will be added to the position calculated for the |
| 15391 * given `verticalAlign`. Use a negative value to offset towards the | 15422 * given `verticalAlign`, in the direction of alignment. You can think |
| 15392 * top, or a positive value to offset towards the bottom. | 15423 * of it as increasing or decreasing the distance to the side of the |
| 15424 * screen given by `verticalAlign`. |
| 15425 * |
| 15426 * If `verticalAlign` is "top", this offset will increase or decrease |
| 15427 * the distance to the top side of the screen: a negative offset will |
| 15428 * move the dropdown upwards; a positive one, downwards. |
| 15429 * |
| 15430 * Conversely if `verticalAlign` is "bottom", this offset will increas
e |
| 15431 * or decrease the distance to the bottom side of the screen: a negati
ve |
| 15432 * offset will move the dropdown downwards; a positive one, upwards. |
| 15393 */ | 15433 */ |
| 15394 verticalOffset: { | 15434 verticalOffset: { |
| 15395 type: Number, | 15435 type: Number, |
| 15396 value: 0, | 15436 value: 0, |
| 15397 notify: true | 15437 notify: true |
| 15398 }, | 15438 }, |
| 15399 | 15439 |
| 15400 /** | 15440 /** |
| 15401 * The element that should be used to position the dropdown when | 15441 * The element that should be used to position the dropdown when |
| 15402 * it is opened. | 15442 * it is opened. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15482 }, | 15522 }, |
| 15483 | 15523 |
| 15484 /** | 15524 /** |
| 15485 * The element that should be focused when the dropdown opens. | 15525 * The element that should be focused when the dropdown opens. |
| 15486 */ | 15526 */ |
| 15487 get _focusTarget() { | 15527 get _focusTarget() { |
| 15488 return this.focusTarget || this.containedElement; | 15528 return this.focusTarget || this.containedElement; |
| 15489 }, | 15529 }, |
| 15490 | 15530 |
| 15491 /** | 15531 /** |
| 15532 * Whether the text direction is RTL |
| 15533 */ |
| 15534 _isRTL: function() { |
| 15535 return window.getComputedStyle(this).direction == 'rtl'; |
| 15536 }, |
| 15537 |
| 15538 /** |
| 15492 * The element that should be used to position the dropdown when | 15539 * The element that should be used to position the dropdown when |
| 15493 * it opens, if no position target is configured. | 15540 * it opens, if no position target is configured. |
| 15494 */ | 15541 */ |
| 15495 get _defaultPositionTarget() { | 15542 get _defaultPositionTarget() { |
| 15496 var parent = Polymer.dom(this).parentNode; | 15543 var parent = Polymer.dom(this).parentNode; |
| 15497 | 15544 |
| 15498 if (parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | 15545 if (parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { |
| 15499 parent = parent.host; | 15546 parent = parent.host; |
| 15500 } | 15547 } |
| 15501 | 15548 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 15512 | 15559 |
| 15513 return this._positionRectMemo; | 15560 return this._positionRectMemo; |
| 15514 }, | 15561 }, |
| 15515 | 15562 |
| 15516 /** | 15563 /** |
| 15517 * The horizontal offset value used to position the dropdown. | 15564 * The horizontal offset value used to position the dropdown. |
| 15518 */ | 15565 */ |
| 15519 get _horizontalAlignTargetValue() { | 15566 get _horizontalAlignTargetValue() { |
| 15520 var target; | 15567 var target; |
| 15521 | 15568 |
| 15522 if (this.horizontalAlign === 'right') { | 15569 // In RTL, the direction flips, so what is "right" in LTR becomes "lef
t". |
| 15570 var isRTL = this._isRTL(); |
| 15571 if ((!isRTL && this.horizontalAlign === 'right') || |
| 15572 (isRTL && this.horizontalAlign === 'left')) { |
| 15523 target = document.documentElement.clientWidth - this._positionRect.r
ight; | 15573 target = document.documentElement.clientWidth - this._positionRect.r
ight; |
| 15524 } else { | 15574 } else { |
| 15525 target = this._positionRect.left; | 15575 target = this._positionRect.left; |
| 15526 } | 15576 } |
| 15527 | 15577 |
| 15528 target += this.horizontalOffset; | 15578 target += this.horizontalOffset; |
| 15529 | 15579 |
| 15530 return Math.max(target, 0); | 15580 return Math.max(target, 0); |
| 15531 }, | 15581 }, |
| 15532 | 15582 |
| 15533 /** | 15583 /** |
| 15534 * The vertical offset value used to position the dropdown. | 15584 * The vertical offset value used to position the dropdown. |
| 15535 */ | 15585 */ |
| 15536 get _verticalAlignTargetValue() { | 15586 get _verticalAlignTargetValue() { |
| 15537 var target; | 15587 var target; |
| 15538 | 15588 |
| 15539 if (this.verticalAlign === 'bottom') { | 15589 if (this.verticalAlign === 'bottom') { |
| 15540 target = document.documentElement.clientHeight - this._positionRect.
bottom; | 15590 target = document.documentElement.clientHeight - this._positionRect.
bottom; |
| 15541 } else { | 15591 } else { |
| 15542 target = this._positionRect.top; | 15592 target = this._positionRect.top; |
| 15543 } | 15593 } |
| 15544 | 15594 |
| 15545 target += this.verticalOffset; | 15595 target += this.verticalOffset; |
| 15546 | 15596 |
| 15547 return Math.max(target, 0); | 15597 return Math.max(target, 0); |
| 15548 }, | 15598 }, |
| 15549 | 15599 |
| 15550 /** | 15600 /** |
| 15601 * The horizontal align value, accounting for the RTL/LTR text direction
. |
| 15602 */ |
| 15603 get _localeHorizontalAlign() { |
| 15604 // In RTL, "left" becomes "right". |
| 15605 if (this._isRTL()) { |
| 15606 return this.horizontalAlign === 'right' ? 'left' : 'right'; |
| 15607 } else { |
| 15608 return this.horizontalAlign; |
| 15609 } |
| 15610 }, |
| 15611 |
| 15612 /** |
| 15551 * Called when the value of `opened` changes. | 15613 * Called when the value of `opened` changes. |
| 15552 * | 15614 * |
| 15553 * @param {boolean} opened True if the dropdown is opened. | 15615 * @param {boolean} opened True if the dropdown is opened. |
| 15554 */ | 15616 */ |
| 15555 _openedChanged: function(opened) { | 15617 _openedChanged: function(opened) { |
| 15556 if (opened && this.disabled) { | 15618 if (opened && this.disabled) { |
| 15557 this.cancel(); | 15619 this.cancel(); |
| 15558 } else { | 15620 } else { |
| 15559 this.cancelAnimation(); | 15621 this.cancelAnimation(); |
| 15560 this._prepareDropdown(); | 15622 this._prepareDropdown(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15688 * and vertical alignment, and re-memoizes these values for the sake | 15750 * and vertical alignment, and re-memoizes these values for the sake |
| 15689 * of behavior in `IronFitBehavior`. | 15751 * of behavior in `IronFitBehavior`. |
| 15690 */ | 15752 */ |
| 15691 _updateOverlayPosition: function() { | 15753 _updateOverlayPosition: function() { |
| 15692 this._positionRectMemo = null; | 15754 this._positionRectMemo = null; |
| 15693 | 15755 |
| 15694 if (!this.positionTarget) { | 15756 if (!this.positionTarget) { |
| 15695 return; | 15757 return; |
| 15696 } | 15758 } |
| 15697 | 15759 |
| 15698 this.style[this.horizontalAlign] = | 15760 this.style[this._localeHorizontalAlign] = |
| 15699 this._horizontalAlignTargetValue + 'px'; | 15761 this._horizontalAlignTargetValue + 'px'; |
| 15700 | 15762 |
| 15701 this.style[this.verticalAlign] = | 15763 this.style[this.verticalAlign] = |
| 15702 this._verticalAlignTargetValue + 'px'; | 15764 this._verticalAlignTargetValue + 'px'; |
| 15703 | 15765 |
| 15704 // NOTE(cdata): We re-memoize inline styles here, otherwise | 15766 // NOTE(cdata): We re-memoize inline styles here, otherwise |
| 15705 // calling `refit` from `IronFitBehavior` will reset inline styles | 15767 // calling `refit` from `IronFitBehavior` will reset inline styles |
| 15706 // to whatever they were when the dropdown first opened. | 15768 // to whatever they were when the dropdown first opened. |
| 15707 if (this._fitInfo) { | 15769 if (this._fitInfo) { |
| 15708 this._fitInfo.inlineStyle[this.horizontalAlign] = | 15770 this._fitInfo.inlineStyle[this.horizontalAlign] = |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16321 /** | 16383 /** |
| 16322 * Use this property instead of `value` for two-way data binding. | 16384 * Use this property instead of `value` for two-way data binding. |
| 16323 */ | 16385 */ |
| 16324 bindValue: { | 16386 bindValue: { |
| 16325 observer: '_bindValueChanged', | 16387 observer: '_bindValueChanged', |
| 16326 type: String | 16388 type: String |
| 16327 }, | 16389 }, |
| 16328 | 16390 |
| 16329 /** | 16391 /** |
| 16330 * Set to true to prevent the user from entering invalid input. The new in
put characters are | 16392 * Set to true to prevent the user from entering invalid input. The new in
put characters are |
| 16331 * matched with `allowedPattern` if it is set, otherwise it will use the `
pattern` attribute if | 16393 * matched with `allowedPattern` if it is set, otherwise it will use the `
type` attribute (only |
| 16332 * set, or the `type` attribute (only supported for `type=number`). | 16394 * supported for `type=number`). |
| 16333 */ | 16395 */ |
| 16334 preventInvalidInput: { | 16396 preventInvalidInput: { |
| 16335 type: Boolean | 16397 type: Boolean |
| 16336 }, | 16398 }, |
| 16337 | 16399 |
| 16338 /** | 16400 /** |
| 16339 * Regular expression to match valid input characters. | 16401 * Regular expression expressing a set of characters to enforce the validi
ty of input characters. |
| 16402 * The recommended value should follow this format: `[a-ZA-Z0-9.+-!;:]` th
at list the characters |
| 16403 * allowed as input. |
| 16340 */ | 16404 */ |
| 16341 allowedPattern: { | 16405 allowedPattern: { |
| 16342 type: String, | 16406 type: String, |
| 16343 observer: "_allowedPatternChanged" | 16407 observer: "_allowedPatternChanged" |
| 16344 }, | 16408 }, |
| 16345 | 16409 |
| 16346 _previousValidInput: { | 16410 _previousValidInput: { |
| 16347 type: String, | 16411 type: String, |
| 16348 value: '' | 16412 value: '' |
| 16349 }, | 16413 }, |
| 16350 | 16414 |
| 16351 _patternAlreadyChecked: { | 16415 _patternAlreadyChecked: { |
| 16352 type: Boolean, | 16416 type: Boolean, |
| 16353 value: false | 16417 value: false |
| 16354 } | 16418 } |
| 16355 | 16419 |
| 16356 }, | 16420 }, |
| 16357 | 16421 |
| 16358 listeners: { | 16422 listeners: { |
| 16359 'input': '_onInput', | 16423 'input': '_onInput', |
| 16360 'keypress': '_onKeypress' | 16424 'keypress': '_onKeypress' |
| 16361 }, | 16425 }, |
| 16362 | 16426 |
| 16363 get _patternRegExp() { | 16427 get _patternRegExp() { |
| 16364 var pattern; | 16428 var pattern; |
| 16365 if (this.allowedPattern) { | 16429 if (this.allowedPattern) { |
| 16366 pattern = new RegExp(this.allowedPattern); | 16430 pattern = new RegExp(this.allowedPattern); |
| 16367 } else if (this.pattern) { | |
| 16368 pattern = new RegExp(this.pattern); | |
| 16369 } else { | 16431 } else { |
| 16370 switch (this.type) { | 16432 switch (this.type) { |
| 16371 case 'number': | 16433 case 'number': |
| 16372 pattern = /[0-9.,e-]/; | 16434 pattern = /[0-9.,e-]/; |
| 16373 break; | 16435 break; |
| 16374 } | 16436 } |
| 16375 } | 16437 } |
| 16376 return pattern; | 16438 return pattern; |
| 16377 }, | 16439 }, |
| 16378 | 16440 |
| 16379 ready: function() { | 16441 ready: function() { |
| 16380 this.bindValue = this.value; | 16442 this.bindValue = this.value; |
| 16381 }, | 16443 }, |
| 16382 | 16444 |
| 16383 /** | 16445 /** |
| 16384 * @suppress {checkTypes} | 16446 * @suppress {checkTypes} |
| 16385 */ | 16447 */ |
| 16386 _bindValueChanged: function() { | 16448 _bindValueChanged: function() { |
| 16387 if (this.value !== this.bindValue) { | 16449 if (this.value !== this.bindValue) { |
| 16388 this.value = !(this.bindValue || this.bindValue === 0) ? '' : this.bindV
alue; | 16450 this.value = !(this.bindValue || this.bindValue === 0 || this.bindValue
=== false) ? '' : this.bindValue; |
| 16389 } | 16451 } |
| 16390 // manually notify because we don't want to notify until after setting val
ue | 16452 // manually notify because we don't want to notify until after setting val
ue |
| 16391 this.fire('bind-value-changed', {value: this.bindValue}); | 16453 this.fire('bind-value-changed', {value: this.bindValue}); |
| 16392 }, | 16454 }, |
| 16393 | 16455 |
| 16394 _allowedPatternChanged: function() { | 16456 _allowedPatternChanged: function() { |
| 16395 // Force to prevent invalid input when an `allowed-pattern` is set | 16457 // Force to prevent invalid input when an `allowed-pattern` is set |
| 16396 this.preventInvalidInput = this.allowedPattern ? true : false; | 16458 this.preventInvalidInput = this.allowedPattern ? true : false; |
| 16397 }, | 16459 }, |
| 16398 | 16460 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16487 // Empty, non-required input is valid. | 16549 // Empty, non-required input is valid. |
| 16488 if (!this.required && this.value == '') { | 16550 if (!this.required && this.value == '') { |
| 16489 this.invalid = false; | 16551 this.invalid = false; |
| 16490 return true; | 16552 return true; |
| 16491 } | 16553 } |
| 16492 | 16554 |
| 16493 var valid; | 16555 var valid; |
| 16494 if (this.hasValidator()) { | 16556 if (this.hasValidator()) { |
| 16495 valid = Polymer.IronValidatableBehavior.validate.call(this, this.value); | 16557 valid = Polymer.IronValidatableBehavior.validate.call(this, this.value); |
| 16496 } else { | 16558 } else { |
| 16497 this.invalid = !this.validity.valid; | 16559 valid = this.checkValidity(); |
| 16498 valid = this.validity.valid; | 16560 this.invalid = !valid; |
| 16499 } | 16561 } |
| 16500 this.fire('iron-input-validate'); | 16562 this.fire('iron-input-validate'); |
| 16501 return valid; | 16563 return valid; |
| 16502 } | 16564 } |
| 16503 | 16565 |
| 16504 }); | 16566 }); |
| 16505 | 16567 |
| 16506 /* | 16568 /* |
| 16507 The `iron-input-validate` event is fired whenever `validate()` is called. | 16569 The `iron-input-validate` event is fired whenever `validate()` is called. |
| 16508 @event iron-input-validate | 16570 @event iron-input-validate |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17132 Manager.get().updateItem_(index, data); | 17194 Manager.get().updateItem_(index, data); |
| 17133 }; | 17195 }; |
| 17134 | 17196 |
| 17135 return {Manager: Manager}; | 17197 return {Manager: Manager}; |
| 17136 }); | 17198 }); |
| 17137 // Copyright 2015 The Chromium Authors. All rights reserved. | 17199 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 17138 // Use of this source code is governed by a BSD-style license that can be | 17200 // Use of this source code is governed by a BSD-style license that can be |
| 17139 // found in the LICENSE file. | 17201 // found in the LICENSE file. |
| 17140 | 17202 |
| 17141 window.addEventListener('load', downloads.Manager.onLoad); | 17203 window.addEventListener('load', downloads.Manager.onLoad); |
| OLD | NEW |