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 'getLinkPositionReply': |
| 80 if (this.getLinkPositionCallback_) { |
| 81 this.getLinkPositionCallback_(event.data.x, |
| 82 event.data.y); |
| 83 this.getLinkPositionCallback_ = null; |
| 84 } |
| 85 break; |
79 case 'getSelectedTextReply': | 86 case 'getSelectedTextReply': |
80 if (this.selectedTextCallback_) { | 87 if (this.selectedTextCallback_) { |
81 this.selectedTextCallback_(event.data.selectedText); | 88 this.selectedTextCallback_(event.data.selectedText); |
82 this.selectedTextCallback_ = null; | 89 this.selectedTextCallback_ = null; |
83 } | 90 } |
84 break; | 91 break; |
85 case 'sendKeyEvent': | 92 case 'sendKeyEvent': |
86 if (this.keyEventCallback_) | 93 if (this.keyEventCallback_) |
87 this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent)); | 94 this.keyEventCallback_(DeserializeKeyEvent(event.data.keyEvent)); |
88 break; | 95 break; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 /** | 229 /** |
223 * Send a key event to the extension. | 230 * Send a key event to the extension. |
224 * @param {Event} keyEvent the key event to send to the extension. | 231 * @param {Event} keyEvent the key event to send to the extension. |
225 */ | 232 */ |
226 sendKeyEvent: function(keyEvent) { | 233 sendKeyEvent: function(keyEvent) { |
227 this.sendMessage_({ | 234 this.sendMessage_({ |
228 type: 'sendKeyEvent', | 235 type: 'sendKeyEvent', |
229 keyEvent: SerializeKeyEvent(keyEvent) | 236 keyEvent: SerializeKeyEvent(keyEvent) |
230 }); | 237 }); |
231 }, | 238 }, |
| 239 |
| 240 /** |
| 241 * Get position of the first link in the most visible page of the document. |
| 242 * @return {boolean} true if the function is successful, false if there is an |
| 243 * outstanding request that has not been answered. |
| 244 */ |
| 245 getLinkPosition: function(callback) { |
| 246 if (this.getLinkPositionCallback_) |
| 247 return false; |
| 248 this.getLinkPositionCallback_ = callback; |
| 249 this.sendMessage_({ |
| 250 type: 'getLinkPosition', |
| 251 }); |
| 252 return true; |
| 253 }, |
232 }; | 254 }; |
233 | 255 |
234 /** | 256 /** |
235 * Creates a PDF viewer with a scripting interface. This is basically 1) an | 257 * Creates a PDF viewer with a scripting interface. This is basically 1) an |
236 * iframe which is navigated to the PDF viewer extension and 2) a scripting | 258 * iframe which is navigated to the PDF viewer extension and 2) a scripting |
237 * interface which provides access to various features of the viewer for use | 259 * interface which provides access to various features of the viewer for use |
238 * by print preview and accessibility. | 260 * by print preview and accessibility. |
239 * @param {string} src the source URL of the PDF to load initially. | 261 * @param {string} src the source URL of the PDF to load initially. |
240 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. | 262 * @return {HTMLIFrameElement} the iframe element containing the PDF viewer. |
241 */ | 263 */ |
(...skipping 11 matching lines...) Expand all Loading... |
253 // Add the functions to the iframe so that they can be called directly. | 275 // Add the functions to the iframe so that they can be called directly. |
254 iframe.setViewportChangedCallback = | 276 iframe.setViewportChangedCallback = |
255 client.setViewportChangedCallback.bind(client); | 277 client.setViewportChangedCallback.bind(client); |
256 iframe.setLoadCallback = client.setLoadCallback.bind(client); | 278 iframe.setLoadCallback = client.setLoadCallback.bind(client); |
257 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); | 279 iframe.setKeyEventCallback = client.setKeyEventCallback.bind(client); |
258 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); | 280 iframe.resetPrintPreviewMode = client.resetPrintPreviewMode.bind(client); |
259 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); | 281 iframe.loadPreviewPage = client.loadPreviewPage.bind(client); |
260 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); | 282 iframe.sendKeyEvent = client.sendKeyEvent.bind(client); |
261 return iframe; | 283 return iframe; |
262 } | 284 } |
OLD | NEW |