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

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: Fixing mouse events outside the plugin area, adding documentations 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..b3e2fbb63b57da75250238b7293067c21eb60414 100644
--- a/chrome/browser/resources/print_preview/margin_utils.js
+++ b/chrome/browser/resources/print_preview/margin_utils.js
@@ -31,18 +31,88 @@ cr.define('print_preview', function() {
}
/**
+ * Checks whether |value| is within range [0, limit].
+ * @return {number} 0 if within the range, -1 if smaller, 1 if larger.
+ */
+ function validateMarginValue(value, limit) {
+ if (value <= limit && value >= 0)
+ return 0;
+ else if (value < 0)
+ return -1;
+ else (value > limit)
+ return 1;
+ }
+
+ /**
* @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} -2 if |text| can't be converted to number, 0 if it
+ * represents a valid margin value, -1 if the value is less than the
+ * minimum margin, 1 if the value is larger than the maximum margin.
*/
- function isMarginTextValid(text, limit) {
+ function validateMarginText(text, limit) {
var value = extractMarginValue(text);
if (value == -1)
- return false;
+ return -2;
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.
+ * @param {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);
+ }
+
+
+ function Point(x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ Point.prototype = {
+ /**
+ * @param {Point} rhs The point to compare with.
+ * @return {number} The horizontal distance between |this| point and |rhs|.
+ */
+ distanceXFrom: function(rhs) {
+ return rhs.x - this.x;
+ },
+
+ /**
+ * @param {Point} rhs The point to compare with.
+ * @return {number} The vertical distance between |this| point and |rhs|.
+ */
+ distanceYFrom: function(rhs) {
+ return rhs.y - this.y;
+ },
}
/**
@@ -76,12 +146,21 @@ cr.define('print_preview', function() {
get middleY() {
return this.y + this.height / 2;
+ },
+
+ clone: function() {
+ return new Rect(this.x, this.y, this.width, this.height);
}
};
return {
extractMarginValue: extractMarginValue,
- isMarginTextValid: isMarginTextValid,
+ validateMarginText: validateMarginText,
+ validateMarginValue: validateMarginValue,
+ convertPointsToInchesText: convertPointsToInchesText,
+ convertInchesToInchesText: convertInchesToInchesText,
+ convertPointsToInchesTextAndBack:convertPointsToInchesTextAndBack,
Rect: Rect,
+ Point: Point
};
});

Powered by Google App Engine
This is Rietveld 408576698