OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 click. | |
234 * @param {Event} e The 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 Loading... | |
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.removeEventListener('keydown', onKeyDown); | |
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 {Event} e The keydown event. | |
1127 */ | |
Dan Beam
2012/03/10 02:58:51
:1125,1127s/^ //
Lei Zhang
2012/03/10 03:08:26
Done.
| |
1128 function tryToHandleDirectionKeyDown(e) { | |
1129 // Make sure the PDF plugin is there. | |
1130 if (!previewArea.pdfPlugin) | |
1131 return; | |
1132 | |
1133 // We only care about: PageUp, PageDown, Left, Up, Right, Down. | |
1134 if (!(e.keyCode == 33 || e.keyCode == 34 || | |
1135 (e.keyCode >= 37 && e.keyCode <= 40))) { | |
Dan Beam
2012/03/10 02:58:51
:1135s/^/ / to show that this is a sub expression
Lei Zhang
2012/03/10 03:08:26
Done.
| |
1136 return; | |
1137 } | |
1138 | |
1139 // If the user is holding a modifier key, ignore. | |
1140 if (e.metaKey || e.altKey || e.shiftKey || e.ctrlKey) | |
1141 return; | |
1142 | |
1143 // Don't handle the key event for these elements. | |
1144 var tagName = document.activeElement.tagName; | |
1145 if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'EMBED') | |
1146 return; | |
1147 | |
1148 // For the most part, if any div of header was the last clicked element, | |
1149 // then the active element is the body. Starting with the last clicked | |
1150 // element, and work up the DOM tree to see if any element has a scrollbar. | |
1151 // If there exists a scrollbar, do not handle the key event here. | |
1152 var element = document.activeElement; | |
1153 if (element == document.body) { | |
1154 if (lastClickedElement) | |
1155 element = lastClickedElement; | |
1156 while (element) { | |
1157 if (element.scrollHeight > element.clientHeight) | |
1158 return; | |
1159 element = element.parentElement; | |
1160 } | |
1161 } | |
1162 | |
1163 // No scroll bar anywhere, or the active element is something else, like a | |
1164 // button. Note: buttons have a bigger scrollHeight than clientHeight. | |
1165 previewArea.pdfPlugin.sendKeyEvent(e.keyCode); | |
1166 e.preventDefault(); | |
1167 } | |
1168 | |
1169 /** | |
1112 * Handle keyboard events. | 1170 * Handle keyboard events. |
1113 * @param {KeyboardEvent} e The keyboard event. | 1171 * @param {KeyboardEvent} e The keyboard event. |
1114 */ | 1172 */ |
1115 function onKeyDown(e) { | 1173 function onKeyDown(e) { |
1116 // Escape key closes the dialog. | 1174 // Escape key closes the dialog. |
1117 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { | 1175 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { |
1118 printHeader.disableCancelButton(); | 1176 printHeader.disableCancelButton(); |
1119 closePrintPreviewTab(); | 1177 closePrintPreviewTab(); |
1178 e.preventDefault(); | |
1120 } | 1179 } |
1180 // Ctrl + Shift + p / Mac equivalent. | |
1121 if (e.keyCode == 80) { | 1181 if (e.keyCode == 80) { |
1122 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || | 1182 if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) || |
1123 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { | 1183 (!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) { |
1124 window.onkeydown = null; | 1184 window.removeEventListener('keydown', onKeyDown); |
1125 onSystemDialogLinkClicked(); | 1185 onSystemDialogLinkClicked(); |
1186 e.preventDefault(); | |
1126 } | 1187 } |
1127 } | 1188 } |
1189 | |
1190 tryToHandleDirectionKeyDown(e); | |
1128 } | 1191 } |
1129 | 1192 |
1130 window.addEventListener('DOMContentLoaded', onLoad); | 1193 window.addEventListener('DOMContentLoaded', onLoad); |
1131 window.onkeydown = onKeyDown; | 1194 window.addEventListener('keydown', onKeyDown); |
1132 | 1195 |
1133 /// Pull in all other scripts in a single shot. | 1196 /// Pull in all other scripts in a single shot. |
1134 <include src="print_preview_animations.js"/> | 1197 <include src="print_preview_animations.js"/> |
1135 <include src="print_preview_cloud.js"/> | 1198 <include src="print_preview_cloud.js"/> |
1136 <include src="print_preview_utils.js"/> | 1199 <include src="print_preview_utils.js"/> |
1137 <include src="print_header.js"/> | 1200 <include src="print_header.js"/> |
1138 <include src="page_settings.js"/> | 1201 <include src="page_settings.js"/> |
1139 <include src="copies_settings.js"/> | 1202 <include src="copies_settings.js"/> |
1140 <include src="header_footer_settings.js"/> | 1203 <include src="header_footer_settings.js"/> |
1141 <include src="layout_settings.js"/> | 1204 <include src="layout_settings.js"/> |
1142 <include src="color_settings.js"/> | 1205 <include src="color_settings.js"/> |
1143 <include src="margin_settings.js"/> | 1206 <include src="margin_settings.js"/> |
1144 <include src="margin_textbox.js"/> | 1207 <include src="margin_textbox.js"/> |
1145 <include src="margin_utils.js"/> | 1208 <include src="margin_utils.js"/> |
1146 <include src="margins_ui.js"/> | 1209 <include src="margins_ui.js"/> |
1147 <include src="margins_ui_pair.js"/> | 1210 <include src="margins_ui_pair.js"/> |
1148 <include src="preview_area.js"/> | 1211 <include src="preview_area.js"/> |
OLD | NEW |