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

Side by Side Diff: pdf/instance.cc

Issue 431303002: PDF: Handle the space bar key like page down. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "pdf/instance.h" 5 #include "pdf/instance.h"
6 6
7 #include <algorithm> // for min() 7 #include <algorithm> // for min()
8 #define _USE_MATH_DEFINES // for M_PI 8 #define _USE_MATH_DEFINES // for M_PI
9 #include <cmath> // for log() and pow() 9 #include <cmath> // for log() and pow()
10 #include <math.h> 10 #include <math.h>
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 490 }
491 default: 491 default:
492 break; 492 break;
493 } 493 }
494 if (try_engine_first && engine_->HandleEvent(offset_event)) 494 if (try_engine_first && engine_->HandleEvent(offset_event))
495 return true; 495 return true;
496 496
497 // Left/Right arrows should scroll to the beginning of the Prev/Next page if 497 // Left/Right arrows should scroll to the beginning of the Prev/Next page if
498 // there is no horizontal scroll bar. 498 // there is no horizontal scroll bar.
499 // If fit-to-height, PgDown/PgUp should scroll to the beginning of the 499 // If fit-to-height, PgDown/PgUp should scroll to the beginning of the
500 // Prev/Next page. 500 // Prev/Next page. Spacebar / shift+spacebar should do the same.
501 if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) { 501 if (v_scrollbar_.get() && event.GetType() == PP_INPUTEVENT_TYPE_KEYDOWN) {
502 pp::KeyboardInputEvent keyboard_event(event); 502 pp::KeyboardInputEvent keyboard_event(event);
503 bool page_down = 503 bool no_h_scrollbar = !h_scrollbar_.get();
504 (!h_scrollbar_.get() && 504 uint32_t key_code = keyboard_event.GetKeyCode();
505 keyboard_event.GetKeyCode() == ui::VKEY_RIGHT) || 505 bool page_down = no_h_scrollbar && key_code == ui::VKEY_RIGHT;
506 (zoom_mode_ == ZOOM_FIT_TO_PAGE && 506 bool page_up = no_h_scrollbar && key_code == ui::VKEY_LEFT;
507 keyboard_event.GetKeyCode() == ui::VKEY_NEXT); 507 if (zoom_mode_ == ZOOM_FIT_TO_PAGE) {
508 bool page_up = 508 bool has_shift =
509 (!h_scrollbar_.get() && 509 keyboard_event.GetModifiers() & PP_INPUTEVENT_MODIFIER_SHIFTKEY;
510 keyboard_event.GetKeyCode() == ui::VKEY_LEFT) || 510 bool key_is_space = key_code == ui::VKEY_SPACE;
511 (zoom_mode_ == ZOOM_FIT_TO_PAGE && 511 page_down |= key_is_space || key_code == ui::VKEY_NEXT;
512 keyboard_event.GetKeyCode() == ui::VKEY_PRIOR); 512 page_up |= (key_is_space && has_shift) || (key_code == ui::VKEY_PRIOR);
513 513 }
514 if (page_down) { 514 if (page_down) {
515 int page = engine_->GetFirstVisiblePage(); 515 int page = engine_->GetFirstVisiblePage();
516 // Engine calculates visible page including delimiter to the page size. 516 // Engine calculates visible page including delimiter to the page size.
517 // We need to check here if the page itself is completely out of view and 517 // We need to check here if the page itself is completely out of view and
518 // scroll to the next one in that case. 518 // scroll to the next one in that case.
519 if (engine_->GetPageRect(page).bottom() * zoom_ <= 519 if (engine_->GetPageRect(page).bottom() * zoom_ <=
520 v_scrollbar_->GetValue()) 520 v_scrollbar_->GetValue())
521 page++; 521 page++;
522 ScrollToPage(page + 1); 522 ScrollToPage(page + 1);
523 UpdateCursor(PP_CURSORTYPE_POINTER); 523 UpdateCursor(PP_CURSORTYPE_POINTER);
(...skipping 2199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2723 return instance_->HasScriptableMethod(name, exception); 2723 return instance_->HasScriptableMethod(name, exception);
2724 } 2724 }
2725 2725
2726 pp::Var PDFScriptableObject::Call(const pp::Var& method, 2726 pp::Var PDFScriptableObject::Call(const pp::Var& method,
2727 const std::vector<pp::Var>& args, 2727 const std::vector<pp::Var>& args,
2728 pp::Var* exception) { 2728 pp::Var* exception) {
2729 return instance_->CallScriptableMethod(method, args, exception); 2729 return instance_->CallScriptableMethod(method, args, exception);
2730 } 2730 }
2731 2731
2732 } // namespace chrome_pdf 2732 } // namespace chrome_pdf
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698