OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 * Class that represents a UI component. | 9 * Class that represents a UI component. |
10 * @constructor | 10 * @constructor |
(...skipping 13 matching lines...) Expand all Loading... | |
24 | 24 |
25 /** | 25 /** |
26 * Component's event tracker. | 26 * Component's event tracker. |
27 * @type {EventTracker} | 27 * @type {EventTracker} |
28 * @private | 28 * @private |
29 */ | 29 */ |
30 this.tracker_ = new EventTracker(); | 30 this.tracker_ = new EventTracker(); |
31 | 31 |
32 /** | 32 /** |
33 * Child components of the component. | 33 * Child components of the component. |
34 * @type {Array.<print_preview.Component>} | 34 * @type {Array.<!print_preview.Component>} |
35 * @private | 35 * @private |
36 */ | 36 */ |
37 this.children_ = []; | 37 this.children_ = []; |
38 }; | 38 }; |
39 | 39 |
40 Component.prototype = { | 40 Component.prototype = { |
41 __proto__: cr.EventTarget.prototype, | 41 __proto__: cr.EventTarget.prototype, |
42 | 42 |
43 /** Gets the component's element. */ | 43 /** Gets the component's element. */ |
44 getElement: function() { | 44 getElement: function() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 * @param {Element} element Element to decorate. | 112 * @param {Element} element Element to decorate. |
113 */ | 113 */ |
114 decorate: function(element) { | 114 decorate: function(element) { |
115 assert(!this.isInDocument, 'Component is already in the document'); | 115 assert(!this.isInDocument, 'Component is already in the document'); |
116 this.setElementInternal(element); | 116 this.setElementInternal(element); |
117 this.decorateInternal(); | 117 this.decorateInternal(); |
118 this.enterDocument(); | 118 this.enterDocument(); |
119 }, | 119 }, |
120 | 120 |
121 /** | 121 /** |
122 * @param {print_preview.Component} child Component to add as a child of | 122 * @param {!print_preview.Component} child Component to add as a child of |
123 * this component. | 123 * this component. |
124 */ | 124 */ |
125 addChild: function(child) { | 125 addChild: function(child) { |
126 this.children_.push(child); | 126 this.children_.push(child); |
127 }, | 127 }, |
128 | 128 |
129 /** | 129 /** |
130 * @param {!print_preview.Component} child Component to remove from this | 130 * @param {!print_preview.Component} child Component to remove from this |
131 * component's children. | 131 * component's children. |
132 */ | 132 */ |
(...skipping 14 matching lines...) Expand all Loading... | |
147 removeChildren: function() { | 147 removeChildren: function() { |
148 while (this.children_.length > 0) { | 148 while (this.children_.length > 0) { |
149 this.removeChild(this.children_[0]); | 149 this.removeChild(this.children_[0]); |
150 } | 150 } |
151 }, | 151 }, |
152 | 152 |
153 /** | 153 /** |
154 * @param {string} query Selector query to select an element starting from | 154 * @param {string} query Selector query to select an element starting from |
155 * the component's root element using a depth first search for the first | 155 * the component's root element using a depth first search for the first |
156 * element that matches the query. | 156 * element that matches the query. |
157 * @return {HTMLElement} Element selected by the given query. | 157 * @return {!HTMLElement} Element selected by the given query. |
Aleksey Shlyapnikov
2014/09/19 18:54:42
Why? This is a generic function and it's not guara
Vitaly Pavlenko
2014/09/19 20:33:09
I tried to add this assert, compile the browser an
Aleksey Shlyapnikov
2014/09/19 20:48:59
So with no assert and @return {HTMLElement} declar
Vitaly Pavlenko
2014/09/19 21:12:53
Yes, without this assert you get 40 errors like th
| |
158 */ | 158 */ |
159 getChildElement: function(query) { | 159 getChildElement: function(query) { |
160 return this.element_.querySelector(query); | 160 return assert(this.element_.querySelector(query)); |
161 }, | 161 }, |
162 | 162 |
163 /** | 163 /** |
164 * Sets the component's element. | 164 * Sets the component's element. |
165 * @param {Element} element HTML element to set as the component's element. | 165 * @param {Element} element HTML element to set as the component's element. |
166 * @protected | 166 * @protected |
167 */ | 167 */ |
168 setElementInternal: function(element) { | 168 setElementInternal: function(element) { |
169 this.element_ = element; | 169 this.element_ = element; |
170 }, | 170 }, |
(...skipping 22 matching lines...) Expand all Loading... | |
193 setIsVisible(el, true); | 193 setIsVisible(el, true); |
194 } | 194 } |
195 return el; | 195 return el; |
196 } | 196 } |
197 }; | 197 }; |
198 | 198 |
199 return { | 199 return { |
200 Component: Component | 200 Component: Component |
201 }; | 201 }; |
202 }); | 202 }); |
OLD | NEW |