| Index: chrome/browser/resources/print_preview/data/margins.js
|
| diff --git a/chrome/browser/resources/print_preview/data/margins.js b/chrome/browser/resources/print_preview/data/margins.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d59b8f1310232383c3a43f20bbae28fa8efc0b7d
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/print_preview/data/margins.js
|
| @@ -0,0 +1,114 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +cr.define('print_preview', function() {
|
| + 'use strict';
|
| +
|
| + /**
|
| + * Creates a Margins object that holds four margin values. The units in which
|
| + * the values are expressed can be any numeric value.
|
| + * @param {number} top The top margin.
|
| + * @param {number} right The right margin.
|
| + * @param {number} bottom The bottom margin.
|
| + * @param {number} left The left margin.
|
| + * @param {print_preview.MeasurementSystem} measurementSystem The measurement
|
| + * system.
|
| + * @constructor
|
| + */
|
| + function Margins(top, right, bottom, left, measurementSystem) {
|
| + this[Margins.TOP_GROUP] = top;
|
| + this[Margins.RIGHT_GROUP] = right;
|
| + this[Margins.BOTTOM_GROUP] = bottom;
|
| + this[Margins.LEFT_GROUP] = left;
|
| + this.measurementSystem_ = measurementSystem;
|
| + };
|
| +
|
| + /**
|
| + * Enumeration of margin types. Matches enum MarginType in
|
| + * printing/print_job_constants.h.
|
| + * @enum {number}
|
| + */
|
| + Margins.Type = {
|
| + DEFAULT: 0,
|
| + NO_MARGINS: 1,
|
| + MINIMUM: 2,
|
| + CUSTOM: 3
|
| + },
|
| +
|
| + // Group name corresponding to the top margin.
|
| + Margins.TOP_GROUP = 'top';
|
| + // Group name corresponding to the left margin.
|
| + Margins.LEFT_GROUP = 'left';
|
| + // Group name corresponding to the right margin.
|
| + Margins.RIGHT_GROUP = 'right';
|
| + // Group name corresponding to the bottom margin.
|
| + Margins.BOTTOM_GROUP = 'bottom';
|
| +
|
| + /**
|
| + * Rounds |value| keeping |precision| decimal numbers. Example: 32.76643
|
| + * becomes 32.77.
|
| + * @param {number} value The number to round.
|
| + * @param {number} precision The desired precision.
|
| + * @return {number} The rounded number.
|
| + */
|
| + Margins.roundToPrecision = function(value, precision) {
|
| + return Math.round(value * Math.pow(10, precision)) /
|
| + Math.pow(10, precision);
|
| + };
|
| +
|
| + Margins.prototype = {
|
| + /**
|
| + * Checks if |rhs| is equal to |this|.
|
| + * @param {Margins} rhs The Margins object to compare against.
|
| + * @return {boolean} true if they are equal.
|
| + */
|
| + isEqual: function(rhs) {
|
| + if (!rhs)
|
| + return false;
|
| + return this[Margins.TOP_GROUP] === rhs[Margins.TOP_GROUP] &&
|
| + this[Margins.LEFT_GROUP] === rhs[Margins.LEFT_GROUP] &&
|
| + this[Margins.RIGHT_GROUP] ===
|
| + rhs[Margins.RIGHT_GROUP] &&
|
| + this[Margins.BOTTOM_GROUP] ===
|
| + rhs[Margins.BOTTOM_GROUP];
|
| + },
|
| +
|
| + clone: function() {
|
| + return new Margins(this[Margins.LEFT_GROUP],
|
| + this[Margins.TOP_GROUP],
|
| + this[Margins.RIGHT_GROUP],
|
| + this[Margins.BOTTOM_GROUP]);
|
| + },
|
| +
|
| + /**
|
| + * Helper method returning an array of the string indices used for accessing
|
| + * all margins.
|
| + * @return {array} An array of string indices.
|
| + * @private
|
| + */
|
| + indicesAsArray_: function() {
|
| + return [Margins.LEFT_GROUP, Margins.TOP_GROUP,
|
| + Margins.RIGHT_GROUP, Margins.BOTTOM_GROUP];
|
| + },
|
| +
|
| + /**
|
| + * Rounds |this| based on the precision used when displaying the margins in
|
| + * the user's prefered units. This is done by converting from points to
|
| + * those units (mm/inches) and back to points.
|
| + */
|
| + roundToLocaleUnits: function() {
|
| + var indicesAsArray = this.indicesAsArray_();
|
| + for (var i = 0; i < indicesAsArray.length; i++) {
|
| + this[indicesAsArray[i]] =
|
| + print_preview.convertPointsToLocaleUnitsAndBack(
|
| + this[indicesAsArray[i]]);
|
| + }
|
| + }
|
| + };
|
| +
|
| + // Export
|
| + return {
|
| + Margins: Margins
|
| + };
|
| +});
|
|
|