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 Polymer = {dom: 'shadow'}; | 5 Polymer = {dom: 'shadow'}; |
6 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 6 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
7 // Use of this source code is governed by a BSD-style license that can be | 7 // Use of this source code is governed by a BSD-style license that can be |
8 // found in the LICENSE file. | 8 // found in the LICENSE file. |
9 | 9 |
10 /** | 10 /** |
(...skipping 10835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10846 // TODO(dfreedm): `pointer-events: none` works around https://crbug.com/
370136 | 10846 // TODO(dfreedm): `pointer-events: none` works around https://crbug.com/
370136 |
10847 // TODO(sjmiles): inline style may not be ideal, but avoids requiring a
shadow-root | 10847 // TODO(sjmiles): inline style may not be ideal, but avoids requiring a
shadow-root |
10848 svg.style.cssText = 'pointer-events: none; display: block; width: 100%;
height: 100%;'; | 10848 svg.style.cssText = 'pointer-events: none; display: block; width: 100%;
height: 100%;'; |
10849 svg.appendChild(content).removeAttribute('id'); | 10849 svg.appendChild(content).removeAttribute('id'); |
10850 return svg; | 10850 return svg; |
10851 } | 10851 } |
10852 return null; | 10852 return null; |
10853 } | 10853 } |
10854 | 10854 |
10855 }); | 10855 }); |
10856 Polymer({ | |
10857 is: 'paper-material', | |
10858 | |
10859 properties: { | |
10860 | |
10861 /** | |
10862 * The z-depth of this element, from 0-5. Setting to 0 will remove the | |
10863 * shadow, and each increasing number greater than 0 will be "deeper" | |
10864 * than the last. | |
10865 * | |
10866 * @attribute elevation | |
10867 * @type number | |
10868 * @default 1 | |
10869 */ | |
10870 elevation: { | |
10871 type: Number, | |
10872 reflectToAttribute: true, | |
10873 value: 1 | |
10874 }, | |
10875 | |
10876 /** | |
10877 * Set this to true to animate the shadow when setting a new | |
10878 * `elevation` value. | |
10879 * | |
10880 * @attribute animated | |
10881 * @type boolean | |
10882 * @default false | |
10883 */ | |
10884 animated: { | |
10885 type: Boolean, | |
10886 reflectToAttribute: true, | |
10887 value: false | |
10888 } | |
10889 } | |
10890 }); | |
10891 (function() { | 10856 (function() { |
10892 'use strict'; | 10857 'use strict'; |
10893 | 10858 |
10894 /** | 10859 /** |
10895 * Chrome uses an older version of DOM Level 3 Keyboard Events | 10860 * Chrome uses an older version of DOM Level 3 Keyboard Events |
10896 * | 10861 * |
10897 * Most keys are labeled as text, but some are Unicode codepoints. | 10862 * Most keys are labeled as text, but some are Unicode codepoints. |
10898 * Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-200712
21/keyset.html#KeySet-Set | 10863 * Values taken from: http://www.w3.org/TR/2007/WD-DOM-Level-3-Events-200712
21/keyset.html#KeySet-Set |
10899 */ | 10864 */ |
10900 var KEY_IDENTIFIER = { | 10865 var KEY_IDENTIFIER = { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11288 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { | 11253 _triggerKeyHandler: function(keyCombo, handlerName, keyboardEvent) { |
11289 var detail = Object.create(keyCombo); | 11254 var detail = Object.create(keyCombo); |
11290 detail.keyboardEvent = keyboardEvent; | 11255 detail.keyboardEvent = keyboardEvent; |
11291 | 11256 |
11292 this[handlerName].call(this, new CustomEvent(keyCombo.event, { | 11257 this[handlerName].call(this, new CustomEvent(keyCombo.event, { |
11293 detail: detail | 11258 detail: detail |
11294 })); | 11259 })); |
11295 } | 11260 } |
11296 }; | 11261 }; |
11297 })(); | 11262 })(); |
| 11263 /** |
| 11264 * @demo demo/index.html |
| 11265 * @polymerBehavior |
| 11266 */ |
| 11267 Polymer.IronControlState = { |
| 11268 |
| 11269 properties: { |
| 11270 |
| 11271 /** |
| 11272 * If true, the element currently has focus. |
| 11273 */ |
| 11274 focused: { |
| 11275 type: Boolean, |
| 11276 value: false, |
| 11277 notify: true, |
| 11278 readOnly: true, |
| 11279 reflectToAttribute: true |
| 11280 }, |
| 11281 |
| 11282 /** |
| 11283 * If true, the user cannot interact with this element. |
| 11284 */ |
| 11285 disabled: { |
| 11286 type: Boolean, |
| 11287 value: false, |
| 11288 notify: true, |
| 11289 observer: '_disabledChanged', |
| 11290 reflectToAttribute: true |
| 11291 }, |
| 11292 |
| 11293 _oldTabIndex: { |
| 11294 type: Number |
| 11295 }, |
| 11296 |
| 11297 _boundFocusBlurHandler: { |
| 11298 type: Function, |
| 11299 value: function() { |
| 11300 return this._focusBlurHandler.bind(this); |
| 11301 } |
| 11302 } |
| 11303 |
| 11304 }, |
| 11305 |
| 11306 observers: [ |
| 11307 '_changedControlState(focused, disabled)' |
| 11308 ], |
| 11309 |
| 11310 ready: function() { |
| 11311 this.addEventListener('focus', this._boundFocusBlurHandler, true); |
| 11312 this.addEventListener('blur', this._boundFocusBlurHandler, true); |
| 11313 }, |
| 11314 |
| 11315 _focusBlurHandler: function(event) { |
| 11316 // NOTE(cdata): if we are in ShadowDOM land, `event.target` will |
| 11317 // eventually become `this` due to retargeting; if we are not in |
| 11318 // ShadowDOM land, `event.target` will eventually become `this` due |
| 11319 // to the second conditional which fires a synthetic event (that is also |
| 11320 // handled). In either case, we can disregard `event.path`. |
| 11321 |
| 11322 if (event.target === this) { |
| 11323 var focused = event.type === 'focus'; |
| 11324 this._setFocused(focused); |
| 11325 } else if (!this.shadowRoot) { |
| 11326 this.fire(event.type, {sourceEvent: event}, { |
| 11327 node: this, |
| 11328 bubbles: event.bubbles, |
| 11329 cancelable: event.cancelable |
| 11330 }); |
| 11331 } |
| 11332 }, |
| 11333 |
| 11334 _disabledChanged: function(disabled, old) { |
| 11335 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); |
| 11336 this.style.pointerEvents = disabled ? 'none' : ''; |
| 11337 if (disabled) { |
| 11338 this._oldTabIndex = this.tabIndex; |
| 11339 this.focused = false; |
| 11340 this.tabIndex = -1; |
| 11341 } else if (this._oldTabIndex !== undefined) { |
| 11342 this.tabIndex = this._oldTabIndex; |
| 11343 } |
| 11344 }, |
| 11345 |
| 11346 _changedControlState: function() { |
| 11347 // _controlStateChanged is abstract, follow-on behaviors may implement it |
| 11348 if (this._controlStateChanged) { |
| 11349 this._controlStateChanged(); |
| 11350 } |
| 11351 } |
| 11352 |
| 11353 }; |
| 11354 /** |
| 11355 * @demo demo/index.html |
| 11356 * @polymerBehavior Polymer.IronButtonState |
| 11357 */ |
| 11358 Polymer.IronButtonStateImpl = { |
| 11359 |
| 11360 properties: { |
| 11361 |
| 11362 /** |
| 11363 * If true, the user is currently holding down the button. |
| 11364 */ |
| 11365 pressed: { |
| 11366 type: Boolean, |
| 11367 readOnly: true, |
| 11368 value: false, |
| 11369 reflectToAttribute: true, |
| 11370 observer: '_pressedChanged' |
| 11371 }, |
| 11372 |
| 11373 /** |
| 11374 * If true, the button toggles the active state with each tap or press |
| 11375 * of the spacebar. |
| 11376 */ |
| 11377 toggles: { |
| 11378 type: Boolean, |
| 11379 value: false, |
| 11380 reflectToAttribute: true |
| 11381 }, |
| 11382 |
| 11383 /** |
| 11384 * If true, the button is a toggle and is currently in the active state. |
| 11385 */ |
| 11386 active: { |
| 11387 type: Boolean, |
| 11388 value: false, |
| 11389 notify: true, |
| 11390 reflectToAttribute: true |
| 11391 }, |
| 11392 |
| 11393 /** |
| 11394 * True if the element is currently being pressed by a "pointer," which |
| 11395 * is loosely defined as mouse or touch input (but specifically excluding |
| 11396 * keyboard input). |
| 11397 */ |
| 11398 pointerDown: { |
| 11399 type: Boolean, |
| 11400 readOnly: true, |
| 11401 value: false |
| 11402 }, |
| 11403 |
| 11404 /** |
| 11405 * True if the input device that caused the element to receive focus |
| 11406 * was a keyboard. |
| 11407 */ |
| 11408 receivedFocusFromKeyboard: { |
| 11409 type: Boolean, |
| 11410 readOnly: true |
| 11411 }, |
| 11412 |
| 11413 /** |
| 11414 * The aria attribute to be set if the button is a toggle and in the |
| 11415 * active state. |
| 11416 */ |
| 11417 ariaActiveAttribute: { |
| 11418 type: String, |
| 11419 value: 'aria-pressed', |
| 11420 observer: '_ariaActiveAttributeChanged' |
| 11421 } |
| 11422 }, |
| 11423 |
| 11424 listeners: { |
| 11425 down: '_downHandler', |
| 11426 up: '_upHandler', |
| 11427 tap: '_tapHandler' |
| 11428 }, |
| 11429 |
| 11430 observers: [ |
| 11431 '_detectKeyboardFocus(focused)', |
| 11432 '_activeChanged(active, ariaActiveAttribute)' |
| 11433 ], |
| 11434 |
| 11435 keyBindings: { |
| 11436 'enter:keydown': '_asyncClick', |
| 11437 'space:keydown': '_spaceKeyDownHandler', |
| 11438 'space:keyup': '_spaceKeyUpHandler', |
| 11439 }, |
| 11440 |
| 11441 _mouseEventRe: /^mouse/, |
| 11442 |
| 11443 _tapHandler: function() { |
| 11444 if (this.toggles) { |
| 11445 // a tap is needed to toggle the active state |
| 11446 this._userActivate(!this.active); |
| 11447 } else { |
| 11448 this.active = false; |
| 11449 } |
| 11450 }, |
| 11451 |
| 11452 _detectKeyboardFocus: function(focused) { |
| 11453 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); |
| 11454 }, |
| 11455 |
| 11456 // to emulate native checkbox, (de-)activations from a user interaction fire |
| 11457 // 'change' events |
| 11458 _userActivate: function(active) { |
| 11459 if (this.active !== active) { |
| 11460 this.active = active; |
| 11461 this.fire('change'); |
| 11462 } |
| 11463 }, |
| 11464 |
| 11465 _downHandler: function(event) { |
| 11466 this._setPointerDown(true); |
| 11467 this._setPressed(true); |
| 11468 this._setReceivedFocusFromKeyboard(false); |
| 11469 }, |
| 11470 |
| 11471 _upHandler: function() { |
| 11472 this._setPointerDown(false); |
| 11473 this._setPressed(false); |
| 11474 }, |
| 11475 |
| 11476 _spaceKeyDownHandler: function(event) { |
| 11477 var keyboardEvent = event.detail.keyboardEvent; |
| 11478 keyboardEvent.preventDefault(); |
| 11479 keyboardEvent.stopImmediatePropagation(); |
| 11480 this._setPressed(true); |
| 11481 }, |
| 11482 |
| 11483 _spaceKeyUpHandler: function() { |
| 11484 if (this.pressed) { |
| 11485 this._asyncClick(); |
| 11486 } |
| 11487 this._setPressed(false); |
| 11488 }, |
| 11489 |
| 11490 // trigger click asynchronously, the asynchrony is useful to allow one |
| 11491 // event handler to unwind before triggering another event |
| 11492 _asyncClick: function() { |
| 11493 this.async(function() { |
| 11494 this.click(); |
| 11495 }, 1); |
| 11496 }, |
| 11497 |
| 11498 // any of these changes are considered a change to button state |
| 11499 |
| 11500 _pressedChanged: function(pressed) { |
| 11501 this._changedButtonState(); |
| 11502 }, |
| 11503 |
| 11504 _ariaActiveAttributeChanged: function(value, oldValue) { |
| 11505 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { |
| 11506 this.removeAttribute(oldValue); |
| 11507 } |
| 11508 }, |
| 11509 |
| 11510 _activeChanged: function(active, ariaActiveAttribute) { |
| 11511 if (this.toggles) { |
| 11512 this.setAttribute(this.ariaActiveAttribute, |
| 11513 active ? 'true' : 'false'); |
| 11514 } else { |
| 11515 this.removeAttribute(this.ariaActiveAttribute); |
| 11516 } |
| 11517 this._changedButtonState(); |
| 11518 }, |
| 11519 |
| 11520 _controlStateChanged: function() { |
| 11521 if (this.disabled) { |
| 11522 this._setPressed(false); |
| 11523 } else { |
| 11524 this._changedButtonState(); |
| 11525 } |
| 11526 }, |
| 11527 |
| 11528 // provide hook for follow-on behaviors to react to button-state |
| 11529 |
| 11530 _changedButtonState: function() { |
| 11531 if (this._buttonStateChanged) { |
| 11532 this._buttonStateChanged(); // abstract |
| 11533 } |
| 11534 } |
| 11535 |
| 11536 }; |
| 11537 |
| 11538 /** @polymerBehavior */ |
| 11539 Polymer.IronButtonState = [ |
| 11540 Polymer.IronA11yKeysBehavior, |
| 11541 Polymer.IronButtonStateImpl |
| 11542 ]; |
11298 (function() { | 11543 (function() { |
11299 var Utility = { | 11544 var Utility = { |
11300 distance: function(x1, y1, x2, y2) { | 11545 distance: function(x1, y1, x2, y2) { |
11301 var xDelta = (x1 - x2); | 11546 var xDelta = (x1 - x2); |
11302 var yDelta = (y1 - y2); | 11547 var yDelta = (y1 - y2); |
11303 | 11548 |
11304 return Math.sqrt(xDelta * xDelta + yDelta * yDelta); | 11549 return Math.sqrt(xDelta * xDelta + yDelta * yDelta); |
11305 }, | 11550 }, |
11306 | 11551 |
11307 now: window.performance && window.performance.now ? | 11552 now: window.performance && window.performance.now ? |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11891 } | 12136 } |
11892 }, | 12137 }, |
11893 | 12138 |
11894 _noinkChanged: function(noink, attached) { | 12139 _noinkChanged: function(noink, attached) { |
11895 if (attached) { | 12140 if (attached) { |
11896 this.keyEventTarget = noink ? this : this.target; | 12141 this.keyEventTarget = noink ? this : this.target; |
11897 } | 12142 } |
11898 } | 12143 } |
11899 }); | 12144 }); |
11900 })(); | 12145 })(); |
11901 /** | |
11902 * @demo demo/index.html | |
11903 * @polymerBehavior | |
11904 */ | |
11905 Polymer.IronControlState = { | |
11906 | |
11907 properties: { | |
11908 | |
11909 /** | |
11910 * If true, the element currently has focus. | |
11911 */ | |
11912 focused: { | |
11913 type: Boolean, | |
11914 value: false, | |
11915 notify: true, | |
11916 readOnly: true, | |
11917 reflectToAttribute: true | |
11918 }, | |
11919 | |
11920 /** | |
11921 * If true, the user cannot interact with this element. | |
11922 */ | |
11923 disabled: { | |
11924 type: Boolean, | |
11925 value: false, | |
11926 notify: true, | |
11927 observer: '_disabledChanged', | |
11928 reflectToAttribute: true | |
11929 }, | |
11930 | |
11931 _oldTabIndex: { | |
11932 type: Number | |
11933 }, | |
11934 | |
11935 _boundFocusBlurHandler: { | |
11936 type: Function, | |
11937 value: function() { | |
11938 return this._focusBlurHandler.bind(this); | |
11939 } | |
11940 } | |
11941 | |
11942 }, | |
11943 | |
11944 observers: [ | |
11945 '_changedControlState(focused, disabled)' | |
11946 ], | |
11947 | |
11948 ready: function() { | |
11949 this.addEventListener('focus', this._boundFocusBlurHandler, true); | |
11950 this.addEventListener('blur', this._boundFocusBlurHandler, true); | |
11951 }, | |
11952 | |
11953 _focusBlurHandler: function(event) { | |
11954 // NOTE(cdata): if we are in ShadowDOM land, `event.target` will | |
11955 // eventually become `this` due to retargeting; if we are not in | |
11956 // ShadowDOM land, `event.target` will eventually become `this` due | |
11957 // to the second conditional which fires a synthetic event (that is also | |
11958 // handled). In either case, we can disregard `event.path`. | |
11959 | |
11960 if (event.target === this) { | |
11961 var focused = event.type === 'focus'; | |
11962 this._setFocused(focused); | |
11963 } else if (!this.shadowRoot) { | |
11964 this.fire(event.type, {sourceEvent: event}, { | |
11965 node: this, | |
11966 bubbles: event.bubbles, | |
11967 cancelable: event.cancelable | |
11968 }); | |
11969 } | |
11970 }, | |
11971 | |
11972 _disabledChanged: function(disabled, old) { | |
11973 this.setAttribute('aria-disabled', disabled ? 'true' : 'false'); | |
11974 this.style.pointerEvents = disabled ? 'none' : ''; | |
11975 if (disabled) { | |
11976 this._oldTabIndex = this.tabIndex; | |
11977 this.focused = false; | |
11978 this.tabIndex = -1; | |
11979 } else if (this._oldTabIndex !== undefined) { | |
11980 this.tabIndex = this._oldTabIndex; | |
11981 } | |
11982 }, | |
11983 | |
11984 _changedControlState: function() { | |
11985 // _controlStateChanged is abstract, follow-on behaviors may implement it | |
11986 if (this._controlStateChanged) { | |
11987 this._controlStateChanged(); | |
11988 } | |
11989 } | |
11990 | |
11991 }; | |
11992 /** | |
11993 * @demo demo/index.html | |
11994 * @polymerBehavior Polymer.IronButtonState | |
11995 */ | |
11996 Polymer.IronButtonStateImpl = { | |
11997 | |
11998 properties: { | |
11999 | |
12000 /** | |
12001 * If true, the user is currently holding down the button. | |
12002 */ | |
12003 pressed: { | |
12004 type: Boolean, | |
12005 readOnly: true, | |
12006 value: false, | |
12007 reflectToAttribute: true, | |
12008 observer: '_pressedChanged' | |
12009 }, | |
12010 | |
12011 /** | |
12012 * If true, the button toggles the active state with each tap or press | |
12013 * of the spacebar. | |
12014 */ | |
12015 toggles: { | |
12016 type: Boolean, | |
12017 value: false, | |
12018 reflectToAttribute: true | |
12019 }, | |
12020 | |
12021 /** | |
12022 * If true, the button is a toggle and is currently in the active state. | |
12023 */ | |
12024 active: { | |
12025 type: Boolean, | |
12026 value: false, | |
12027 notify: true, | |
12028 reflectToAttribute: true | |
12029 }, | |
12030 | |
12031 /** | |
12032 * True if the element is currently being pressed by a "pointer," which | |
12033 * is loosely defined as mouse or touch input (but specifically excluding | |
12034 * keyboard input). | |
12035 */ | |
12036 pointerDown: { | |
12037 type: Boolean, | |
12038 readOnly: true, | |
12039 value: false | |
12040 }, | |
12041 | |
12042 /** | |
12043 * True if the input device that caused the element to receive focus | |
12044 * was a keyboard. | |
12045 */ | |
12046 receivedFocusFromKeyboard: { | |
12047 type: Boolean, | |
12048 readOnly: true | |
12049 }, | |
12050 | |
12051 /** | |
12052 * The aria attribute to be set if the button is a toggle and in the | |
12053 * active state. | |
12054 */ | |
12055 ariaActiveAttribute: { | |
12056 type: String, | |
12057 value: 'aria-pressed', | |
12058 observer: '_ariaActiveAttributeChanged' | |
12059 } | |
12060 }, | |
12061 | |
12062 listeners: { | |
12063 down: '_downHandler', | |
12064 up: '_upHandler', | |
12065 tap: '_tapHandler' | |
12066 }, | |
12067 | |
12068 observers: [ | |
12069 '_detectKeyboardFocus(focused)', | |
12070 '_activeChanged(active, ariaActiveAttribute)' | |
12071 ], | |
12072 | |
12073 keyBindings: { | |
12074 'enter:keydown': '_asyncClick', | |
12075 'space:keydown': '_spaceKeyDownHandler', | |
12076 'space:keyup': '_spaceKeyUpHandler', | |
12077 }, | |
12078 | |
12079 _mouseEventRe: /^mouse/, | |
12080 | |
12081 _tapHandler: function() { | |
12082 if (this.toggles) { | |
12083 // a tap is needed to toggle the active state | |
12084 this._userActivate(!this.active); | |
12085 } else { | |
12086 this.active = false; | |
12087 } | |
12088 }, | |
12089 | |
12090 _detectKeyboardFocus: function(focused) { | |
12091 this._setReceivedFocusFromKeyboard(!this.pointerDown && focused); | |
12092 }, | |
12093 | |
12094 // to emulate native checkbox, (de-)activations from a user interaction fire | |
12095 // 'change' events | |
12096 _userActivate: function(active) { | |
12097 if (this.active !== active) { | |
12098 this.active = active; | |
12099 this.fire('change'); | |
12100 } | |
12101 }, | |
12102 | |
12103 _downHandler: function(event) { | |
12104 this._setPointerDown(true); | |
12105 this._setPressed(true); | |
12106 this._setReceivedFocusFromKeyboard(false); | |
12107 }, | |
12108 | |
12109 _upHandler: function() { | |
12110 this._setPointerDown(false); | |
12111 this._setPressed(false); | |
12112 }, | |
12113 | |
12114 _spaceKeyDownHandler: function(event) { | |
12115 var keyboardEvent = event.detail.keyboardEvent; | |
12116 keyboardEvent.preventDefault(); | |
12117 keyboardEvent.stopImmediatePropagation(); | |
12118 this._setPressed(true); | |
12119 }, | |
12120 | |
12121 _spaceKeyUpHandler: function() { | |
12122 if (this.pressed) { | |
12123 this._asyncClick(); | |
12124 } | |
12125 this._setPressed(false); | |
12126 }, | |
12127 | |
12128 // trigger click asynchronously, the asynchrony is useful to allow one | |
12129 // event handler to unwind before triggering another event | |
12130 _asyncClick: function() { | |
12131 this.async(function() { | |
12132 this.click(); | |
12133 }, 1); | |
12134 }, | |
12135 | |
12136 // any of these changes are considered a change to button state | |
12137 | |
12138 _pressedChanged: function(pressed) { | |
12139 this._changedButtonState(); | |
12140 }, | |
12141 | |
12142 _ariaActiveAttributeChanged: function(value, oldValue) { | |
12143 if (oldValue && oldValue != value && this.hasAttribute(oldValue)) { | |
12144 this.removeAttribute(oldValue); | |
12145 } | |
12146 }, | |
12147 | |
12148 _activeChanged: function(active, ariaActiveAttribute) { | |
12149 if (this.toggles) { | |
12150 this.setAttribute(this.ariaActiveAttribute, | |
12151 active ? 'true' : 'false'); | |
12152 } else { | |
12153 this.removeAttribute(this.ariaActiveAttribute); | |
12154 } | |
12155 this._changedButtonState(); | |
12156 }, | |
12157 | |
12158 _controlStateChanged: function() { | |
12159 if (this.disabled) { | |
12160 this._setPressed(false); | |
12161 } else { | |
12162 this._changedButtonState(); | |
12163 } | |
12164 }, | |
12165 | |
12166 // provide hook for follow-on behaviors to react to button-state | |
12167 | |
12168 _changedButtonState: function() { | |
12169 if (this._buttonStateChanged) { | |
12170 this._buttonStateChanged(); // abstract | |
12171 } | |
12172 } | |
12173 | |
12174 }; | |
12175 | |
12176 /** @polymerBehavior */ | |
12177 Polymer.IronButtonState = [ | |
12178 Polymer.IronA11yKeysBehavior, | |
12179 Polymer.IronButtonStateImpl | |
12180 ]; | |
12181 /** | 12146 /** |
12182 * `Polymer.PaperRippleBehavior` dynamically implements a ripple | 12147 * `Polymer.PaperRippleBehavior` dynamically implements a ripple |
12183 * when the element has focus via pointer or keyboard. | 12148 * when the element has focus via pointer or keyboard. |
12184 * | 12149 * |
12185 * NOTE: This behavior is intended to be used in conjunction with and after | 12150 * NOTE: This behavior is intended to be used in conjunction with and after |
12186 * `Polymer.IronButtonState` and `Polymer.IronControlState`. | 12151 * `Polymer.IronButtonState` and `Polymer.IronControlState`. |
12187 * | 12152 * |
12188 * @polymerBehavior Polymer.PaperRippleBehavior | 12153 * @polymerBehavior Polymer.PaperRippleBehavior |
12189 */ | 12154 */ |
12190 Polymer.PaperRippleBehavior = { | 12155 Polymer.PaperRippleBehavior = { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12272 return document.createElement('paper-ripple'); | 12237 return document.createElement('paper-ripple'); |
12273 }, | 12238 }, |
12274 | 12239 |
12275 _noinkChanged: function(noink) { | 12240 _noinkChanged: function(noink) { |
12276 if (this.hasRipple()) { | 12241 if (this.hasRipple()) { |
12277 this._ripple.noink = noink; | 12242 this._ripple.noink = noink; |
12278 } | 12243 } |
12279 } | 12244 } |
12280 | 12245 |
12281 }; | 12246 }; |
| 12247 /** |
| 12248 * `Polymer.PaperInkyFocusBehavior` implements a ripple when the element has k
eyboard focus. |
| 12249 * |
| 12250 * @polymerBehavior Polymer.PaperInkyFocusBehaviorImpl |
| 12251 */ |
| 12252 Polymer.PaperInkyFocusBehaviorImpl = { |
| 12253 |
| 12254 observers: [ |
| 12255 '_focusedChanged(receivedFocusFromKeyboard)' |
| 12256 ], |
| 12257 |
| 12258 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 12259 if (receivedFocusFromKeyboard) { |
| 12260 this.ensureRipple(); |
| 12261 } |
| 12262 if (this.hasRipple()) { |
| 12263 this._ripple.holdDown = receivedFocusFromKeyboard; |
| 12264 } |
| 12265 }, |
| 12266 |
| 12267 _createRipple: function() { |
| 12268 var ripple = Polymer.PaperRippleBehavior._createRipple(); |
| 12269 ripple.id = 'ink'; |
| 12270 ripple.setAttribute('center', ''); |
| 12271 ripple.classList.add('circle'); |
| 12272 return ripple; |
| 12273 } |
| 12274 |
| 12275 }; |
| 12276 |
| 12277 /** @polymerBehavior Polymer.PaperInkyFocusBehavior */ |
| 12278 Polymer.PaperInkyFocusBehavior = [ |
| 12279 Polymer.IronButtonState, |
| 12280 Polymer.IronControlState, |
| 12281 Polymer.PaperRippleBehavior, |
| 12282 Polymer.PaperInkyFocusBehaviorImpl |
| 12283 ]; |
| 12284 Polymer({ |
| 12285 is: 'paper-material', |
| 12286 |
| 12287 properties: { |
| 12288 |
| 12289 /** |
| 12290 * The z-depth of this element, from 0-5. Setting to 0 will remove the |
| 12291 * shadow, and each increasing number greater than 0 will be "deeper" |
| 12292 * than the last. |
| 12293 * |
| 12294 * @attribute elevation |
| 12295 * @type number |
| 12296 * @default 1 |
| 12297 */ |
| 12298 elevation: { |
| 12299 type: Number, |
| 12300 reflectToAttribute: true, |
| 12301 value: 1 |
| 12302 }, |
| 12303 |
| 12304 /** |
| 12305 * Set this to true to animate the shadow when setting a new |
| 12306 * `elevation` value. |
| 12307 * |
| 12308 * @attribute animated |
| 12309 * @type boolean |
| 12310 * @default false |
| 12311 */ |
| 12312 animated: { |
| 12313 type: Boolean, |
| 12314 reflectToAttribute: true, |
| 12315 value: false |
| 12316 } |
| 12317 } |
| 12318 }); |
12282 /** @polymerBehavior Polymer.PaperButtonBehavior */ | 12319 /** @polymerBehavior Polymer.PaperButtonBehavior */ |
12283 Polymer.PaperButtonBehaviorImpl = { | 12320 Polymer.PaperButtonBehaviorImpl = { |
12284 | 12321 |
12285 properties: { | 12322 properties: { |
12286 | 12323 |
12287 /** | 12324 /** |
12288 * The z-depth of this element, from 0-5. Setting to 0 will remove the | 12325 * The z-depth of this element, from 0-5. Setting to 0 will remove the |
12289 * shadow, and each increasing number greater than 0 will be "deeper" | 12326 * shadow, and each increasing number greater than 0 will be "deeper" |
12290 * than the last. | 12327 * than the last. |
12291 * | 12328 * |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12577 _hideSecondaryProgress: function(secondaryRatio) { | 12614 _hideSecondaryProgress: function(secondaryRatio) { |
12578 return secondaryRatio === 0; | 12615 return secondaryRatio === 0; |
12579 } | 12616 } |
12580 | 12617 |
12581 }); | 12618 }); |
12582 // Copyright 2015 The Chromium Authors. All rights reserved. | 12619 // Copyright 2015 The Chromium Authors. All rights reserved. |
12583 // Use of this source code is governed by a BSD-style license that can be | 12620 // Use of this source code is governed by a BSD-style license that can be |
12584 // found in the LICENSE file. | 12621 // found in the LICENSE file. |
12585 | 12622 |
12586 cr.define('downloads', function() { | 12623 cr.define('downloads', function() { |
| 12624 var InkyTextButton = Polymer({ |
| 12625 is: 'inky-text-button', |
| 12626 |
| 12627 behaviors: [ |
| 12628 Polymer.PaperInkyFocusBehavior |
| 12629 ], |
| 12630 |
| 12631 hostAttributes: { |
| 12632 role: 'button', |
| 12633 tabindex: 0, |
| 12634 }, |
| 12635 }); |
| 12636 |
12587 var Item = Polymer({ | 12637 var Item = Polymer({ |
12588 is: 'downloads-item', | 12638 is: 'downloads-item', |
12589 | 12639 |
12590 properties: { | 12640 properties: { |
12591 data: { | 12641 data: { |
12592 type: Object, | 12642 type: Object, |
12593 }, | 12643 }, |
12594 | 12644 |
12595 hideDate: { | 12645 hideDate: { |
12596 type: Boolean, | 12646 type: Boolean, |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12893 onSaveDangerousTap_: function() { | 12943 onSaveDangerousTap_: function() { |
12894 downloads.ActionService.getInstance().saveDangerous(this.data.id); | 12944 downloads.ActionService.getInstance().saveDangerous(this.data.id); |
12895 }, | 12945 }, |
12896 | 12946 |
12897 /** @private */ | 12947 /** @private */ |
12898 onShowTap_: function() { | 12948 onShowTap_: function() { |
12899 downloads.ActionService.getInstance().show(this.data.id); | 12949 downloads.ActionService.getInstance().show(this.data.id); |
12900 }, | 12950 }, |
12901 }); | 12951 }); |
12902 | 12952 |
12903 return {Item: Item}; | 12953 return { |
| 12954 InkyTextButton: InkyTextButton, |
| 12955 Item: Item, |
| 12956 }; |
12904 }); | 12957 }); |
12905 Polymer({ | 12958 Polymer({ |
12906 is: 'paper-item', | 12959 is: 'paper-item', |
12907 | 12960 |
12908 hostAttributes: { | 12961 hostAttributes: { |
12909 role: 'listitem', | 12962 role: 'listitem', |
12910 tabindex: '0' | 12963 tabindex: '0' |
12911 }, | 12964 }, |
12912 | 12965 |
12913 behaviors: [ | 12966 behaviors: [ |
(...skipping 2961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15875 this.close(); | 15928 this.close(); |
15876 } | 15929 } |
15877 } | 15930 } |
15878 }); | 15931 }); |
15879 | 15932 |
15880 PaperMenuButton.ANIMATION_CUBIC_BEZIER = 'cubic-bezier(.3,.95,.5,1)'; | 15933 PaperMenuButton.ANIMATION_CUBIC_BEZIER = 'cubic-bezier(.3,.95,.5,1)'; |
15881 PaperMenuButton.MAX_ANIMATION_TIME_MS = 400; | 15934 PaperMenuButton.MAX_ANIMATION_TIME_MS = 400; |
15882 | 15935 |
15883 Polymer.PaperMenuButton = PaperMenuButton; | 15936 Polymer.PaperMenuButton = PaperMenuButton; |
15884 })(); | 15937 })(); |
15885 /** | |
15886 * `Polymer.PaperInkyFocusBehavior` implements a ripple when the element has k
eyboard focus. | |
15887 * | |
15888 * @polymerBehavior Polymer.PaperInkyFocusBehaviorImpl | |
15889 */ | |
15890 Polymer.PaperInkyFocusBehaviorImpl = { | |
15891 | |
15892 observers: [ | |
15893 '_focusedChanged(receivedFocusFromKeyboard)' | |
15894 ], | |
15895 | |
15896 _focusedChanged: function(receivedFocusFromKeyboard) { | |
15897 if (receivedFocusFromKeyboard) { | |
15898 this.ensureRipple(); | |
15899 } | |
15900 if (this.hasRipple()) { | |
15901 this._ripple.holdDown = receivedFocusFromKeyboard; | |
15902 } | |
15903 }, | |
15904 | |
15905 _createRipple: function() { | |
15906 var ripple = Polymer.PaperRippleBehavior._createRipple(); | |
15907 ripple.id = 'ink'; | |
15908 ripple.setAttribute('center', ''); | |
15909 ripple.classList.add('circle'); | |
15910 return ripple; | |
15911 } | |
15912 | |
15913 }; | |
15914 | |
15915 /** @polymerBehavior Polymer.PaperInkyFocusBehavior */ | |
15916 Polymer.PaperInkyFocusBehavior = [ | |
15917 Polymer.IronButtonState, | |
15918 Polymer.IronControlState, | |
15919 Polymer.PaperRippleBehavior, | |
15920 Polymer.PaperInkyFocusBehaviorImpl | |
15921 ]; | |
15922 Polymer({ | 15938 Polymer({ |
15923 is: 'paper-icon-button', | 15939 is: 'paper-icon-button', |
15924 | 15940 |
15925 hostAttributes: { | 15941 hostAttributes: { |
15926 role: 'button', | 15942 role: 'button', |
15927 tabindex: '0' | 15943 tabindex: '0' |
15928 }, | 15944 }, |
15929 | 15945 |
15930 behaviors: [ | 15946 behaviors: [ |
15931 Polymer.PaperInkyFocusBehavior | 15947 Polymer.PaperInkyFocusBehavior |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16879 }; | 16895 }; |
16880 | 16896 |
16881 Manager.onLoad = function() { | 16897 Manager.onLoad = function() { |
16882 document.querySelector('downloads-manager').onLoad_(); | 16898 document.querySelector('downloads-manager').onLoad_(); |
16883 }; | 16899 }; |
16884 | 16900 |
16885 return {Manager: Manager}; | 16901 return {Manager: Manager}; |
16886 }); | 16902 }); |
16887 | 16903 |
16888 window.addEventListener('load', downloads.Manager.onLoad); | 16904 window.addEventListener('load', downloads.Manager.onLoad); |
OLD | NEW |