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 var headerStyle = |
not at google - send to devlin
2014/08/20 02:07:15
You might want to add a meta-comment here, like:
ericzeng
2014/08/20 18:44:07
Done.
| |
68 window.getComputedStyle($('extension-options-overlay-title')); | |
69 var headerHeight = parseInt(headerStyle.lineHeight) + | |
70 parseInt(headerStyle.paddingTop) + | |
71 parseInt(headerStyle.paddingBottom); | |
not at google - send to devlin
2014/08/20 02:07:15
Can you get this from one of the other height prop
| |
72 var overlayMaxHeight = | |
73 parseInt($('extension-options-overlay').style.maxHeight); | |
74 extensionoptions.maxheight = overlayMaxHeight - headerHeight; | |
75 | |
76 extensionoptions.minwidth = | |
77 parseInt(window.getComputedStyle($('extension-options-overlay')) | |
78 .minWidth); | |
79 | |
80 extensionoptions.shouldDeferAutoSize(true); | |
not at google - send to devlin
2014/08/20 02:07:15
You mention in the comment that you don't actually
ericzeng
2014/08/20 02:23:30
Oh, I tried removing it and it turns out that it l
| |
81 | |
68 extensionoptions.onsizechanged = function(evt) { | 82 extensionoptions.onsizechanged = function(evt) { |
69 $('extension-options-overlay').style.width = evt.width; | 83 var overlayStyle = |
70 $('extension-options-overlay').style.height = evt.height; | 84 window.getComputedStyle($('extension-options-overlay')); |
85 var oldWidth = parseInt(overlayStyle.width); | |
86 var oldHeight = parseInt(overlayStyle.height); | |
87 | |
88 // animationTime is the amount of time in ms that will be used to resize | |
89 // the overlay. It is a function of the pythagorean distance between old | |
90 // and the new size, so that the speed at which the overlay changes is | |
91 // constant for all sizes. | |
not at google - send to devlin
2014/08/20 02:07:15
Nit: could you say like "0.25 means the popup resi
ericzeng
2014/08/20 18:44:07
Done.
| |
92 var animationTime = 0.25 * Math.sqrt( | |
93 Math.pow(evt.newWidth - oldWidth, 2) + | |
94 Math.pow(evt.newHeight - oldHeight, 2)); | |
95 | |
96 var player = $('extension-options-overlay').animate([ | |
97 {width: oldWidth + 'px', height: oldHeight + 'px'}, | |
98 {width: evt.newWidth + 'px', height: evt.newHeight + 'px'} | |
99 ], { | |
100 duration: animationTime, | |
101 delay: 0 | |
102 }); | |
103 | |
104 player.onfinish = function(e) { | |
105 extensionoptions.resumeDeferredAutoSize(); | |
not at google - send to devlin
2014/08/20 02:07:15
Heh how did you figure out how to use animate... d
ericzeng
2014/08/20 02:23:30
This was sufficient documentation for me to implem
not at google - send to devlin
2014/08/20 02:29:34
Specifically I was wondering about an onerror or o
ericzeng
2014/08/20 18:44:07
Hm, I can't actually open that link, do you have t
| |
106 $('extension-options-overlay-guest').style.position = 'static'; | |
107 $('extension-options-overlay-guest').style.left = 'auto'; | |
108 }; | |
71 }.bind(this); | 109 }.bind(this); |
72 | 110 |
73 $('extension-options-overlay').appendChild(extensionoptions); | 111 $('extension-options-overlay-guest').style.position = 'absolute'; |
112 $('extension-options-overlay-guest').style.left = '10000px'; | |
not at google - send to devlin
2014/08/20 02:07:15
This is to implement that off-screen resize?
You
ericzeng
2014/08/20 18:44:07
Done.
| |
74 | 113 |
114 $('extension-options-overlay-guest').appendChild(extensionoptions); | |
75 $('extension-options-overlay-title').textContent = extensionName; | 115 $('extension-options-overlay-title').textContent = extensionName; |
76 | 116 |
77 this.setVisible_(true); | 117 this.setVisible_(true); |
78 }, | 118 }, |
79 | 119 |
80 /** | 120 /** |
81 * Toggles the visibility of the ExtensionOptionsOverlay. | 121 * Toggles the visibility of the ExtensionOptionsOverlay. |
82 * @param {boolean} isVisible Whether the overlay should be visible. | 122 * @param {boolean} isVisible Whether the overlay should be visible. |
83 * @private | 123 * @private |
84 */ | 124 */ |
85 setVisible_: function(isVisible) { | 125 setVisible_: function(isVisible) { |
86 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); | 126 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); |
87 } | 127 } |
88 }; | 128 }; |
89 | 129 |
90 // Export | 130 // Export |
91 return { | 131 return { |
92 ExtensionOptionsOverlay: ExtensionOptionsOverlay | 132 ExtensionOptionsOverlay: ExtensionOptionsOverlay |
93 }; | 133 }; |
94 }); | 134 }); |
OLD | NEW |