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

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

Issue 420063002: OOP PDF - Add support for "zoom" open pdf parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback (nit fixes, zoom fix) 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
« no previous file with comments | « no previous file | 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 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 if (chrome.tabs) { 139 if (chrome.tabs) {
140 chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'}, 140 chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'},
141 this.afterZoom_.bind(this)); 141 this.afterZoom_.bind(this));
142 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { 142 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
143 // If the zoom level is close enough to the current zoom level, don't 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 144 // change it. This avoids us getting into an infinite loop of zoom changes
145 // due to floating point error. 145 // due to floating point error.
146 var MIN_ZOOM_DELTA = 0.01; 146 var MIN_ZOOM_DELTA = 0.01;
147 var zoomDelta = Math.abs(this.viewport_.zoom - 147 var zoomDelta = Math.abs(this.viewport_.zoom -
148 zoomChangeInfo.newZoomFactor); 148 zoomChangeInfo.newZoomFactor);
149 if (zoomDelta > MIN_ZOOM_DELTA) 149 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
Nikhil 2014/08/21 11:36:50 This was again calling setZoom() with older zoom f
raymes 2014/08/22 03:52:21 Hmm I'm not sure if this is completely correct. Ba
150 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); 150 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
151 }.bind(this)); 151 }.bind(this));
152 } 152 }
153 } 153 }
154 154
155 PDFViewer.prototype = { 155 PDFViewer.prototype = {
156 /** 156 /**
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.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 * @private 257 * @private
258 * Notify the plugin to print. 258 * Notify the plugin to print.
259 */ 259 */
260 print_: function() { 260 print_: function() {
261 this.plugin_.postMessage({ 261 this.plugin_.postMessage({
262 type: 'print', 262 type: 'print',
263 }); 263 });
264 }, 264 },
265 265
266 /** 266 /**
267 * Handle zoom parameter of open PDF parameters. If this
268 * parameter is passed while opening PDF then PDF should be opened
269 * at the specified zoom level.
270 * @param {number} zoom value.
271 */
272 handleZoomParam_: function(paramValue) {
273 var paramValueSplit = paramValue.split(',');
274 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3))
275 return;
276
277 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0.
278 var zoomFactor = parseFloat(paramValueSplit[0]) / 100;
279
280 // Handle #zoom=scale.
281 if (paramValueSplit.length == 1) {
282 this.viewport_.setZoom(zoomFactor);
283 return;
284 }
285
286 // Handle #zoom=scale,left,top.
287 var position = {x: parseFloat(paramValueSplit[1]),
288 y: parseFloat(paramValueSplit[2])};
289 this.viewport_.position = position;
290 this.viewport_.setZoom(zoomFactor);
291 },
292
293 /**
267 * @private 294 * @private
268 * Handle open PDF parameters. These parameters are mentioned in the URL 295 * Handle open PDF parameters. These parameters are mentioned in the URL
269 * and specify actions to be performed when opening PDF files. 296 * and specify actions to be performed when opening PDF files.
270 * See http://crbug.com/64309 for details. 297 * See http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_ parameters.pdf
raymes 2014/08/22 03:52:21 you'll have to split up the URL so it doesn't exte
298 * for details.
271 */ 299 */
272 handleOpenPDFParams_: function() { 300 handleOpenPDFParams_: function() {
273 var originalUrl = this.streamDetails.originalUrl; 301 var originalUrl = this.streamDetails.originalUrl;
274 var paramIndex = originalUrl.search('#'); 302 var paramIndex = originalUrl.search('#');
275 if (paramIndex == -1) 303 if (paramIndex == -1)
276 return; 304 return;
277 305
278 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); 306 var paramTokens = originalUrl.substring(paramIndex + 1).split('&');
279 var paramsDictionary = {}; 307 var paramsDictionary = {};
280 for (var i = 0; i < paramTokens.length; ++i) { 308 for (var i = 0; i < paramTokens.length; ++i) {
281 var keyValueSplit = paramTokens[i].split('='); 309 var keyValueSplit = paramTokens[i].split('=');
282 if (keyValueSplit.length != 2) 310 if (keyValueSplit.length != 2)
283 continue; 311 continue;
284 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; 312 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1];
285 } 313 }
286 314
287 // Order is important as later actions can override the effects 315 // Order is important as later actions can override the effects
288 // of previous actions. 316 // of previous actions.
289 if ('page' in paramsDictionary) { 317 if ('page' in paramsDictionary) {
290 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. 318 // |pageNumber| is 1-based, but goToPage() take a zero-based page number.
291 var pageNumber = parseInt(paramsDictionary['page']); 319 var pageNumber = parseInt(paramsDictionary['page']);
292 if (!isNaN(pageNumber)) 320 if (!isNaN(pageNumber))
293 this.viewport_.goToPage(pageNumber - 1); 321 this.viewport_.goToPage(pageNumber - 1);
294 } 322 }
323 if ('zoom' in paramsDictionary)
324 this.handleZoomParam_(paramsDictionary['zoom']);
295 }, 325 },
raymes 2014/08/22 03:52:21 This class is already quite large and I'd like to
296 326
297 /** 327 /**
298 * @private 328 * @private
299 * Update the loading progress of the document in response to a progress 329 * Update the loading progress of the document in response to a progress
300 * message being received from the plugin. 330 * message being received from the plugin.
301 * @param {number} progress the progress as a percentage. 331 * @param {number} progress the progress as a percentage.
302 */ 332 */
303 updateProgress_: function(progress) { 333 updateProgress_: function(progress) {
304 this.progressBar_.progress = progress; 334 this.progressBar_.progress = progress;
305 if (progress == -1) { 335 if (progress == -1) {
306 // Document load failed. 336 // Document load failed.
307 this.errorScreen_.style.visibility = 'visible'; 337 this.errorScreen_.style.visibility = 'visible';
308 this.sizer_.style.display = 'none'; 338 this.sizer_.style.display = 'none';
309 this.toolbar_.style.visibility = 'hidden'; 339 this.toolbar_.style.visibility = 'hidden';
310 if (this.passwordScreen_.active) { 340 if (this.passwordScreen_.active) {
311 this.passwordScreen_.deny(); 341 this.passwordScreen_.deny();
312 this.passwordScreen_.active = false; 342 this.passwordScreen_.active = false;
313 } 343 }
314 } else if (progress == 100) { 344 } else if (progress == 100) {
315 // Document load complete. 345 // Document load complete.
346 if (this.lastViewportPosition_)
347 this.viewport_.position = this.lastViewportPosition_;
316 this.handleOpenPDFParams_(); 348 this.handleOpenPDFParams_();
317 this.loaded = true; 349 this.loaded = true;
318 var loadEvent = new Event('pdfload'); 350 var loadEvent = new Event('pdfload');
319 window.dispatchEvent(loadEvent); 351 window.dispatchEvent(loadEvent);
320 this.sendScriptingMessage_({ 352 this.sendScriptingMessage_({
321 type: 'documentLoaded' 353 type: 'documentLoaded'
322 }); 354 });
323 if (this.lastViewportPosition_)
324 this.viewport_.position = this.lastViewportPosition_;
325 } 355 }
326 }, 356 },
327 357
328 /** 358 /**
329 * @private 359 * @private
330 * An event handler for handling password-submitted events. These are fired 360 * An event handler for handling password-submitted events. These are fired
331 * when an event is entered into the password screen. 361 * when an event is entered into the password screen.
332 * @param {Object} event a password-submitted event. 362 * @param {Object} event a password-submitted event.
333 */ 363 */
334 onPasswordSubmitted_: function(event) { 364 onPasswordSubmitted_: function(event) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 601
572 /** 602 /**
573 * @type {Viewport} the viewport of the PDF viewer. 603 * @type {Viewport} the viewport of the PDF viewer.
574 */ 604 */
575 get viewport() { 605 get viewport() {
576 return this.viewport_; 606 return this.viewport_;
577 } 607 }
578 }; 608 };
579 609
580 var viewer = new PDFViewer(); 610 var viewer = new PDFViewer();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698