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 '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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 this.pageIndicator_ = $('page-indicator'); | 45 this.pageIndicator_ = $('page-indicator'); |
46 this.progressBar_ = $('progress-bar'); | 46 this.progressBar_ = $('progress-bar'); |
47 this.passwordScreen_ = $('password-screen'); | 47 this.passwordScreen_ = $('password-screen'); |
48 this.passwordScreen_.addEventListener('password-submitted', | 48 this.passwordScreen_.addEventListener('password-submitted', |
49 this.onPasswordSubmitted_.bind(this)); | 49 this.onPasswordSubmitted_.bind(this)); |
50 this.errorScreen_ = $('error-screen'); | 50 this.errorScreen_ = $('error-screen'); |
51 | 51 |
52 // Create the viewport. | 52 // Create the viewport. |
53 this.viewport_ = new Viewport(window, | 53 this.viewport_ = new Viewport(window, |
54 this.sizer_, | 54 this.sizer_, |
55 this.viewportChangedCallback_.bind(this), | 55 this.viewportChanged_.bind(this), |
| 56 this.beforeZoom_.bind(this), |
| 57 this.afterZoom_.bind(this), |
56 getScrollbarWidth()); | 58 getScrollbarWidth()); |
57 | 59 |
58 // Create the plugin object dynamically so we can set its src. The plugin | 60 // Create the plugin object dynamically so we can set its src. The plugin |
59 // element is sized to fill the entire window and is set to be fixed | 61 // element is sized to fill the entire window and is set to be fixed |
60 // positioning, acting as a viewport. The plugin renders into this viewport | 62 // positioning, acting as a viewport. The plugin renders into this viewport |
61 // according to the scroll position of the window. | 63 // according to the scroll position of the window. |
62 this.plugin_ = document.createElement('object'); | 64 this.plugin_ = document.createElement('object'); |
63 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 65 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
64 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 66 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
65 this.plugin_.id = 'plugin'; | 67 this.plugin_.id = 'plugin'; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 for (var header in this.streamDetails.responseHeaders) { | 104 for (var header in this.streamDetails.responseHeaders) { |
103 headers += header + ': ' + | 105 headers += header + ': ' + |
104 this.streamDetails.responseHeaders[header] + '\n'; | 106 this.streamDetails.responseHeaders[header] + '\n'; |
105 } | 107 } |
106 this.plugin_.setAttribute('headers', headers); | 108 this.plugin_.setAttribute('headers', headers); |
107 | 109 |
108 if (window.top == window) | 110 if (window.top == window) |
109 this.plugin_.setAttribute('full-frame', ''); | 111 this.plugin_.setAttribute('full-frame', ''); |
110 document.body.appendChild(this.plugin_); | 112 document.body.appendChild(this.plugin_); |
111 | 113 |
| 114 // TODO(raymes): Remove this spurious message once crbug.com/388606 is fixed. |
| 115 // This is a hack to initialize pepper sync scripting and avoid re-entrancy. |
| 116 this.plugin_.postMessage({ |
| 117 type: 'viewport', |
| 118 zoom: 1, |
| 119 xOffset: 0, |
| 120 yOffset: 0 |
| 121 }); |
| 122 |
112 // Setup the button event listeners. | 123 // Setup the button event listeners. |
113 $('fit-to-width-button').addEventListener('click', | 124 $('fit-to-width-button').addEventListener('click', |
114 this.viewport_.fitToWidth.bind(this.viewport_)); | 125 this.viewport_.fitToWidth.bind(this.viewport_)); |
115 $('fit-to-page-button').addEventListener('click', | 126 $('fit-to-page-button').addEventListener('click', |
116 this.viewport_.fitToPage.bind(this.viewport_)); | 127 this.viewport_.fitToPage.bind(this.viewport_)); |
117 $('zoom-in-button').addEventListener('click', | 128 $('zoom-in-button').addEventListener('click', |
118 this.viewport_.zoomIn.bind(this.viewport_)); | 129 this.viewport_.zoomIn.bind(this.viewport_)); |
119 $('zoom-out-button').addEventListener('click', | 130 $('zoom-out-button').addEventListener('click', |
120 this.viewport_.zoomOut.bind(this.viewport_)); | 131 this.viewport_.zoomOut.bind(this.viewport_)); |
121 $('save-button-link').href = this.streamDetails.originalUrl; | 132 $('save-button-link').href = this.streamDetails.originalUrl; |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 this.errorScreen_.text = message.data.loadFailedString; | 357 this.errorScreen_.text = message.data.loadFailedString; |
347 break; | 358 break; |
348 case 'cancelStreamUrl': | 359 case 'cancelStreamUrl': |
349 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); | 360 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); |
350 break; | 361 break; |
351 } | 362 } |
352 }, | 363 }, |
353 | 364 |
354 /** | 365 /** |
355 * @private | 366 * @private |
356 * A callback that's called when the viewport changes. | 367 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 368 * reacting to scroll events while zoom is taking place to avoid flickering. |
357 */ | 369 */ |
358 viewportChangedCallback_: function() { | 370 beforeZoom_: function() { |
| 371 this.plugin_.postMessage({ |
| 372 type: 'stopScrolling' |
| 373 }); |
| 374 }, |
| 375 |
| 376 /** |
| 377 * @private |
| 378 * A callback that's called after the zoom changes. Notify the plugin of the |
| 379 * zoom change and to continue reacting to scroll events. |
| 380 */ |
| 381 afterZoom_: function() { |
| 382 var position = this.viewport_.position; |
| 383 var zoom = this.viewport_.zoom; |
| 384 this.plugin_.postMessage({ |
| 385 type: 'viewport', |
| 386 zoom: zoom, |
| 387 xOffset: position.x, |
| 388 yOffset: position.y |
| 389 }); |
| 390 }, |
| 391 |
| 392 /** |
| 393 * @private |
| 394 * A callback that's called after the viewport changes. |
| 395 */ |
| 396 viewportChanged_: function() { |
359 if (!this.documentDimensions_) | 397 if (!this.documentDimensions_) |
360 return; | 398 return; |
361 | 399 |
362 // Update the buttons selected. | 400 // Update the buttons selected. |
363 $('fit-to-page-button').classList.remove('polymer-selected'); | 401 $('fit-to-page-button').classList.remove('polymer-selected'); |
364 $('fit-to-width-button').classList.remove('polymer-selected'); | 402 $('fit-to-width-button').classList.remove('polymer-selected'); |
365 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 403 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
366 $('fit-to-page-button').classList.add('polymer-selected'); | 404 $('fit-to-page-button').classList.add('polymer-selected'); |
367 } else if (this.viewport_.fittingType == | 405 } else if (this.viewport_.fittingType == |
368 Viewport.FittingType.FIT_TO_WIDTH) { | 406 Viewport.FittingType.FIT_TO_WIDTH) { |
(...skipping 15 matching lines...) Expand all Loading... |
384 // Update the page indicator. | 422 // Update the page indicator. |
385 var visiblePage = this.viewport_.getMostVisiblePage(); | 423 var visiblePage = this.viewport_.getMostVisiblePage(); |
386 this.pageIndicator_.index = visiblePage; | 424 this.pageIndicator_.index = visiblePage; |
387 if (this.documentDimensions_.pageDimensions.length > 1 && | 425 if (this.documentDimensions_.pageDimensions.length > 1 && |
388 hasScrollbars.vertical) { | 426 hasScrollbars.vertical) { |
389 this.pageIndicator_.style.visibility = 'visible'; | 427 this.pageIndicator_.style.visibility = 'visible'; |
390 } else { | 428 } else { |
391 this.pageIndicator_.style.visibility = 'hidden'; | 429 this.pageIndicator_.style.visibility = 'hidden'; |
392 } | 430 } |
393 | 431 |
394 var position = this.viewport_.position; | |
395 var zoom = this.viewport_.zoom; | |
396 // Notify the plugin of the viewport change. | |
397 this.plugin_.postMessage({ | |
398 type: 'viewport', | |
399 zoom: zoom, | |
400 xOffset: position.x, | |
401 yOffset: position.y | |
402 }); | |
403 | |
404 var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage); | 432 var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage); |
405 var size = this.viewport_.size; | 433 var size = this.viewport_.size; |
406 this.sendScriptingMessage_({ | 434 this.sendScriptingMessage_({ |
407 type: 'viewport', | 435 type: 'viewport', |
408 pageX: visiblePageDimensions.x, | 436 pageX: visiblePageDimensions.x, |
409 pageY: visiblePageDimensions.y, | 437 pageY: visiblePageDimensions.y, |
410 pageWidth: visiblePageDimensions.width, | 438 pageWidth: visiblePageDimensions.width, |
411 viewportWidth: size.width, | 439 viewportWidth: size.width, |
412 viewportHeight: size.height, | 440 viewportHeight: size.height, |
413 }); | 441 }); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 506 |
479 /** | 507 /** |
480 * @type {Viewport} the viewport of the PDF viewer. | 508 * @type {Viewport} the viewport of the PDF viewer. |
481 */ | 509 */ |
482 get viewport() { | 510 get viewport() { |
483 return this.viewport_; | 511 return this.viewport_; |
484 } | 512 } |
485 }; | 513 }; |
486 | 514 |
487 var viewer = new PDFViewer(); | 515 var viewer = new PDFViewer(); |
OLD | NEW |