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

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: Addressing comments 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
106 var uiPairs = this.pairsAsList;
107 for (var i = 0; i < uiPairs.length; i++)
108 uiPairs[i].draw();
109 },
110
111 /**
112 * Shows the margins UI.
113 */
114 show: function() {
115 this.classList.remove('hidden');
Evan Stade 2011/10/05 03:05:23 use hidden attribute?
dpapad 2011/10/05 16:39:49 Done.
116 },
117
118 /**
119 * Hides the margins UI.
120 */
121 hide: function() {
122 this.classList.add('hidden');
123 },
124
125 /**
126 * Applies a clipping mask on |this| so that it does not paint on top of the
127 * scrollbars (if any).
128 */
129 applyClippingMask_: function() {
130 var top = 0;
131 var left = 0;
132 var bottom = previewArea.height;
133 var right = previewArea.width;
134 this.style.clip = "rect(" + top + "px," + right +"px, " + bottom +
135 "px, " + left + "px)";
136 }
137
138 };
139
140 return {
141 MarginsUI: MarginsUI
142 };
143 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698