| 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 |
| 11 * times. | 11 * times. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 /** @const */ var HOURS_PER_DAY = 24; | 14 /** @const */ var HOURS_PER_DAY = 24; |
| 15 /** @const */ var MIN_KNOBS_DISTANCE_MINUTES = 30; | 15 /** @const */ var MIN_KNOBS_DISTANCE_MINUTES = 60; |
| 16 /** @const */ var OFFSET_MINUTES_6PM = 18 * 60; | 16 /** @const */ var OFFSET_MINUTES_6PM = 18 * 60; |
| 17 /** @const */ var TOTAL_MINUTES_PER_DAY = 24 * 60; | 17 /** @const */ var TOTAL_MINUTES_PER_DAY = 24 * 60; |
| 18 | 18 |
| 19 Polymer({ | 19 Polymer({ |
| 20 is: 'night-light-slider', | 20 is: 'night-light-slider', |
| 21 | 21 |
| 22 behaviors: [ | 22 behaviors: [ |
| 23 PrefsBehavior, | 23 PrefsBehavior, |
| 24 Polymer.IronA11yKeysBehavior, | 24 Polymer.IronA11yKeysBehavior, |
| 25 Polymer.PaperInkyFocusBehavior, | 25 Polymer.PaperInkyFocusBehavior, |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 /** | 343 /** |
| 344 * If the label bubbles overlap, this function fixes them by moving the end | 344 * If the label bubbles overlap, this function fixes them by moving the end |
| 345 * label up a little. | 345 * label up a little. |
| 346 * @private | 346 * @private |
| 347 */ | 347 */ |
| 348 fixLabelsOverlapIfAny_: function() { | 348 fixLabelsOverlapIfAny_: function() { |
| 349 var startLabel = this.$.startLabel; | 349 var startLabel = this.$.startLabel; |
| 350 var endLabel = this.$.endLabel; | 350 var endLabel = this.$.endLabel; |
| 351 var distance = Math.abs( | 351 var distance = Math.abs( |
| 352 parseFloat(startLabel.style.left) - parseFloat(endLabel.style.left)); | 352 parseFloat(startLabel.style.left) - parseFloat(endLabel.style.left)); |
| 353 if (distance <= startLabel.offsetWidth) { | 353 // Both knobs have the same width, but the one being dragged is scaled up by |
| 354 // 125%. |
| 355 if (distance <= (1.25 * startLabel.offsetWidth)) { |
| 354 // Shift the end label up so that it doesn't overlap with the start label. | 356 // Shift the end label up so that it doesn't overlap with the start label. |
| 355 endLabel.classList.add('end-label-overlap'); | 357 endLabel.classList.add('end-label-overlap'); |
| 356 } else { | 358 } else { |
| 357 endLabel.classList.remove('end-label-overlap'); | 359 endLabel.classList.remove('end-label-overlap'); |
| 358 } | 360 } |
| 359 }, | 361 }, |
| 360 | 362 |
| 361 /** | 363 /** |
| 362 * Given the |prefPath| that corresponds to one knob time, it gets the value | 364 * Given the |prefPath| that corresponds to one knob time, it gets the value |
| 363 * of the pref that corresponds to the other knob. | 365 * of the pref that corresponds to the other knob. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 382 * @param {number} increment | 384 * @param {number} increment |
| 383 * @private | 385 * @private |
| 384 */ | 386 */ |
| 385 incrementPref_: function(prefPath, increment) { | 387 incrementPref_: function(prefPath, increment) { |
| 386 var value = this.getPref(prefPath).value + increment; | 388 var value = this.getPref(prefPath).value + increment; |
| 387 | 389 |
| 388 var otherValue = this.getOtherKnobPrefValue_(prefPath); | 390 var otherValue = this.getOtherKnobPrefValue_(prefPath); |
| 389 if (otherValue > value && | 391 if (otherValue > value && |
| 390 ((otherValue - value) < MIN_KNOBS_DISTANCE_MINUTES)) { | 392 ((otherValue - value) < MIN_KNOBS_DISTANCE_MINUTES)) { |
| 391 // We are incrementing the minutes offset moving towards the other knob. | 393 // We are incrementing the minutes offset moving towards the other knob. |
| 392 // We have a minimum 30 minutes overlap threshold. Move this knob to the | 394 // We have a minimum 60 minutes overlap threshold. Move this knob to the |
| 393 // other side of the other knob. | 395 // other side of the other knob. |
| 394 // | 396 // |
| 395 // Was: | 397 // Was: |
| 396 // ------ (+) --- 29 MIN --- + ------->> | 398 // ------ (+) --- 59 MIN --- + ------->> |
| 397 // | 399 // |
| 398 // Now: | 400 // Now: |
| 399 // ------ + --- 30 MIN --- (+) ------->> | 401 // ------ + --- 60 MIN --- (+) ------->> |
| 400 // | 402 // |
| 401 // (+) ==> Knob being moved. | 403 // (+) ==> Knob being moved. |
| 402 value = otherValue + MIN_KNOBS_DISTANCE_MINUTES; | 404 value = otherValue + MIN_KNOBS_DISTANCE_MINUTES; |
| 403 } | 405 } |
| 404 | 406 |
| 405 // The knobs are allowed to wrap around. | 407 // The knobs are allowed to wrap around. |
| 406 this.setPrefValue(prefPath, (value % TOTAL_MINUTES_PER_DAY)); | 408 this.setPrefValue(prefPath, (value % TOTAL_MINUTES_PER_DAY)); |
| 407 }, | 409 }, |
| 408 | 410 |
| 409 /** | 411 /** |
| 410 * Decrements the value of the pref whose path is given by |prefPath| by the | 412 * Decrements the value of the pref whose path is given by |prefPath| by the |
| 411 * amount given in |decrement|. | 413 * amount given in |decrement|. |
| 412 * @param {string} prefPath | 414 * @param {string} prefPath |
| 413 * @param {number} decrement | 415 * @param {number} decrement |
| 414 * @private | 416 * @private |
| 415 */ | 417 */ |
| 416 decrementPref_: function(prefPath, decrement) { | 418 decrementPref_: function(prefPath, decrement) { |
| 417 var value = | 419 var value = |
| 418 /** @type {number} */ (this.getPref(prefPath).value) - decrement; | 420 /** @type {number} */ (this.getPref(prefPath).value) - decrement; |
| 419 | 421 |
| 420 var otherValue = this.getOtherKnobPrefValue_(prefPath); | 422 var otherValue = this.getOtherKnobPrefValue_(prefPath); |
| 421 if (value > otherValue && | 423 if (value > otherValue && |
| 422 ((value - otherValue) < MIN_KNOBS_DISTANCE_MINUTES)) { | 424 ((value - otherValue) < MIN_KNOBS_DISTANCE_MINUTES)) { |
| 423 // We are decrementing the minutes offset moving towards the other knob. | 425 // We are decrementing the minutes offset moving towards the other knob. |
| 424 // We have a minimum 30 minutes overlap threshold. Move this knob to the | 426 // We have a minimum 60 minutes overlap threshold. Move this knob to the |
| 425 // other side of the other knob. | 427 // other side of the other knob. |
| 426 // | 428 // |
| 427 // Was: | 429 // Was: |
| 428 // <<------ + --- 29 MIN --- (+) ------- | 430 // <<------ + --- 59 MIN --- (+) ------- |
| 429 // | 431 // |
| 430 // Now: | 432 // Now: |
| 431 // <<------ (+) --- 30 MIN --- + ------ | 433 // <<------ (+) --- 60 MIN --- + ------ |
| 432 // | 434 // |
| 433 // (+) ==> Knob being moved. | 435 // (+) ==> Knob being moved. |
| 434 value = otherValue - MIN_KNOBS_DISTANCE_MINUTES; | 436 value = otherValue - MIN_KNOBS_DISTANCE_MINUTES; |
| 435 } | 437 } |
| 436 | 438 |
| 437 // The knobs are allowed to wrap around. | 439 // The knobs are allowed to wrap around. |
| 438 if (value < 0) | 440 if (value < 0) |
| 439 value += TOTAL_MINUTES_PER_DAY; | 441 value += TOTAL_MINUTES_PER_DAY; |
| 440 | 442 |
| 441 this.setPrefValue(prefPath, Math.abs(value) % TOTAL_MINUTES_PER_DAY); | 443 this.setPrefValue(prefPath, Math.abs(value) % TOTAL_MINUTES_PER_DAY); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 _focusedChanged: function(receivedFocusFromKeyboard) { | 549 _focusedChanged: function(receivedFocusFromKeyboard) { |
| 548 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that | 550 // Overrides the _focusedChanged() from the PaperInkyFocusBehavior so that |
| 549 // it does nothing. This function is called only once for the entire | 551 // it does nothing. This function is called only once for the entire |
| 550 // night-light-slider element even when focus is moved between the two | 552 // night-light-slider element even when focus is moved between the two |
| 551 // knobs. This doesn't allow us to decide on which knob the ripple will be | 553 // knobs. This doesn't allow us to decide on which knob the ripple will be |
| 552 // created. Hence we handle focus and blur explicitly above. | 554 // created. Hence we handle focus and blur explicitly above. |
| 553 } | 555 } |
| 554 }); | 556 }); |
| 555 | 557 |
| 556 })(); | 558 })(); |
| OLD | NEW |