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

Side by Side Diff: third_party/polymer/v1_0/components/paper-slider/paper-slider.html

Issue 1187823002: Update Polymer components and re-run reproduce.sh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!-- 1 <!--
2 @license 2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE 4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS
7 Code distributed by Google as part of the polymer project is also 7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS
9 --> 9 -->
10 10
11 <link rel="import" href="../polymer/polymer.html">
11 <link rel="import" href="../paper-styles/paper-styles.html"> 12 <link rel="import" href="../paper-styles/paper-styles.html">
12 <link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
13 <link rel="import" href="../iron-behaviors/iron-control-state.html">
14 <link rel="import" href="../paper-progress/paper-progress.html"> 13 <link rel="import" href="../paper-progress/paper-progress.html">
15 <link rel="import" href="../paper-input/paper-input.html"> 14 <link rel="import" href="../paper-input/paper-input.html">
15 <link rel="import" href="../paper-behaviors/paper-inky-focus-behavior.html">
16 <link rel="import" href="../paper-ripple/paper-ripple.html">
17 <link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html ">
18 <link rel="import" href="../iron-form-element-behavior/iron-form-element-behavio r.html">
16 19
17 <!-- 20 <!--
18 `paper-slider` allows user to select a value from a range of values by 21 `paper-slider` allows user to select a value from a range of values by
19 moving the slider thumb. The interactive nature of the slider makes it a 22 moving the slider thumb. The interactive nature of the slider makes it a
20 great choice for settings that reflect intensity levels, such as volume, 23 great choice for settings that reflect intensity levels, such as volume,
21 brightness, or color saturation. 24 brightness, or color saturation.
22 25
23 Example: 26 Example:
24 27
25 <paper-slider></paper-slider> 28 <paper-slider></paper-slider>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 --paper-slider-disabled-secondary-color: #ccc; 77 --paper-slider-disabled-secondary-color: #ccc;
75 } 78 }
76 79
77 @group Paper Elements 80 @group Paper Elements
78 @element paper-slider 81 @element paper-slider
79 @demo demo/index.html 82 @demo demo/index.html
80 @hero hero.svg 83 @hero hero.svg
81 --> 84 -->
82 85
83 <dom-module id="paper-slider"> 86 <dom-module id="paper-slider">
87
84 <link rel="import" type="css" href="paper-slider.css"> 88 <link rel="import" type="css" href="paper-slider.css">
89
85 <template> 90 <template>
86 <template is="dom-if" if="{{!disabled}}"> 91 <div id="sliderContainer"
87 </template> 92 class$="[[_getClassNames(disabled, pin, snaps, immediateValue, min, expand , dragging, transiting, editable)]]">
88 93
89 <div id="sliderContainer" class$="[[_getClassNames(disabled, pin, snaps, imm ediateValue, min, expand, dragging, transiting, editable)]]">
90 <div class="bar-container"> 94 <div class="bar-container">
91 <paper-progress id="sliderBar" aria-hidden="true" min="[[min]]" max="[[m ax]]" value="[[immediateValue]]" secondary-progress="[[secondaryProgress]]" 95 <paper-progress
92 on-down="_bardown" on-up="_resetKnob" on-track="_onTrack"></paper-prog ress> 96 id="sliderBar"
97 aria-hidden="true"
98 min="[[min]]"
99 max="[[max]]"
100 step="[[step]]"
101 value="[[immediateValue]]"
102 secondary-progress="[[secondaryProgress]]"
103 on-down="_bardown"
104 on-up="_resetKnob"
105 on-track="_onTrack">
106 </paper-progress>
93 </div> 107 </div>
94 108
95 <template is="dom-if" if="[[snaps]]"> 109 <template is="dom-if" if="[[snaps]]">
96 <div class="slider-markers horizontal layout"> 110 <div class="slider-markers horizontal layout">
97 <template is="dom-repeat" items="[[markers]]"> 111 <template is="dom-repeat" items="[[markers]]">
98 <div class="slider-marker flex"></div> 112 <div class="slider-marker flex"></div>
99 </template> 113 </template>
100 </div> 114 </div>
101 </template> 115 </template>
102 116
103 <div id="sliderKnob" on-down="_knobdown" on-up="_resetKnob" 117 <div id="sliderKnob"
118 class="center-justified center horizontal layout"
119 on-down="_knobdown"
120 on-up="_resetKnob"
104 on-track="_onTrack" 121 on-track="_onTrack"
105 on-transitionend="_knobTransitionEnd" 122 on-transitionend="_knobTransitionEnd">
106 center-justified center horizontal layout> 123 <paper-ripple id="ink" class="circle" center></paper-ripple>
107 124 <div id="sliderKnobInner" value$="[[immediateValue]]"></div>
108 <div id="sliderKnobInner" value$="[[immediateValue]]"></div>
109 </div> 125 </div>
110 </div> 126 </div>
111 127
112 <template is="dom-if" if="[[editable]]"> 128 <template is="dom-if" if="[[editable]]">
113 <paper-input id="input" class="slider-input" disabled$="[[disabled]]" on-c hange="_inputChange"></paper-input> 129 <paper-input
130 id="input"
131 class="slider-input"
132 disabled$="[[disabled]]"
133 on-change="_inputChange">
134 </paper-input>
114 </template> 135 </template>
136 </template>
115 137
116 </template>
117 </dom-module> 138 </dom-module>
118 139
119 <script> 140 <script>
120 /** 141 /**
121 * Fired when the slider's value changes. 142 * Fired when the slider's value changes.
122 * 143 *
123 * @event value-change 144 * @event value-change
124 */ 145 */
125 146
126 /** 147 /**
127 * Fired when the slider's immediateValue changes. 148 * Fired when the slider's immediateValue changes.
128 * 149 *
129 * @event immediate-value-change 150 * @event immediate-value-change
130 */ 151 */
131 152
132 /** 153 /**
133 * Fired when the slider's value changes due to user interaction. 154 * Fired when the slider's value changes due to user interaction.
134 * 155 *
135 * Changes to the slider's value due to changes in an underlying 156 * Changes to the slider's value due to changes in an underlying
136 * bound variable will not trigger this event. 157 * bound variable will not trigger this event.
137 * 158 *
138 * @event change 159 * @event change
139 */ 160 */
140 161
141 Polymer({ 162 Polymer({
142 is: 'paper-slider', 163 is: 'paper-slider',
143 164
144 behaviors: [ 165 behaviors: [
145 Polymer.IronRangeBehavior, 166 Polymer.IronRangeBehavior,
146 Polymer.IronControlState 167 Polymer.IronA11yKeysBehavior,
168 Polymer.IronFormElementBehavior,
169 Polymer.PaperInkyFocusBehavior
147 ], 170 ],
148 171
149 properties: { 172 properties: {
150
151 /** 173 /**
152 * If true, the slider thumb snaps to tick marks evenly spaced based 174 * If true, the slider thumb snaps to tick marks evenly spaced based
153 * on the `step` property value. 175 * on the `step` property value.
154 */ 176 */
155 snaps: { 177 snaps: {
156 type: Boolean, 178 type: Boolean,
157 value: false, 179 value: false,
158 notify: true 180 notify: true
159 }, 181 },
160 182
161 /** 183 /**
162 * If true, a pin with numeric value label is shown when the slider thumb 184 * If true, a pin with numeric value label is shown when the slider thumb
163 * is pressed. Use for settings for which users need to know the exact 185 * is pressed. Use for settings for which users need to know the exact
164 * value of the setting. 186 * value of the setting.
165 */ 187 */
166 pin: { 188 pin: {
167 type: Boolean, 189 type: Boolean,
168 value: false, 190 value: false,
169 notify: true 191 notify: true
170 }, 192 },
171 193
172 /** 194 /**
173 * The number that represents the current secondary progress. 195 * The number that represents the current secondary progress.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 readOnly: true 247 readOnly: true
226 }, 248 },
227 249
228 transiting: { 250 transiting: {
229 type: Boolean, 251 type: Boolean,
230 value: false, 252 value: false,
231 readOnly: true 253 readOnly: true
232 }, 254 },
233 255
234 markers: { 256 markers: {
257 type: Array,
235 readOnly: true, 258 readOnly: true,
236 value: [] 259 value: []
237 }, 260 },
238 }, 261 },
239 262
240 observers: [ 263 observers: [
241 '_updateKnob(value, min, max, snaps, step)', 264 '_updateKnob(value, min, max, snaps, step)',
242 '_minChanged(min)', 265 '_minChanged(min)',
243 '_maxChanged(max)', 266 '_maxChanged(max)',
244 '_valueChanged(value)', 267 '_valueChanged(value)',
245 '_immediateValueChanged(immediateValue)' 268 '_immediateValueChanged(immediateValue)'
246 ], 269 ],
247 270
271 hostAttributes: {
272 role: 'slider',
273 tabindex: 0
274 },
275
276 keyBindings: {
277 'left down pagedown home': '_decrementKey',
278 'right up pageup end': '_incrementKey'
279 },
280
248 ready: function() { 281 ready: function() {
249 // issue polymer/polymer#1305 282 // issue polymer/polymer#1305
283
250 this.async(function() { 284 this.async(function() {
251 this._updateKnob(this.value); 285 this._updateKnob(this.value);
252 this._updateInputValue(); 286 this._updateInputValue();
253 }, 1); 287 }, 1);
254 }, 288 },
255 289
256 /** 290 /**
257 * Increases value by `step` but not above `max`. 291 * Increases value by `step` but not above `max`.
258 * @method increment 292 * @method increment
259 */ 293 */
(...skipping 20 matching lines...) Expand all
280 _maxChanged: function() { 314 _maxChanged: function() {
281 this.setAttribute('aria-valuemax', this.max); 315 this.setAttribute('aria-valuemax', this.max);
282 }, 316 },
283 317
284 _valueChanged: function() { 318 _valueChanged: function() {
285 this.setAttribute('aria-valuenow', this.value); 319 this.setAttribute('aria-valuenow', this.value);
286 this.fire('value-change'); 320 this.fire('value-change');
287 }, 321 },
288 322
289 _immediateValueChanged: function() { 323 _immediateValueChanged: function() {
290 if (!this.dragging) { 324 if (this.dragging) {
325 this.fire('immediate-value-change');
326 } else {
291 this.value = this.immediateValue; 327 this.value = this.immediateValue;
292 } 328 }
293 this._updateInputValue(); 329 this._updateInputValue();
294 this.fire('immediate-value-change');
295 }, 330 },
296 331
297 _secondaryProgressChanged: function() { 332 _secondaryProgressChanged: function() {
298 this.secondaryProgress = this._clampValue(this.secondaryProgress); 333 this.secondaryProgress = this._clampValue(this.secondaryProgress);
299 }, 334 },
300 335
301 _updateInputValue: function() { 336 _updateInputValue: function() {
302 if (this.editable) { 337 if (this.editable) {
303 this.$$('#input').value = this.immediateValue; 338 this.$$('#input').value = this.immediateValue.toString();
304 } 339 }
305 }, 340 },
306 341
307 _expandKnob: function() { 342 _expandKnob: function() {
343 this.$.ink.holdDown = false;
308 this._setExpand(true); 344 this._setExpand(true);
309 }, 345 },
310 346
311 _resetKnob: function() { 347 _resetKnob: function() {
312 this._expandJob && this._expandJob.stop(); 348 this.cancelDebouncer('expandKnob');
313 this._setExpand(false); 349 this._setExpand(false);
350 this.$.ink.hidden = true;
314 }, 351 },
315 352
316 _positionKnob: function(ratio) { 353 _positionKnob: function(ratio) {
317 this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio)) || 0 ); 354 this._setImmediateValue(this._calcStep(this._calcKnobPosition(ratio)));
318 this._setRatio(this.snaps ? this._calcRatio(this.immediateValue) : ratio); 355 this._setRatio(this._calcRatio(this.immediateValue));
319 this.$.sliderKnob.style.left = this.ratio * 100 + '%'; 356
357 this.$.sliderKnob.style.left = (this.ratio * 100) + '%';
320 }, 358 },
321 359
322 _inputChange: function() { 360 _inputChange: function() {
323 this.value = this.$$('#input').value; 361 this.value = this.$$('#input').value;
324 this.fire('change'); 362 this.fire('change');
325 }, 363 },
326 364
327 _calcKnobPosition: function(ratio) { 365 _calcKnobPosition: function(ratio) {
328 return (this.max - this.min) * ratio + this.min; 366 return (this.max - this.min) * ratio + this.min;
329 }, 367 },
330 368
331 _onTrack: function(e) { 369 _onTrack: function(event) {
332 switch (event.detail.state) { 370 switch (event.detail.state) {
333 case 'end': 371 case 'start':
334 this._trackEnd(event); 372 this._trackStart(event);
335 break; 373 break;
336 case 'track': 374 case 'track':
337 this._trackX(event); 375 this._trackX(event);
338 break; 376 break;
339 case 'start': 377 case 'end':
340 this._trackStart(event); 378 this._trackEnd();
341 break; 379 break;
342 } 380 }
343 }, 381 },
344 382
345 _trackStart: function(e) { 383 _trackStart: function(event) {
346 this._w = this.$.sliderBar.offsetWidth; 384 this._w = this.$.sliderBar.offsetWidth;
347 this._x = this.ratio * this._w; 385 this._x = this.ratio * this._w;
348 this._startx = this._x || 0; 386 this._startx = this._x || 0;
349 this._minx = - this._startx; 387 this._minx = - this._startx;
350 this._maxx = this._w - this._startx; 388 this._maxx = this._w - this._startx;
351 this.$.sliderKnob.classList.add('dragging'); 389 this.$.sliderKnob.classList.add('dragging');
390
352 this._setDragging(true); 391 this._setDragging(true);
353 e.preventDefault();
354 }, 392 },
355 393
356 _trackX: function(e) { 394 _trackX: function(e) {
357 if (!this.dragging) { 395 if (!this.dragging) {
358 this._trackStart(e); 396 this._trackStart(e);
359 } 397 }
360 var x = Math.min(this._maxx, Math.max(this._minx, e.detail.dx)); 398
361 this._x = this._startx + x; 399 var dx = Math.min(this._maxx, Math.max(this._minx, e.detail.dx));
362 this._setImmediateValue(this._calcStep( 400 this._x = this._startx + dx;
363 this._calcKnobPosition(this._x / this._w)) || 0); 401
364 var s = this.$.sliderKnob.style; 402 var immediateValue = this._calcStep(this._calcKnobPosition(this._x / this. _w));
365 s.transform = s.webkitTransform = 'translate3d(' + (this.snaps ? 403 this._setImmediateValue(immediateValue);
366 (this._calcRatio(this.immediateValue) * this._w) - this._startx : x) + 'px, 0, 0)'; 404
405 // update knob's position
406 var translateX = ((this._calcRatio(immediateValue) * this._w) - this._star tx);
407 this.translate3d(translateX + 'px', 0, 0, this.$.sliderKnob);
367 }, 408 },
368 409
369 _trackEnd: function() { 410 _trackEnd: function() {
370 var s = this.$.sliderKnob.style; 411 var s = this.$.sliderKnob.style;
371 s.transform = s.webkitTransform = ''; 412
372 this.$.sliderKnob.classList.remove('dragging'); 413 this.$.sliderKnob.classList.remove('dragging');
373 this._setDragging(false); 414 this._setDragging(false);
374 this._resetKnob(); 415 this._resetKnob();
375 this.value = this.immediateValue; 416 this.value = this.immediateValue;
417
418 s.transform = s.webkitTransform = '';
419
376 this.fire('change'); 420 this.fire('change');
377 }, 421 },
378 422
379 _knobdown: function(e) { 423 _knobdown: function(event) {
380 e.preventDefault();
381 this._expandKnob(); 424 this._expandKnob();
425
426 // cancel selection
427 event.detail.sourceEvent.preventDefault();
428
429 // set the focus manually because we will called prevent default
430 this.focus();
382 }, 431 },
383 432
384 _bardown: function(e) { 433 _bardown: function(event) {
385 e.preventDefault(); 434 this.$.ink.hidden = true;
386 this._setTransiting(true); 435
436 event.preventDefault();
437
387 this._w = this.$.sliderBar.offsetWidth; 438 this._w = this.$.sliderBar.offsetWidth;
388 var rect = this.$.sliderBar.getBoundingClientRect(); 439 var rect = this.$.sliderBar.getBoundingClientRect();
389 var ratio = (e.detail.x - rect.left) / this._w; 440 var ratio = (event.detail.x - rect.left) / this._w;
441 var prevRatio = this.ratio;
442
443 this._setTransiting(true);
444
390 this._positionKnob(ratio); 445 this._positionKnob(ratio);
391 this._expandJob = this.debounce(this._expandJob, this._expandKnob, 60); 446
447 this.debounce('expandKnob', this._expandKnob, 60);
448
449 // if the ratio doesn't change, sliderKnob's animation won't start
450 // and `_knobTransitionEnd` won't be called
451 // Therefore, we need to manually update the `transiting` state
452
453 if (prevRatio === this.ratio) {
454 this._setTransiting(false);
455 }
392 456
393 this.async(function() { 457 this.async(function() {
394 this.fire('change'); 458 this.fire('change');
395 }); 459 });
460
461 // cancel selection
462 event.detail.sourceEvent.preventDefault();
396 }, 463 },
397 464
398 _knobTransitionEnd: function(e) { 465 _knobTransitionEnd: function(event) {
399 if (e.target === this.$.sliderKnob) { 466 if (event.target === this.$.sliderKnob) {
400 this._setTransiting(false); 467 this._setTransiting(false);
401 } 468 }
402 }, 469 },
403 470
404 _maxMarkersChanged: function(maxMarkers) { 471 _maxMarkersChanged: function(maxMarkers) {
405 var l = (this.max - this.min) / this.step; 472 var l = (this.max - this.min) / this.step;
406 if (!this.snaps && l > maxMarkers) { 473 if (!this.snaps && l > maxMarkers) {
407 this._setMarkers([]); 474 this._setMarkers([]);
408 } else { 475 } else {
409 this._setMarkers(new Array(l)); 476 this._setMarkers(new Array(l));
410 } 477 }
411 }, 478 },
412 479
413 _getClassNames: function() { 480 _getClassNames: function() {
414 var classes = {}; 481 var classes = {};
415 482
416 classes['disabled'] = this.disabled; 483 classes.disabled = this.disabled;
417 classes['pin'] = this.pin; 484 classes.pin = this.pin;
418 classes['snaps'] = this.snaps; 485 classes.snaps = this.snaps;
419 classes['ring'] = this.immediateValue <= this.min; 486 classes.ring = this.immediateValue <= this.min;
420 classes['expand'] = this.expand; 487 classes.expand = this.expand;
421 classes['dragging'] = this.dragging; 488 classes.dragging = this.dragging;
422 classes['transiting'] = this.transiting; 489 classes.transiting = this.transiting;
423 classes['editable'] = this.editable; 490 classes.editable = this.editable;
424 491
425 return Object.keys(classes).filter( 492 return Object.keys(classes).filter(
426 function(className) { 493 function(className) {
427 return classes[className]; 494 return classes[className];
428 }).join(' '); 495 }).join(' ');
429 }, 496 },
430 497
431 _incrementKey: function(ev, keys) { 498 _incrementKey: function(event) {
432 if (keys.key === 'end') { 499 if (event.detail.key === 'end') {
433 this.value = this.max; 500 this.value = this.max;
434 } else { 501 } else {
435 this.increment(); 502 this.increment();
436 } 503 }
437 this.fire('change'); 504 this.fire('change');
438 }, 505 },
439 506
440 _decrementKey: function(ev, keys) { 507 _decrementKey: function(event) {
441 if (keys.key === 'home') { 508 if (event.detail.key === 'home') {
442 this.value = this.min; 509 this.value = this.min;
443 } else { 510 } else {
444 this.decrement(); 511 this.decrement();
445 } 512 }
446 this.fire('change'); 513 this.fire('change');
447 } 514 }
448 }) 515 })
449 </script> 516 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698