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

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

Issue 480243003: Implement smoother autosizing of the extension options overlay (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 }, 56 },
57 57
58 /** 58 /**
59 * Associate an extension with the overlay and display it. 59 * Associate an extension with the overlay and display it.
60 * @param {string} extensionId The id of the extension whose options page 60 * @param {string} extensionId The id of the extension whose options page
61 * should be displayed in the overlay. 61 * should be displayed in the overlay.
62 * @param {string} extensionName The name of the extension, which is used 62 * @param {string} extensionName The name of the extension, which is used
63 * as the header of the overlay. 63 * as the header of the overlay.
64 */ 64 */
65 setExtensionAndShowOverlay: function(extensionId, extensionName) { 65 setExtensionAndShowOverlay: function(extensionId, extensionName) {
66 $('extension-options-overlay-title').textContent = extensionName;
67
66 var extensionoptions = new ExtensionOptions(); 68 var extensionoptions = new ExtensionOptions();
67 extensionoptions.extension = extensionId; 69 extensionoptions.extension = extensionId;
68 extensionoptions.autosize = 'on'; 70 extensionoptions.autosize = 'on';
69 71
72 // The <extensionoptions> content's size needs to be restricted to the
73 // bounds of the overlay window. The overlay gives a min width and
74 // max height, but the maxheight does not include our header height
75 // (title and close button), so we need to subtract that to get the
76 // max height for the extension options.
77 var headerHeight = $('extension-options-overlay-title').offsetHeight;
78 var overlayMaxHeight =
79 parseInt($('extension-options-overlay').style.maxHeight);
80 extensionoptions.maxheight = overlayMaxHeight - headerHeight;
81
82 extensionoptions.minwidth =
83 parseInt(window.getComputedStyle($('extension-options-overlay'))
84 .minWidth);
85
86 extensionoptions.setDeferAutoSize(true);
87
70 extensionoptions.onclose = function() { 88 extensionoptions.onclose = function() {
71 this.handleDismiss_(); 89 this.handleDismiss_();
72 }.bind(this); 90 }.bind(this);
73 91
74 // TODO(ericzeng): Resize in a non-jarring way. 92 // Resize the overlay if the <extensionoptions> changes size.
75 extensionoptions.onsizechanged = function(evt) { 93 extensionoptions.onsizechanged = function(evt) {
76 $('extension-options-overlay').style.width = evt.width; 94 var overlayStyle =
77 $('extension-options-overlay').style.height = evt.height; 95 window.getComputedStyle($('extension-options-overlay'));
96 var oldWidth = parseInt(overlayStyle.width);
97 var oldHeight = parseInt(overlayStyle.height);
98
99 // animationTime is the amount of time in ms that will be used to resize
100 // the overlay. It is calculated by multiplying the pythagorean distance
101 // between old and the new size (in px) with a constant speed of
102 // 0.25 ms/px.
103 var animationTime = 0.25 * Math.sqrt(
104 Math.pow(evt.newWidth - oldWidth, 2) +
105 Math.pow(evt.newHeight - oldHeight, 2));
106
107 var player = $('extension-options-overlay').animate([
108 {width: oldWidth + 'px', height: oldHeight + 'px'},
109 {width: evt.newWidth + 'px', height: evt.newHeight + 'px'}
110 ], {
111 duration: animationTime,
112 delay: 0
113 });
114
115 player.onfinish = function(e) {
116 // Allow the <extensionoptions> to autosize now that the overlay
117 // has resized, and move it back on-screen.
118 extensionoptions.resumeDeferredAutoSize();
119 $('extension-options-overlay-guest').style.position = 'static';
120 $('extension-options-overlay-guest').style.left = 'auto';
121 };
78 }.bind(this); 122 }.bind(this);
79 123
124 // Don't allow the <extensionoptions> to autosize until the overlay
125 // animation is complete.
126 extensionoptions.setDeferAutoSize(true);
127
128 // Move the <extensionoptions> off screen until the overlay is ready
129 $('extension-options-overlay-guest').style.position = 'fixed';
130 $('extension-options-overlay-guest').style.left =
131 window.outerWidth + 'px';
132
80 $('extension-options-overlay-guest').appendChild(extensionoptions); 133 $('extension-options-overlay-guest').appendChild(extensionoptions);
81
82 $('extension-options-overlay-title').textContent = extensionName;
83
84 this.setVisible_(true); 134 this.setVisible_(true);
85 }, 135 },
86 136
87 /** 137 /**
88 * Toggles the visibility of the ExtensionOptionsOverlay. 138 * Toggles the visibility of the ExtensionOptionsOverlay.
89 * @param {boolean} isVisible Whether the overlay should be visible. 139 * @param {boolean} isVisible Whether the overlay should be visible.
90 * @private 140 * @private
91 */ 141 */
92 setVisible_: function(isVisible) { 142 setVisible_: function(isVisible) {
93 this.showOverlay_(isVisible ? $('extension-options-overlay') : null); 143 this.showOverlay_(isVisible ? $('extension-options-overlay') : null);
94 } 144 }
95 }; 145 };
96 146
97 // Export 147 // Export
98 return { 148 return {
99 ExtensionOptionsOverlay: ExtensionOptionsOverlay 149 ExtensionOptionsOverlay: ExtensionOptionsOverlay
100 }; 150 };
101 }); 151 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/extensions/extension_options_overlay.css ('k') | chrome/browser/resources/extensions/extensions.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698