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

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

Issue 398643002: Revert 283225 "Hookup the PDF extension to the chrome extensions..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 5 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 | trunk/src/chrome/browser/resources/pdf/viewport.js » ('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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 this.viewport_.fitToPage.bind(this.viewport_)); 127 this.viewport_.fitToPage.bind(this.viewport_));
128 $('zoom-in-button').addEventListener('click', 128 $('zoom-in-button').addEventListener('click',
129 this.viewport_.zoomIn.bind(this.viewport_)); 129 this.viewport_.zoomIn.bind(this.viewport_));
130 $('zoom-out-button').addEventListener('click', 130 $('zoom-out-button').addEventListener('click',
131 this.viewport_.zoomOut.bind(this.viewport_)); 131 this.viewport_.zoomOut.bind(this.viewport_));
132 $('save-button-link').href = this.streamDetails.originalUrl; 132 $('save-button-link').href = this.streamDetails.originalUrl;
133 $('print-button').addEventListener('click', this.print_.bind(this)); 133 $('print-button').addEventListener('click', this.print_.bind(this));
134 134
135 // Setup the keyboard event listener. 135 // Setup the keyboard event listener.
136 document.onkeydown = this.handleKeyEvent_.bind(this); 136 document.onkeydown = this.handleKeyEvent_.bind(this);
137
138 // Set up the zoom API.
139 chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'},
140 this.afterZoom_.bind(this));
141 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
142 // If the zoom level is close enough to the current zoom level, don't change
143 // it. This avoids us getting into an infinite loop of zoom changes to to
144 // floating point error.
145 var MIN_ZOOM_DELTA = 0.01;
146 var zoomDelta = Math.abs(this.viewport_.zoom -
147 zoomChangeInfo.newZoomFactor);
148 if (zoomDelta > MIN_ZOOM_DELTA)
149 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
150 }.bind(this));
151 } 137 }
152 138
153 PDFViewer.prototype = { 139 PDFViewer.prototype = {
154 /** 140 /**
155 * @private 141 * @private
156 * Handle key events. These may come from the user directly or via the 142 * Handle key events. These may come from the user directly or via the
157 * scripting API. 143 * scripting API.
158 * @param {KeyboardEvent} e the event to handle. 144 * @param {KeyboardEvent} e the event to handle.
159 */ 145 */
160 handleKeyEvent_: function(e) { 146 handleKeyEvent_: function(e) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 position.x += Viewport.SCROLL_INCREMENT; 198 position.x += Viewport.SCROLL_INCREMENT;
213 this.viewport.position = position; 199 this.viewport.position = position;
214 } 200 }
215 return; 201 return;
216 case 40: // Down arrow key. 202 case 40: // Down arrow key.
217 if (fromScriptingAPI) { 203 if (fromScriptingAPI) {
218 position.y += Viewport.SCROLL_INCREMENT; 204 position.y += Viewport.SCROLL_INCREMENT;
219 this.viewport.position = position; 205 this.viewport.position = position;
220 } 206 }
221 return; 207 return;
208 case 187: // +/= key.
209 case 107: // Numpad + key.
210 if (e.ctrlKey || e.metaKey) {
211 this.viewport_.zoomIn();
212 // Since we do the zooming of the page.
213 e.preventDefault();
214 }
215 return;
216 case 189: // -/_ key.
217 case 109: // Numpad - key.
218 if (e.ctrlKey || e.metaKey) {
219 this.viewport_.zoomOut();
220 // Since we do the zooming of the page.
221 e.preventDefault();
222 }
223 return;
222 case 83: // s key. 224 case 83: // s key.
223 if (e.ctrlKey || e.metaKey) { 225 if (e.ctrlKey || e.metaKey) {
224 // Simulate a click on the button so that the <a download ...> 226 // Simulate a click on the button so that the <a download ...>
225 // attribute is used. 227 // attribute is used.
226 $('save-button-link').click(); 228 $('save-button-link').click();
227 // Since we do the saving of the page. 229 // Since we do the saving of the page.
228 e.preventDefault(); 230 e.preventDefault();
229 } 231 }
230 return; 232 return;
231 case 80: // p key. 233 case 80: // p key.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 }, 374 },
373 375
374 /** 376 /**
375 * @private 377 * @private
376 * A callback that's called after the zoom changes. Notify the plugin of the 378 * A callback that's called after the zoom changes. Notify the plugin of the
377 * zoom change and to continue reacting to scroll events. 379 * zoom change and to continue reacting to scroll events.
378 */ 380 */
379 afterZoom_: function() { 381 afterZoom_: function() {
380 var position = this.viewport_.position; 382 var position = this.viewport_.position;
381 var zoom = this.viewport_.zoom; 383 var zoom = this.viewport_.zoom;
382 if (!this.setZoomInProgress_) {
383 this.setZoomInProgress_ = true;
384 chrome.tabs.setZoom(zoom, this.setZoomComplete_.bind(this, zoom));
385 }
386 this.plugin_.postMessage({ 384 this.plugin_.postMessage({
387 type: 'viewport', 385 type: 'viewport',
388 zoom: zoom, 386 zoom: zoom,
389 xOffset: position.x, 387 xOffset: position.x,
390 yOffset: position.y 388 yOffset: position.y
391 }); 389 });
392 }, 390 },
393 391
394 /** 392 /**
395 * @private 393 * @private
396 * A callback that's called after chrome.tabs.setZoom is complete. This will
397 * call chrome.tabs.setZoom again if the zoom level has changed since it was
398 * last called.
399 * @param {number} lastZoom the zoom level that chrome.tabs.setZoom was called
400 * with.
401 */
402 setZoomComplete_: function(lastZoom) {
403 var zoom = this.viewport_.zoom;
404 if (zoom != lastZoom)
405 chrome.tabs.setZoom(zoom, this.setZoomComplete_.bind(this, zoom));
406 else
407 this.setZoomInProgress_ = false;
408 },
409
410 /**
411 * @private
412 * A callback that's called after the viewport changes. 394 * A callback that's called after the viewport changes.
413 */ 395 */
414 viewportChanged_: function() { 396 viewportChanged_: function() {
415 if (!this.documentDimensions_) 397 if (!this.documentDimensions_)
416 return; 398 return;
417 399
418 // Update the buttons selected. 400 // Update the buttons selected.
419 $('fit-to-page-button').classList.remove('polymer-selected'); 401 $('fit-to-page-button').classList.remove('polymer-selected');
420 $('fit-to-width-button').classList.remove('polymer-selected'); 402 $('fit-to-width-button').classList.remove('polymer-selected');
421 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { 403 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 506
525 /** 507 /**
526 * @type {Viewport} the viewport of the PDF viewer. 508 * @type {Viewport} the viewport of the PDF viewer.
527 */ 509 */
528 get viewport() { 510 get viewport() {
529 return this.viewport_; 511 return this.viewport_;
530 } 512 }
531 }; 513 };
532 514
533 var viewer = new PDFViewer(); 515 var viewer = new PDFViewer();
OLDNEW
« no previous file with comments | « no previous file | trunk/src/chrome/browser/resources/pdf/viewport.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698