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

Side by Side Diff: chrome/browser/resources/print_preview/page_settings.js

Issue 7639023: Revert 96567 - Reland 96406 - Print preview page selection should not require a rerendering of dr... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 * Creates a PageSettings object. This object encapsulates all settings and 9 * Creates a PageSettings object. This object encapsulates all settings and
10 * logic related to page selection. 10 * logic related to page selection.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 this.previouslySelectedPages_.push(i + 1); 170 this.previouslySelectedPages_.push(i + 1);
171 } 171 }
172 172
173 if (!this.isPageSelectionValid()) 173 if (!this.isPageSelectionValid())
174 this.onSelectedPagesTextfieldChanged(); 174 this.onSelectedPagesTextfieldChanged();
175 }, 175 },
176 176
177 /** 177 /**
178 * Updates |this.previouslySelectedPages_| with the currently selected 178 * Updates |this.previouslySelectedPages_| with the currently selected
179 * pages. 179 * pages.
180 * @private
180 */ 181 */
181 updatePageSelection: function() { 182 updatePageSelection_: function() {
182 this.previouslySelectedPages_ = this.selectedPagesSet; 183 this.previouslySelectedPages_ = this.selectedPagesSet;
183 }, 184 },
184 185
185 /** 186 /**
186 * @private 187 * @private
187 * @return {boolean} true if currently selected pages differ from 188 * @return {boolean} true if currently selected pages differ from
188 * |this.previouslySelectesPages_|. 189 * |this.previouslySelectesPages_|.
189 */ 190 */
190 hasPageSelectionChanged_: function() { 191 hasPageSelectionChanged_: function() {
191 return !areArraysEqual(this.previouslySelectedPages_, 192 return !areArraysEqual(this.previouslySelectedPages_,
192 this.selectedPagesSet); 193 this.selectedPagesSet);
193 }, 194 },
194 195
195 /** 196 /**
196 * Checks if the page selection has changed and is valid.
197 * @return {boolean} true if the page selection is changed and is valid.
198 */
199 hasPageSelectionChangedAndIsValid: function() {
200 return this.isPageSelectionValid() && this.hasPageSelectionChanged_();
201 },
202
203 /**
204 * Validates the contents of |this.selectedPagesTextfield|. 197 * Validates the contents of |this.selectedPagesTextfield|.
205 * 198 *
206 * @return {boolean} true if the text is valid. 199 * @return {boolean} true if the text is valid.
207 */ 200 */
208 isPageSelectionValid: function() { 201 isPageSelectionValid: function() {
209 if (this.allPagesRadioButton_.checked || 202 if (this.allPagesRadioButton_.checked ||
210 this.selectedPagesText.length == 0) { 203 this.selectedPagesText.length == 0) {
211 return true; 204 return true;
212 } 205 }
213 return isPageRangeTextValid(this.selectedPagesText, this.totalPageCount_); 206 return isPageRangeTextValid(this.selectedPagesText, this.totalPageCount_);
214 }, 207 },
215 208
216 /** 209 /**
217 * Checks all page selection related settings and requests a new print 210 * Checks all page selection related settings and requests a new print
218 * previw if needed. 211 * previw if needed.
219 * @return {boolean} true if a new preview was requested. 212 * @return {boolean} true if a new preview was requested.
220 */ 213 */
221 requestPrintPreviewIfNeeded: function() { 214 requestPrintPreviewIfNeeded: function() {
222 if (this.hasPageSelectionChangedAndIsValid()) { 215 if (this.isPageSelectionValid() && this.hasPageSelectionChanged_()) {
223 this.updatePageSelection(); 216 this.updatePageSelection_();
224 requestPrintPreview(); 217 requestPrintPreview();
225 return true; 218 return true;
226 } 219 }
227 if (!this.isPageSelectionValid()) 220 if (!this.isPageSelectionValid())
228 this.onSelectedPagesTextfieldChanged(); 221 this.onSelectedPagesTextfieldChanged();
229 return false; 222 return false;
230 }, 223 },
231 224
232 /** 225 /**
233 * Validates the selected pages and updates the hint accordingly. 226 * Validates the selected pages and updates the hint accordingly.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 this.onSelectedPagesTextfieldChanged(); 267 this.onSelectedPagesTextfieldChanged();
275 268
276 // Toggling between "all pages"/"some pages" radio buttons while having an 269 // Toggling between "all pages"/"some pages" radio buttons while having an
277 // invalid entry in the page selection textfield still requires updating 270 // invalid entry in the page selection textfield still requires updating
278 // the print summary and print button. 271 // the print summary and print button.
279 if (!this.isPageSelectionValid() || !this.hasPageSelectionChanged_()) { 272 if (!this.isPageSelectionValid() || !this.hasPageSelectionChanged_()) {
280 cr.dispatchSimpleEvent(document, 'updateSummary'); 273 cr.dispatchSimpleEvent(document, 'updateSummary');
281 cr.dispatchSimpleEvent(document, 'updatePrintButton'); 274 cr.dispatchSimpleEvent(document, 'updatePrintButton');
282 return; 275 return;
283 } 276 }
277 this.previouslySelectedPages_ = this.selectedPagesSet;
284 requestPrintPreview(); 278 requestPrintPreview();
285 }, 279 },
286 280
287 /** 281 /**
288 * Whenever |this.selectedPagesTextfield| gains focus we add a timer to 282 * Whenever |this.selectedPagesTextfield| gains focus we add a timer to
289 * detect when the user stops typing in order to update the print preview. 283 * detect when the user stops typing in order to update the print preview.
290 * @private 284 * @private
291 */ 285 */
292 addTimerToSelectedPagesTextfield_: function() { 286 addTimerToSelectedPagesTextfield_: function() {
293 this.timerId_ = window.setTimeout( 287 this.timerId_ = window.setTimeout(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 this.onSelectedPagesMayHaveChanged_(); 370 this.onSelectedPagesMayHaveChanged_();
377 } 371 }
378 }.bind(this); 372 }.bind(this);
379 } 373 }
380 }; 374 };
381 375
382 return { 376 return {
383 PageSettings: PageSettings, 377 PageSettings: PageSettings,
384 }; 378 };
385 }); 379 });
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.cc ('k') | chrome/browser/resources/print_preview/print_preview.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698