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 * @fileoverview | 6 * @fileoverview |
7 * A module that contains basic utility components and methods for the | 7 * A module that contains basic utility components and methods for the |
8 * chromoting project | 8 * chromoting project |
9 * | 9 * |
10 */ | 10 */ |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 return '[' + new Date().toISOString() + ']'; | 782 return '[' + new Date().toISOString() + ']'; |
783 }; | 783 }; |
784 | 784 |
785 /** | 785 /** |
786 * Size the current window to fit its content. | 786 * Size the current window to fit its content. |
787 * @param {boolean=} opt_centerWindow If true, position the window in the | 787 * @param {boolean=} opt_centerWindow If true, position the window in the |
788 * center of the screen after resizing it. | 788 * center of the screen after resizing it. |
789 */ | 789 */ |
790 base.resizeWindowToContent = function(opt_centerWindow) { | 790 base.resizeWindowToContent = function(opt_centerWindow) { |
791 var appWindow = chrome.app.window.current(); | 791 var appWindow = chrome.app.window.current(); |
792 var outerBounds = appWindow.outerBounds; | 792 var borderX = appWindow.outerBounds.width - appWindow.innerBounds.width; |
793 var borderX = outerBounds.width - appWindow.innerBounds.width; | 793 var borderY = appWindow.outerBounds.height - appWindow.innerBounds.height; |
794 var borderY = outerBounds.height - appWindow.innerBounds.height; | 794 var width = Math.ceil(document.documentElement.scrollWidth + borderX); |
795 var newWidth = document.documentElement.scrollWidth + borderX; | 795 var height = Math.ceil(document.documentElement.scrollHeight + borderY); |
796 var newHeight = document.documentElement.scrollHeight + borderY; | 796 appWindow.outerBounds.width = width; |
797 appWindow.resizeTo(newWidth, newHeight); | 797 appWindow.outerBounds.height = height; |
798 var left = outerBounds.left; | |
799 var top = outerBounds.top; | |
800 if (opt_centerWindow) { | 798 if (opt_centerWindow) { |
801 var screenWidth = screen.availWidth; | 799 var screenWidth = screen.availWidth; |
802 var screenHeight = screen.availHeight; | 800 var screenHeight = screen.availHeight; |
803 left = (screenWidth - newWidth) / 2; | 801 appWindow.outerBounds.left = Math.round((screenWidth - width) / 2); |
804 top = (screenHeight - newHeight) / 2; | 802 appWindow.outerBounds.top = Math.round((screenHeight - height) / 2); |
805 } | 803 } |
806 // Sometimes, resizing the window causes its position to be reset to (0, 0), | |
807 // so restore it explicitly, even if it doesn't need to be centered. | |
808 appWindow.moveTo(left, top); | |
809 }; | 804 }; |
OLD | NEW |