Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 marker.style.left = (i * 100 / HOURS_PER_DAY) + '%'; | 68 marker.style.left = (i * 100 / HOURS_PER_DAY) + '%'; |
| 69 } | 69 } |
| 70 | 70 |
| 71 this.async(function() { | 71 this.async(function() { |
| 72 // Read the initial prefs values and refresh the slider. | 72 // Read the initial prefs values and refresh the slider. |
| 73 this.customTimesChanged_(); | 73 this.customTimesChanged_(); |
| 74 }); | 74 }); |
| 75 }, | 75 }, |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * @return {boolean} True if window is in a right-to-left locale. | |
| 79 * @private | |
| 80 */ | |
| 81 isRTL_: function() { | |
| 82 return window.getComputedStyle(document.firstElementChild).direction === | |
| 83 'rtl'; | |
|
stevenjb
2017/06/22 21:17:22
This is an element so the following should work:
afakhry
2017/06/22 21:51:26
I tried all of this the first thing but it doesn't
stevenjb
2017/06/22 22:12:05
You need to pass isRTL_ to the functions in the HT
afakhry
2017/06/22 22:38:21
This works. Thank you very much for suggesting! It
| |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * Gets the style of legend div determining its absolute left position. | |
| 88 * @param {number} percent The value of the div's left as a percent (0 - 100). | |
| 89 * @return {string} the CSS style of the legend div. | |
| 90 * @private | |
| 91 */ | |
| 92 getLegendStyle_: function(percent) { | |
| 93 percent = this.isRTL_() ? 100 - percent : percent; | |
| 94 return 'left: ' + percent + '%'; | |
| 95 }, | |
| 96 | |
| 97 /** | |
| 78 * Expands or un-expands the knob being dragged along with its corresponding | 98 * Expands or un-expands the knob being dragged along with its corresponding |
| 79 * label bubble. | 99 * label bubble. |
| 80 * @param {boolean} expand True to expand, and false to un-expand. | 100 * @param {boolean} expand True to expand, and false to un-expand. |
| 81 * @private | 101 * @private |
| 82 */ | 102 */ |
| 83 setExpanded_: function(expand) { | 103 setExpanded_: function(expand) { |
| 84 var knob = this.$.startKnob; | 104 var knob = this.$.startKnob; |
| 85 var label = this.$.startLabel; | 105 var label = this.$.startLabel; |
| 86 if (this.dragObject_ == this.$.endKnob) { | 106 if (this.dragObject_ == this.$.endKnob) { |
| 87 knob = this.$.endKnob; | 107 knob = this.$.endKnob; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 doKnobTracking_: function(event) { | 183 doKnobTracking_: function(event) { |
| 164 var deltaRatio = Math.abs(event.detail.ddx) / this.$.sliderBar.offsetWidth; | 184 var deltaRatio = Math.abs(event.detail.ddx) / this.$.sliderBar.offsetWidth; |
| 165 var deltaMinutes = Math.floor(deltaRatio * TOTAL_MINUTES_PER_DAY); | 185 var deltaMinutes = Math.floor(deltaRatio * TOTAL_MINUTES_PER_DAY); |
| 166 if (deltaMinutes <= 0) | 186 if (deltaMinutes <= 0) |
| 167 return; | 187 return; |
| 168 | 188 |
| 169 var knobPref = this.dragObject_ == this.$.startKnob ? | 189 var knobPref = this.dragObject_ == this.$.startKnob ? |
| 170 'ash.night_light.custom_start_time' : | 190 'ash.night_light.custom_start_time' : |
| 171 'ash.night_light.custom_end_time'; | 191 'ash.night_light.custom_end_time'; |
| 172 | 192 |
| 173 if (event.detail.ddx > 0) { | 193 var ddx = this.isRTL_() ? event.detail.ddx * -1 : event.detail.ddx; |
| 194 if (ddx > 0) { | |
| 174 // Increment the knob's pref by the amount of deltaMinutes. | 195 // Increment the knob's pref by the amount of deltaMinutes. |
| 175 this.incrementPref_(knobPref, deltaMinutes); | 196 this.incrementPref_(knobPref, deltaMinutes); |
| 176 } else { | 197 } else { |
| 177 // Decrement the knob's pref by the amount of deltaMinutes. | 198 // Decrement the knob's pref by the amount of deltaMinutes. |
| 178 this.decrementPref_(knobPref, deltaMinutes); | 199 this.decrementPref_(knobPref, deltaMinutes); |
| 179 } | 200 } |
| 180 }, | 201 }, |
| 181 | 202 |
| 182 /** | 203 /** |
| 183 * Ends the dragging. | 204 * Ends the dragging. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 | 285 |
| 265 if (ratio == 0) { | 286 if (ratio == 0) { |
| 266 // If the ratio is 0, then there are two possibilities: | 287 // 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. | 288 // - 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. | 289 // - 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 | 290 // We need to check the current knob offset ratio to determine which case |
| 270 // it is. | 291 // it is. |
| 271 var currentKnobRatio = this.getKnobRatio_(knob); | 292 var currentKnobRatio = this.getKnobRatio_(knob); |
| 272 ratio = currentKnobRatio > 0.5 ? 1.0 : 0.0; | 293 ratio = currentKnobRatio > 0.5 ? 1.0 : 0.0; |
| 273 } | 294 } |
| 274 | 295 ratio = this.isRTL_() ? (1.0 - ratio) : ratio; |
| 275 knob.style.left = (ratio * this.$.sliderBar.offsetWidth) + 'px'; | 296 knob.style.left = (ratio * this.$.sliderBar.offsetWidth) + 'px'; |
| 276 }, | 297 }, |
| 277 | 298 |
| 278 /** | 299 /** |
| 279 * Refreshes elements of the slider other than the knobs (the label bubbles, | 300 * Refreshes elements of the slider other than the knobs (the label bubbles, |
| 280 * and the progress bar). | 301 * and the progress bar). |
| 281 * @private | 302 * @private |
| 282 */ | 303 */ |
| 283 refresh_: function() { | 304 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 | 305 // The label bubbles have the same left coordinates as their corresponding |
| 292 // knobs. | 306 // knobs. |
| 293 startLabel.style.left = startKnob.style.left; | 307 this.$.startLabel.style.left = this.$.startKnob.style.left; |
| 294 endLabel.style.left = endKnob.style.left; | 308 this.$.endLabel.style.left = this.$.endKnob.style.left; |
| 309 | |
| 310 // In RTL locales, the relative positions of the knobs are flipped for the | |
| 311 // purpose of calculating the styles of the progress bars below. | |
| 312 var rtl = this.isRTL_(); | |
| 313 var endKnob = rtl ? this.$.startKnob : this.$.endKnob; | |
| 314 var startKnob = rtl ? this.$.endKnob : this.$.startKnob; | |
| 315 var startProgress = rtl ? this.$.endProgress : this.$.startProgress; | |
| 316 var endProgress = rtl ? this.$.startProgress : this.$.endProgress; | |
| 295 | 317 |
| 296 // The end progress bar starts from either the start knob or the start of | 318 // 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. | 319 // the slider (whichever is to its left) and ends at the end knob. |
| 298 var endProgressLeft = startKnob.offsetLeft >= endKnob.offsetLeft ? | 320 var endProgressLeft = startKnob.offsetLeft >= endKnob.offsetLeft ? |
| 299 '0px' : | 321 '0px' : |
| 300 startKnob.style.left; | 322 startKnob.style.left; |
| 301 endProgress.style.left = endProgressLeft; | 323 endProgress.style.left = endProgressLeft; |
| 302 endProgress.style.width = | 324 endProgress.style.width = |
| 303 (parseFloat(endKnob.style.left) - parseFloat(endProgressLeft)) + 'px'; | 325 (parseFloat(endKnob.style.left) - parseFloat(endProgressLeft)) + 'px'; |
| 304 | 326 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 /** | 458 /** |
| 437 * Handles the 'left' key event. | 459 * Handles the 'left' key event. |
| 438 * @private | 460 * @private |
| 439 */ | 461 */ |
| 440 onLeftKey_: function(e) { | 462 onLeftKey_: function(e) { |
| 441 e.preventDefault(); | 463 e.preventDefault(); |
| 442 var knobPref = this.getFocusedKnobPrefPathIfAny_(); | 464 var knobPref = this.getFocusedKnobPrefPathIfAny_(); |
| 443 if (!knobPref) | 465 if (!knobPref) |
| 444 return; | 466 return; |
| 445 | 467 |
| 446 this.decrementPref_(knobPref, 1); | 468 if (this.isRTL_()) |
| 469 this.incrementPref_(knobPref, 1); | |
| 470 else | |
| 471 this.decrementPref_(knobPref, 1); | |
| 447 }, | 472 }, |
| 448 | 473 |
| 449 /** | 474 /** |
| 450 * Handles the 'right' key event. | 475 * Handles the 'right' key event. |
| 451 * @private | 476 * @private |
| 452 */ | 477 */ |
| 453 onRightKey_: function(e) { | 478 onRightKey_: function(e) { |
| 454 e.preventDefault(); | 479 e.preventDefault(); |
| 455 var knobPref = this.getFocusedKnobPrefPathIfAny_(); | 480 var knobPref = this.getFocusedKnobPrefPathIfAny_(); |
| 456 if (!knobPref) | 481 if (!knobPref) |
| 457 return; | 482 return; |
| 458 | 483 |
| 459 this.incrementPref_(knobPref, 1); | 484 if (this.isRTL_()) |
| 485 this.decrementPref_(knobPref, 1); | |
| 486 else | |
| 487 this.incrementPref_(knobPref, 1); | |
| 460 }, | 488 }, |
| 461 | 489 |
| 462 /** | 490 /** |
| 463 * @return {boolean} Whether either of the two knobs is focused. | 491 * @return {boolean} Whether either of the two knobs is focused. |
| 464 * @private | 492 * @private |
| 465 */ | 493 */ |
| 466 isEitherKnobFocused_: function() { | 494 isEitherKnobFocused_: function() { |
| 467 var activeElement = this.shadowRoot.activeElement; | 495 var activeElement = this.shadowRoot.activeElement; |
| 468 return activeElement == this.$.startKnob || activeElement == this.$.endKnob; | 496 return activeElement == this.$.startKnob || activeElement == this.$.endKnob; |
| 469 }, | 497 }, |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 516 _focusedChanged: function(receivedFocusFromKeyboard) { | 544 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 517 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that | 545 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that |
| 518 // it does nothing. This function is called only once for the entire | 546 // 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 | 547 // 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 | 548 // 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. | 549 // created. Hence we handle focus and blur explicitly above. |
| 522 } | 550 } |
| 523 }); | 551 }); |
| 524 | 552 |
| 525 })(); | 553 })(); |
| OLD | NEW |