OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
6 * Turn a dictionary received from postMessage into a key event. | 6 * Turn a dictionary received from postMessage into a key event. |
7 * @param {Object} dict A dictionary representing the key event. | 7 * @param {Object} dict A dictionary representing the key event. |
8 * @return {Event} A key event. | 8 * @return {Event} A key event. |
9 */ | 9 */ |
10 function DeserializeKeyEvent(dict) { | 10 function DeserializeKeyEvent(dict) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 event.data.pageY, | 69 event.data.pageY, |
70 event.data.pageWidth, | 70 event.data.pageWidth, |
71 event.data.viewportWidth, | 71 event.data.viewportWidth, |
72 event.data.viewportHeight); | 72 event.data.viewportHeight); |
73 break; | 73 break; |
74 case 'documentLoaded': | 74 case 'documentLoaded': |
75 this.loadState_ = event.data.load_state; | 75 this.loadState_ = event.data.load_state; |
76 if (this.loadCallback_) | 76 if (this.loadCallback_) |
77 this.loadCallback_(this.loadState_ == LoadState.SUCCESS); | 77 this.loadCallback_(this.loadState_ == LoadState.SUCCESS); |
78 break; | 78 break; |
79 case 'getAccessibilityJSONReply': | |
80 if (this.accessibilityCallback_) { | |
81 this.accessibilityCallback_(event.data.json); | |
82 this.accessibilityCallback_ = null; | |
83 } | |
84 break; | |
85 case 'getSelectedTextReply': | 79 case 'getSelectedTextReply': |
86 if (this.selectedTextCallback_) { | 80 if (this.selectedTextCallback_) { |
87 this.selectedTextCallback_(event.data.selectedText); | 81 this.selectedTextCallback_(event.data.selectedText); |
88 this.selectedTextCallback_ = null; | 82 this.selectedTextCallback_ = null; |
89 } | 83 } |
90 break; | 84 break; |
91 case 'sendKeyEvent': | 85 case 'sendKeyEvent': |
92 if (this.keyEventCallback_) | 86 if (this.keyEventCallback_) |
93 this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent)); | 87 this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent)); |
94 break; | 88 break; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 */ | 177 */ |
184 loadPreviewPage: function(url, index) { | 178 loadPreviewPage: function(url, index) { |
185 this.sendMessage_({ | 179 this.sendMessage_({ |
186 type: 'loadPreviewPage', | 180 type: 'loadPreviewPage', |
187 url: url, | 181 url: url, |
188 index: index | 182 index: index |
189 }); | 183 }); |
190 }, | 184 }, |
191 | 185 |
192 /** | 186 /** |
193 * Get accessibility JSON for the document. May only be called after document | |
194 * load. | |
195 * @param {Function} callback a callback to be called with the accessibility | |
196 * json that has been retrieved. | |
197 * @param {number} [page] the 0-indexed page number to get accessibility data | |
198 * for. If this is not provided, data about the entire document is | |
199 * returned. | |
200 * @return {boolean} true if the function is successful, false if there is an | |
201 * outstanding request for accessibility data that has not been answered. | |
202 */ | |
203 getAccessibilityJSON: function(callback, page) { | |
204 if (this.accessibilityCallback_) | |
205 return false; | |
206 this.accessibilityCallback_ = callback; | |
207 var message = { | |
208 type: 'getAccessibilityJSON', | |
209 }; | |
210 if (page || page == 0) | |
211 message.page = page; | |
212 this.sendMessage_(message); | |
213 return true; | |
214 }, | |
215 | |
216 /** | |
217 * Select all the text in the document. May only be called after document | 187 * Select all the text in the document. May only be called after document |
218 * load. | 188 * load. |
219 */ | 189 */ |
220 selectAll: function() { | 190 selectAll: function() { |
221 this.sendMessage_({ | 191 this.sendMessage_({ |
222 type: 'selectAll' | 192 type: 'selectAll' |
223 }); | 193 }); |
224 }, | 194 }, |
225 | 195 |
226 /** | 196 /** |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // Add the functions to the iframe so that they can be called directly. | 253 // Add the functions to the iframe so that they can be called directly. |
284 iframe.setViewportChangedCallback = | 254 iframe.setViewportChangedCallback = |
285 client.setViewportChangedCallback.bind(client); | 255 client.setViewportChangedCallback.bind(client); |
286 iframe.setLoadCallback = client.setLoadCallback.bind(client); | 256 iframe.setLoadCallback = client.setLoadCallback.bind(client); |
287 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); | 257 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); |
288 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); | 258 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); |
289 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); | 259 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); |
290 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); | 260 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); |
291 return iframe; | 261 return iframe; |
292 } | 262 } |
OLD | NEW |