OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 'use strict'; | |
7 | |
8 /** | |
9 * Creates a MarginSettings object. This object encapsulates all settings and | |
10 * logic related to the margins mode. | |
11 * | |
12 * @param {print_preview.PrintTicketStore!} printTicketStore Used to get | |
13 * ticket margins value. | |
14 * @constructor | |
15 * @extends {print_preview.Component} | |
16 */ | |
17 function MarginSettings(printTicketStore) { | |
18 print_preview.Component.call(this); | |
19 | |
20 /** | |
21 * Used to get ticket margins value. | |
22 * @type {print_preview.PrintTicketStore!} | |
23 * @private | |
24 */ | |
25 this.printTicketStore_ = printTicketStore; | |
26 | |
27 /** | |
28 * @private | |
29 */ | |
30 this.marginsUI_ = null; | |
31 | |
32 /** | |
33 * Holds the custom margin values in points (if set). | |
34 * @type {print_preview.Margins} | |
35 * @private | |
36 */ | |
37 this.customMargins_ = null; | |
38 | |
39 /** | |
40 * Holds the previous custom margin values in points. | |
41 * @type {print_preview.Margins} | |
42 * @private | |
43 */ | |
44 this.previousCustomMargins_ = null; | |
45 | |
46 /** | |
47 * Holds the width of the page in points. | |
48 * @type {number} | |
49 * @private | |
50 */ | |
51 this.pageWidth_ = -1; | |
52 | |
53 /** | |
54 * Holds the height of the page in points. | |
55 * @type {number} | |
56 * @private | |
57 */ | |
58 this.pageHeight_ = -1; | |
59 | |
60 /** | |
61 * True if the margins UI should be diplayed when the next | |
62 * |customEvents.PDF_LOADED| event occurs. | |
63 * @type {boolean} | |
64 * @private | |
65 */ | |
66 this.forceMarginsUIOnPDFLoad_ = false; | |
67 | |
68 /** | |
69 * Holds the currently updated default page layout values. | |
70 * @type {print_preview.PageLayout} | |
71 * @private | |
72 */ | |
73 this.currentDefaultPageLayout = null; | |
74 | |
75 /** | |
76 * True if the margins UI should be shown regardless of mouse position. | |
77 * @private | |
78 */ | |
79 this.forceDisplayingMarginLines_ = true; | |
80 }; | |
81 | |
82 /** | |
83 * Minimum allowed distance in points between top-bottom, left-right margins. | |
84 * @type {number} | |
85 * @private | |
86 */ | |
87 MarginSettings.MINIMUM_MARGINS_DISTANCE_ = 36; | |
88 | |
89 /** | |
90 * Default Margins option index. | |
91 * @type {string} | |
92 * @private | |
93 */ | |
94 MarginSettings.DEFAULT_MARGINS_VALUE_ = 0; | |
95 | |
96 /** | |
97 * CSS classes used by the margin settings component. | |
98 * @enum {string} | |
99 * @private | |
100 */ | |
101 MarginSettings.Classes_ = { | |
102 SELECT: 'margin-settings-select' | |
103 }; | |
104 | |
105 MarginSettings.prototype = { | |
106 __proto__: print_preview.Component.prototype, | |
107 | |
108 set isEnabled(isEnabled) { | |
109 this.select_.disabled = !isEnabled; | |
110 }, | |
111 | |
112 /** @override */ | |
113 enterDocument: function() { | |
114 print_preview.Component.prototype.enterDocument.call(this); | |
115 this.tracker.add( | |
116 this.select_, 'change', this.onSelectChange_.bind(this)); | |
117 this.tracker.add( | |
118 this.printTicketStore_, | |
119 print_preview.PrintTicketStore.Event.DOCUMENT_CHANGE, | |
120 this.onPrintTicketStoreChange_.bind(this)); | |
121 this.tracker.add( | |
122 this.printTicketStore_, | |
123 print_preview.PrintTicketStore.Event.TICKET_CHANGE, | |
124 this.onPrintTicketStoreChange_.bind(this)); | |
125 this.tracker.add( | |
126 this.printTicketStore_, | |
127 print_preview.PrintTicketStore.Event.CAPABILITIES_CHANGE, | |
128 this.onPrintTicketStoreChange_.bind(this)); | |
129 }, | |
130 | |
131 /** | |
132 * @return {HTMLSelectElement} Select element containing the margin options. | |
133 * @private | |
134 */ | |
135 get select_() { | |
dpapad1
2012/04/26 16:04:44
"get foo()" syntax for private functions seems unn
Robert Toscano
2012/04/28 01:41:37
What do you suggest? a "getSelect_" method?
dpapad
2012/04/30 16:19:25
Either a getSelect_, or adding a select_ member va
Robert Toscano
2012/05/05 00:02:50
Done.
| |
136 return this.getElement().getElementsByClassName( | |
137 MarginSettings.Classes_.SELECT)[0]; | |
138 }, | |
139 | |
140 /** | |
141 * Called when the select element is changed. Updates the print ticket | |
142 * margin type. | |
143 * @private | |
144 */ | |
145 onSelectChange_: function() { | |
146 var select = this.select_; | |
147 var marginsType = parseInt(select.options[select.selectedIndex].value); | |
148 this.printTicketStore_.updateMarginsType(marginsType); | |
149 }, | |
150 | |
151 /** | |
152 * Called when the print ticket store changes. | |
153 * @private | |
154 */ | |
155 onPrintTicketStoreChange_: function() { | |
156 if (this.printTicketStore_.hasMarginsCapability()) { | |
157 var select = this.select_; | |
158 var marginsType = this.printTicketStore_.getMarginsType(); | |
159 if (marginsType != select.selectedIndex) { | |
160 select.options[select.selectedIndex].selected = false; | |
161 select.options[marginsType].selected = true; | |
162 } | |
163 fadeInOption(this.getElement()); | |
164 } else { | |
165 fadeOutOption(this.getElement()); | |
166 } | |
167 } | |
168 }; | |
169 | |
170 // Export | |
171 return { | |
172 MarginSettings: MarginSettings | |
173 }; | |
174 }); | |
OLD | NEW |