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

Unified Diff: chrome/browser/resources/print_preview/settings/more_settings.js

Issue 565213005: Make Print Preview elements transitions smoother. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/print_preview/settings/more_settings.js
diff --git a/chrome/browser/resources/print_preview/settings/more_settings.js b/chrome/browser/resources/print_preview/settings/more_settings.js
index 2143bbf98bc58d0466be306c28092d33c6c4b065..000e01a4e807823b11b6262f7c154ee4969ba013 100644
--- a/chrome/browser/resources/print_preview/settings/more_settings.js
+++ b/chrome/browser/resources/print_preview/settings/more_settings.js
@@ -7,19 +7,30 @@ cr.define('print_preview', function() {
/**
* Toggles visibility of the specified printing options sections.
+ * @param {!print_preview.DestinationStore} destinationStore To listen for
+ * destination changes.
* @param {!Array.<print_preview.SettingsSection>} settingsSections Sections
* to toggle by this component.
* @constructor
* @extends {print_preview.Component}
*/
- function MoreSettings(settingsSections) {
+ function MoreSettings(destinationStore, settingsSections) {
print_preview.Component.call(this);
+ /** @private {!print_preview.DestinationStore} */
+ this.destinationStore_ = destinationStore;
+
/** @private {!Array.<print_preview.SettingsSection>} */
this.settingsSections_ = settingsSections;
/** @private {MoreSettings.SettingsToShow} */
this.settingsToShow_ = MoreSettings.SettingsToShow.MOST_POPULAR;
+
+ /** @private {boolean} */
+ this.capabilitiesReady_ = false;
+
+ /** @private {boolean} */
+ this.firstDestinationReady_ = false;
};
/**
@@ -39,6 +50,15 @@ cr.define('print_preview', function() {
print_preview.Component.prototype.enterDocument.call(this);
this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this));
+ this.tracker.add(
+ this.destinationStore_,
+ print_preview.DestinationStore.EventType.DESTINATION_SELECT,
+ this.onDestinationChanged_.bind(this));
+ this.tracker.add(
+ this.destinationStore_,
+ print_preview.DestinationStore.EventType.
+ SELECTED_DESTINATION_CAPABILITIES_READY,
+ this.onDestinationCapabilitiesReady_.bind(this));
this.settingsSections_.forEach(function(section) {
this.tracker.add(
section,
@@ -46,7 +66,7 @@ cr.define('print_preview', function() {
this.updateState_.bind(this));
}.bind(this));
- this.updateState_();
+ this.updateState_(true);
},
/**
@@ -59,14 +79,40 @@ cr.define('print_preview', function() {
this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR ?
MoreSettings.SettingsToShow.ALL :
MoreSettings.SettingsToShow.MOST_POPULAR;
- this.updateState_();
+ this.updateState_(false);
+ },
+
+ /**
+ * Called when the destination selection has changed. Updates UI elements.
+ * @private
+ */
+ onDestinationChanged_: function() {
+ this.firstDestinationReady_ = true;
+ this.capabilitiesReady_ = false;
+ this.updateState_(false);
+ },
+
+ /**
+ * Called when the destination selection has changed. Updates UI elements.
+ * @private
+ */
+ onDestinationCapabilitiesReady_: function() {
+ this.capabilitiesReady_ = true;
+ this.updateState_(false);
},
/**
* Updates the component appearance according to the current state.
+ * @param {boolean} noAnimation Whether section visibility transitions
+ * should not be animated.
* @private
*/
- updateState_: function() {
+ updateState_: function(noAnimation) {
+ if (!this.firstDestinationReady_) {
+ fadeOutElement(this.getElement(), noAnimation);
+ return;
+ }
+
var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL;
this.getChildElement('.more-settings-label').textContent =
localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel');
@@ -80,23 +126,24 @@ cr.define('print_preview', function() {
}, 0);
// Magic 6 is chosen as the number of sections when it still feels like
- // manageable and not too crowded.
+ // manageable and not too crowded. Also, when capabilities are not know
+ // yet, ignore this limit to avoid unnecessary fade in/out cycles.
var hasSectionsToToggle =
- availableSections > 6 &&
+ (availableSections > 6 || !this.capabilitiesReady_) &&
this.settingsSections_.some(function(section) {
return section.hasCollapsibleContent();
});
if (hasSectionsToToggle)
- fadeInElement(this.getElement());
+ fadeInElement(this.getElement(), noAnimation);
else
- fadeOutElement(this.getElement());
+ fadeOutElement(this.getElement(), noAnimation);
var collapseContent =
this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR &&
hasSectionsToToggle;
this.settingsSections_.forEach(function(section) {
- section.collapseContent = collapseContent;
+ section.setCollapseContent(collapseContent, noAnimation);
});
}
};

Powered by Google App Engine
This is Rietveld 408576698