Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: trunk/src/chrome/browser/resources/extensions/extension_options_overlay.js

Issue 498633002: Revert 291286: broke 'ExtensionOptionsApiTest.ExtensionCanEmbedOwnOptions'. (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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-guest').removeChild(extensionoptions); 52 $('extension-options-overlay').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 $('extension-options-overlay-title').textContent = extensionName;
64
65 var extensionoptions = new ExtensionOptions(); 63 var extensionoptions = new ExtensionOptions();
66 extensionoptions.extension = extensionId; 64 extensionoptions.extension = extensionId;
67 extensionoptions.autosize = 'on'; 65 extensionoptions.autosize = 'on';
68 66
69 // The <extensionoptions> content's size needs to be restricted to the 67 // TODO(ericzeng): Resize in a non-jarring way.
70 // bounds of the overlay window. The overlay gives a min width and
71 // max height, but the maxheight does not include our header height
72 // (title and close button), so we need to subtract that to get the
73 // max height for the extension options.
74 var headerHeight = $('extension-options-overlay-title').offsetHeight;
75 var overlayMaxHeight =
76 parseInt($('extension-options-overlay').style.maxHeight);
77 extensionoptions.maxheight = overlayMaxHeight - headerHeight;
78
79 extensionoptions.minwidth =
80 parseInt(window.getComputedStyle($('extension-options-overlay'))
81 .minWidth);
82
83 // Resize the overlay if the <extensionoptions> changes size.
84 extensionoptions.onsizechanged = function(evt) { 68 extensionoptions.onsizechanged = function(evt) {
85 var overlayStyle = 69 $('extension-options-overlay').style.width = evt.width;
86 window.getComputedStyle($('extension-options-overlay')); 70 $('extension-options-overlay').style.height = evt.height;
87 var oldWidth = parseInt(overlayStyle.width);
88 var oldHeight = parseInt(overlayStyle.height);
89
90 // animationTime is the amount of time in ms that will be used to resize
91 // the overlay. It is calculated by multiplying the pythagorean distance
92 // between old and the new size (in px) with a constant speed of
93 // 0.25 ms/px.
94 var animationTime = 0.25 * Math.sqrt(
95 Math.pow(evt.newWidth - oldWidth, 2) +
96 Math.pow(evt.newHeight - oldHeight, 2));
97
98 var player = $('extension-options-overlay').animate([
99 {width: oldWidth + 'px', height: oldHeight + 'px'},
100 {width: evt.newWidth + 'px', height: evt.newHeight + 'px'}
101 ], {
102 duration: animationTime,
103 delay: 0
104 });
105
106 player.onfinish = function(e) {
107 // Allow the <extensionoptions> to autosize now that the overlay
108 // has resized, and move it back on-screen.
109 extensionoptions.resumeDeferredAutoSize();
110 $('extension-options-overlay-guest').style.position = 'static';
111 $('extension-options-overlay-guest').style.left = 'auto';
112 };
113 }.bind(this); 71 }.bind(this);
114 72
115 // Don't allow the <extensionoptions> to autosize until the overlay 73 $('extension-options-overlay').appendChild(extensionoptions);
116 // animation is complete.
117 extensionoptions.setDeferAutoSize(true);
118 74
119 // Move the <extensionoptions> off screen until the overlay is ready 75 $('extension-options-overlay-title').textContent = extensionName;
120 $('extension-options-overlay-guest').style.position = 'fixed';
121 $('extension-options-overlay-guest').style.left =
122 window.outerWidth + 'px';
123 76
124 $('extension-options-overlay-guest').appendChild(extensionoptions);
125 this.setVisible_(true); 77 this.setVisible_(true);
126 }, 78 },
127 79
128 /** 80 /**
129 * Toggles the visibility of the ExtensionOptionsOverlay. 81 * Toggles the visibility of the ExtensionOptionsOverlay.
130 * @param {boolean} isVisible Whether the overlay should be visible. 82 * @param {boolean} isVisible Whether the overlay should be visible.
131 * @private 83 * @private
132 */ 84 */
133 setVisible_: function(isVisible) { 85 setVisible_: function(isVisible) {
134 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); 86 this.showOverlay_(isVisible ? $('extension-options-overlay') : null);
135 } 87 }
136 }; 88 };
137 89
138 // Export 90 // Export
139 return { 91 return {
140 ExtensionOptionsOverlay: ExtensionOptionsOverlay 92 ExtensionOptionsOverlay: ExtensionOptionsOverlay
141 }; 93 };
142 }); 94 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698