| 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 {!Function} getNamedDestinationsFunction The function called to fetch | 10 * @param {!Function} getNamedDestinationsFunction The function called to fetch |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 if (isNaN(zoomFactor)) | 35 if (isNaN(zoomFactor)) |
| 36 return; | 36 return; |
| 37 | 37 |
| 38 // Handle #zoom=scale. | 38 // Handle #zoom=scale. |
| 39 if (paramValueSplit.length == 1) { | 39 if (paramValueSplit.length == 1) { |
| 40 viewportPosition['zoom'] = zoomFactor; | 40 viewportPosition['zoom'] = zoomFactor; |
| 41 return; | 41 return; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Handle #zoom=scale,left,top. | 44 // Handle #zoom=scale,left,top. |
| 45 var position = {x: parseFloat(paramValueSplit[1]), | 45 var position = { |
| 46 y: parseFloat(paramValueSplit[2])}; | 46 x: parseFloat(paramValueSplit[1]), |
| 47 y: parseFloat(paramValueSplit[2]) |
| 48 }; |
| 47 viewportPosition['position'] = position; | 49 viewportPosition['position'] = position; |
| 48 viewportPosition['zoom'] = zoomFactor; | 50 viewportPosition['zoom'] = zoomFactor; |
| 49 }, | 51 }, |
| 50 | 52 |
| 51 /** | 53 /** |
| 52 * Parse the parameters encoded in the fragment of a URL into a dictionary. | 54 * Parse the parameters encoded in the fragment of a URL into a dictionary. |
| 53 * @private | 55 * @private |
| 54 * @param {string} url to parse | 56 * @param {string} url to parse |
| 55 * @return {Object} Key-value pairs of URL parameters | 57 * @return {Object} Key-value pairs of URL parameters |
| 56 */ | 58 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 var pageNumber = parseInt(paramsDictionary['page'], 10); | 118 var pageNumber = parseInt(paramsDictionary['page'], 10); |
| 117 if (!isNaN(pageNumber) && pageNumber > 0) | 119 if (!isNaN(pageNumber) && pageNumber > 0) |
| 118 viewportPosition['page'] = pageNumber - 1; | 120 viewportPosition['page'] = pageNumber - 1; |
| 119 } | 121 } |
| 120 | 122 |
| 121 if ('zoom' in paramsDictionary) | 123 if ('zoom' in paramsDictionary) |
| 122 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); | 124 this.parseZoomParam_(paramsDictionary['zoom'], viewportPosition); |
| 123 | 125 |
| 124 if (viewportPosition.page === undefined && | 126 if (viewportPosition.page === undefined && |
| 125 'nameddest' in paramsDictionary) { | 127 'nameddest' in paramsDictionary) { |
| 126 this.outstandingRequests_.push({ | 128 this.outstandingRequests_.push( |
| 127 callback: callback, | 129 {callback: callback, viewportPosition: viewportPosition}); |
| 128 viewportPosition: viewportPosition | |
| 129 }); | |
| 130 this.getNamedDestinationsFunction_(paramsDictionary['nameddest']); | 130 this.getNamedDestinationsFunction_(paramsDictionary['nameddest']); |
| 131 } else { | 131 } else { |
| 132 callback(viewportPosition); | 132 callback(viewportPosition); |
| 133 } | 133 } |
| 134 }, | 134 }, |
| 135 | 135 |
| 136 /** | 136 /** |
| 137 * This is called when a named destination is received and the page number | 137 * This is called when a named destination is received and the page number |
| 138 * corresponding to the request for which a named destination is passed. | 138 * corresponding to the request for which a named destination is passed. |
| 139 * @param {number} pageNumber The page corresponding to the named destination | 139 * @param {number} pageNumber The page corresponding to the named destination |
| 140 * requested. | 140 * requested. |
| 141 */ | 141 */ |
| 142 onNamedDestinationReceived: function(pageNumber) { | 142 onNamedDestinationReceived: function(pageNumber) { |
| 143 var outstandingRequest = this.outstandingRequests_.shift(); | 143 var outstandingRequest = this.outstandingRequests_.shift(); |
| 144 if (pageNumber != -1) | 144 if (pageNumber != -1) |
| 145 outstandingRequest.viewportPosition.page = pageNumber; | 145 outstandingRequest.viewportPosition.page = pageNumber; |
| 146 outstandingRequest.callback(outstandingRequest.viewportPosition); | 146 outstandingRequest.callback(outstandingRequest.viewportPosition); |
| 147 }, | 147 }, |
| 148 }; | 148 }; |
| OLD | NEW |