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

Side by Side Diff: chrome/browser/resources/print_preview/settings/margin_settings.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 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.addEventListeners_();
116 },
117
118 /**
119 * @return {HTMLSelectElement} Select element containing the margin options.
120 * @private
121 */
122 get select_() {
123 return this.getElement().getElementsByClassName(
124 MarginSettings.Classes_.SELECT)[0];
125 },
126
127 /**
128 * Adds listeners to all margin related controls.
129 * @private
130 */
131 addEventListeners_: function() {
132 this.tracker.add(
133 this.select_, 'change', this.onSelectChange_.bind(this));
134 this.tracker.add(
135 this.printTicketStore_,
136 print_preview.PrintTicketStore.Event.DOCUMENT_CHANGE,
137 this.onPrintTicketStoreChange_.bind(this));
138 this.tracker.add(
139 this.printTicketStore_,
140 print_preview.PrintTicketStore.Event.TICKET_CHANGE,
141 this.onPrintTicketStoreChange_.bind(this));
142 this.tracker.add(
143 this.printTicketStore_,
144 print_preview.PrintTicketStore.Event.CAPABILITIES_CHANGE,
145 this.onPrintTicketStoreChange_.bind(this));
146 },
147
148 /**
149 * Called when the select element is changed. Updates the print ticket
150 * margin type.
151 * @private
152 */
153 onSelectChange_: function() {
154 var select = this.select_;
155 var marginType = parseInt(select.options[select.selectedIndex].value);
156 this.printTicketStore_.updateMarginType(marginType);
157 },
158
159 /**
160 * Called when the print ticket store changes.
161 * @private
162 */
163 onPrintTicketStoreChange_: function() {
164 if (this.printTicketStore_.hasMarginCapability()) {
165 var select = this.select_;
166 var marginType = this.printTicketStore_.getMarginType();
167 if (marginType != select.selectedIndex) {
168 select.options[select.selectedIndex].selected = false;
169 select.options[marginType].selected = true;
170 }
171 fadeInOption(this.getElement());
172 } else {
173 fadeOutOption(this.getElement());
174 }
175 }
176 };
177
178 // Export
179 return {
180 MarginSettings: MarginSettings
181 };
182 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698