| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 7 /** |
| 8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters | 8 * Creates a new OpenPDFParamsParser. This parses the open pdf parameters |
| 9 * passed in the url to set initial viewport settings for opening the pdf. | 9 * passed in the url to set initial viewport settings for opening the pdf. |
| 10 * @param {Object} getNamedDestinationsFunction The function called to fetch | 10 * @param {Object} getNamedDestinationsFunction The function called to fetch |
| 11 * the page number for a named destination. | 11 * the page number for a named destination. |
| 12 * @constructor |
| 12 */ | 13 */ |
| 13 function OpenPDFParamsParser(getNamedDestinationsFunction) { | 14 function OpenPDFParamsParser(getNamedDestinationsFunction) { |
| 14 this.outstandingRequests_ = []; | 15 this.outstandingRequests_ = []; |
| 15 this.getNamedDestinationsFunction_ = getNamedDestinationsFunction; | 16 this.getNamedDestinationsFunction_ = getNamedDestinationsFunction; |
| 16 } | 17 } |
| 17 | 18 |
| 18 OpenPDFParamsParser.prototype = { | 19 OpenPDFParamsParser.prototype = { |
| 19 /** | 20 /** |
| 20 * @private | 21 * @private |
| 21 * Parse zoom parameter of open PDF parameters. If this | 22 * Parse zoom parameter of open PDF parameters. If this |
| 22 * parameter is passed while opening PDF then PDF should be opened | 23 * parameter is passed while opening PDF then PDF should be opened |
| 23 * at the specified zoom level. | 24 * at the specified zoom level. |
| 24 * @param {number} zoom value. | 25 * @param {string} paramValue zoom value. |
| 25 * @param {Object} viewportPosition to store zoom and position value. | 26 * @param {Object} viewportPosition to store zoom and position value. |
| 26 */ | 27 */ |
| 27 parseZoomParam_: function(paramValue, viewportPosition) { | 28 parseZoomParam_: function(paramValue, viewportPosition) { |
| 28 var paramValueSplit = paramValue.split(','); | 29 var paramValueSplit = paramValue.split(','); |
| 29 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) | 30 if ((paramValueSplit.length != 1) && (paramValueSplit.length != 3)) |
| 30 return; | 31 return; |
| 31 | 32 |
| 32 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. | 33 // User scale of 100 means zoom value of 100% i.e. zoom factor of 1.0. |
| 33 var zoomFactor = parseFloat(paramValueSplit[0]) / 100; | 34 var zoomFactor = parseFloat(paramValueSplit[0]) / 100; |
| 34 if (isNaN(zoomFactor)) | 35 if (isNaN(zoomFactor)) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 * @param {Function} callback function to be called with viewport info. | 106 * @param {Function} callback function to be called with viewport info. |
| 106 */ | 107 */ |
| 107 getViewportFromUrlParams: function(url, callback) { | 108 getViewportFromUrlParams: function(url, callback) { |
| 108 var viewportPosition = {}; | 109 var viewportPosition = {}; |
| 109 viewportPosition['url'] = url; | 110 viewportPosition['url'] = url; |
| 110 | 111 |
| 111 var paramsDictionary = this.parseUrlParams_(url); | 112 var paramsDictionary = this.parseUrlParams_(url); |
| 112 | 113 |
| 113 if ('page' in paramsDictionary) { | 114 if ('page' in paramsDictionary) { |
| 114 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. | 115 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. |
| 115 var pageNumber = parseInt(paramsDictionary['page']); | 116 var pageNumber = parseInt(paramsDictionary['page'], 10); |
| 116 if (!isNaN(pageNumber) && pageNumber > 0) | 117 if (!isNaN(pageNumber) && pageNumber > 0) |
| 117 viewportPosition['page'] = pageNumber - 1; | 118 viewportPosition['page'] = pageNumber - 1; |
| 118 } | 119 } |
| 119 | 120 |
| 120 if ('zoom' in paramsDictionary) | 121 if ('zoom' in paramsDictionary) |
| 121 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); | 122 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); |
| 122 | 123 |
| 123 if (viewportPosition.page === undefined && | 124 if (viewportPosition.page === undefined && |
| 124 'nameddest' in paramsDictionary) { | 125 'nameddest' in paramsDictionary) { |
| 125 this.outstandingRequests_.push({ | 126 this.outstandingRequests_.push({ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 * @param {number} pageNumber The page corresponding to the named destination | 139 * @param {number} pageNumber The page corresponding to the named destination |
| 139 * requested. | 140 * requested. |
| 140 */ | 141 */ |
| 141 onNamedDestinationReceived: function(pageNumber) { | 142 onNamedDestinationReceived: function(pageNumber) { |
| 142 var outstandingRequest = this.outstandingRequests_.shift(); | 143 var outstandingRequest = this.outstandingRequests_.shift(); |
| 143 if (pageNumber != -1) | 144 if (pageNumber != -1) |
| 144 outstandingRequest.viewportPosition.page = pageNumber; | 145 outstandingRequest.viewportPosition.page = pageNumber; |
| 145 outstandingRequest.callback(outstandingRequest.viewportPosition); | 146 outstandingRequest.callback(outstandingRequest.viewportPosition); |
| 146 }, | 147 }, |
| 147 }; | 148 }; |
| OLD | NEW |