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