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(true); | 302 this.marginsUI.hide(true); |
302 } | 303 } |
303 }, | 304 }, |
304 | 305 |
305 /** | 306 /** |
306 * Executes whenever a "DragEvent" occurs. | 307 * Executes whenever a |customEvents.MARGIN_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.MARGIN_LINE_DRAG, |
429 this.eventTracker_.add(document, 'marginTextboxFocused', | 430 this.onMarginsLineDrag_.bind(this), |
| 431 false); |
| 432 this.eventTracker_.add(document, customEvents.MARGIN_TEXTBOX_FOCUSED, |
430 this.onMarginTextboxFocused_.bind(this), false); | 433 this.onMarginTextboxFocused_.bind(this), false); |
431 }, | 434 }, |
432 | 435 |
433 /** | 436 /** |
434 * Removes the event listeners associated with the custom margins option. | 437 * Removes the event listeners associated with the custom margins option. |
435 * @private | 438 * @private |
436 */ | 439 */ |
437 removeCustomMarginEventListeners_: function() { | 440 removeCustomMarginEventListeners_: function() { |
438 $('mainview').onmouseover = null; | 441 $('mainview').onmouseover = null; |
439 $('sidebar').onmouseover = null; | 442 $('sidebar').onmouseover = null; |
440 this.eventTracker_.remove(this.marginsUI, 'DragEvent'); | 443 this.eventTracker_.remove(this.marginsUI, customEvents.MARGIN_LINE_DRAG); |
441 this.eventTracker_.remove(document, 'marginTextboxFocused'); | 444 this.eventTracker_.remove(document, customEvents.MARGIN_TEXTBOX_FOCUSED); |
442 this.marginsUI.hide(true); | 445 this.marginsUI.hide(true); |
443 }, | 446 }, |
444 | 447 |
445 /** | 448 /** |
446 * Updates |this.marginsUI| depending on the specified margins and the | 449 * Updates |this.marginsUI| depending on the specified margins and the |
447 * position of the page within the plugin. | 450 * position of the page within the plugin. |
448 * @private | 451 * @private |
449 */ | 452 */ |
450 drawCustomMarginsUI_: function() { | 453 drawCustomMarginsUI_: function() { |
451 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| | 454 // TODO(dpapad): find out why passing |!this.areMarginsSettingsValid()| |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 if (this.isCustomMarginsSelected()) { | 603 if (this.isCustomMarginsSelected()) { |
601 this.marginList_.options[ | 604 this.marginList_.options[ |
602 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; | 605 MarginSettings.DEFAULT_MARGINS_OPTION_INDEX].selected = true; |
603 this.removeCustomMarginEventListeners_(); | 606 this.removeCustomMarginEventListeners_(); |
604 this.forceDisplayingMarginLines_ = true; | 607 this.forceDisplayingMarginLines_ = true; |
605 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; | 608 this.lastSelectedOption_ = MarginSettings.MARGINS_VALUE_DEFAULT; |
606 } | 609 } |
607 }, | 610 }, |
608 | 611 |
609 /** | 612 /** |
610 * Executes when a PDFLoaded event occurs. | 613 * Executes when a |customEvents.PDF_LOADED| event occurs. |
611 * @private | 614 * @private |
612 */ | 615 */ |
613 onPDFLoaded_: function() { | 616 onPDFLoaded_: function() { |
614 if (!previewModifiable) | 617 if (!previewModifiable) |
615 fadeOutElement(this.marginsOption_); | 618 fadeOutElement(this.marginsOption_); |
616 } | 619 } |
617 }; | 620 }; |
618 | 621 |
619 return { | 622 return { |
620 MarginSettings: MarginSettings, | 623 MarginSettings: MarginSettings, |
621 PageLayout: PageLayout, | 624 PageLayout: PageLayout, |
622 setNumberFormatAndMeasurementSystem: | 625 setNumberFormatAndMeasurementSystem: |
623 MarginSettings.setNumberFormatAndMeasurementSystem, | 626 MarginSettings.setNumberFormatAndMeasurementSystem, |
624 }; | 627 }; |
625 }); | 628 }); |
OLD | NEW |