Chromium Code Reviews| 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_); |