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

Unified 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: @private 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/device_page/night_light_slider.js
diff --git a/chrome/browser/resources/settings/device_page/night_light_slider.js b/chrome/browser/resources/settings/device_page/night_light_slider.js
index 3c84b8692e0128884d263b859ebbd9e9164448b4..8f4a67f194daa61af4f670c89d952d4f853f9785 100644
--- a/chrome/browser/resources/settings/device_page/night_light_slider.js
+++ b/chrome/browser/resources/settings/device_page/night_light_slider.js
@@ -37,6 +37,12 @@ Polymer({
* @private
*/
endTime_: String,
+
+ /**
+ * Whether the window is in RTL locales.
+ * @private
+ */
+ isRTL_: Boolean,
},
observers: [
@@ -56,6 +62,11 @@ Polymer({
*/
dragObject_: null,
+ /** @override */
+ attached: function() {
+ this.isRTL_ = window.getComputedStyle(this).direction == 'rtl';
+ },
+
/** @override */
ready: function() {
// Build the legend markers.
@@ -74,6 +85,18 @@ Polymer({
});
},
+ /**
+ * Gets the style of legend div determining its absolute left position.
+ * @param {number} percent The value of the div's left as a percent (0 - 100).
+ * @param {boolean} isRTL whether window is in RTL locale.
+ * @return {string} The CSS style of the legend div.
+ * @private
+ */
+ getLegendStyle_: function(percent, isRTL) {
+ percent = isRTL ? 100 - percent : percent;
+ return 'left: ' + percent + '%';
+ },
+
/**
* Expands or un-expands the knob being dragged along with its corresponding
* label bubble.
@@ -170,7 +193,8 @@ Polymer({
'ash.night_light.custom_start_time' :
'ash.night_light.custom_end_time';
- if (event.detail.ddx > 0) {
+ var ddx = this.isRTL_ ? event.detail.ddx * -1 : event.detail.ddx;
+ if (ddx > 0) {
// Increment the knob's pref by the amount of deltaMinutes.
this.incrementPref_(knobPref, deltaMinutes);
} else {
@@ -271,7 +295,7 @@ Polymer({
var currentKnobRatio = this.getKnobRatio_(knob);
ratio = currentKnobRatio > 0.5 ? 1.0 : 0.0;
}
-
+ ratio = this.isRTL_ ? (1.0 - ratio) : ratio;
knob.style.left = (ratio * this.$.sliderBar.offsetWidth) + 'px';
},
@@ -281,17 +305,18 @@ Polymer({
* @private
*/
refresh_: function() {
- var endKnob = this.$.endKnob;
- var startKnob = this.$.startKnob;
- var startProgress = this.$.startProgress;
- var endProgress = this.$.endProgress;
- var startLabel = this.$.startLabel;
- var endLabel = this.$.endLabel;
-
// The label bubbles have the same left coordinates as their corresponding
// knobs.
- startLabel.style.left = startKnob.style.left;
- endLabel.style.left = endKnob.style.left;
+ this.$.startLabel.style.left = this.$.startKnob.style.left;
+ this.$.endLabel.style.left = this.$.endKnob.style.left;
+
+ // In RTL locales, the relative positions of the knobs are flipped for the
+ // purpose of calculating the styles of the progress bars below.
+ var rtl = this.isRTL_;
+ var endKnob = rtl ? this.$.startKnob : this.$.endKnob;
+ var startKnob = rtl ? this.$.endKnob : this.$.startKnob;
+ var startProgress = rtl ? this.$.endProgress : this.$.startProgress;
+ var endProgress = rtl ? this.$.startProgress : this.$.endProgress;
// The end progress bar starts from either the start knob or the start of
// the slider (whichever is to its left) and ends at the end knob.
@@ -443,7 +468,10 @@ Polymer({
if (!knobPref)
return;
- this.decrementPref_(knobPref, 1);
+ if (this.isRTL_)
+ this.incrementPref_(knobPref, 1);
+ else
+ this.decrementPref_(knobPref, 1);
},
/**
@@ -456,7 +484,10 @@ Polymer({
if (!knobPref)
return;
- this.incrementPref_(knobPref, 1);
+ if (this.isRTL_)
+ this.decrementPref_(knobPref, 1);
+ else
+ this.incrementPref_(knobPref, 1);
},
/**
« 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