| 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. |
| 158 * TODO(alekseys): Check all call sites and rename this function to |
| 159 * something like getRequiredChildElement. |
| 158 */ | 160 */ |
| 159 getChildElement: function(query) { | 161 getChildElement: function(query) { |
| 160 return this.element_.querySelector(query); | 162 return assert(this.element_.querySelector(query)); |
| 161 }, | 163 }, |
| 162 | 164 |
| 163 /** | 165 /** |
| 164 * Sets the component's element. | 166 * Sets the component's element. |
| 165 * @param {Element} element HTML element to set as the component's element. | 167 * @param {Element} element HTML element to set as the component's element. |
| 166 * @protected | 168 * @protected |
| 167 */ | 169 */ |
| 168 setElementInternal: function(element) { | 170 setElementInternal: function(element) { |
| 169 this.element_ = element; | 171 this.element_ = element; |
| 170 }, | 172 }, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 193 setIsVisible(el, true); | 195 setIsVisible(el, true); |
| 194 } | 196 } |
| 195 return el; | 197 return el; |
| 196 } | 198 } |
| 197 }; | 199 }; |
| 198 | 200 |
| 199 return { | 201 return { |
| 200 Component: Component | 202 Component: Component |
| 201 }; | 203 }; |
| 202 }); | 204 }); |
| OLD | NEW |