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

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

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

Powered by Google App Engine
This is Rietveld 408576698