OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 * @param {!UI.SuggestBox.Suggestions} items | 127 * @param {!UI.SuggestBox.Suggestions} items |
128 */ | 128 */ |
129 _updateWidth(items) { | 129 _updateWidth(items) { |
130 if (this._hasVerticalScroll) { | 130 if (this._hasVerticalScroll) { |
131 this._element.style.width = '100vw'; | 131 this._element.style.width = '100vw'; |
132 return; | 132 return; |
133 } | 133 } |
134 if (!items.length) | 134 if (!items.length) |
135 return; | 135 return; |
136 // If there are no scrollbars, set the width to the width of the largest row
. | 136 // If there are no scrollbars, set the width to the width of the largest row
. |
137 var maxItem = items[0]; | 137 var maxItem; |
138 for (var i = 1; i < items.length; i++) { | 138 var maxLength = -Infinity; |
139 if (items[i].title.length > maxItem.title.length) | 139 for (var i = 0; i < items.length; i++) { |
| 140 var length = items[i].title.length + (items[i].subtitle || '').length; |
| 141 if (length > maxLength) { |
| 142 maxLength = length; |
140 maxItem = items[i]; | 143 maxItem = items[i]; |
| 144 } |
141 } | 145 } |
142 this._element.style.width = UI.measurePreferredSize(this.createElementForIte
m(maxItem), this._element).width + 'px'; | 146 this._element.style.width = |
| 147 UI.measurePreferredSize( |
| 148 this.createElementForItem(/** @type {!UI.SuggestBox.Suggestion} */
(maxItem)), this._element) |
| 149 .width + |
| 150 'px'; |
143 } | 151 } |
144 | 152 |
145 /** | 153 /** |
146 * @param {!Event} event | 154 * @param {!Event} event |
147 */ | 155 */ |
148 _onBoxMouseDown(event) { | 156 _onBoxMouseDown(event) { |
149 if (this._hideTimeoutId) { | 157 if (this._hideTimeoutId) { |
150 window.clearTimeout(this._hideTimeoutId); | 158 window.clearTimeout(this._hideTimeoutId); |
151 delete this._hideTimeoutId; | 159 delete this._hideTimeoutId; |
152 } | 160 } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 this.element.style.left = containerBox.x + 'px'; | 467 this.element.style.left = containerBox.x + 'px'; |
460 this.element.style.top = containerBox.y + 'px'; | 468 this.element.style.top = containerBox.y + 'px'; |
461 this.element.style.height = containerBox.height + 'px'; | 469 this.element.style.height = containerBox.height + 'px'; |
462 this.element.style.width = containerBox.width + 'px'; | 470 this.element.style.width = containerBox.width + 'px'; |
463 } | 471 } |
464 | 472 |
465 dispose() { | 473 dispose() { |
466 this.element.remove(); | 474 this.element.remove(); |
467 } | 475 } |
468 }; | 476 }; |
OLD | NEW |