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

Side by Side Diff: chrome/browser/resources/pdf/pdf.js

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 | « no previous file | pdf/instance.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 'use strict'; 5 'use strict';
6 6
7 <include src="../../../../ui/webui/resources/js/util.js"> 7 <include src="../../../../ui/webui/resources/js/util.js">
8 <include src="pdf_scripting_api.js"> 8 <include src="pdf_scripting_api.js">
9 <include src="viewport.js"> 9 <include src="viewport.js">
10 10
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 * @private 157 * @private
158 * Handle key events. These may come from the user directly or via the 158 * Handle key events. These may come from the user directly or via the
159 * scripting API. 159 * scripting API.
160 * @param {KeyboardEvent} e the event to handle. 160 * @param {KeyboardEvent} e the event to handle.
161 */ 161 */
162 handleKeyEvent_: function(e) { 162 handleKeyEvent_: function(e) {
163 var position = this.viewport_.position; 163 var position = this.viewport_.position;
164 // Certain scroll events may be sent from outside of the extension. 164 // Certain scroll events may be sent from outside of the extension.
165 var fromScriptingAPI = e.type == 'scriptingKeypress'; 165 var fromScriptingAPI = e.type == 'scriptingKeypress';
166 166
167 var pageUpHandler = function() {
168 // Go to the previous page if we are fit-to-page.
169 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
170 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
171 // Since we do the movement of the page.
172 e.preventDefault();
173 } else if (fromScriptingAPI) {
174 position.y -= this.viewport.size.height;
175 this.viewport.position = position;
176 }
177 };
178 var pageDownHandler = function() {
179 // Go to the next page if we are fit-to-page.
180 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
181 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
182 // Since we do the movement of the page.
183 e.preventDefault();
184 } else if (fromScriptingAPI) {
185 position.y += this.viewport.size.height;
186 this.viewport.position = position;
187 }
188 };
189
167 switch (e.keyCode) { 190 switch (e.keyCode) {
191 case 32: // Space key.
192 if (e.shiftKey)
193 pageUpHandler();
194 else
195 pageDownHandler();
196 return;
168 case 33: // Page up key. 197 case 33: // Page up key.
169 // Go to the previous page if we are fit-to-page. 198 pageUpHandler();
170 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
171 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
172 // Since we do the movement of the page.
173 e.preventDefault();
174 } else if (fromScriptingAPI) {
175 position.y -= this.viewport.size.height;
176 this.viewport.position = position;
177 }
178 return; 199 return;
179 case 34: // Page down key. 200 case 34: // Page down key.
180 // Go to the next page if we are fit-to-page. 201 pageDownHandler();
181 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
182 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() + 1);
183 // Since we do the movement of the page.
184 e.preventDefault();
185 } else if (fromScriptingAPI) {
186 position.y += this.viewport.size.height;
187 this.viewport.position = position;
188 }
189 return; 202 return;
190 case 37: // Left arrow key. 203 case 37: // Left arrow key.
191 // Go to the previous page if there are no horizontal scrollbars. 204 // Go to the previous page if there are no horizontal scrollbars.
192 if (!this.viewport_.documentHasScrollbars().x) { 205 if (!this.viewport_.documentHasScrollbars().x) {
193 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1); 206 this.viewport_.goToPage(this.viewport_.getMostVisiblePage() - 1);
194 // Since we do the movement of the page. 207 // Since we do the movement of the page.
195 e.preventDefault(); 208 e.preventDefault();
196 } else if (fromScriptingAPI) { 209 } else if (fromScriptingAPI) {
197 position.x -= Viewport.SCROLL_INCREMENT; 210 position.x -= Viewport.SCROLL_INCREMENT;
198 this.viewport.position = position; 211 this.viewport.position = position;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 539
527 /** 540 /**
528 * @type {Viewport} the viewport of the PDF viewer. 541 * @type {Viewport} the viewport of the PDF viewer.
529 */ 542 */
530 get viewport() { 543 get viewport() {
531 return this.viewport_; 544 return this.viewport_;
532 } 545 }
533 }; 546 };
534 547
535 var viewer = new PDFViewer(); 548 var viewer = new PDFViewer();
OLDNEW
« no previous file with comments | « no previous file | pdf/instance.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698