| 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 |
| 11 // positioning, acting as a viewport. The plugin renders into this viewport | 11 // positioning, acting as a viewport. The plugin renders into this viewport |
| 12 // according to the scroll position of the window. | 12 // according to the scroll position of the window. |
| 13 var gPlugin; | 13 var gPlugin; |
| 14 | 14 |
| 15 // This element is placed behind the plugin element to cause scrollbars to be | 15 // This element is placed behind the plugin element to cause scrollbars to be |
| 16 // displayed in the window. It is sized according to the document size of the | 16 // displayed in the window. It is sized according to the document size of the |
| 17 // pdf and zoom level. | 17 // pdf and zoom level. |
| 18 var gSizer; | 18 var gSizer; |
| 19 | 19 |
| 20 // The toolbar element. | 20 // The toolbar element. |
| 21 var gViewerToolbar; | 21 var gViewerToolbar; |
| 22 | 22 |
| 23 // The page indicator element. |
| 24 var gViewerPageIndicator; |
| 25 |
| 26 // The progress bar element. |
| 27 var gViewerProgressBar; |
| 28 |
| 23 // The viewport object. | 29 // The viewport object. |
| 24 var gViewport; | 30 var gViewport; |
| 25 | 31 |
| 26 // Returns true if the fit-to-page button is enabled. | 32 // Returns true if the fit-to-page button is enabled. |
| 27 function isFitToPageEnabled() { | 33 function isFitToPageEnabled() { |
| 28 return $('btn-ftp').classList.contains('polymer-selected'); | 34 return $('fit-to-page-button').classList.contains('polymer-selected'); |
| 29 } | 35 } |
| 30 | 36 |
| 31 // Called when a message is received from the plugin. | 37 // Called when a message is received from the plugin. |
| 32 function handleMessage(message) { | 38 function handleMessage(message) { |
| 33 if (message.data.type == 'documentDimensions') { | 39 if (message.data.type == 'documentDimensions') { |
| 34 gViewport.setDocumentDimensions(message.data); | 40 gViewport.setDocumentDimensions(message.data); |
| 41 } else if (message.data.type == 'loadProgress') { |
| 42 gViewerProgressBar.progress = message.data['progress']; |
| 35 } | 43 } |
| 36 } | 44 } |
| 37 | 45 |
| 38 // Callback that's called when the viewport changes. | 46 // Callback that's called when the viewport changes. |
| 39 function viewportChangedCallback(zoom, x, y, scrollbarWidth, hasScrollbars) { | 47 function viewportChangedCallback(zoom, |
| 48 x, |
| 49 y, |
| 50 scrollbarWidth, |
| 51 hasScrollbars, |
| 52 page) { |
| 40 // Offset the toolbar position so that it doesn't move if scrollbars appear. | 53 // Offset the toolbar position so that it doesn't move if scrollbars appear. |
| 41 var toolbarRight = hasScrollbars.y ? 0 : scrollbarWidth; | 54 var toolbarRight = hasScrollbars.y ? 0 : scrollbarWidth; |
| 42 var toolbarBottom = hasScrollbars.x ? 0 : scrollbarWidth; | 55 var toolbarBottom = hasScrollbars.x ? 0 : scrollbarWidth; |
| 43 gViewerToolbar.style.right = toolbarRight + 'px'; | 56 gViewerToolbar.style.right = toolbarRight + 'px'; |
| 44 gViewerToolbar.style.bottom = toolbarBottom + 'px'; | 57 gViewerToolbar.style.bottom = toolbarBottom + 'px'; |
| 45 | 58 |
| 59 // Update the most visible page. |
| 60 gViewerPageIndicator.text = page + 1; |
| 61 |
| 46 // Notify the plugin of the viewport change. | 62 // Notify the plugin of the viewport change. |
| 47 gPlugin.postMessage({ | 63 gPlugin.postMessage({ |
| 48 type: 'viewport', | 64 type: 'viewport', |
| 49 zoom: zoom, | 65 zoom: zoom, |
| 50 xOffset: x, | 66 xOffset: x, |
| 51 yOffset: y | 67 yOffset: y |
| 52 }); | 68 }); |
| 53 } | 69 } |
| 54 | 70 |
| 55 function load() { | 71 function load() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 85 $('fit-to-width-button').addEventListener('click', | 101 $('fit-to-width-button').addEventListener('click', |
| 86 function() { gViewport.fitToWidth(); }); | 102 function() { gViewport.fitToWidth(); }); |
| 87 $('fit-to-page-button').addEventListener('click', | 103 $('fit-to-page-button').addEventListener('click', |
| 88 function() { gViewport.fitToPage(); }); | 104 function() { gViewport.fitToPage(); }); |
| 89 $('zoom-in-button').addEventListener('click', | 105 $('zoom-in-button').addEventListener('click', |
| 90 function() { gViewport.zoomIn(); }); | 106 function() { gViewport.zoomIn(); }); |
| 91 $('zoom-out-button').addEventListener('click', | 107 $('zoom-out-button').addEventListener('click', |
| 92 function() { gViewport.zoomOut(); }); | 108 function() { gViewport.zoomOut(); }); |
| 93 | 109 |
| 94 gViewerToolbar = $('toolbar'); | 110 gViewerToolbar = $('toolbar'); |
| 111 gViewerPageIndicator = $('page-indicator'); |
| 112 gViewerProgressBar = $('progress-bar'); |
| 95 | 113 |
| 96 // Setup keyboard event listeners. | 114 // Setup keyboard event listeners. |
| 97 document.onkeydown = function(e) { | 115 document.onkeydown = function(e) { |
| 98 switch (e.keyCode) { | 116 switch (e.keyCode) { |
| 99 case 37: // Left arrow key. | 117 case 37: // Left arrow key. |
| 100 // Go to the previous page if there are no horizontal scrollbars. | 118 // Go to the previous page if there are no horizontal scrollbars. |
| 101 if (!gViewport.documentHasScrollbars().x) { | 119 if (!gViewport.documentHasScrollbars().x) { |
| 102 gViewport.goToPage(gViewport.getMostVisiblePage() - 1); | 120 gViewport.goToPage(gViewport.getMostVisiblePage() - 1); |
| 103 e.stopPropagation(); | 121 e.stopPropagation(); |
| 104 return false; | 122 return false; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 return false; | 146 return false; |
| 129 } | 147 } |
| 130 return true; | 148 return true; |
| 131 } | 149 } |
| 132 }; | 150 }; |
| 133 } | 151 } |
| 134 | 152 |
| 135 load(); | 153 load(); |
| 136 | 154 |
| 137 })(); | 155 })(); |
| OLD | NEW |