OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('print_preview', function() { | |
6 'strict'; | |
7 | |
8 /** | |
9 * Creates a PreviewArea object. | |
Evan Stade
2011/10/05 03:05:23
explain what PreviewArea is
dpapad
2011/10/05 16:39:49
Done.
| |
10 * @constructor | |
11 */ | |
12 function PreviewArea() { | |
13 // The embedded pdf plugin object. | |
14 this.pdfPlugin_ = null; | |
15 | |
16 // True if the pdf document is loaded in the preview area. | |
17 this.pdfLoaded_ = false; | |
18 | |
19 // Contains the zoom level just before a new preview is requested so the | |
20 // same zoom level can be restored. | |
21 this.zoomLevel_ = null; | |
22 // Contains the page offset values just before a new preview is requested so | |
23 // the same scroll amount can be maintained. | |
24 this.pageOffset_ = null; | |
25 } | |
26 | |
27 cr.addSingletonGetter(PreviewArea); | |
28 | |
29 PreviewArea.prototype = { | |
30 /** | |
31 * The width of the plugin area excluding any visible scrollbars in pixels. | |
32 * @type {number} | |
33 */ | |
34 get width() { | |
35 return this.widthPercent * this.pdfPlugin_.offsetWidth; | |
36 }, | |
37 | |
38 /** | |
39 * The height of the plugin area excluding any visible scrollbars in pixels. | |
40 * @type {number} | |
41 */ | |
42 get height() { | |
43 return this.heightPercent * this.pdfPlugin_.offsetHeight; | |
44 }, | |
45 | |
46 /** | |
47 * The width of the plugin area excluding any visible scrollbars in percent. | |
48 * @type {number} | |
49 */ | |
50 get widthPercent() { | |
51 var width = this.pdfPlugin_.getWidth(); | |
52 var scrollbarWidth = this.pdfPlugin_.getVerticalScrollbarThickness(); | |
53 return (width - scrollbarWidth) / width; | |
54 }, | |
55 | |
56 /** | |
57 * The height of the plugin area excluding any visible scrollbars in | |
58 * percent. | |
59 * @type {number} | |
60 */ | |
61 get heightPercent() { | |
62 var height = this.pdfPlugin_.getHeight(); | |
63 var scrollbarHeight = this.pdfPlugin_.getHorizontalScrollbarThickness(); | |
64 return (height - scrollbarHeight) / height; | |
65 }, | |
66 | |
67 get pdfLoaded() { | |
68 return this.pdfLoaded_; | |
69 }, | |
70 | |
71 set pdfLoaded(pdfLoaded) { | |
72 this.pdfLoaded_ = pdfLoaded; | |
73 }, | |
74 | |
75 /** | |
76 * @return {print_preview.Rect} A rectangle describing the postion of the | |
77 * most visible page normalized with respect to the total height and width | |
78 * of the plugin. | |
79 */ | |
80 getPageLocationNormalized: function() { | |
81 var pluginLocation = | |
82 this.pdfPlugin_.getPageLocationNormalized().split(';'); | |
83 return new print_preview.Rect(parseFloat(pluginLocation[0]), | |
84 parseFloat(pluginLocation[1]), | |
85 parseFloat(pluginLocation[2]), | |
86 parseFloat(pluginLocation[3])); | |
87 }, | |
88 | |
89 /** | |
90 * Resets the state variables of |this|. | |
91 */ | |
92 resetState: function() { | |
93 if (this.pdfPlugin_) { | |
94 this.zoomLevel_ = this.pdfPlugin_.getZoomLevel(); | |
95 this.pageOffset_ = new print_preview.Point( | |
96 this.pdfPlugin_.pageXOffset(), | |
97 this.pdfPlugin_.pageYOffset()); | |
98 } | |
99 this.pdfLoaded_ = false; | |
100 }, | |
101 | |
102 /** | |
103 * Adds event listeners for various events. | |
104 * @private | |
105 */ | |
106 addEventListeners: function() { | |
107 document.addEventListener('PDFLoaded', | |
108 this.onPDFLoaded_.bind(this)); | |
109 }, | |
110 | |
111 /** | |
112 * Listener executing when a PDFLoaded event occurs. | |
113 * @private | |
114 */ | |
115 onPDFLoaded_: function() { | |
116 this.pdfPlugin_ = $('pdf-viewer'); | |
117 this.pdfLoaded_ = true; | |
118 if (this.zoomLevel_ != null && this.pageOffset_ != null) { | |
119 this.pdfPlugin_.setZoomLevel(this.zoomLevel_); | |
120 this.pdfPlugin_.setPageXOffset(this.pageOffset_.x); | |
121 this.pdfPlugin_.setPageYOffset(this.pageOffset_.y); | |
122 } else { | |
123 this.pdfPlugin_.fitToHeight(); | |
124 } | |
125 } | |
126 }; | |
127 | |
128 return { | |
129 PreviewArea: PreviewArea, | |
130 }; | |
131 }); | |
OLD | NEW |