| OLD | NEW |
| 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 (function() { | 5 (function() { |
| 6 | 6 |
| 7 <include src="../../../../ui/webui/resources/js/util.js"></include> | 7 <include src="../../../../ui/webui/resources/js/util.js"></include> |
| 8 <include src="viewport.js"></include> | 8 <include src="viewport.js"></include> |
| 9 | 9 |
| 10 // The plugin element is sized to fill the entire window and is set to be fixed | 10 // The plugin element is sized to fill the entire window and is set to be fixed |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // The progress bar element. | 26 // The progress bar element. |
| 27 var viewerProgressBar; | 27 var viewerProgressBar; |
| 28 | 28 |
| 29 // The viewport object. | 29 // The viewport object. |
| 30 var viewport; | 30 var viewport; |
| 31 | 31 |
| 32 // The document dimensions. | 32 // The document dimensions. |
| 33 var documentDimensions; | 33 var documentDimensions; |
| 34 | 34 |
| 35 // Notify the plugin to print. |
| 36 function print() { |
| 37 plugin.postMessage({ |
| 38 type: 'print', |
| 39 }); |
| 40 } |
| 41 |
| 35 // Returns true if the fit-to-page button is enabled. | 42 // Returns true if the fit-to-page button is enabled. |
| 36 function isFitToPageEnabled() { | 43 function isFitToPageEnabled() { |
| 37 return $('fit-to-page-button').classList.contains('polymer-selected'); | 44 return $('fit-to-page-button').classList.contains('polymer-selected'); |
| 38 } | 45 } |
| 39 | 46 |
| 40 function updateProgress(progress) { | 47 function updateProgress(progress) { |
| 41 viewerProgressBar.progress = progress; | 48 viewerProgressBar.progress = progress; |
| 42 if (progress == -1) { | 49 if (progress == -1) { |
| 43 // Document load failed. | 50 // Document load failed. |
| 44 sizer.style.display = 'none'; | 51 sizer.style.display = 'none'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 viewport = new Viewport(window, | 107 viewport = new Viewport(window, |
| 101 sizer, | 108 sizer, |
| 102 isFitToPageEnabled, | 109 isFitToPageEnabled, |
| 103 viewportChangedCallback); | 110 viewportChangedCallback); |
| 104 | 111 |
| 105 // Create the plugin object dynamically so we can set its src. | 112 // Create the plugin object dynamically so we can set its src. |
| 106 plugin = document.createElement('object'); | 113 plugin = document.createElement('object'); |
| 107 plugin.id = 'plugin'; | 114 plugin.id = 'plugin'; |
| 108 plugin.type = 'application/x-google-chrome-pdf'; | 115 plugin.type = 'application/x-google-chrome-pdf'; |
| 109 plugin.addEventListener('message', handleMessage, false); | 116 plugin.addEventListener('message', handleMessage, false); |
| 110 // The pdf location is passed in the document url in the format: | 117 // The pdf location is passed in stream details in the background page. |
| 111 // http://<.../pdf.html>?<pdf location>. | 118 var streamDetails = chrome.extension.getBackgroundPage().getStreamDetails(); |
| 112 var url = window.location.search.substring(1); | 119 plugin.setAttribute('src', streamDetails.streamURL); |
| 113 plugin.setAttribute('src', url); | |
| 114 document.body.appendChild(plugin); | 120 document.body.appendChild(plugin); |
| 115 | 121 |
| 116 // Setup the button event listeners. | 122 // Setup the button event listeners. |
| 117 $('fit-to-width-button').addEventListener('click', | 123 $('fit-to-width-button').addEventListener('click', |
| 118 viewport.fitToWidth.bind(viewport)); | 124 viewport.fitToWidth.bind(viewport)); |
| 119 $('fit-to-page-button').addEventListener('click', | 125 $('fit-to-page-button').addEventListener('click', |
| 120 viewport.fitToPage.bind(viewport)); | 126 viewport.fitToPage.bind(viewport)); |
| 121 $('zoom-in-button').addEventListener('click', | 127 $('zoom-in-button').addEventListener('click', |
| 122 viewport.zoomIn.bind(viewport)); | 128 viewport.zoomIn.bind(viewport)); |
| 123 $('zoom-out-button').addEventListener('click', | 129 $('zoom-out-button').addEventListener('click', |
| 124 viewport.zoomOut.bind(viewport)); | 130 viewport.zoomOut.bind(viewport)); |
| 131 $('save-button-link').href = streamDetails.originalURL; |
| 132 $('print-button').addEventListener('click', print); |
| 133 |
| 125 | 134 |
| 126 // Setup keyboard event listeners. | 135 // Setup keyboard event listeners. |
| 127 document.onkeydown = function(e) { | 136 document.onkeydown = function(e) { |
| 128 switch (e.keyCode) { | 137 switch (e.keyCode) { |
| 129 case 37: // Left arrow key. | 138 case 37: // Left arrow key. |
| 130 // Go to the previous page if there are no horizontal scrollbars. | 139 // Go to the previous page if there are no horizontal scrollbars. |
| 131 if (!viewport.documentHasScrollbars().x) { | 140 if (!viewport.documentHasScrollbars().x) { |
| 132 viewport.goToPage(viewport.getMostVisiblePage() - 1); | 141 viewport.goToPage(viewport.getMostVisiblePage() - 1); |
| 133 // Since we do the movement of the page | 142 // Since we do the movement of the page |
| 134 e.preventDefault(); | 143 e.preventDefault(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 e.preventDefault(); | 164 e.preventDefault(); |
| 156 } | 165 } |
| 157 return; | 166 return; |
| 158 } | 167 } |
| 159 }; | 168 }; |
| 160 } | 169 } |
| 161 | 170 |
| 162 load(); | 171 load(); |
| 163 | 172 |
| 164 })(); | 173 })(); |
| OLD | NEW |