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 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * The ExtensionOptionsOverlay will show an extension's options page using | 9 * The ExtensionOptionsOverlay will show an extension's options page using |
10 * an <extensionoptions> element. | 10 * an <extensionoptions> element. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 /** | 43 /** |
44 * Handles a click on the close button. | 44 * Handles a click on the close button. |
45 * @param {Event} e The click event. | 45 * @param {Event} e The click event. |
46 * @private | 46 * @private |
47 */ | 47 */ |
48 handleDismiss_: function(event) { | 48 handleDismiss_: function(event) { |
49 this.setVisible_(false); | 49 this.setVisible_(false); |
50 var extensionoptions = document.querySelector('extensionoptions'); | 50 var extensionoptions = document.querySelector('extensionoptions'); |
51 if (extensionoptions) | 51 if (extensionoptions) |
52 $('extension-options-overlay').removeChild(extensionoptions); | 52 $('extension-options-overlay-guest').removeChild(extensionoptions); |
53 }, | 53 }, |
54 | 54 |
55 /** | 55 /** |
56 * Associate an extension with the overlay and display it. | 56 * Associate an extension with the overlay and display it. |
57 * @param {string} extensionId The id of the extension whose options page | 57 * @param {string} extensionId The id of the extension whose options page |
58 * should be displayed in the overlay. | 58 * should be displayed in the overlay. |
59 * @param {string} extensionName The name of the extension, which is used | 59 * @param {string} extensionName The name of the extension, which is used |
60 * as the header of the overlay. | 60 * as the header of the overlay. |
61 */ | 61 */ |
62 setExtensionAndShowOverlay: function(extensionId, extensionName) { | 62 setExtensionAndShowOverlay: function(extensionId, extensionName) { |
63 var extensionoptions = new ExtensionOptions(); | 63 var extensionoptions = new ExtensionOptions(); |
64 extensionoptions.extension = extensionId; | 64 extensionoptions.extension = extensionId; |
65 extensionoptions.autosize = 'on'; | 65 extensionoptions.autosize = 'on'; |
66 | 66 |
67 // TODO(ericzeng): Resize in a non-jarring way. | 67 // The <extensionoptions> content's size needs to be restricted to the |
68 // bounds of the overlay window. The overlay gives a min width and | |
69 // max height, but the maxheight does not include our header height | |
70 // (title and close button), so we need to subtract that to get the | |
71 // max height for the extension options. | |
72 var headerStyle = | |
73 window.getComputedStyle($('extension-options-overlay-title')); | |
74 var headerHeight = parseInt(headerStyle.lineHeight) + | |
not at google - send to devlin
2014/08/20 20:08:57
Remember to fix this; test by making the header st
ericzeng
2014/08/20 23:10:16
offsetHeight works, thanks
| |
75 parseInt(headerStyle.paddingTop) + | |
76 parseInt(headerStyle.paddingBottom); | |
77 var overlayMaxHeight = | |
78 parseInt($('extension-options-overlay').style.maxHeight); | |
79 extensionoptions.maxheight = overlayMaxHeight - headerHeight; | |
80 | |
81 extensionoptions.minwidth = | |
82 parseInt(window.getComputedStyle($('extension-options-overlay')) | |
83 .minWidth); | |
84 | |
not at google - send to devlin
2014/08/20 20:08:57
Explain why you defer autosize.
ericzeng
2014/08/20 23:10:16
Done, also moved it with the rest of the animation
| |
85 extensionoptions.setDeferAutoSize(true); | |
86 | |
68 extensionoptions.onsizechanged = function(evt) { | 87 extensionoptions.onsizechanged = function(evt) { |
69 $('extension-options-overlay').style.width = evt.width; | 88 var overlayStyle = |
70 $('extension-options-overlay').style.height = evt.height; | 89 window.getComputedStyle($('extension-options-overlay')); |
90 var oldWidth = parseInt(overlayStyle.width); | |
91 var oldHeight = parseInt(overlayStyle.height); | |
92 | |
93 // animationTime is the amount of time in ms that will be used to resize | |
94 // the overlay. It is calculated by multiplying the pythagorean distance | |
95 // between old and the new size (in px) with a constant speed of | |
96 // 0.25 ms/px. | |
97 var animationTime = 0.25 * Math.sqrt( | |
98 Math.pow(evt.newWidth - oldWidth, 2) + | |
99 Math.pow(evt.newHeight - oldHeight, 2)); | |
100 | |
101 var player = $('extension-options-overlay').animate([ | |
102 {width: oldWidth + 'px', height: oldHeight + 'px'}, | |
103 {width: evt.newWidth + 'px', height: evt.newHeight + 'px'} | |
104 ], { | |
105 duration: animationTime, | |
106 delay: 0 | |
107 }); | |
108 | |
109 player.onfinish = function(e) { | |
110 extensionoptions.resumeDeferredAutoSize(); | |
111 $('extension-options-overlay-guest').style.position = 'static'; | |
112 $('extension-options-overlay-guest').style.left = 'auto'; | |
113 }; | |
71 }.bind(this); | 114 }.bind(this); |
72 | 115 |
73 $('extension-options-overlay').appendChild(extensionoptions); | 116 $('extension-options-overlay-guest').style.position = 'fixed'; |
117 $('extension-options-overlay-guest').style.left = | |
118 window.outerWidth + 'px'; | |
74 | 119 |
120 $('extension-options-overlay-guest').appendChild(extensionoptions); | |
75 $('extension-options-overlay-title').textContent = extensionName; | 121 $('extension-options-overlay-title').textContent = extensionName; |
76 | 122 |
77 this.setVisible_(true); | 123 this.setVisible_(true); |
78 }, | 124 }, |
79 | 125 |
80 /** | 126 /** |
81 * Toggles the visibility of the ExtensionOptionsOverlay. | 127 * Toggles the visibility of the ExtensionOptionsOverlay. |
82 * @param {boolean} isVisible Whether the overlay should be visible. | 128 * @param {boolean} isVisible Whether the overlay should be visible. |
83 * @private | 129 * @private |
84 */ | 130 */ |
85 setVisible_: function(isVisible) { | 131 setVisible_: function(isVisible) { |
86 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); | 132 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); |
87 } | 133 } |
88 }; | 134 }; |
89 | 135 |
90 // Export | 136 // Export |
91 return { | 137 return { |
92 ExtensionOptionsOverlay: ExtensionOptionsOverlay | 138 ExtensionOptionsOverlay: ExtensionOptionsOverlay |
93 }; | 139 }; |
94 }); | 140 }); |
OLD | NEW |