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

Side by Side 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 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('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** 8 /**
9 * Toggles visibility of the specified printing options sections. 9 * Toggles visibility of the specified printing options sections.
10 * @param {!print_preview.DestinationStore} destinationStore To listen for
11 * destination changes.
10 * @param {!Array.<print_preview.SettingsSection>} settingsSections Sections 12 * @param {!Array.<print_preview.SettingsSection>} settingsSections Sections
11 * to toggle by this component. 13 * to toggle by this component.
12 * @constructor 14 * @constructor
13 * @extends {print_preview.Component} 15 * @extends {print_preview.Component}
14 */ 16 */
15 function MoreSettings(settingsSections) { 17 function MoreSettings(destinationStore, settingsSections) {
16 print_preview.Component.call(this); 18 print_preview.Component.call(this);
17 19
20 /** @private {!print_preview.DestinationStore} */
21 this.destinationStore_ = destinationStore;
22
18 /** @private {!Array.<print_preview.SettingsSection>} */ 23 /** @private {!Array.<print_preview.SettingsSection>} */
19 this.settingsSections_ = settingsSections; 24 this.settingsSections_ = settingsSections;
20 25
21 /** @private {MoreSettings.SettingsToShow} */ 26 /** @private {MoreSettings.SettingsToShow} */
22 this.settingsToShow_ = MoreSettings.SettingsToShow.MOST_POPULAR; 27 this.settingsToShow_ = MoreSettings.SettingsToShow.MOST_POPULAR;
28
29 /** @private {boolean} */
30 this.capabilitiesReady_ = false;
31
32 /** @private {boolean} */
33 this.firstDestinationReady_ = false;
23 }; 34 };
24 35
25 /** 36 /**
26 * Which settings are visible to the user. 37 * Which settings are visible to the user.
27 * @enum {number} 38 * @enum {number}
28 */ 39 */
29 MoreSettings.SettingsToShow = { 40 MoreSettings.SettingsToShow = {
30 MOST_POPULAR: 1, 41 MOST_POPULAR: 1,
31 ALL: 2 42 ALL: 2
32 }; 43 };
33 44
34 MoreSettings.prototype = { 45 MoreSettings.prototype = {
35 __proto__: print_preview.Component.prototype, 46 __proto__: print_preview.Component.prototype,
36 47
37 /** @override */ 48 /** @override */
38 enterDocument: function() { 49 enterDocument: function() {
39 print_preview.Component.prototype.enterDocument.call(this); 50 print_preview.Component.prototype.enterDocument.call(this);
40 51
41 this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this)); 52 this.tracker.add(this.getElement(), 'click', this.onClick_.bind(this));
53 this.tracker.add(
54 this.destinationStore_,
55 print_preview.DestinationStore.EventType.DESTINATION_SELECT,
56 this.onDestinationChanged_.bind(this));
57 this.tracker.add(
58 this.destinationStore_,
59 print_preview.DestinationStore.EventType.
60 SELECTED_DESTINATION_CAPABILITIES_READY,
61 this.onDestinationCapabilitiesReady_.bind(this));
42 this.settingsSections_.forEach(function(section) { 62 this.settingsSections_.forEach(function(section) {
43 this.tracker.add( 63 this.tracker.add(
44 section, 64 section,
45 print_preview.SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED, 65 print_preview.SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED,
46 this.updateState_.bind(this)); 66 this.updateState_.bind(this));
47 }.bind(this)); 67 }.bind(this));
48 68
49 this.updateState_(); 69 this.updateState_(true);
50 }, 70 },
51 71
52 /** 72 /**
53 * Toggles "more/fewer options" state and notifies all the options sections 73 * Toggles "more/fewer options" state and notifies all the options sections
54 * to reflect the new state. 74 * to reflect the new state.
55 * @private 75 * @private
56 */ 76 */
57 onClick_: function() { 77 onClick_: function() {
58 this.settingsToShow_ = 78 this.settingsToShow_ =
59 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR ? 79 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR ?
60 MoreSettings.SettingsToShow.ALL : 80 MoreSettings.SettingsToShow.ALL :
61 MoreSettings.SettingsToShow.MOST_POPULAR; 81 MoreSettings.SettingsToShow.MOST_POPULAR;
62 this.updateState_(); 82 this.updateState_(false);
83 },
84
85 /**
86 * Called when the destination selection has changed. Updates UI elements.
87 * @private
88 */
89 onDestinationChanged_: function() {
90 this.firstDestinationReady_ = true;
91 this.capabilitiesReady_ = false;
92 this.updateState_(false);
93 },
94
95 /**
96 * Called when the destination selection has changed. Updates UI elements.
97 * @private
98 */
99 onDestinationCapabilitiesReady_: function() {
100 this.capabilitiesReady_ = true;
101 this.updateState_(false);
63 }, 102 },
64 103
65 /** 104 /**
66 * Updates the component appearance according to the current state. 105 * Updates the component appearance according to the current state.
106 * @param {boolean} noAnimation Whether section visibility transitions
107 * should not be animated.
67 * @private 108 * @private
68 */ 109 */
69 updateState_: function() { 110 updateState_: function(noAnimation) {
111 if (!this.firstDestinationReady_) {
112 fadeOutElement(this.getElement(), noAnimation);
113 return;
114 }
115
70 var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL; 116 var all = this.settingsToShow_ == MoreSettings.SettingsToShow.ALL;
71 this.getChildElement('.more-settings-label').textContent = 117 this.getChildElement('.more-settings-label').textContent =
72 localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel'); 118 localStrings.getString(all ? 'lessOptionsLabel' : 'moreOptionsLabel');
73 var iconEl = this.getChildElement('.more-settings-icon'); 119 var iconEl = this.getChildElement('.more-settings-icon');
74 iconEl.classList.toggle('more-settings-icon-plus', !all); 120 iconEl.classList.toggle('more-settings-icon-plus', !all);
75 iconEl.classList.toggle('more-settings-icon-minus', all); 121 iconEl.classList.toggle('more-settings-icon-minus', all);
76 122
77 var availableSections = this.settingsSections_.reduce( 123 var availableSections = this.settingsSections_.reduce(
78 function(count, section) { 124 function(count, section) {
79 return count + (section.isAvailable() ? 1 : 0); 125 return count + (section.isAvailable() ? 1 : 0);
80 }, 0); 126 }, 0);
81 127
82 // Magic 6 is chosen as the number of sections when it still feels like 128 // Magic 6 is chosen as the number of sections when it still feels like
83 // manageable and not too crowded. 129 // manageable and not too crowded. Also, when capabilities are not know
130 // yet, ignore this limit to avoid unnecessary fade in/out cycles.
84 var hasSectionsToToggle = 131 var hasSectionsToToggle =
85 availableSections > 6 && 132 (availableSections > 6 || !this.capabilitiesReady_) &&
86 this.settingsSections_.some(function(section) { 133 this.settingsSections_.some(function(section) {
87 return section.hasCollapsibleContent(); 134 return section.hasCollapsibleContent();
88 }); 135 });
89 136
90 if (hasSectionsToToggle) 137 if (hasSectionsToToggle)
91 fadeInElement(this.getElement()); 138 fadeInElement(this.getElement(), noAnimation);
92 else 139 else
93 fadeOutElement(this.getElement()); 140 fadeOutElement(this.getElement(), noAnimation);
94 141
95 var collapseContent = 142 var collapseContent =
96 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR && 143 this.settingsToShow_ == MoreSettings.SettingsToShow.MOST_POPULAR &&
97 hasSectionsToToggle; 144 hasSectionsToToggle;
98 this.settingsSections_.forEach(function(section) { 145 this.settingsSections_.forEach(function(section) {
99 section.collapseContent = collapseContent; 146 section.setCollapseContent(collapseContent, noAnimation);
100 }); 147 });
101 } 148 }
102 }; 149 };
103 150
104 // Export 151 // Export
105 return { 152 return {
106 MoreSettings: MoreSettings 153 MoreSettings: MoreSettings
107 }; 154 };
108 }); 155 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698