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

Side by Side 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: Nit 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'strict';
7
8 /**
9 * @constructor
10 * This class represents a margin line and a textbox corresponding to that
11 * margin.
12 */
13 function MarginsUIPair(groupName) {
14 this.line_ = new print_preview.MarginLine(groupName);
15 this.box_ = new print_preview.MarginTextbox(groupName);
16 }
17
18 MarginsUIPair.prototype = {
19 __proto__: MarginsUIPair.prototype,
20
21 /**
22 * Updates the state.
23 */
24 update: function(marginsRectangle, value, valueLimit, keepDisplayedValue) {
25 this.line_.update(marginsRectangle);
26 this.box_.update(marginsRectangle, value, valueLimit, keepDisplayedValue);
27 },
28
29 /**
30 * Draws |this| based on the state.
31 */
32 draw: function() {
33 this.line_.draw();
34 this.box_.draw();
35 }
36 };
37
38 function MarginsUI(parentNode) {
39 var marginsUI = document.createElement('div');
40 marginsUI.__proto__ = MarginsUI.prototype;
41 marginsUI.id = 'customized-margins';
42
43 marginsUI.topPair_ = new MarginsUIPair(
44 print_preview.MarginSettings.TOP_GROUP);
45 marginsUI.leftPair_ = new MarginsUIPair(
46 print_preview.MarginSettings.LEFT_GROUP);
47 marginsUI.rightPair_ = new MarginsUIPair(
48 print_preview.MarginSettings.RIGHT_GROUP);
49 marginsUI.bottomPair_ = new MarginsUIPair(
50 print_preview.MarginSettings.BOTTOM_GROUP);
51 parentNode.appendChild(marginsUI);
52
53 var uiPairs = marginsUI.pairsAsList;
54 for (var i = 0; i < uiPairs.length; i++) {
55 marginsUI.appendChild(uiPairs[i].line_);
56 marginsUI.appendChild(uiPairs[i].box_);
57 }
58 return marginsUI;
59 }
60
61 MarginsUI.prototype = {
62 __proto__: HTMLDivElement.prototype,
63
64 /**
65 * Adds an observer for |MarginsMayHaveChanged| event.
66 * @param {function} func A callback function to be called when
67 * |MarginsMayHaveChanged| event occurs.
68 */
69 addObserver: function(func) {
70 var uiPairs = this.pairsAsList;
71 for (var i = 0; i < uiPairs.length; i++)
72 uiPairs[i].box_.addEventListener('MarginsMayHaveChanged', func);
73 },
74
75 /**
76 * @return {array} An array including all |MarginUIPair| objects.
77 */
78 get pairsAsList() {
79 return [this.topPair_, this.leftPair_, this.rightPair_, this.bottomPair_];
80 },
81
82 /**
83 * Updates the state of the margins UI.
84 * @param {print_preview.Rect}
85 * @param {Margins} marginValues
86 * @param {array} valueLimits
87 */
88 update: function(marginsRectangle, marginValues, valueLimits,
89 keepDisplayedValue) {
90 var uiPairs = this.pairsAsList;
91 var order = ['top', 'left', 'right', 'bottom'];
92 for (var i = 0; i < uiPairs.length; i++) {
93 uiPairs[i].update(marginsRectangle,
94 marginValues[order[i]],
95 valueLimits[i],
96 keepDisplayedValue);
97 }
98 },
99
100 /**
101 * Draws |this| based on the latest state.
102 */
103 draw: function() {
104 this.applyClippingMask_();
105 this.pairsAsList.forEach(function(pair) { pair.draw(); });
106 },
107
108 /**
109 * Shows the margins UI.
110 */
111 show: function() {
112 this.hidden = false;
113 },
114
115 /**
116 * Hides the margins UI.
117 */
118 hide: function() {
119 this.hidden = true;
120 },
121
122 /**
123 * Applies a clipping mask on |this| so that it does not paint on top of the
124 * scrollbars (if any).
125 */
126 applyClippingMask_: function() {
127 var top = 0;
128 var left = 0;
129 var bottom = previewArea.height;
130 var right = previewArea.width;
131 this.style.clip = "rect(" + top + ", " + right + "px, "
Evan Stade 2011/10/07 19:53:09 I'd just put 0 straight in there instead of storin
132 + bottom + "px, " + left + ")";
133 }
134 };
135
136 return {
137 MarginsUI: MarginsUI
138 };
139 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/margin_utils.js ('k') | chrome/browser/resources/print_preview/preview_area.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698