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('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Base class for print option section components. | 9 * Base class for print option section components. |
10 * @constructor | 10 * @constructor |
11 * @extends {print_preview.Component} | 11 * @extends {print_preview.Component} |
12 */ | 12 */ |
13 function SettingsSection() { | 13 function SettingsSection() { |
14 print_preview.Component.call(this); | 14 print_preview.Component.call(this); |
15 | 15 |
16 /** | 16 /** |
17 * Cached "hasCollapsibleContent" status for COLLAPSIBLE_CONTENT_CHANGED | 17 * Cached "hasCollapsibleContent" status for COLLAPSIBLE_CONTENT_CHANGED |
18 * notification. | 18 * notification. |
19 * @private {?boolean} | 19 * @private {?boolean} |
20 */ | 20 */ |
21 this.hasCollapsibleContentCached_ = null; | 21 this.hasCollapsibleContentCached_ = null; |
22 | 22 |
23 /** | 23 /** |
24 * Whether content of this section should be collapsed or not. | 24 * Whether content of this section should be collapsed or not. |
25 * @private {boolean} | 25 * @private {boolean} |
26 */ | 26 */ |
27 this.collapseContent_ = false; | 27 this.collapseContent_ = true; |
28 }; | 28 }; |
29 | 29 |
30 /** | 30 /** |
31 * Event types dispatched by this class. | 31 * Event types dispatched by this class. |
32 * @enum {string} | 32 * @enum {string} |
33 */ | 33 */ |
34 SettingsSection.EventType = { | 34 SettingsSection.EventType = { |
35 COLLAPSIBLE_CONTENT_CHANGED: | 35 COLLAPSIBLE_CONTENT_CHANGED: |
36 'print_preview.SettingsSection.COLLAPSIBLE_CONTENT_CHANGED' | 36 'print_preview.SettingsSection.COLLAPSIBLE_CONTENT_CHANGED' |
37 }; | 37 }; |
(...skipping 23 matching lines...) Expand all Loading... |
61 * @return {boolean} Whether the content of this section should be | 61 * @return {boolean} Whether the content of this section should be |
62 * collapsed. | 62 * collapsed. |
63 */ | 63 */ |
64 get collapseContent() { | 64 get collapseContent() { |
65 return this.collapseContent_; | 65 return this.collapseContent_; |
66 }, | 66 }, |
67 | 67 |
68 /** | 68 /** |
69 * @param {boolean} collapseContent Whether the content of this section | 69 * @param {boolean} collapseContent Whether the content of this section |
70 * should be collapsed, even if this section is available. | 70 * should be collapsed, even if this section is available. |
| 71 * @param {boolean} noAnimation Whether section visibility transition |
| 72 * should not be animated. |
71 */ | 73 */ |
72 set collapseContent(collapseContent) { | 74 setCollapseContent: function(collapseContent, noAnimation) { |
73 this.collapseContent_ = collapseContent && this.hasCollapsibleContent(); | 75 this.collapseContent_ = collapseContent && this.hasCollapsibleContent(); |
74 this.updateUiStateInternal(); | 76 this.updateUiStateInternal(noAnimation); |
75 }, | 77 }, |
76 | 78 |
77 /** @override */ | 79 /** @override */ |
78 enterDocument: function() { | 80 enterDocument: function() { |
79 print_preview.Component.prototype.enterDocument.call(this); | 81 print_preview.Component.prototype.enterDocument.call(this); |
80 this.isAvailable_ = this.isAvailable(); | 82 this.isAvailable_ = this.isAvailable(); |
81 if (!this.isAvailable()) | 83 if (!this.isAvailable()) |
82 fadeOutOption(this.getElement(), true); | 84 fadeOutOption(this.getElement(), true); |
83 }, | 85 }, |
84 | 86 |
85 /** | 87 /** |
86 * Updates the component appearance according to the current state. | 88 * Updates the component appearance according to the current state. |
| 89 * @param {boolean=} opt_noAnimation Whether section visibility transition |
| 90 * should not be animated. |
87 * @protected | 91 * @protected |
88 */ | 92 */ |
89 updateUiStateInternal: function() { | 93 updateUiStateInternal: function(opt_noAnimation) { |
90 var hasCollapsibleContent = this.hasCollapsibleContent(); | 94 var hasCollapsibleContent = this.hasCollapsibleContent(); |
91 var changed = this.hasCollapsibleContentCached_ != hasCollapsibleContent; | 95 var changed = this.hasCollapsibleContentCached_ != hasCollapsibleContent; |
92 this.hasCollapsibleContentCached_ = hasCollapsibleContent; | 96 this.hasCollapsibleContentCached_ = hasCollapsibleContent; |
93 | 97 |
94 if (this.isSectionVisibleInternal()) | 98 if (this.isSectionVisibleInternal()) |
95 fadeInOption(this.getElement()); | 99 fadeInOption(this.getElement(), opt_noAnimation); |
96 else | 100 else |
97 fadeOutOption(this.getElement()); | 101 fadeOutOption(this.getElement(), opt_noAnimation); |
98 | 102 |
99 if (changed) { | 103 if (changed) { |
100 cr.dispatchSimpleEvent( | 104 cr.dispatchSimpleEvent( |
101 this, SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED); | 105 this, SettingsSection.EventType.COLLAPSIBLE_CONTENT_CHANGED); |
102 } | 106 } |
103 }, | 107 }, |
104 | 108 |
105 /** | 109 /** |
106 * @return {boolean} Whether this section should be displayed or not. | 110 * @return {boolean} Whether this section should be displayed or not. |
107 * @protected | 111 * @protected |
108 */ | 112 */ |
109 isSectionVisibleInternal: function() { | 113 isSectionVisibleInternal: function() { |
110 return this.isAvailable() && !this.collapseContent_; | 114 return this.isAvailable() && !this.collapseContent_; |
111 } | 115 } |
112 }; | 116 }; |
113 | 117 |
114 // Export | 118 // Export |
115 return { | 119 return { |
116 SettingsSection: SettingsSection | 120 SettingsSection: SettingsSection |
117 }; | 121 }; |
118 }); | 122 }); |
OLD | NEW |