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

Side by Side Diff: chrome/browser/resources/settings/device_page/night_light_slider.js

Issue 2950393002: [MD-Settings][Night Light] CL10: Add RTL languages support to the slider (Closed)
Patch Set: Making it a property Created 3 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
« no previous file with comments | « chrome/browser/resources/settings/device_page/night_light_slider.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 (function() { 5 (function() {
6 6
7 /** 7 /**
8 * @fileoverview 8 * @fileoverview
9 * night-light-slider is used to set the custom automatic schedule of the 9 * night-light-slider is used to set the custom automatic schedule of the
10 * Night Light feature, so that users can set their desired start and end 10 * Night Light feature, so that users can set their desired start and end
(...skipping 19 matching lines...) Expand all
30 * The start knob time as a string to be shown on the start label bubble. 30 * The start knob time as a string to be shown on the start label bubble.
31 * @private 31 * @private
32 */ 32 */
33 startTime_: String, 33 startTime_: String,
34 34
35 /** 35 /**
36 * The end knob time as a string to be shown on the end label bubble. 36 * The end knob time as a string to be shown on the end label bubble.
37 * @private 37 * @private
38 */ 38 */
39 endTime_: String, 39 endTime_: String,
40
41 /**
42 * Whether the window is in RTL locales.
stevenjb 2017/06/22 22:48:41 @private
afakhry 2017/06/22 23:08:41 Done.
43 */
44 isRTL_: Boolean,
40 }, 45 },
41 46
42 observers: [ 47 observers: [
43 'customTimesChanged_(prefs.ash.night_light.custom_start_time.*, ' + 48 'customTimesChanged_(prefs.ash.night_light.custom_start_time.*, ' +
44 'prefs.ash.night_light.custom_end_time.*)', 49 'prefs.ash.night_light.custom_end_time.*)',
45 ], 50 ],
46 51
47 keyBindings: { 52 keyBindings: {
48 'left': 'onLeftKey_', 53 'left': 'onLeftKey_',
49 'right': 'onRightKey_', 54 'right': 'onRightKey_',
50 }, 55 },
51 56
52 /** 57 /**
53 * The object currently being dragged. Either the start or end knobs. 58 * The object currently being dragged. Either the start or end knobs.
54 * @type {?Object} 59 * @type {?Object}
55 * @private 60 * @private
56 */ 61 */
57 dragObject_: null, 62 dragObject_: null,
58 63
59 /** @override */ 64 /** @override */
65 attached: function() {
66 this.isRTL_ = window.getComputedStyle(this).direction == 'rtl';
67 },
68
69 /** @override */
60 ready: function() { 70 ready: function() {
61 // Build the legend markers. 71 // Build the legend markers.
62 var markersContainer = this.$.markersContainer; 72 var markersContainer = this.$.markersContainer;
63 var width = markersContainer.offsetWidth; 73 var width = markersContainer.offsetWidth;
64 for (var i = 0; i <= HOURS_PER_DAY; ++i) { 74 for (var i = 0; i <= HOURS_PER_DAY; ++i) {
65 var marker = document.createElement('div'); 75 var marker = document.createElement('div');
66 marker.className = 'markers'; 76 marker.className = 'markers';
67 markersContainer.appendChild(marker); 77 markersContainer.appendChild(marker);
68 marker.style.left = (i * 100 / HOURS_PER_DAY) + '%'; 78 marker.style.left = (i * 100 / HOURS_PER_DAY) + '%';
69 } 79 }
70 80
71 this.async(function() { 81 this.async(function() {
72 // Read the initial prefs values and refresh the slider. 82 // Read the initial prefs values and refresh the slider.
73 this.customTimesChanged_(); 83 this.customTimesChanged_();
74 }); 84 });
75 }, 85 },
76 86
77 /** 87 /**
88 * Gets the style of legend div determining its absolute left position.
89 * @param {number} percent The value of the div's left as a percent (0 - 100).
90 * @param {boolean} isRTL whether window is in RTL locale.
91 * @return {string} The CSS style of the legend div.
92 * @private
93 */
94 getLegendStyle_: function(percent, isRTL) {
95 percent = isRTL ? 100 - percent : percent;
96 return 'left: ' + percent + '%';
97 },
98
99 /**
78 * Expands or un-expands the knob being dragged along with its corresponding 100 * Expands or un-expands the knob being dragged along with its corresponding
79 * label bubble. 101 * label bubble.
80 * @param {boolean} expand True to expand, and false to un-expand. 102 * @param {boolean} expand True to expand, and false to un-expand.
81 * @private 103 * @private
82 */ 104 */
83 setExpanded_: function(expand) { 105 setExpanded_: function(expand) {
84 var knob = this.$.startKnob; 106 var knob = this.$.startKnob;
85 var label = this.$.startLabel; 107 var label = this.$.startLabel;
86 if (this.dragObject_ == this.$.endKnob) { 108 if (this.dragObject_ == this.$.endKnob) {
87 knob = this.$.endKnob; 109 knob = this.$.endKnob;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 doKnobTracking_: function(event) { 185 doKnobTracking_: function(event) {
164 var deltaRatio = Math.abs(event.detail.ddx) / this.$.sliderBar.offsetWidth; 186 var deltaRatio = Math.abs(event.detail.ddx) / this.$.sliderBar.offsetWidth;
165 var deltaMinutes = Math.floor(deltaRatio * TOTAL_MINUTES_PER_DAY); 187 var deltaMinutes = Math.floor(deltaRatio * TOTAL_MINUTES_PER_DAY);
166 if (deltaMinutes <= 0) 188 if (deltaMinutes <= 0)
167 return; 189 return;
168 190
169 var knobPref = this.dragObject_ == this.$.startKnob ? 191 var knobPref = this.dragObject_ == this.$.startKnob ?
170 'ash.night_light.custom_start_time' : 192 'ash.night_light.custom_start_time' :
171 'ash.night_light.custom_end_time'; 193 'ash.night_light.custom_end_time';
172 194
173 if (event.detail.ddx > 0) { 195 var ddx = this.isRTL_ ? event.detail.ddx * -1 : event.detail.ddx;
196 if (ddx > 0) {
174 // Increment the knob's pref by the amount of deltaMinutes. 197 // Increment the knob's pref by the amount of deltaMinutes.
175 this.incrementPref_(knobPref, deltaMinutes); 198 this.incrementPref_(knobPref, deltaMinutes);
176 } else { 199 } else {
177 // Decrement the knob's pref by the amount of deltaMinutes. 200 // Decrement the knob's pref by the amount of deltaMinutes.
178 this.decrementPref_(knobPref, deltaMinutes); 201 this.decrementPref_(knobPref, deltaMinutes);
179 } 202 }
180 }, 203 },
181 204
182 /** 205 /**
183 * Ends the dragging. 206 * Ends the dragging.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 287
265 if (ratio == 0) { 288 if (ratio == 0) {
266 // If the ratio is 0, then there are two possibilities: 289 // If the ratio is 0, then there are two possibilities:
267 // - The knob time is 6:00 PM on the left side of the slider. 290 // - The knob time is 6:00 PM on the left side of the slider.
268 // - The knob time is 6:00 PM on the right side of the slider. 291 // - The knob time is 6:00 PM on the right side of the slider.
269 // We need to check the current knob offset ratio to determine which case 292 // We need to check the current knob offset ratio to determine which case
270 // it is. 293 // it is.
271 var currentKnobRatio = this.getKnobRatio_(knob); 294 var currentKnobRatio = this.getKnobRatio_(knob);
272 ratio = currentKnobRatio > 0.5 ? 1.0 : 0.0; 295 ratio = currentKnobRatio > 0.5 ? 1.0 : 0.0;
273 } 296 }
274 297 ratio = this.isRTL_ ? (1.0 - ratio) : ratio;
275 knob.style.left = (ratio * this.$.sliderBar.offsetWidth) + 'px'; 298 knob.style.left = (ratio * this.$.sliderBar.offsetWidth) + 'px';
276 }, 299 },
277 300
278 /** 301 /**
279 * Refreshes elements of the slider other than the knobs (the label bubbles, 302 * Refreshes elements of the slider other than the knobs (the label bubbles,
280 * and the progress bar). 303 * and the progress bar).
281 * @private 304 * @private
282 */ 305 */
283 refresh_: function() { 306 refresh_: function() {
284 var endKnob = this.$.endKnob;
285 var startKnob = this.$.startKnob;
286 var startProgress = this.$.startProgress;
287 var endProgress = this.$.endProgress;
288 var startLabel = this.$.startLabel;
289 var endLabel = this.$.endLabel;
290
291 // The label bubbles have the same left coordinates as their corresponding 307 // The label bubbles have the same left coordinates as their corresponding
292 // knobs. 308 // knobs.
293 startLabel.style.left = startKnob.style.left; 309 this.$.startLabel.style.left = this.$.startKnob.style.left;
294 endLabel.style.left = endKnob.style.left; 310 this.$.endLabel.style.left = this.$.endKnob.style.left;
311
312 // In RTL locales, the relative positions of the knobs are flipped for the
313 // purpose of calculating the styles of the progress bars below.
314 var rtl = this.isRTL_;
315 var endKnob = rtl ? this.$.startKnob : this.$.endKnob;
316 var startKnob = rtl ? this.$.endKnob : this.$.startKnob;
317 var startProgress = rtl ? this.$.endProgress : this.$.startProgress;
318 var endProgress = rtl ? this.$.startProgress : this.$.endProgress;
295 319
296 // The end progress bar starts from either the start knob or the start of 320 // The end progress bar starts from either the start knob or the start of
297 // the slider (whichever is to its left) and ends at the end knob. 321 // the slider (whichever is to its left) and ends at the end knob.
298 var endProgressLeft = startKnob.offsetLeft >= endKnob.offsetLeft ? 322 var endProgressLeft = startKnob.offsetLeft >= endKnob.offsetLeft ?
299 '0px' : 323 '0px' :
300 startKnob.style.left; 324 startKnob.style.left;
301 endProgress.style.left = endProgressLeft; 325 endProgress.style.left = endProgressLeft;
302 endProgress.style.width = 326 endProgress.style.width =
303 (parseFloat(endKnob.style.left) - parseFloat(endProgressLeft)) + 'px'; 327 (parseFloat(endKnob.style.left) - parseFloat(endProgressLeft)) + 'px';
304 328
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 /** 460 /**
437 * Handles the 'left' key event. 461 * Handles the 'left' key event.
438 * @private 462 * @private
439 */ 463 */
440 onLeftKey_: function(e) { 464 onLeftKey_: function(e) {
441 e.preventDefault(); 465 e.preventDefault();
442 var knobPref = this.getFocusedKnobPrefPathIfAny_(); 466 var knobPref = this.getFocusedKnobPrefPathIfAny_();
443 if (!knobPref) 467 if (!knobPref)
444 return; 468 return;
445 469
446 this.decrementPref_(knobPref, 1); 470 if (this.isRTL_)
471 this.incrementPref_(knobPref, 1);
472 else
473 this.decrementPref_(knobPref, 1);
447 }, 474 },
448 475
449 /** 476 /**
450 * Handles the 'right' key event. 477 * Handles the 'right' key event.
451 * @private 478 * @private
452 */ 479 */
453 onRightKey_: function(e) { 480 onRightKey_: function(e) {
454 e.preventDefault(); 481 e.preventDefault();
455 var knobPref = this.getFocusedKnobPrefPathIfAny_(); 482 var knobPref = this.getFocusedKnobPrefPathIfAny_();
456 if (!knobPref) 483 if (!knobPref)
457 return; 484 return;
458 485
459 this.incrementPref_(knobPref, 1); 486 if (this.isRTL_)
487 this.decrementPref_(knobPref, 1);
488 else
489 this.incrementPref_(knobPref, 1);
460 }, 490 },
461 491
462 /** 492 /**
463 * @return {boolean} Whether either of the two knobs is focused. 493 * @return {boolean} Whether either of the two knobs is focused.
464 * @private 494 * @private
465 */ 495 */
466 isEitherKnobFocused_: function() { 496 isEitherKnobFocused_: function() {
467 var activeElement = this.shadowRoot.activeElement; 497 var activeElement = this.shadowRoot.activeElement;
468 return activeElement == this.$.startKnob || activeElement == this.$.endKnob; 498 return activeElement == this.$.startKnob || activeElement == this.$.endKnob;
469 }, 499 },
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 _focusedChanged: function(receivedFocusFromKeyboard) { 546 _focusedChanged: function(receivedFocusFromKeyboard) {
517 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that 547 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that
518 // it does nothing. This function is called only once for the entire 548 // it does nothing. This function is called only once for the entire
519 // night-light-slider element even when focus is moved between the two 549 // night-light-slider element even when focus is moved between the two
520 // knobs. This doesn't allow us to decide on which knob the ripple will be 550 // knobs. This doesn't allow us to decide on which knob the ripple will be
521 // created. Hence we handle focus and blur explicitly above. 551 // created. Hence we handle focus and blur explicitly above.
522 } 552 }
523 }); 553 });
524 554
525 })(); 555 })();
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/device_page/night_light_slider.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698