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

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 1162863002: Material PDF: Fix inconsistent behaviour in page selector, update styling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test for shouldIgnoreKeyEvents Created 5 years, 7 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
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 97b7fa095aed2354f975e821e937f50c8b7af3ba..2cc2a70639924a055e599a1e758d57003afc4ca9 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -52,6 +52,21 @@ function onNavigateInNewTab(url) {
}
/**
+ * Whether keydown events should currently be ignored. Events are ignored when
+ * an editable element has focus, to allow for proper editing controls.
+ * @param {HTMLElement} activeElement The currently selected DOM node.
+ * @return {boolean} True if keydown events should be ignored.
+ */
+function shouldIgnoreKeyEvents(activeElement) {
+ while (activeElement.shadowRoot != null)
+ activeElement = activeElement.shadowRoot.activeElement;
+
+ return (activeElement.isContentEditable ||
+ activeElement.tagName == 'INPUT' ||
+ activeElement.tagName == 'TEXTAREA');
+}
+
+/**
* The minimum number of pixels to offset the toolbar by from the bottom and
* right side of the screen.
*/
@@ -206,6 +221,9 @@ PDFViewer.prototype = {
// Certain scroll events may be sent from outside of the extension.
var fromScriptingAPI = e.fromScriptingAPI;
+ if (shouldIgnoreKeyEvents(document.activeElement) || e.defaultPrevented)
+ return;
+
var pageUpHandler = function() {
// Go to the previous page if we are fit-to-page.
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
@@ -623,7 +641,7 @@ PDFViewer.prototype = {
// Update the page indicator.
var visiblePage = this.viewport_.getMostVisiblePage();
if (this.isMaterial_) {
- this.materialToolbar_.pageIndex = visiblePage;
+ this.materialToolbar_.pageNo = visiblePage + 1;
} else {
this.pageIndicator_.index = visiblePage;
if (this.documentDimensions_.pageDimensions.length > 1 &&

Powered by Google App Engine
This is Rietveld 408576698