| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Creates a Margins object that holds four margin values. The units in which | 9 * Creates a Margins object that holds four margin values. The units in which |
| 10 * the values are expressed can be any numeric value. | 10 * the values are expressed can be any numeric value. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 this.forceDisplayingMarginLines_ = false; | 279 this.forceDisplayingMarginLines_ = false; |
| 280 this.marginsUI.show(); | 280 this.marginsUI.show(); |
| 281 }, | 281 }, |
| 282 | 282 |
| 283 /** | 283 /** |
| 284 * Adds listeners to all margin related controls. | 284 * Adds listeners to all margin related controls. |
| 285 * @private | 285 * @private |
| 286 */ | 286 */ |
| 287 addEventListeners_: function() { | 287 addEventListeners_: function() { |
| 288 this.marginList_.onchange = this.onMarginsChanged_.bind(this); | 288 this.marginList_.onchange = this.onMarginsChanged_.bind(this); |
| 289 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); | 289 document.addEventListener(customEvents.PDF_LOADED, |
| 290 document.addEventListener('PDFGenerationError', | 290 this.onPDFLoaded_.bind(this)); |
| 291 document.addEventListener(customEvents.PDF_GENERATION_ERROR, |
| 291 this.onPDFGenerationError_.bind(this)); | 292 this.onPDFGenerationError_.bind(this)); |
| 292 }, | 293 }, |
| 293 | 294 |
| 294 /** | 295 /** |
| 295 * Executes when an 'PDFGenerationError' event occurs. | 296 * Executes when a |customEvents.PDF_GENERATION_ERROR| event occurs. |
| 296 * @private | 297 * @private |
| 297 */ | 298 */ |
| 298 onPDFGenerationError_: function() { | 299 onPDFGenerationError_: function() { |
| 299 if (this.isCustomMarginsSelected()) { | 300 if (this.isCustomMarginsSelected()) { |
| 300 this.removeCustomMarginEventListeners_(); | 301 this.removeCustomMarginEventListeners_(); |
| 301 this.marginsUI.hide(); | 302 this.marginsUI.hide(); |
| 302 } | 303 } |
| 303 }, | 304 }, |
| 304 | 305 |
| 305 /** | 306 /** |
| 306 * Executes whenever a "DragEvent" occurs. | 307 * Executes whenever a |customEvents.MARGINS_LINE_DRAG| occurs. |
| 307 * @param {cr.Event} e The event that triggered this listener. | 308 * @param {cr.Event} e The event that triggered this listener. |
| 308 */ | 309 */ |
| 309 onDragEvent_: function(e) { | 310 onMarginsLineDrag_: function(e) { |
| 310 var dragDeltaInPoints = this.convertDragDeltaToPoints_(e.dragDelta); | 311 var dragDeltaInPoints = this.convertDragDeltaToPoints_(e.dragDelta); |
| 311 this.marginsUI.lastClickedMarginsUIPair.updateWhileDragging( | 312 this.marginsUI.lastClickedMarginsUIPair.updateWhileDragging( |
| 312 dragDeltaInPoints, e.destinationPoint); | 313 dragDeltaInPoints, e.destinationPoint); |
| 313 }, | 314 }, |
| 314 | 315 |
| 315 /** | 316 /** |
| 316 * @param {number} dragDelta The difference in pixels between the original | 317 * @param {number} dragDelta The difference in pixels between the original |
| 317 * and current postion of the last clicked margin line. | 318 * and current postion of the last clicked margin line. |
| 318 * @return {number} The difference in points. | 319 * @return {number} The difference in points. |
| 319 * @private | 320 * @private |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 return this.marginsUI_; | 418 return this.marginsUI_; |
| 418 }, | 419 }, |
| 419 | 420 |
| 420 /** | 421 /** |
| 421 * Adds listeners when the custom margins option is selected. | 422 * Adds listeners when the custom margins option is selected. |
| 422 * @private | 423 * @private |
| 423 */ | 424 */ |
| 424 addCustomMarginEventListeners_: function() { | 425 addCustomMarginEventListeners_: function() { |
| 425 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); | 426 $('mainview').onmouseover = this.onMainviewMouseOver_.bind(this); |
| 426 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); | 427 $('sidebar').onmouseover = this.onSidebarMouseOver_.bind(this); |
| 427 this.eventTracker_.add( | 428 this.eventTracker_.add(this.marginsUI, |
| 428 this.marginsUI, 'DragEvent', this.onDragEvent_.bind(this), false); | 429 customEvents.MARGINS_LINE_DRAG, |
| 430 this.onMarginsLineDrag_.bind(this), |
| 431 false); |
| 429 }, | 432 }, |
| 430 | 433 |
| 431 /** | 434 /** |
| 432 * Removes the event listeners associated with the custom margins option. | 435 * Removes the event listeners associated with the custom margins option. |
| 433 * @private | 436 * @private |
| 434 */ | 437 */ |
| 435 removeCustomMarginEventListeners_: function() { | 438 removeCustomMarginEventListeners_: function() { |
| 436 $('mainview').onmouseover = null; | 439 $('mainview').onmouseover = null; |
| 437 $('sidebar').onmouseover = null; | 440 $('sidebar').onmouseover = null; |
| 438 this.eventTracker_.remove(this.marginsUI, 'DragEvent'); | 441 this.eventTracker_.remove(this.marginsUI, customEvents.MARGINS_LINE_DRAG); |
| 439 this.marginsUI.hide(); | 442 this.marginsUI.hide(); |
| 440 }, | 443 }, |
| 441 | 444 |
| 442 /** | 445 /** |
| 443 * Updates |this.marginsUI| depending on the specified margins and the | 446 * Updates |this.marginsUI| depending on the specified margins and the |
| 444 * position of the page within the plugin. | 447 * position of the page within the plugin. |
| 445 * @private | 448 * @private |
| 446 */ | 449 */ |
| 447 drawCustomMarginsUI_: function() { | 450 drawCustomMarginsUI_: function() { |
| 448 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| | 451 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 if (this.isCustomMarginsSelected()) { | 590 if (this.isCustomMarginsSelected()) { |
| 588 this.marginList_.options[ | 591 this.marginList_.options[ |
| 589 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; | 592 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; |
| 590 this.removeCustomMarginEventListeners_(); | 593 this.removeCustomMarginEventListeners_(); |
| 591 this.forceDisplayingMarginLines_ = true; | 594 this.forceDisplayingMarginLines_ = true; |
| 592 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 595 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
| 593 } | 596 } |
| 594 }, | 597 }, |
| 595 | 598 |
| 596 /** | 599 /** |
| 597 * Executes when a PDFLoaded event occurs. | 600 * Executes when a |customEvents.PDF_LOADED| event occurs. |
| 598 * @private | 601 * @private |
| 599 */ | 602 */ |
| 600 onPDFLoaded_: function() { | 603 onPDFLoaded_: function() { |
| 601 if (!previewModifiable) | 604 if (!previewModifiable) |
| 602 fadeOutElement(this.marginsOption_); | 605 fadeOutElement(this.marginsOption_); |
| 603 } | 606 } |
| 604 }; | 607 }; |
| 605 | 608 |
| 606 return { | 609 return { |
| 607 MarginSettings: MarginSettings, | 610 MarginSettings: MarginSettings, |
| 608 PageLayout: PageLayout, | 611 PageLayout: PageLayout, |
| 609 setNumberFormatAndMeasurementSystem: | 612 setNumberFormatAndMeasurementSystem: |
| 610 MarginSettings.setNumberFormatAndMeasurementSystem, | 613 MarginSettings.setNumberFormatAndMeasurementSystem, |
| 611 }; | 614 }; |
| 612 }); | 615 }); |
| OLD | NEW |