Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate | 53 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate |
| 54 * @param {number=} maxItemsHeight | 54 * @param {number=} maxItemsHeight |
| 55 * @param {boolean=} captureEnter | 55 * @param {boolean=} captureEnter |
| 56 */ | 56 */ |
| 57 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) { | 57 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) { |
| 58 this._suggestBoxDelegate = suggestBoxDelegate; | 58 this._suggestBoxDelegate = suggestBoxDelegate; |
| 59 this._maxItemsHeight = maxItemsHeight; | 59 this._maxItemsHeight = maxItemsHeight; |
| 60 this._captureEnter = captureEnter; | 60 this._captureEnter = captureEnter; |
| 61 this._rowHeight = 17; | 61 this._rowHeight = 17; |
| 62 this._userInteracted = false; | 62 this._userInteracted = false; |
| 63 this._userInteractionStyling = false; | |
| 63 this._userEnteredText = ''; | 64 this._userEnteredText = ''; |
| 64 /** @type {?string} */ | 65 /** @type {?string} */ |
| 65 this._onlyCompletion = null; | 66 this._onlyCompletion = null; |
| 66 | 67 |
| 67 /** @type {!UI.ListControl<!UI.SuggestBox.Suggestion>} */ | 68 /** @type {!UI.ListControl<!UI.SuggestBox.Suggestion>} */ |
| 68 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); | 69 this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems); |
| 69 this._element = this._list.element; | 70 this._element = this._list.element; |
| 70 this._element.classList.add('suggest-box'); | 71 this._element.classList.add('suggest-box'); |
| 71 this._element.addEventListener('mousedown', event => event.preventDefault(), true); | 72 this._element.addEventListener('mousedown', event => event.preventDefault(), true); |
| 72 | 73 |
| 73 this._glassPane = new UI.GlassPane(); | 74 this._glassPane = new UI.GlassPane(); |
| 74 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); | 75 this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom); |
| 75 this._glassPane.setSetOutsideClickCallback(this.hide.bind(this)); | 76 this._glassPane.setSetOutsideClickCallback(this.hide.bind(this)); |
| 76 var shadowRoot = UI.createShadowRootWithCoreStyles(this._glassPane.contentEl ement, 'ui/suggestBox.css'); | 77 var shadowRoot = UI.createShadowRootWithCoreStyles(this._glassPane.contentEl ement, 'ui/suggestBox.css'); |
| 77 shadowRoot.appendChild(this._element); | 78 shadowRoot.appendChild(this._element); |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 82 * @param {boolean} value | |
| 83 */ | |
| 84 setUserInteractionStyling(value) { | |
| 85 this._userInteractionStyling = value; | |
|
dgozman
2017/03/11 00:00:24
Drop it.
lushnikov
2017/03/11 00:09:59
Done.
| |
| 86 this._element.classList.toggle('enable-interaction-styling', value); | |
| 87 } | |
| 88 | |
| 89 /** | |
| 90 * @param {boolean} value | |
| 91 */ | |
| 92 _setUserInteracted(value) { | |
| 93 this._userInteracted = value; | |
| 94 this._element.classList.toggle('user-has-interacted', value); | |
| 95 } | |
| 96 | |
| 97 /** | |
| 81 * @return {boolean} | 98 * @return {boolean} |
| 82 */ | 99 */ |
| 83 visible() { | 100 visible() { |
| 84 return this._glassPane.isShowing(); | 101 return this._glassPane.isShowing(); |
| 85 } | 102 } |
| 86 | 103 |
| 87 /** | 104 /** |
| 88 * @param {!AnchorBox} anchorBox | 105 * @param {!AnchorBox} anchorBox |
| 89 */ | 106 */ |
| 90 setPosition(anchorBox) { | 107 setPosition(anchorBox) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 return; | 147 return; |
| 131 // TODO(dgozman): take document as a parameter. | 148 // TODO(dgozman): take document as a parameter. |
| 132 this._glassPane.show(document); | 149 this._glassPane.show(document); |
| 133 this._rowHeight = | 150 this._rowHeight = |
| 134 UI.measurePreferredSize(this.createElementForItem({text: '1', subtitle: '12'}), this._element).height; | 151 UI.measurePreferredSize(this.createElementForItem({text: '1', subtitle: '12'}), this._element).height; |
| 135 } | 152 } |
| 136 | 153 |
| 137 hide() { | 154 hide() { |
| 138 if (!this.visible()) | 155 if (!this.visible()) |
| 139 return; | 156 return; |
| 140 this._userInteracted = false; | 157 this._setUserInteracted(false); |
| 141 this._glassPane.hide(); | 158 this._glassPane.hide(); |
| 142 } | 159 } |
| 143 | 160 |
| 144 /** | 161 /** |
| 145 * @param {boolean=} isIntermediateSuggestion | 162 * @param {boolean=} isIntermediateSuggestion |
| 146 * @return {boolean} | 163 * @return {boolean} |
| 147 */ | 164 */ |
| 148 _applySuggestion(isIntermediateSuggestion) { | 165 _applySuggestion(isIntermediateSuggestion) { |
| 149 if (this._onlyCompletion) { | 166 if (this._onlyCompletion) { |
| 150 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isIntermedi ateSuggestion); | 167 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isIntermedi ateSuggestion); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 titleElement.createChild('span', 'query').textContent = displayText.substr ing(index, index + query.length); | 219 titleElement.createChild('span', 'query').textContent = displayText.substr ing(index, index + query.length); |
| 203 titleElement.createChild('span').textContent = displayText.substring(index > -1 ? index + query.length : 0); | 220 titleElement.createChild('span').textContent = displayText.substring(index > -1 ? index + query.length : 0); |
| 204 titleElement.createChild('span', 'spacer'); | 221 titleElement.createChild('span', 'spacer'); |
| 205 if (item.subtitle) { | 222 if (item.subtitle) { |
| 206 var subtitleElement = element.createChild('span', 'suggestion-subtitle'); | 223 var subtitleElement = element.createChild('span', 'suggestion-subtitle'); |
| 207 subtitleElement.textContent = item.subtitle.trimEnd(maxTextLength - displa yText.length); | 224 subtitleElement.textContent = item.subtitle.trimEnd(maxTextLength - displa yText.length); |
| 208 } | 225 } |
| 209 | 226 |
| 210 element.addEventListener('click', event => { | 227 element.addEventListener('click', event => { |
| 211 this._list.selectItem(item); | 228 this._list.selectItem(item); |
| 212 this._userInteracted = true; | 229 this._setUserInteracted(true); |
| 213 event.consume(true); | 230 event.consume(true); |
| 214 this.acceptSuggestion(); | 231 this.acceptSuggestion(); |
| 215 }); | 232 }); |
| 216 return element; | 233 return element; |
| 217 } | 234 } |
| 218 | 235 |
| 219 /** | 236 /** |
| 220 * @override | 237 * @override |
| 221 * @param {!UI.SuggestBox.Suggestion} item | 238 * @param {!UI.SuggestBox.Suggestion} item |
| 222 * @return {number} | 239 * @return {number} |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 case 'PageUp': | 345 case 'PageUp': |
| 329 selected = this._list.selectItemPreviousPage(false); | 346 selected = this._list.selectItemPreviousPage(false); |
| 330 break; | 347 break; |
| 331 case 'PageDown': | 348 case 'PageDown': |
| 332 selected = this._list.selectItemNextPage(false); | 349 selected = this._list.selectItemNextPage(false); |
| 333 break; | 350 break; |
| 334 default: | 351 default: |
| 335 return false; | 352 return false; |
| 336 } | 353 } |
| 337 if (selected) { | 354 if (selected) { |
| 338 this._userInteracted = true; | 355 this._setUserInteracted(true); |
| 339 return true; | 356 return true; |
| 340 } | 357 } |
| 341 return false; | 358 return false; |
| 342 } | 359 } |
| 343 | 360 |
| 344 /** | 361 /** |
| 345 * @return {boolean} | 362 * @return {boolean} |
| 346 */ | 363 */ |
| 347 enterKeyPressed() { | 364 enterKeyPressed() { |
| 348 if (!this._userInteracted && this._captureEnter) | 365 if (!this._userInteracted && this._captureEnter) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 359 | 376 |
| 360 /** | 377 /** |
| 361 * @typedef {!{text: string, subtitle: (string|undefined), iconType: (string|und efined), priority: (number|undefined), isSecondary: (boolean|undefined), title: (string|undefined)}} | 378 * @typedef {!{text: string, subtitle: (string|undefined), iconType: (string|und efined), priority: (number|undefined), isSecondary: (boolean|undefined), title: (string|undefined)}} |
| 362 */ | 379 */ |
| 363 UI.SuggestBox.Suggestion; | 380 UI.SuggestBox.Suggestion; |
| 364 | 381 |
| 365 /** | 382 /** |
| 366 * @typedef {!Array<!UI.SuggestBox.Suggestion>} | 383 * @typedef {!Array<!UI.SuggestBox.Suggestion>} |
| 367 */ | 384 */ |
| 368 UI.SuggestBox.Suggestions; | 385 UI.SuggestBox.Suggestions; |
| OLD | NEW |