| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 this.errorScreen_.text = message.data.loadFailedString; | 348 this.errorScreen_.text = message.data.loadFailedString; |
| 347 break; | 349 break; |
| 348 case 'cancelStreamUrl': | 350 case 'cancelStreamUrl': |
| 349 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); | 351 chrome.streamsPrivate.abort(this.streamDetails.streamUrl); |
| 350 break; | 352 break; |
| 351 } | 353 } |
| 352 }, | 354 }, |
| 353 | 355 |
| 354 /** | 356 /** |
| 355 * @private | 357 * @private |
| 356 * A callback that's called when the viewport changes. | 358 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 359 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 357 */ | 360 */ |
| 358 viewportChangedCallback_: function() { | 361 beforeZoom_: function() { |
| 362 this.plugin_.postMessage({ |
| 363 type: 'stopScrolling' |
| 364 }); |
| 365 }, |
| 366 |
| 367 /** |
| 368 * @private |
| 369 * A callback that's called after the zoom changes. Notify the plugin of the |
| 370 * zoom change and to continue reacting to scroll events. |
| 371 */ |
| 372 afterZoom_: function() { |
| 373 var position = this.viewport_.position; |
| 374 var zoom = this.viewport_.zoom; |
| 375 this.plugin_.postMessage({ |
| 376 type: 'viewport', |
| 377 zoom: zoom, |
| 378 xOffset: position.x, |
| 379 yOffset: position.y |
| 380 }); |
| 381 }, |
| 382 |
| 383 /** |
| 384 * @private |
| 385 * A callback that's called after the viewport changes. |
| 386 */ |
| 387 viewportChanged_: function() { |
| 359 if (!this.documentDimensions_) | 388 if (!this.documentDimensions_) |
| 360 return; | 389 return; |
| 361 | 390 |
| 362 // Update the buttons selected. | 391 // Update the buttons selected. |
| 363 $('fit-to-page-button').classList.remove('polymer-selected'); | 392 $('fit-to-page-button').classList.remove('polymer-selected'); |
| 364 $('fit-to-width-button').classList.remove('polymer-selected'); | 393 $('fit-to-width-button').classList.remove('polymer-selected'); |
| 365 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { | 394 if (this.viewport_.fittingType == Viewport.FittingType.FIT_TO_PAGE) { |
| 366 $('fit-to-page-button').classList.add('polymer-selected'); | 395 $('fit-to-page-button').classList.add('polymer-selected'); |
| 367 } else if (this.viewport_.fittingType == | 396 } else if (this.viewport_.fittingType == |
| 368 Viewport.FittingType.FIT_TO_WIDTH) { | 397 Viewport.FittingType.FIT_TO_WIDTH) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 384 // Update the page indicator. | 413 // Update the page indicator. |
| 385 var visiblePage = this.viewport_.getMostVisiblePage(); | 414 var visiblePage = this.viewport_.getMostVisiblePage(); |
| 386 this.pageIndicator_.index = visiblePage; | 415 this.pageIndicator_.index = visiblePage; |
| 387 if (this.documentDimensions_.pageDimensions.length > 1 && | 416 if (this.documentDimensions_.pageDimensions.length > 1 && |
| 388 hasScrollbars.vertical) { | 417 hasScrollbars.vertical) { |
| 389 this.pageIndicator_.style.visibility = 'visible'; | 418 this.pageIndicator_.style.visibility = 'visible'; |
| 390 } else { | 419 } else { |
| 391 this.pageIndicator_.style.visibility = 'hidden'; | 420 this.pageIndicator_.style.visibility = 'hidden'; |
| 392 } | 421 } |
| 393 | 422 |
| 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); | 423 var visiblePageDimensions = this.viewport_.getPageScreenRect(visiblePage); |
| 405 var size = this.viewport_.size; | 424 var size = this.viewport_.size; |
| 406 this.sendScriptingMessage_({ | 425 this.sendScriptingMessage_({ |
| 407 type: 'viewport', | 426 type: 'viewport', |
| 408 pageX: visiblePageDimensions.x, | 427 pageX: visiblePageDimensions.x, |
| 409 pageY: visiblePageDimensions.y, | 428 pageY: visiblePageDimensions.y, |
| 410 pageWidth: visiblePageDimensions.width, | 429 pageWidth: visiblePageDimensions.width, |
| 411 viewportWidth: size.width, | 430 viewportWidth: size.width, |
| 412 viewportHeight: size.height, | 431 viewportHeight: size.height, |
| 413 }); | 432 }); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 497 |
| 479 /** | 498 /** |
| 480 * @type {Viewport} the viewport of the PDF viewer. | 499 * @type {Viewport} the viewport of the PDF viewer. |
| 481 */ | 500 */ |
| 482 get viewport() { | 501 get viewport() { |
| 483 return this.viewport_; | 502 return this.viewport_; |
| 484 } | 503 } |
| 485 }; | 504 }; |
| 486 | 505 |
| 487 var viewer = new PDFViewer(); | 506 var viewer = new PDFViewer(); |
| OLD | NEW |