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

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

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Component that renders the scaling settings UI. 9 * Component that renders the scaling settings UI.
10 * @param {!print_preview.ticket_items.Scaling} scalingTicketItem 10 * @param {!print_preview.ticket_items.Scaling} scalingTicketItem
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 * Whether this component is enabled or not. 45 * Whether this component is enabled or not.
46 * @private {boolean} 46 * @private {boolean}
47 */ 47 */
48 this.isEnabled_ = true; 48 this.isEnabled_ = true;
49 49
50 /** 50 /**
51 * The textfield input element 51 * The textfield input element
52 * @private {HTMLElement} 52 * @private {HTMLElement}
53 */ 53 */
54 this.inputField_ = null; 54 this.inputField_ = null;
55
56 } 55 }
57 56
58 /** 57 /**
59 * Delay in milliseconds before processing the textfield. 58 * Delay in milliseconds before processing the textfield.
60 * @private {number} 59 * @private {number}
61 * @const 60 * @const
62 */ 61 */
63 ScalingSettings.TEXTFIELD_DELAY_MS_ = 250; 62 ScalingSettings.TEXTFIELD_DELAY_MS_ = 250;
64 63
65 ScalingSettings.prototype = { 64 ScalingSettings.prototype = {
(...skipping 15 matching lines...) Expand all
81 this.isEnabled_ = isEnabled; 80 this.isEnabled_ = isEnabled;
82 if (isEnabled) 81 if (isEnabled)
83 this.updateState_(); 82 this.updateState_();
84 }, 83 },
85 84
86 /** @override */ 85 /** @override */
87 enterDocument: function() { 86 enterDocument: function() {
88 this.inputField_ = assert(this.getChildElement('input.user-value')); 87 this.inputField_ = assert(this.getChildElement('input.user-value'));
89 print_preview.SettingsSection.prototype.enterDocument.call(this); 88 print_preview.SettingsSection.prototype.enterDocument.call(this);
90 this.tracker.add( 89 this.tracker.add(
91 this.inputField_, 90 this.inputField_, 'keydown', this.onTextfieldKeyDown_.bind(this));
92 'keydown',
93 this.onTextfieldKeyDown_.bind(this));
94 this.tracker.add( 91 this.tracker.add(
95 this.inputField_, 92 this.inputField_, 'input', this.onTextfieldInput_.bind(this));
96 'input',
97 this.onTextfieldInput_.bind(this));
98 this.tracker.add( 93 this.tracker.add(
99 this.inputField_, 94 this.inputField_, 'blur', this.onTextfieldBlur_.bind(this));
100 'blur',
101 this.onTextfieldBlur_.bind(this));
102 this.tracker.add( 95 this.tracker.add(
103 this.scalingTicketItem_, 96 this.scalingTicketItem_,
104 print_preview.ticket_items.TicketItem.EventType.CHANGE, 97 print_preview.ticket_items.TicketItem.EventType.CHANGE,
105 this.updateState_.bind(this)); 98 this.updateState_.bind(this));
106 this.tracker.add( 99 this.tracker.add(
107 this.fitToPageTicketItem_, 100 this.fitToPageTicketItem_,
108 print_preview.ticket_items.TicketItem.EventType.CHANGE, 101 print_preview.ticket_items.TicketItem.EventType.CHANGE,
109 this.onFitToPageChange_.bind(this)); 102 this.onFitToPageChange_.bind(this));
110 }, 103 },
111 104
112 /** 105 /**
113 * @return {boolean} true if fit to page is available and selected. 106 * @return {boolean} true if fit to page is available and selected.
114 * @private 107 * @private
115 */ 108 */
116 isFitToPageSelected: function() { 109 isFitToPageSelected: function() {
117 return this.fitToPageTicketItem_.isCapabilityAvailable() && 110 return this.fitToPageTicketItem_.isCapabilityAvailable() &&
118 !!this.fitToPageTicketItem_.getValue(); 111 !!this.fitToPageTicketItem_.getValue();
119 }, 112 },
120 113
121 /** 114 /**
122 * @return {number} The current input field value as an integer. 115 * @return {number} The current input field value as an integer.
123 * @private 116 * @private
124 */ 117 */
125 getInputAsNumber: function() { 118 getInputAsNumber: function() {
126 return this.inputField_.valueAsNumber; 119 return this.inputField_.valueAsNumber;
127 }, 120 },
128 121
129 /** 122 /**
130 * Display the fit to page scaling in the scaling field if there is a valid 123 * Display the fit to page scaling in the scaling field if there is a valid
131 * fit to page scaling value. If not, make the field blank. 124 * fit to page scaling value. If not, make the field blank.
132 * @private 125 * @private
133 */ 126 */
134 displayFitToPageScaling: function() { 127 displayFitToPageScaling: function() {
135 this.inputField_.value = this.fitToPageScaling_ || ''; 128 this.inputField_.value = this.fitToPageScaling_ || '';
136 }, 129 },
137 130
138 /** 131 /**
139 * Whether the displayed scaling value matches the fit to page scaling. 132 * Whether the displayed scaling value matches the fit to page scaling.
140 * @private 133 * @private
141 */ 134 */
142 displayMatchesFitToPage: function() { 135 displayMatchesFitToPage: function() {
143 return (this.getInputAsNumber() == this.fitToPageScaling_ || 136 return (
144 (this.inputField_.value == '' && !this.fitToPageScaling_)); 137 this.getInputAsNumber() == this.fitToPageScaling_ ||
138 (this.inputField_.value == '' && !this.fitToPageScaling_));
145 }, 139 },
146 140
147 /** 141 /**
148 * Updates the fit to page scaling value of the scalings settings UI. 142 * Updates the fit to page scaling value of the scalings settings UI.
149 * @param {number} fitToPageScaling The updated percentage scaling required 143 * @param {number} fitToPageScaling The updated percentage scaling required
150 * to fit the document to page. 144 * to fit the document to page.
151 */ 145 */
152 updateFitToPageScaling: function(fitToPageScaling) { 146 updateFitToPageScaling: function(fitToPageScaling) {
153 this.fitToPageScaling_ = fitToPageScaling; 147 this.fitToPageScaling_ = fitToPageScaling;
154 // Display the new value if fit to page is checked. 148 // Display the new value if fit to page is checked.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 182
189 /** 183 /**
190 * Helper function to adjust the scaling display if fit to page is checked 184 * Helper function to adjust the scaling display if fit to page is checked
191 * by the user. 185 * by the user.
192 * @private 186 * @private
193 */ 187 */
194 onFitToPageChange_: function() { 188 onFitToPageChange_: function() {
195 if (this.isFitToPageSelected()) { 189 if (this.isFitToPageSelected()) {
196 // Fit to page was checked. Set scaling to the fit to page scaling. 190 // Fit to page was checked. Set scaling to the fit to page scaling.
197 this.displayFitToPageScaling(); 191 this.displayFitToPageScaling();
198 } else if (this.fitToPageTicketItem_.isCapabilityAvailable() && 192 } else if (
199 this.displayMatchesFitToPage()) { 193 this.fitToPageTicketItem_.isCapabilityAvailable() &&
194 this.displayMatchesFitToPage()) {
200 // Fit to page unchecked. Return to last scaling. 195 // Fit to page unchecked. Return to last scaling.
201 this.inputField_.value = this.scalingTicketItem_.getValue(); 196 this.inputField_.value = this.scalingTicketItem_.getValue();
202 } 197 }
203 }, 198 },
204 199
205 /** 200 /**
206 * Called after a timeout after user input into the textfield. 201 * Called after a timeout after user input into the textfield.
207 * @private 202 * @private
208 */ 203 */
209 onTextfieldTimeout_: function() { 204 onTextfieldTimeout_: function() {
210 this.textfieldTimeout_ = null; 205 this.textfieldTimeout_ = null;
211 if (!this.inputField_.validity.valid){ 206 if (!this.inputField_.validity.valid) {
212 this.updateState_(); 207 this.updateState_();
213 return; 208 return;
214 } 209 }
215 if (this.isFitToPageSelected() && !this.displayMatchesFitToPage()) { 210 if (this.isFitToPageSelected() && !this.displayMatchesFitToPage()) {
216 // User modified value away from fit to page. 211 // User modified value away from fit to page.
217 this.fitToPageTicketItem_.updateValue(false); 212 this.fitToPageTicketItem_.updateValue(false);
218 } 213 }
219 // Check this after checking for fit to page in case the user went 214 // Check this after checking for fit to page in case the user went
220 // back to their old value. 215 // back to their old value.
221 if (this.inputField_.valueAsNumber.toString() === 216 if (this.inputField_.valueAsNumber.toString() ===
222 this.scalingTicketItem_.getValue()) { 217 this.scalingTicketItem_.getValue()) {
223 this.updateState_(); 218 this.updateState_();
224 return; 219 return;
225 } 220 }
226 if (this.inputField_.value == '') 221 if (this.inputField_.value == '')
227 return; 222 return;
228 this.scalingTicketItem_.updateValue( 223 this.scalingTicketItem_.updateValue(
229 this.inputField_.valueAsNumber.toString()); 224 this.inputField_.valueAsNumber.toString());
230 }, 225 },
231 226
232 /** 227 /**
233 * Called when a key is pressed on the custom input. 228 * Called when a key is pressed on the custom input.
234 * @param {!Event} event Contains the key that was pressed. 229 * @param {!Event} event Contains the key that was pressed.
235 * @private 230 * @private
236 */ 231 */
237 onTextfieldKeyDown_: function(event) { 232 onTextfieldKeyDown_: function(event) {
238 if (event.keyCode != 'Enter') 233 if (event.keyCode != 'Enter')
239 return; 234 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 this.inputField_.value = '100'; 268 this.inputField_.value = '100';
274 else 269 else
275 this.scalingTicketItem_.updateValue('100'); 270 this.scalingTicketItem_.updateValue('100');
276 } 271 }
277 } 272 }
278 }, 273 },
279 274
280 }; 275 };
281 276
282 // Export 277 // Export
283 return { 278 return {ScalingSettings: ScalingSettings};
284 ScalingSettings: ScalingSettings
285 };
286 }); 279 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698