Commit 8aa55065 authored by thestig@chromium.org's avatar thestig@chromium.org

PDF: Handle the space bar key like page down.

BUG=397624

Review URL: https://codereview.chromium.org/431303002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287520 0039d316-1c4b-4281-b951-d872f2087c98
parent 8854fe56
...@@ -164,8 +164,7 @@ PDFViewer.prototype = { ...@@ -164,8 +164,7 @@ PDFViewer.prototype = {
// Certain scroll events may be sent from outside of the extension. // Certain scroll events may be sent from outside of the extension.
var fromScriptingAPI = e.type == 'scriptingKeypress'; var fromScriptingAPI = e.type == 'scriptingKeypress';
switch (e.keyCode) { var pageUpHandler = function() {
case 33: // Page up key.
// Go to the previous page if we are fit-to-page. // Go to the previous page if we are fit-to-page.
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
...@@ -175,8 +174,8 @@ PDFViewer.prototype = { ...@@ -175,8 +174,8 @@ PDFViewer.prototype = {
position.y -= this.viewport.size.height; position.y -= this.viewport.size.height;
this.viewport.position = position; this.viewport.position = position;
} }
return; };
case 34: // Page down key. var pageDownHandler = function() {
// Go to the next page if we are fit-to-page. // Go to the next page if we are fit-to-page.
if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1); this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
...@@ -186,6 +185,20 @@ PDFViewer.prototype = { ...@@ -186,6 +185,20 @@ PDFViewer.prototype = {
position.y += this.viewport.size.height; position.y += this.viewport.size.height;
this.viewport.position = position; this.viewport.position = position;
} }
};
switch (e.keyCode) {
case 32: // Space key.
if (e.shiftKey)
pageUpHandler();
else
pageDownHandler();
return;
case 33: // Page up key.
pageUpHandler();
return;
case 34: // Page down key.
pageDownHandler();
return; return;
case 37: // Left arrow key. case 37: // Left arrow key.
// Go to the previous page if there are no horizontal scrollbars. // Go to the previous page if there are no horizontal scrollbars.
......
...@@ -497,20 +497,20 @@ bool Instance::HandleInputEvent(const pp::InputEvent& event) { ...@@ -497,20 +497,20 @@ bool Instance::HandleInputEvent(const pp::InputEvent& event) {
// Left/Right arrows should scroll to the beginning of the Prev/Next page if // Left/Right arrows should scroll to the beginning of the Prev/Next page if
// there is no horizontal scroll bar. // there is no horizontal scroll bar.
// If fit-to-height, PgDown/PgUp should scroll to the beginning of the // If fit-to-height, PgDown/PgUp should scroll to the beginning of the
// Prev/Next page. // Prev/Next page. Spacebar / shift+spacebar should do the same.
if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) { if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) {
pp::KeyboardInputEvent keyboard_event(event); pp::KeyboardInputEvent keyboard_event(event);
bool page_down = bool no_h_scrollbar = !h_scrollbar_.get();
(!h_scrollbar_.get() && uint32_t key_code = keyboard_event.GetKeyCode();
keyboard_event.GetKeyCode() == ui::VKEY_RIGHT) || bool page_down = no_h_scrollbar && key_code == ui::VKEY_RIGHT;
(zoom_mode_ == ZOOM_FIT_TO_PAGE && bool page_up = no_h_scrollbar && key_code == ui::VKEY_LEFT;
keyboard_event.GetKeyCode() == ui::VKEY_NEXT); if (zoom_mode_ == ZOOM_FIT_TO_PAGE) {
bool page_up = bool has_shift =
(!h_scrollbar_.get() && keyboard_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_SHIFTKEY;
keyboard_event.GetKeyCode() == ui::VKEY_LEFT) || bool key_is_space = key_code == ui::VKEY_SPACE;
(zoom_mode_ == ZOOM_FIT_TO_PAGE && page_down |= key_is_space || key_code == ui::VKEY_NEXT;
keyboard_event.GetKeyCode() == ui::VKEY_PRIOR); page_up |= (key_is_space && has_shift) || (key_code == ui::VKEY_PRIOR);
}
if (page_down) { if (page_down) {
int page = engine_->GetFirstVisiblePage(); int page = engine_->GetFirstVisiblePage();
// Engine calculates visible page including delimiter to the page size. // Engine calculates visible page including delimiter to the page size.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment