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

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

Issue 8223009: Print Preview: Keep the cancel button enabled whenever possible. Hook up the escape key to cancel. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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
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 PrintHeader object. This object encapsulates all the elements 9 * Creates a PrintHeader object. This object encapsulates all the elements
10 * and logic related to the top part of the left pane in print_preview.html. 10 * and logic related to the top part of the left pane in print_preview.html.
(...skipping 20 matching lines...) Expand all
31 get summary() { 31 get summary() {
32 return this.summary_; 32 return this.summary_;
33 }, 33 },
34 34
35 /** 35 /**
36 * Adding event listeners where necessary. Listeners take care of changing 36 * Adding event listeners where necessary. Listeners take care of changing
37 * their behavior depending on the current state, no need to remove them. 37 * their behavior depending on the current state, no need to remove them.
38 */ 38 */
39 addEventListeners: function() { 39 addEventListeners: function() {
40 this.cancelButton_.onclick = function() { 40 this.cancelButton_.onclick = function() {
41 chrome.send('closePrintPreviewTab'); 41 this.disableCancelButton_();
42 }; 42 closePrintPreviewTab();
43 }.bind(this);
43 this.printButton_.onclick = this.onPrintButtonClicked_.bind(this); 44 this.printButton_.onclick = this.onPrintButtonClicked_.bind(this);
44 document.addEventListener('updateSummary', 45 document.addEventListener('updateSummary',
45 this.updateSummary_.bind(this)); 46 this.updateSummary_.bind(this));
46 document.addEventListener('updatePrintButton', 47 document.addEventListener('updatePrintButton',
47 this.updatePrintButton_.bind(this)); 48 this.updatePrintButton_.bind(this));
49 document.addEventListener('disableCancelButton',
50 this.disableCancelButton_.bind(this));
48 }, 51 },
49 52
50 /** 53 /**
51 * Listener executing whenever |this.printButton_| is clicked. 54 * Listener executing whenever |this.printButton_| is clicked.
52 * @private 55 * @private
53 */ 56 */
54 onPrintButtonClicked_: function() { 57 onPrintButtonClicked_: function() {
55 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; 58 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF;
56 if (!printToPDF) { 59 if (!printToPDF) {
57 this.printButton_.classList.add('loading'); 60 this.printButton_.classList.add('loading');
58 this.cancelButton_.classList.add('loading'); 61 this.cancelButton_.classList.add('loading');
59 this.summary_.innerHTML = localStrings.getString('printing'); 62 this.summary_.innerHTML = localStrings.getString('printing');
60 } 63 }
64 this.disableCancelButton_();
61 requestToPrintDocument(); 65 requestToPrintDocument();
62 }, 66 },
63 67
64 /** 68 /**
69 * Disables the cancel button and removes its keydown event listener.
70 * @private
71 */
72 disableCancelButton_: function() {
73 window.onkeydown = null;
74 this.cancelButton_.disabled = true;
75 },
76
77 /**
65 * Updates the state of |this.printButton_| depending on the user selection. 78 * Updates the state of |this.printButton_| depending on the user selection.
66 * The button is enabled only when the following conditions are true. 79 * The button is enabled only when the following conditions are true.
67 * 1) The selected page ranges are valid. 80 * 1) The selected page ranges are valid.
68 * 2) The number of copies is valid (if applicable). 81 * 2) The number of copies is valid (if applicable).
69 * @private 82 * @private
70 */ 83 */
71 updatePrintButton_: function() { 84 updatePrintButton_: function() {
72 if (showingSystemDialog) 85 if (showingSystemDialog)
73 return; 86 return;
74 this.printButton_.disabled = !areSettingsValid(); 87 this.printButton_.disabled = !areSettingsValid();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Removing extra spaces from within the string. 136 // Removing extra spaces from within the string.
124 html = html.replace(/\s{2,}/g, ' '); 137 html = html.replace(/\s{2,}/g, ' ');
125 this.summary_.innerHTML = html; 138 this.summary_.innerHTML = html;
126 }, 139 },
127 }; 140 };
128 141
129 return { 142 return {
130 PrintHeader: PrintHeader, 143 PrintHeader: PrintHeader,
131 }; 144 };
132 }); 145 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698