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

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

Issue 8233030: Print Preview: Making margin lines draggable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebasing 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_utils.js
diff --git a/chrome/browser/resources/print_preview/margin_utils.js b/chrome/browser/resources/print_preview/margin_utils.js
index 73a925a3cf15a673c74abcfad04f92b78ecd434f..e217857ffa030b4224f3565a041def442d163b50 100644
--- a/chrome/browser/resources/print_preview/margin_utils.js
+++ b/chrome/browser/resources/print_preview/margin_utils.js
@@ -30,19 +30,70 @@ cr.define('print_preview', function() {
return -1;
}
+ var marginValidationStates = {
+ TOO_SMALL: 0,
+ WITHIN_RANGE: 1,
+ TOO_BIG: 2,
+ NOT_A_NUMBER: 3
+ }
+
+ /**
+ * Checks whether |value| is within range [0, limit].
+ * @return {number} An appropriate value from enum |marginValidationStates|.
+ */
+ function validateMarginValue(value, limit) {
+ if (value <= limit && value >= 0)
+ return marginValidationStates.WITHIN_RANGE;
+ else if (value < 0)
+ return marginValidationStates.TOO_SMALL;
+ else (value > limit)
+ return marginValidationStates.TOO_BIG;
+ }
+
/**
* @param {sting} text The text to check (in inches).
* @param {number} limit The upper bound of the valid margin range (in
* points).
- * @return {boolean} True of |text| can be parsed and it is within the allowed
- * range.
+ * @return {number} An appropriate value from enum |marginValidationStates|.
*/
- function isMarginTextValid(text, limit) {
+ function validateMarginText(text, limit) {
var value = extractMarginValue(text);
- if (value == -1)
- return false;
+ if (value == -1)
+ return marginValidationStates.NOT_A_NUMBER;
value = convertInchesToPoints(value);
- return value <= limit;
+ return validateMarginValue(value, limit);
+ }
+
+ /**
+ * @param {number} toConvert The value to convert in points
+ * @return {string} The equivalent text in inches.
+ */
+ function convertPointsToInchesText(toConvert) {
+ var inInches = convertPointsToInches(toConvert);
+ return convertInchesToInchesText(inInches);
+ }
+
+ /**
+ * @param {number} toConvert The value to convert in inches.
+ * @return {string} The equivalent text in inches with precision of two
+ * digits.
+ */
+ function convertInchesToInchesText(toConvert) {
+ return toConvert.toFixed(2) + '"';
+ }
+
+ /**
+ * Converts |value| to inches text (keeping 2 decimal digits) and then back to
+ * points. Note: Because of the precision the return value might be different
+ * than |value|.
+ * @param {number} value The value in points to convert.
+ * @return {number} The value in points after converting to inches with a
+ * certain precision and back.
+ */
+ function convertPointsToInchesTextAndBack(value) {
+ var text = convertPointsToInchesText(value);
+ var inches = extractMarginValue(text);
+ return convertInchesToPoints(inches);
}
/**
@@ -62,26 +113,37 @@ cr.define('print_preview', function() {
};
Rect.prototype = {
+ /**
+ * @type {number} The x coordinate of the right-most point.
+ */
get right() {
return this.x + this.width;
},
+ /**
+ * @type {number} The y coordinate of the lower-most point.
+ */
get bottom() {
return this.y + this.height;
},
- get middleX() {
- return this.x + this.width / 2;
- },
-
- get middleY() {
- return this.y + this.height / 2;
+ /**
+ * Clones |this| and returns the cloned object.
+ * @return {Rect} A copy of |this|.
+ */
+ clone: function() {
+ return new Rect(this.x, this.y, this.width, this.height);
}
};
return {
+ convertInchesToInchesText: convertInchesToInchesText,
+ convertPointsToInchesTextAndBack:convertPointsToInchesTextAndBack,
+ convertPointsToInchesText: convertPointsToInchesText,
extractMarginValue: extractMarginValue,
- isMarginTextValid: isMarginTextValid,
+ marginValidationStates: marginValidationStates,
Rect: Rect,
+ validateMarginText: validateMarginText,
+ validateMarginValue: validateMarginValue
};
});
« no previous file with comments | « chrome/browser/resources/print_preview/margin_textbox.js ('k') | chrome/browser/resources/print_preview/margins.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698