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

Unified Diff: chrome/browser/resources/print_preview/margin_settings.js

Issue 8345025: Print Preview: Adding support for localized margin units and format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 2 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
Index: chrome/browser/resources/print_preview/margin_settings.js
diff --git a/chrome/browser/resources/print_preview/margin_settings.js b/chrome/browser/resources/print_preview/margin_settings.js
index ea2ec127727196121f3f3f2b776e5e04f0e39934..48e5be9f3e1db99c5e98ac7d44b8894d4f081a47 100644
--- a/chrome/browser/resources/print_preview/margin_settings.js
+++ b/chrome/browser/resources/print_preview/margin_settings.js
@@ -72,37 +72,17 @@ cr.define('print_preview', function() {
/**
* Rounds |this| based on the precision used when displaying the margins in
- * inches. This is done by converting from points to inches and back to
- * points.
+ * the user's prefered units. This is done by converting from points to
+ * those units (mm/inches) and back to points.
*/
- roundToInches: function() {
+ roundToUserLocaleUnits: function() {
var indicesAsArray = this.indicesAsArray_();
for (var i = 0; i < indicesAsArray.length; i++) {
this[indicesAsArray[i]] =
- print_preview.convertPointsToInchesTextAndBack(
+ print_preview.convertPointsToUserLocaleUnitsAndBack(
this[indicesAsArray[i]]);
}
},
-
- /**
- * Converts |this| to inches and returns the result in a new Margins object.
- * |this| is not affected. It assumes that |this| is currently expressed in
- * points.
- * @param {number} The number of decimal points to keep.
- * @return {Margins} The equivalent of |this| in inches.
- */
- toInches: function(precision) {
- return new Margins(
- Margins.roundToPrecision(convertPointsToInches(
- this[MarginSettings.LEFT_GROUP]), precision),
- Margins.roundToPrecision(convertPointsToInches(
- this[MarginSettings.TOP_GROUP]), precision),
- Margins.roundToPrecision(convertPointsToInches(
- this[MarginSettings.RIGHT_GROUP]), precision),
- Margins.roundToPrecision(convertPointsToInches(
- this[MarginSettings.BOTTOM_GROUP]), precision)
- );
- }
};
/**
@@ -186,6 +166,24 @@ cr.define('print_preview', function() {
// Group name corresponding to the bottom margin.
MarginSettings.BOTTOM_GROUP = 'bottom';
+ /**
+ * Extracts the number formatting and measurement system for the current
+ * locale.
+ * @param {string} numberFormat Is the formatted version of a sample number,
+ * sent from the backend.
+ * @oaram {number} measurementSystem 0 for SI (aka metric system), 1 for the
+ * system used in the US. Note: Mathces UMeasurementSystem enum in
+ * third_party/icu/public/i18n/unicode/ulocdata.h.
+ */
+ MarginSettings.setNumberFormatAndMeasurementSystem = function(
+ numberFormat, measurementSystem) {
+ var regex = /^(\d+)(\.|\,)(\d+)(\.|\,)(\d+)$/;
+ var matches = numberFormat.match(regex);
+ MarginSettings.thousandsPoint = matches[2];
+ MarginSettings.decimalPoint = matches[4];
+ MarginSettings.useMetricSystem = measurementSystem == 0;
+ };
+
cr.addSingletonGetter(MarginSettings);
MarginSettings.prototype = {
@@ -256,10 +254,8 @@ cr.define('print_preview', function() {
requestPreviewIfNeeded_: function() {
if (!this.areMarginSettingsValid())
return;
- if (this.customMargins_.toInches(2).isEqual(
- this.previousCustomMargins_.toInches(2))) {
+ if (this.customMargins_.isEqual(this.previousCustomMargins_))
return;
- }
this.previousCustomMargins_.copy(this.customMargins_);
setDefaultValuesAndRegeneratePreview(false);
},
@@ -362,8 +358,9 @@ cr.define('print_preview', function() {
for (var i = 0; i < marginValueLimits.length; i++) {
marginValueLimits[i] = Math.max(marginValueLimits[i], 0);
- marginValueLimits[i] = print_preview.convertPointsToInchesTextAndBack(
- marginValueLimits[i]);
+ marginValueLimits[i] =
+ print_preview.convertPointsToUserLocaleUnitsAndBack(
Evan Stade 2011/10/21 01:33:02 nit: s/UserLocale/Locale/ here and elsewhere
dpapad 2011/10/21 16:12:48 Done.
+ marginValueLimits[i]);
}
return marginValueLimits;
},
@@ -401,7 +398,8 @@ cr.define('print_preview', function() {
*/
onMarginTextValueMayHaveChanged_: function(event) {
var marginBox = event.target;
- var marginBoxValue = convertInchesToPoints(marginBox.margin);
+ var marginBoxValue =
+ print_preview.convertUserLocaleUnitsToPoints(marginBox.margin);
this.customMargins_[marginBox.marginGroup] = marginBoxValue;
this.requestPreviewIfNeeded_();
},
@@ -518,7 +516,7 @@ cr.define('print_preview', function() {
if (this.lastSelectedOption_ == MarginSettings.MARGINS_VALUE_DEFAULT) {
this.customMargins_ = this.currentDefaultPageLayout.margins_;
- this.customMargins_.roundToInches();
+ this.customMargins_.roundToUserLocaleUnits();
}
this.previousCustomMargins_.copy(this.customMargins_);

Powered by Google App Engine
This is Rietveld 408576698