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

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

Issue 7891016: Print Preview: Adding UI for margin settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing causing a regeneration because of rounding error. 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/margins_ui.js
diff --git a/chrome/browser/resources/print_preview/margins_ui.js b/chrome/browser/resources/print_preview/margins_ui.js
new file mode 100644
index 0000000000000000000000000000000000000000..65a67b81380a73d0c59ed7e3ef3af5f97f80afed
--- /dev/null
+++ b/chrome/browser/resources/print_preview/margins_ui.js
@@ -0,0 +1,143 @@
+// Copyright (c) 2011 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() {
+ 'strict';
+
+ /**
+ * @constructor
+ * This class represents a margin line and a textbox corresponding to that
+ * margin.
+ */
+ function MarginsUIPair(groupName) {
+ this.line_ = new print_preview.MarginLine(groupName);
+ this.box_ = new print_preview.MarginTextbox(groupName);
+ }
+
+ MarginsUIPair.prototype = {
+ __proto__: MarginsUIPair.prototype,
+
+ /**
+ * Updates the state.
+ */
+ update: function(marginsRectangle, value, valueLimit, keepDisplayedValue) {
+ this.line_.update(marginsRectangle);
+ this.box_.update(marginsRectangle, value, valueLimit, keepDisplayedValue);
+ },
+
+ /**
+ * Draws |this| based on the state.
+ */
+ draw: function() {
+ this.line_.draw();
+ this.box_.draw();
+ }
+ };
+
+ function MarginsUI(parentNode) {
+ var marginsUI = document.createElement('div');
+ marginsUI.__proto__ = MarginsUI.prototype;
+ marginsUI.id = 'customized-margins';
+
+ marginsUI.topPair_ = new MarginsUIPair(
+ print_preview.MarginSettings.TOP_GROUP);
+ marginsUI.leftPair_ = new MarginsUIPair(
+ print_preview.MarginSettings.LEFT_GROUP);
+ marginsUI.rightPair_ = new MarginsUIPair(
+ print_preview.MarginSettings.RIGHT_GROUP);
+ marginsUI.bottomPair_ = new MarginsUIPair(
+ print_preview.MarginSettings.BOTTOM_GROUP);
+ parentNode.appendChild(marginsUI);
+
+ var uiPairs = marginsUI.pairsAsList;
+ for (var i = 0; i < uiPairs.length; i++) {
+ marginsUI.appendChild(uiPairs[i].line_);
+ marginsUI.appendChild(uiPairs[i].box_);
+ }
+ return marginsUI;
+ }
+
+ MarginsUI.prototype = {
+ __proto__: HTMLDivElement.prototype,
+
+ /**
+ * Adds an observer for |MarginsMayHaveChanged| event.
+ * @param {function} func A callback function to be called when
+ * |MarginsMayHaveChanged| event occurs.
+ */
+ addObserver: function(func) {
+ var uiPairs = this.pairsAsList;
+ for (var i = 0; i < uiPairs.length; i++)
+ uiPairs[i].box_.addEventListener('MarginsMayHaveChanged', func);
+ },
+
+ /**
+ * @return {array} An array including all |MarginUIPair| objects.
+ */
+ get pairsAsList() {
+ return [this.topPair_, this.leftPair_, this.rightPair_, this.bottomPair_];
+ },
+
+ /**
+ * Updates the state of the margins UI.
+ * @param {print_preview.Rect}
+ * @param {Margins} marginValues
+ * @param {array} valueLimits
+ */
+ update: function(marginsRectangle, marginValues, valueLimits,
+ keepDisplayedValue) {
+ var uiPairs = this.pairsAsList;
+ var order = ['top', 'left', 'right', 'bottom'];
+ for (var i = 0; i < uiPairs.length; i++) {
+ uiPairs[i].update(marginsRectangle,
+ marginValues[order[i]],
+ valueLimits[i],
+ keepDisplayedValue);
+ }
+ },
+
+ /**
+ * Draws |this| based on the latest state.
+ */
+ draw: function() {
+ this.applyClippingMask_();
+
+ var uiPairs = this.pairsAsList;
+ for (var i = 0; i < uiPairs.length; i++)
Evan Stade 2011/10/07 03:29:58 consider: uiPairs.forEach(function(pair) { pair.d
dpapad 2011/10/07 16:49:20 Done.
+ uiPairs[i].draw();
+ },
+
+ /**
+ * Shows the margins UI.
+ */
+ show: function() {
+ this.hidden = false;
+ },
+
+ /**
+ * Hides the margins UI.
+ */
+ hide: function() {
+ this.hidden = true;
+ },
+
+ /**
+ * Applies a clipping mask on |this| so that it does not paint on top of the
+ * scrollbars (if any).
+ */
+ applyClippingMask_: function() {
+ var top = 0;
+ var left = 0;
+ var bottom = previewArea.height;
+ var right = previewArea.width;
+ this.style.clip = "rect(" + top + "px," + right +"px, " + bottom +
Evan Stade 2011/10/07 03:29:58 space after + also, I think bottom should be on t
dpapad 2011/10/07 16:49:20 Done. Also removed "px" for top and left since the
Evan Stade 2011/10/07 19:53:09 right, good point, you should get rid of top and l
+ "px, " + left + "px)";
+ }
+
Evan Stade 2011/10/07 03:29:58 remove this newline
dpapad 2011/10/07 16:49:20 Done.
+ };
+
+ return {
+ MarginsUI: MarginsUI
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698