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

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

Issue 9663037: Print Preview: Pass direction keys to the PDF viewer when possible. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // require: cr/ui/print_preview_cloud.js 5 // require: cr/ui/print_preview_cloud.js
6 6
7 var localStrings = new LocalStrings(); 7 var localStrings = new LocalStrings();
8 8
9 // If useCloudPrint is true we attempt to connect to cloud print 9 // If useCloudPrint is true we attempt to connect to cloud print
10 // and populate the list of printers with cloud print printers. 10 // and populate the list of printers with cloud print printers.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // The range of options in the printer dropdown controlled by cloud print. 96 // The range of options in the printer dropdown controlled by cloud print.
97 var firstCloudPrintOptionPos = 0; 97 var firstCloudPrintOptionPos = 0;
98 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; 98 var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
99 99
100 // Store the current previewUid. 100 // Store the current previewUid.
101 var currentPreviewUid = ''; 101 var currentPreviewUid = '';
102 102
103 // True if we need to generate draft preview data. 103 // True if we need to generate draft preview data.
104 var generateDraftData = true; 104 var generateDraftData = true;
105 105
106 // The last element clicked with the mouse.
107 var lastClickedElement = null;
108
106 // A dictionary of cloud printers that have been added to the printer 109 // A dictionary of cloud printers that have been added to the printer
107 // dropdown. 110 // dropdown.
108 var addedCloudPrinters = {}; 111 var addedCloudPrinters = {};
109 112
110 // The maximum number of cloud printers to allow in the dropdown. 113 // The maximum number of cloud printers to allow in the dropdown.
111 const maxCloudPrinters = 10; 114 const maxCloudPrinters = 10;
112 115
113 const MIN_REQUEST_ID = 0; 116 const MIN_REQUEST_ID = 0;
114 const MAX_REQUEST_ID = 32000; 117 const MAX_REQUEST_ID = 32000;
115 118
(...skipping 27 matching lines...) Expand all
143 */ 146 */
144 function onLoad() { 147 function onLoad() {
145 cr.enablePlatformSpecificCSSRules(); 148 cr.enablePlatformSpecificCSSRules();
146 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); 149 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID);
147 lastPreviewRequestID = initialPreviewRequestID; 150 lastPreviewRequestID = initialPreviewRequestID;
148 151
149 previewArea = print_preview.PreviewArea.getInstance(); 152 previewArea = print_preview.PreviewArea.getInstance();
150 printHeader = print_preview.PrintHeader.getInstance(); 153 printHeader = print_preview.PrintHeader.getInstance();
151 document.addEventListener(customEvents.PDF_GENERATION_ERROR, 154 document.addEventListener(customEvents.PDF_GENERATION_ERROR,
152 cancelPendingPrintRequest); 155 cancelPendingPrintRequest);
156 document.addEventListener('click', setLastClickedElement);
153 157
154 if (!checkCompatiblePluginExists()) { 158 if (!checkCompatiblePluginExists()) {
155 disableInputElementsInSidebar(); 159 disableInputElementsInSidebar();
156 $('cancel-button').focus(); 160 $('cancel-button').focus();
157 previewArea.displayErrorMessageWithButtonAndNotify( 161 previewArea.displayErrorMessageWithButtonAndNotify(
158 localStrings.getString('noPlugin'), 162 localStrings.getString('noPlugin'),
159 localStrings.getString('launchNativeDialog'), 163 localStrings.getString('launchNativeDialog'),
160 launchNativePrintDialog); 164 launchNativePrintDialog);
161 $('mainview').parentElement.removeChild($('dummy-viewer')); 165 $('mainview').parentElement.removeChild($('dummy-viewer'));
162 return; 166 return;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 /** 223 /**
220 * Enables the input elements in the sidebar. 224 * Enables the input elements in the sidebar.
221 */ 225 */
222 function enableInputElementsInSidebar() { 226 function enableInputElementsInSidebar() {
223 var els = $('navbar-container').querySelectorAll('input, button, select'); 227 var els = $('navbar-container').querySelectorAll('input, button, select');
224 for (var i = 0; i < els.length; i++) 228 for (var i = 0; i < els.length; i++)
225 els[i].disabled = false; 229 els[i].disabled = false;
226 } 230 }
227 231
228 /** 232 /**
233 * Keep track of the last element to receive a mouse click.
234 * @param {MouseEvent} e The mouse event.
dpapad 2012/03/10 01:14:00 extra space in front. nit optional: Since this is
Dan Beam 2012/03/10 01:14:26 1 less space nit: Generally we say Event instead o
Lei Zhang 2012/03/10 01:35:45 Ok, but this is intended to be for mouse events on
Dan Beam 2012/03/10 01:57:33 That's fine, though pressing space or enter also t
Lei Zhang 2012/03/10 02:20:44 Ok, I changed this to just "click event".
235 */
236 function setLastClickedElement(e) {
237 lastClickedElement = e.target;
238 }
239
240 /**
229 * Disables the controls in the sidebar, shows the throbber and instructs the 241 * Disables the controls in the sidebar, shows the throbber and instructs the
230 * backend to open the native print dialog. 242 * backend to open the native print dialog.
231 */ 243 */
232 function onSystemDialogLinkClicked() { 244 function onSystemDialogLinkClicked() {
233 if (showingSystemDialog) 245 if (showingSystemDialog)
234 return; 246 return;
235 showingSystemDialog = true; 247 showingSystemDialog = true;
236 disableInputElementsInSidebar(); 248 disableInputElementsInSidebar();
237 printHeader.disableCancelButton(); 249 printHeader.disableCancelButton();
238 $('system-dialog-throbber').hidden = false; 250 $('system-dialog-throbber').hidden = false;
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 if (initiatorTabTitle == '') 1109 if (initiatorTabTitle == '')
1098 return; 1110 return;
1099 document.title = localStrings.getStringF( 1111 document.title = localStrings.getStringF(
1100 'printPreviewTitleFormat', initiatorTabTitle); 1112 'printPreviewTitleFormat', initiatorTabTitle);
1101 } 1113 }
1102 1114
1103 /** 1115 /**
1104 * Closes this print preview tab. 1116 * Closes this print preview tab.
1105 */ 1117 */
1106 function closePrintPreviewTab() { 1118 function closePrintPreviewTab() {
1119 window.onkeydown = null;
Dan Beam 2012/03/10 01:14:26 why don't you change to using addEventListener()/d
Lei Zhang 2012/03/10 01:35:45 I don't want any other events to get triggered aft
Dan Beam 2012/03/10 01:57:33 removeEventListener** is cleaner, IMO, as maybe so
Lei Zhang 2012/03/10 02:20:44 Done.
1107 chrome.send('closePrintPreviewTab'); 1120 chrome.send('closePrintPreviewTab');
1108 chrome.send('DialogClose'); 1121 chrome.send('DialogClose');
1109 } 1122 }
1110 1123
1111 /** 1124 /**
1125 * Pass certain directional keyboard events to the PDF viewer.
1126 * @param {KeyboardEvent} e The keyboard event.
Dan Beam 2012/03/10 01:14:26 nit: I'd say same here, but apparently is mattered
Lei Zhang 2012/03/10 01:35:45 Done.
1127 * @return {boolean} true if the keyboard event has been handled.
Dan Beam 2012/03/10 01:14:26 nit: s/true i/I/
Lei Zhang 2012/03/10 01:35:45 Done.
1128 */
1129 function tryToHandleDirectionKeyDown(e) {
1130 // Make sure the PDF plugin is there.
1131 if (!previewArea.pdfPlugin)
1132 return false;
1133
1134 // We only care about: PageUp, PageDown, Left, Up, Right, Down.
1135 if (!(e.keyCode == 33 || e.keyCode == 34 ||
1136 (e.keyCode >= 37 && e.keyCode <= 40))) {
dpapad 2012/03/10 01:14:00 Nit: Indentation should be 4 spaces?
Lei Zhang 2012/03/10 01:35:45 Done.
Dan Beam 2012/03/10 02:58:51 Basically undoing this.
1137 return false;
1138 }
1139
1140 // If the user is holding a modifier key, ignore.
1141 if (e.metaKey || e.altKey || e.shiftKey || e.ctrlKey)
1142 return false;
1143
1144 // Don't handle the key event for these elements.
1145 var tagName = document.activeElement.tagName;
1146 if (tagName == "INPUT" || tagName == "SELECT" || tagName == "EMBED")
1147 return false;
1148
Dan Beam 2012/03/10 01:14:26 nit: remove \n
Lei Zhang 2012/03/10 01:35:45 Done.
1149
1150 // For the most part, if any div of header was the last clicked element,
1151 // then the active element is the body. Starting with the last clicked
1152 // element, and work up the DOM tree to see if any element has a scrollbar.
1153 // If there exists a scrollbar, do not handle the key event here.
1154 var element = document.activeElement;
1155 if (element == document.body) {
1156 if (lastClickedElement)
1157 element = lastClickedElement;
1158 while (element) {
1159 if (element.scrollHeight > element.clientHeight)
1160 return false;
1161 element = element.parentElement;
1162 }
1163 }
1164
1165 // No scroll bar anywhere, or the active element is something else, like a
1166 // button. Note: buttons have a bigger scrollHeight than clientHeight.
1167 previewArea.pdfPlugin.sendKeyEvent(e.keyCode);
1168 return true;
1169 }
1170
1171 /**
1112 * Handle keyboard events. 1172 * Handle keyboard events.
1113 * @param {KeyboardEvent} e The keyboard event. 1173 * @param {KeyboardEvent} e The keyboard event.
1174 * @return {boolean} true to allow the browser to handle the key, else false.
Dan Beam 2012/03/10 01:14:27 * @return {boolean} Whether the key was handled.
Lei Zhang 2012/03/10 01:35:45 Isn't it actually the opposite?
Dan Beam 2012/03/10 01:57:33 See below (you shouldn't have to return anything).
1114 */ 1175 */
1115 function onKeyDown(e) { 1176 function onKeyDown(e) {
1116 // Escape key closes the dialog. 1177 // Escape key closes the dialog.
1117 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { 1178 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
1118 printHeader.disableCancelButton(); 1179 printHeader.disableCancelButton();
1119 closePrintPreviewTab(); 1180 closePrintPreviewTab();
1181 return false;
1120 } 1182 }
1183 // Ctrl + Shift + p / Mac equivalent.
1121 if (e.keyCode == 80) { 1184 if (e.keyCode == 80) {
1122 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || 1185 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) ||
1123 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { 1186 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) {
1124 window.onkeydown = null; 1187 window.onkeydown = null;
1125 onSystemDialogLinkClicked(); 1188 onSystemDialogLinkClicked();
1189 return false;
1126 } 1190 }
1127 } 1191 }
1192
1193 return !tryToHandleDirectionKeyDown(e);
Dan Beam 2012/03/10 01:14:27 who actually listens to this return value?
Lei Zhang 2012/03/10 01:35:45 The renderer. It's like the return value in: <a hr
Dan Beam 2012/03/10 01:57:33 use e.preventDefault() instead either here or insi
Lei Zhang 2012/03/10 02:20:44 Done.
1128 } 1194 }
1129 1195
1130 window.addEventListener('DOMContentLoaded', onLoad); 1196 window.addEventListener('DOMContentLoaded', onLoad);
1131 window.onkeydown = onKeyDown; 1197 window.onkeydown = onKeyDown;
1132 1198
1133 /// Pull in all other scripts in a single shot. 1199 /// Pull in all other scripts in a single shot.
1134 <include src="print_preview_animations.js"/> 1200 <include src="print_preview_animations.js"/>
1135 <include src="print_preview_cloud.js"/> 1201 <include src="print_preview_cloud.js"/>
1136 <include src="print_preview_utils.js"/> 1202 <include src="print_preview_utils.js"/>
1137 <include src="print_header.js"/> 1203 <include src="print_header.js"/>
1138 <include src="page_settings.js"/> 1204 <include src="page_settings.js"/>
1139 <include src="copies_settings.js"/> 1205 <include src="copies_settings.js"/>
1140 <include src="header_footer_settings.js"/> 1206 <include src="header_footer_settings.js"/>
1141 <include src="layout_settings.js"/> 1207 <include src="layout_settings.js"/>
1142 <include src="color_settings.js"/> 1208 <include src="color_settings.js"/>
1143 <include src="margin_settings.js"/> 1209 <include src="margin_settings.js"/>
1144 <include src="margin_textbox.js"/> 1210 <include src="margin_textbox.js"/>
1145 <include src="margin_utils.js"/> 1211 <include src="margin_utils.js"/>
1146 <include src="margins_ui.js"/> 1212 <include src="margins_ui.js"/>
1147 <include src="margins_ui_pair.js"/> 1213 <include src="margins_ui_pair.js"/>
1148 <include src="preview_area.js"/> 1214 <include src="preview_area.js"/>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698