| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @constructor | 8 * @constructor |
| 9 */ | 9 */ |
| 10 function MessageWindowImpl() { | 10 function MessageWindowImpl() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 }; | 38 }; |
| 39 parentWindow.postMessage(message, '*'); | 39 parentWindow.postMessage(message, '*'); |
| 40 this.sentReply_ = true; | 40 this.sentReply_ = true; |
| 41 } else { | 41 } else { |
| 42 // Make sure that the reply we're ignoring is from the window close. | 42 // Make sure that the reply we're ignoring is from the window close. |
| 43 base.debug.assert(result == 0); | 43 base.debug.assert(result == 0); |
| 44 } | 44 } |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * Size the window to its content vertically. | |
| 49 * @private | |
| 50 */ | |
| 51 MessageWindowImpl.prototype.updateSize_ = function() { | |
| 52 var outerBounds = chrome.app.window.current().outerBounds; | |
| 53 var innerBounds = chrome.app.window.current().innerBounds; | |
| 54 var borderY = outerBounds.height - innerBounds.height; | |
| 55 window.resizeTo(outerBounds.width, document.body.clientHeight + borderY); | |
| 56 // Sometimes, resizing the window causes its position to be reset to (0, 0), | |
| 57 // so restore it explicitly. | |
| 58 window.moveTo(outerBounds.left, outerBounds.top); | |
| 59 }; | |
| 60 | |
| 61 /** | |
| 62 * Initializes the button with the label and the click handler. | 48 * Initializes the button with the label and the click handler. |
| 63 * Hides the button if the label is null or undefined. | 49 * Hides the button if the label is null or undefined. |
| 64 * | 50 * |
| 65 * @param{HTMLElement} button | 51 * @param{HTMLElement} button |
| 66 * @param{?string} label | 52 * @param{?string} label |
| 67 * @param{Function} clickHandler | 53 * @param{Function} clickHandler |
| 68 * @private | 54 * @private |
| 69 */ | 55 */ |
| 70 MessageWindowImpl.prototype.initButton_ = | 56 MessageWindowImpl.prototype.initButton_ = |
| 71 function(button, label, clickHandler) { | 57 function(button, label, clickHandler) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 var buttonToFocus = (cancelButtonLabel) ? cancelButton : button; | 124 var buttonToFocus = (cancelButtonLabel) ? cancelButton : button; |
| 139 buttonToFocus.focus(); | 125 buttonToFocus.focus(); |
| 140 | 126 |
| 141 // Add a close handler in case the window is closed without clicking one | 127 // Add a close handler in case the window is closed without clicking one |
| 142 // of the buttons. This will send a 0 as the result. | 128 // of the buttons. This will send a 0 as the result. |
| 143 // Note that when a button is pressed, this will result in sendReply_ | 129 // Note that when a button is pressed, this will result in sendReply_ |
| 144 // being called multiple times (once for the button, once for close). | 130 // being called multiple times (once for the button, once for close). |
| 145 chrome.app.window.current().onClosed.addListener( | 131 chrome.app.window.current().onClosed.addListener( |
| 146 this.sendReply_.bind(this, event.source, messageId, 0)); | 132 this.sendReply_.bind(this, event.source, messageId, 0)); |
| 147 | 133 |
| 148 this.updateSize_(); | 134 base.resizeWindowToContent(); |
| 149 chrome.app.window.current().show(); | 135 chrome.app.window.current().show(); |
| 150 break; | 136 break; |
| 151 | 137 |
| 152 case 'update_message': | 138 case 'update_message': |
| 153 var message = /** @type {string} */ (event.data['message']); | 139 var message = /** @type {string} */ (event.data['message']); |
| 154 if (typeof(message) != 'string') { | 140 if (typeof(message) != 'string') { |
| 155 console.log('Bad update_message message:', event.data); | 141 console.log('Bad update_message message:', event.data); |
| 156 break; | 142 break; |
| 157 } | 143 } |
| 158 | 144 |
| 159 var messageDiv = document.getElementById('message'); | 145 var messageDiv = document.getElementById('message'); |
| 160 messageDiv.innerText = message; | 146 messageDiv.innerText = message; |
| 161 | 147 |
| 162 this.updateSize_(); | 148 base.resizeWindowToContent(); |
| 163 break; | 149 break; |
| 164 | 150 |
| 165 default: | 151 default: |
| 166 console.error('Unexpected message:', event.data); | 152 console.error('Unexpected message:', event.data); |
| 167 } | 153 } |
| 168 }; | 154 }; |
| 169 | 155 |
| 170 var messageWindow = new MessageWindowImpl(); | 156 var messageWindow = new MessageWindowImpl(); |
| OLD | NEW |