summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/pdf/pdf_extension_test.cc8
-rw-r--r--chrome/browser/resources/pdf/pdf.js16
-rw-r--r--chrome/test/data/pdf/page_change_test.js74
-rw-r--r--pdf/out_of_process_instance.cc10
4 files changed, 104 insertions, 4 deletions
diff --git a/chrome/browser/pdf/pdf_extension_test.cc b/chrome/browser/pdf/pdf_extension_test.cc
index 3ddc059..15932d5 100644
--- a/chrome/browser/pdf/pdf_extension_test.cc
+++ b/chrome/browser/pdf/pdf_extension_test.cc
@@ -334,6 +334,10 @@ IN_PROC_BROWSER_TEST_F(PDFExtensionTest, WhitespaceTitle) {
RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf");
}
+IN_PROC_BROWSER_TEST_F(PDFExtensionTest, PageChange) {
+ RunTestsInFile("page_change_test.js", "test-bookmarks.pdf");
+}
+
// Ensure that the internal PDF plugin application/x-google-chrome-pdf won't be
// loaded if it's not loaded in the chrome extension page.
IN_PROC_BROWSER_TEST_F(PDFExtensionTest, EnsureInternalPluginDisabled) {
@@ -428,3 +432,7 @@ IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, Title) {
IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, WhitespaceTitle) {
RunTestsInFile("whitespace_title_test.js", "test-whitespace-title.pdf");
}
+
+IN_PROC_BROWSER_TEST_F(MaterialPDFExtensionTest, PageChange) {
+ RunTestsInFile("page_change_test.js", "test-bookmarks.pdf");
+}
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 8fab2be..5bc98c4 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -115,6 +115,7 @@ function PDFViewer(browserApi) {
this.loadState_ = LoadState.LOADING;
this.parentWindow_ = null;
this.parentOrigin_ = null;
+ this.isFormFieldFocused_ = false;
this.delayedScriptingMessages_ = [];
@@ -325,8 +326,10 @@ PDFViewer.prototype = {
return;
case 37: // Left arrow key.
if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
- // Go to the previous page if there are no horizontal scrollbars.
- if (!this.viewport_.documentHasScrollbars().horizontal) {
+ // Go to the previous page if there are no horizontal scrollbars and
+ // no form field is focused.
+ if (!(this.viewport_.documentHasScrollbars().horizontal ||
+ this.isFormFieldFocused_)) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
// Since we do the movement of the page.
e.preventDefault();
@@ -344,8 +347,10 @@ PDFViewer.prototype = {
return;
case 39: // Right arrow key.
if (!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey)) {
- // Go to the next page if there are no horizontal scrollbars.
- if (!this.viewport_.documentHasScrollbars().horizontal) {
+ // Go to the next page if there are no horizontal scrollbars and no
+ // form field is focused.
+ if (!(this.viewport_.documentHasScrollbars().horizontal ||
+ this.isFormFieldFocused_)) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
// Since we do the movement of the page.
e.preventDefault();
@@ -673,6 +678,9 @@ PDFViewer.prototype = {
this.paramsParser_.onNamedDestinationReceived(
message.data.pageNumber);
break;
+ case 'formFocusChange':
+ this.isFormFieldFocused_ = message.data.focused;
+ break;
}
},
diff --git a/chrome/test/data/pdf/page_change_test.js b/chrome/test/data/pdf/page_change_test.js
new file mode 100644
index 0000000..85395d6
--- /dev/null
+++ b/chrome/test/data/pdf/page_change_test.js
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+function resetDocument() {
+ window.viewer.viewport.goToPage(0);
+ window.viewer.viewport.setZoom(1);
+ window.viewer.isFormFieldFocused_ = false;
+}
+
+function getCurrentPage() {
+ return window.viewer.viewport.getMostVisiblePage();
+}
+
+var tests = [
+ /**
+ * Test that the left/right arrows change page back and forth.
+ */
+ function testPageChangesWithArrows() {
+ // Right arrow -> Go to page 2.
+ MockInteractions.pressAndReleaseKeyOn(document, 39);
+ chrome.test.assertEq(1, getCurrentPage());
+
+ // Left arrow -> Back to page 1.
+ MockInteractions.pressAndReleaseKeyOn(document, 37);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ },
+
+ /**
+ * Test that when a PDF form field is focused, the left/right shortcuts are
+ * disabled. This doesn't test the plugin side of this feature.
+ */
+ function testPageDoesntChangeWhenFormFocused() {
+ // This should be set by a message from plugin -> page when a field is
+ // focused.
+ window.viewer.isFormFieldFocused_ = true;
+
+ // Page should not change when left/right are pressed.
+ MockInteractions.pressAndReleaseKeyOn(document, 39);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ MockInteractions.pressAndReleaseKeyOn(document, 37);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ },
+
+ /**
+ * Test that when the document is in fit to page, pressing page up/page down
+ * changes page back/forth.
+ */
+ function testPageDownInFitPage() {
+ window.viewer.viewport.fitToPage();
+
+ // Page down -> Go to page 2.
+ MockInteractions.pressAndReleaseKeyOn(document, 34);
+ chrome.test.assertEq(1, getCurrentPage());
+
+ // Page up -> Back to page 1.
+ MockInteractions.pressAndReleaseKeyOn(document, 33);
+ chrome.test.assertEq(0, getCurrentPage());
+
+ resetDocument();
+ chrome.test.succeed();
+ }
+];
+
+importTestHelpers().then(function() {
+ chrome.test.runTests(tests);
+});
diff --git a/pdf/out_of_process_instance.cc b/pdf/out_of_process_instance.cc
index 3478b78..cfa11ba 100644
--- a/pdf/out_of_process_instance.cc
+++ b/pdf/out_of_process_instance.cc
@@ -144,6 +144,10 @@ const char kJSNamedDestinationPageNumber[] = "pageNumber";
const char kJSSetIsSelectingType[] = "setIsSelecting";
const char kJSIsSelecting[] = "isSelecting";
+// Notify when a form field is focused (Plugin -> Page)
+const char kJSFieldFocusType[] = "formFocusChange";
+const char kJSFieldFocus[] = "focused";
+
const int kFindResultCooldownMs = 100;
const double kMinZoom = 0.01;
@@ -1264,6 +1268,12 @@ void OutOfProcessInstance::DocumentLoadProgress(uint32 available,
void OutOfProcessInstance::FormTextFieldFocusChange(bool in_focus) {
if (!text_input_.get())
return;
+
+ pp::VarDictionary message;
+ message.Set(pp::Var(kType), pp::Var(kJSFieldFocusType));
+ message.Set(pp::Var(kJSFieldFocus), pp::Var(in_focus));
+ PostMessage(message);
+
if (in_focus)
text_input_->SetTextInputType(PP_TEXTINPUT_TYPE_DEV_TEXT);
else