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

Side by Side Diff: third_party/polymer/v1_0/components-chromium/paper-slider/paper-slider-extracted.js

Issue 2801193002: [Polymer] update paper-slider for RTL support (Closed)
Patch Set: Created 3 years, 8 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 Polymer({ 1 Polymer({
2 is: 'paper-slider', 2 is: 'paper-slider',
3 3
4 behaviors: [ 4 behaviors: [
5 Polymer.IronA11yKeysBehavior, 5 Polymer.IronA11yKeysBehavior,
6 Polymer.IronFormElementBehavior, 6 Polymer.IronFormElementBehavior,
7 Polymer.PaperInkyFocusBehavior, 7 Polymer.PaperInkyFocusBehavior,
8 Polymer.IronRangeBehavior 8 Polymer.IronRangeBehavior
9 ], 9 ],
10 10
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 '_immediateValueChanged(immediateValue)', 107 '_immediateValueChanged(immediateValue)',
108 '_updateMarkers(maxMarkers, min, max, snaps)' 108 '_updateMarkers(maxMarkers, min, max, snaps)'
109 ], 109 ],
110 110
111 hostAttributes: { 111 hostAttributes: {
112 role: 'slider', 112 role: 'slider',
113 tabindex: 0 113 tabindex: 0
114 }, 114 },
115 115
116 keyBindings: { 116 keyBindings: {
117 'left down pagedown home': '_decrementKey', 117 'left': '_leftKey',
118 'right up pageup end': '_incrementKey' 118 'right': '_rightKey',
119 'down pagedown home': '_decrementKey',
120 'up pageup end': '_incrementKey'
119 }, 121 },
120 122
121 /** 123 /**
122 * Increases value by `step` but not above `max`. 124 * Increases value by `step` but not above `max`.
123 * @method increment 125 * @method increment
124 */ 126 */
125 increment: function() { 127 increment: function() {
126 this.value = this._clampValue(this.value + this.step); 128 this.value = this._clampValue(this.value + this.step);
127 }, 129 },
128 130
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 this._maxx = this._w - this._startx; 208 this._maxx = this._w - this._startx;
207 this.$.sliderKnob.classList.add('dragging'); 209 this.$.sliderKnob.classList.add('dragging');
208 this._setDragging(true); 210 this._setDragging(true);
209 }, 211 },
210 212
211 _trackX: function(event) { 213 _trackX: function(event) {
212 if (!this.dragging) { 214 if (!this.dragging) {
213 this._trackStart(event); 215 this._trackStart(event);
214 } 216 }
215 217
216 var dx = Math.min(this._maxx, Math.max(this._minx, event.detail.dx)); 218 var direction = this._isRTL ? -1 : 1;
219 var dx = Math.min(
220 this._maxx, Math.max(this._minx, event.detail.dx * direction));
217 this._x = this._startx + dx; 221 this._x = this._startx + dx;
218 222
219 var immediateValue = this._calcStep(this._calcKnobPosition(this._x / thi s._w)); 223 var immediateValue = this._calcStep(this._calcKnobPosition(this._x / thi s._w));
220 this._setImmediateValue(immediateValue); 224 this._setImmediateValue(immediateValue);
221 225
222 // update knob's position 226 // update knob's position
223 var translateX = ((this._calcRatio(this.immediateValue) * this._w) - thi s._knobstartx); 227 var translateX = ((this._calcRatio(this.immediateValue) * this._w) - thi s._knobstartx);
224 this.translate3d(translateX + 'px', 0, 0, this.$.sliderKnob); 228 this.translate3d(translateX + 'px', 0, 0, this.$.sliderKnob);
225 }, 229 },
226 230
(...skipping 17 matching lines...) Expand all
244 event.preventDefault(); 248 event.preventDefault();
245 249
246 // set the focus manually because we will called prevent default 250 // set the focus manually because we will called prevent default
247 this.focus(); 251 this.focus();
248 }, 252 },
249 253
250 _bardown: function(event) { 254 _bardown: function(event) {
251 this._w = this.$.sliderBar.offsetWidth; 255 this._w = this.$.sliderBar.offsetWidth;
252 var rect = this.$.sliderBar.getBoundingClientRect(); 256 var rect = this.$.sliderBar.getBoundingClientRect();
253 var ratio = (event.detail.x - rect.left) / this._w; 257 var ratio = (event.detail.x - rect.left) / this._w;
258 if (this._isRTL) {
259 ratio = 1 - ratio;
260 }
254 var prevRatio = this.ratio; 261 var prevRatio = this.ratio;
255 262
256 this._setTransiting(true); 263 this._setTransiting(true);
257 264
258 this._positionKnob(ratio); 265 this._positionKnob(ratio);
259 266
260 this.debounce('expandKnob', this._expandKnob, 60); 267 this.debounce('expandKnob', this._expandKnob, 60);
261 268
262 // if the ratio doesn't change, sliderKnob's animation won't start 269 // if the ratio doesn't change, sliderKnob's animation won't start
263 // and `_knobTransitionEnd` won't be called 270 // and `_knobTransitionEnd` won't be called
(...skipping 21 matching lines...) Expand all
285 }, 292 },
286 293
287 _updateMarkers: function(maxMarkers, min, max, snaps) { 294 _updateMarkers: function(maxMarkers, min, max, snaps) {
288 if (!snaps) { 295 if (!snaps) {
289 this._setMarkers([]); 296 this._setMarkers([]);
290 } 297 }
291 var steps = Math.round((max - min) / this.step); 298 var steps = Math.round((max - min) / this.step);
292 if (steps > maxMarkers) { 299 if (steps > maxMarkers) {
293 steps = maxMarkers; 300 steps = maxMarkers;
294 } 301 }
302 if (steps < 0 || !isFinite(steps)) {
303 steps = 0;
304 }
dschuyler 2017/04/07 02:59:59 This is a change that wasn't in my PR, but it look
295 this._setMarkers(new Array(steps)); 305 this._setMarkers(new Array(steps));
296 }, 306 },
297 307
298 _mergeClasses: function(classes) { 308 _mergeClasses: function(classes) {
299 return Object.keys(classes).filter( 309 return Object.keys(classes).filter(
300 function(className) { 310 function(className) {
301 return classes[className]; 311 return classes[className];
302 }).join(' '); 312 }).join(' ');
303 }, 313 },
304 314
305 _getClassNames: function() { 315 _getClassNames: function() {
306 return this._mergeClasses({ 316 return this._mergeClasses({
307 disabled: this.disabled, 317 disabled: this.disabled,
308 pin: this.pin, 318 pin: this.pin,
309 snaps: this.snaps, 319 snaps: this.snaps,
310 ring: this.immediateValue <= this.min, 320 ring: this.immediateValue <= this.min,
311 expand: this.expand, 321 expand: this.expand,
312 dragging: this.dragging, 322 dragging: this.dragging,
313 transiting: this.transiting, 323 transiting: this.transiting,
314 editable: this.editable 324 editable: this.editable
315 }); 325 });
316 }, 326 },
317 327
328 get _isRTL() {
329 if (this.__isRTL === undefined) {
330 this.__isRTL = window.getComputedStyle(this)['direction'] === 'rtl';
331 }
332 return this.__isRTL;
333 },
334
335 _leftKey: function(event) {
336 if (this._isRTL)
337 this._incrementKey(event);
338 else
339 this._decrementKey(event);
340 },
341
342 _rightKey: function(event) {
343 if (this._isRTL)
344 this._decrementKey(event);
345 else
346 this._incrementKey(event);
347 },
348
318 _incrementKey: function(event) { 349 _incrementKey: function(event) {
319 if (!this.disabled) { 350 if (!this.disabled) {
320 if (event.detail.key === 'end') { 351 if (event.detail.key === 'end') {
321 this.value = this.max; 352 this.value = this.max;
322 } else { 353 } else {
323 this.increment(); 354 this.increment();
324 } 355 }
325 this.fire('change'); 356 this.fire('change');
326 event.preventDefault(); 357 event.preventDefault();
327 } 358 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 */ 422 */
392 423
393 /** 424 /**
394 * Fired when the slider's value changes due to user interaction. 425 * Fired when the slider's value changes due to user interaction.
395 * 426 *
396 * Changes to the slider's value due to changes in an underlying 427 * Changes to the slider's value due to changes in an underlying
397 * bound variable will not trigger this event. 428 * bound variable will not trigger this event.
398 * 429 *
399 * @event change 430 * @event change
400 */ 431 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698