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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/print_preview/print_preview.js
===================================================================
--- chrome/browser/resources/print_preview/print_preview.js (revision 125906)
+++ chrome/browser/resources/print_preview/print_preview.js (working copy)
@@ -103,6 +103,9 @@
// True if we need to generate draft preview data.
var generateDraftData = true;
+// The last element clicked with the mouse.
+var lastClickedElement = null;
+
// A dictionary of cloud printers that have been added to the printer
// dropdown.
var addedCloudPrinters = {};
@@ -150,6 +153,7 @@
printHeader = print_preview.PrintHeader.getInstance();
document.addEventListener(customEvents.PDF_GENERATION_ERROR,
cancelPendingPrintRequest);
+ document.addEventListener('click', setLastClickedElement);
if (!checkCompatiblePluginExists()) {
disableInputElementsInSidebar();
@@ -226,6 +230,14 @@
}
/**
+ * Keep track of the last element to receive a click.
+ * @param {Event} e The click event.
+ */
+function setLastClickedElement(e) {
+ lastClickedElement = e.target;
+}
+
+/**
* Disables the controls in the sidebar, shows the throbber and instructs the
* backend to open the native print dialog.
*/
@@ -1104,11 +1116,57 @@
* Closes this print preview tab.
*/
function closePrintPreviewTab() {
+ window.removeEventListener('keydown', onKeyDown);
chrome.send('closePrintPreviewTab');
chrome.send('DialogClose');
}
/**
+ * Pass certain directional keyboard events to the PDF viewer.
+ * @param {Event} e The keydown event.
+ */
Dan Beam 2012/03/10 02:58:51 :1125,1127s/^ //
Lei Zhang 2012/03/10 03:08:26 Done.
+function tryToHandleDirectionKeyDown(e) {
+ // Make sure the PDF plugin is there.
+ if (!previewArea.pdfPlugin)
+ return;
+
+ // We only care about: PageUp, PageDown, Left, Up, Right, Down.
+ if (!(e.keyCode == 33 || e.keyCode == 34 ||
+ (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.
+ return;
+ }
+
+ // If the user is holding a modifier key, ignore.
+ if (e.metaKey || e.altKey || e.shiftKey || e.ctrlKey)
+ return;
+
+ // Don't handle the key event for these elements.
+ var tagName = document.activeElement.tagName;
+ if (tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'EMBED')
+ return;
+
+ // For the most part, if any div of header was the last clicked element,
+ // then the active element is the body. Starting with the last clicked
+ // element, and work up the DOM tree to see if any element has a scrollbar.
+ // If there exists a scrollbar, do not handle the key event here.
+ var element = document.activeElement;
+ if (element == document.body) {
+ if (lastClickedElement)
+ element = lastClickedElement;
+ while (element) {
+ if (element.scrollHeight > element.clientHeight)
+ return;
+ element = element.parentElement;
+ }
+ }
+
+ // No scroll bar anywhere, or the active element is something else, like a
+ // button. Note: buttons have a bigger scrollHeight than clientHeight.
+ previewArea.pdfPlugin.sendKeyEvent(e.keyCode);
+ e.preventDefault();
+}
+
+/**
* Handle keyboard events.
* @param {KeyboardEvent} e The keyboard event.
*/
@@ -1117,18 +1175,23 @@
if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
printHeader.disableCancelButton();
closePrintPreviewTab();
+ e.preventDefault();
}
+ // Ctrl + Shift + p / Mac equivalent.
if (e.keyCode == 80) {
if ((cr.isMac && e.metaKey && e.altKey && !e.shiftKey && !e.ctrlKey) ||
(!cr.isMac && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey)) {
- window.onkeydown = null;
+ window.removeEventListener('keydown', onKeyDown);
onSystemDialogLinkClicked();
+ e.preventDefault();
}
}
+
+ tryToHandleDirectionKeyDown(e);
}
window.addEventListener('DOMContentLoaded', onLoad);
-window.onkeydown = onKeyDown;
+window.addEventListener('keydown', onKeyDown);
/// Pull in all other scripts in a single shot.
<include src="print_preview_animations.js"/>
« 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