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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 /** | 45 /** |
46 * acceptSuggestion will be always called after call to applySuggestion with
isIntermediateSuggestion being equal to false. | 46 * acceptSuggestion will be always called after call to applySuggestion with
isIntermediateSuggestion being equal to false. |
47 */ | 47 */ |
48 acceptSuggestion: function() { }, | 48 acceptSuggestion: function() { }, |
49 } | 49 } |
50 | 50 |
51 /** | 51 /** |
52 * @constructor | 52 * @constructor |
53 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate | 53 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate |
54 * @param {number=} maxItemsHeight | 54 * @param {number=} maxItemsHeight |
| 55 * @param {boolean=} captureEnter |
55 */ | 56 */ |
56 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight) | 57 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight, captureEn
ter) |
57 { | 58 { |
58 this._suggestBoxDelegate = suggestBoxDelegate; | 59 this._suggestBoxDelegate = suggestBoxDelegate; |
59 this._length = 0; | 60 this._length = 0; |
60 this._selectedIndex = -1; | 61 this._selectedIndex = -1; |
61 this._selectedElement = null; | 62 this._selectedElement = null; |
62 this._maxItemsHeight = maxItemsHeight; | 63 this._maxItemsHeight = maxItemsHeight; |
63 this._maybeHideBound = this._maybeHide.bind(this); | 64 this._maybeHideBound = this._maybeHide.bind(this); |
64 this._container = createElementWithClass("div", "suggest-box-container"); | 65 this._container = createElementWithClass("div", "suggest-box-container"); |
65 this._element = this._container.createChild("div", "suggest-box"); | 66 this._element = this._container.createChild("div", "suggest-box"); |
66 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); | 67 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); |
67 this._detailsPopup = this._container.createChild("div", "suggest-box details
-popup monospace"); | 68 this._detailsPopup = this._container.createChild("div", "suggest-box details
-popup monospace"); |
68 this._detailsPopup.classList.add("hidden"); | 69 this._detailsPopup.classList.add("hidden"); |
69 this._asyncDetailsCallback = null; | 70 this._asyncDetailsCallback = null; |
70 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ | 71 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ |
71 this._asyncDetailsPromises = new Map(); | 72 this._asyncDetailsPromises = new Map(); |
| 73 this._userInteracted = false; |
| 74 this._captureEnter = captureEnter; |
72 } | 75 } |
73 | 76 |
74 /** | 77 /** |
75 * @typedef {!Array.<{title: string, className: (string|undefined)}>} | 78 * @typedef {!Array.<{title: string, className: (string|undefined)}>} |
76 */ | 79 */ |
77 WebInspector.SuggestBox.Suggestions; | 80 WebInspector.SuggestBox.Suggestions; |
78 | 81 |
79 WebInspector.SuggestBox.prototype = { | 82 WebInspector.SuggestBox.prototype = { |
80 /** | 83 /** |
81 * @return {boolean} | 84 * @return {boolean} |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr
ue); | 157 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr
ue); |
155 this._overlay = new WebInspector.SuggestBox.Overlay(); | 158 this._overlay = new WebInspector.SuggestBox.Overlay(); |
156 this._overlay.setContentElement(this._container); | 159 this._overlay.setContentElement(this._container); |
157 }, | 160 }, |
158 | 161 |
159 hide: function() | 162 hide: function() |
160 { | 163 { |
161 if (!this.visible()) | 164 if (!this.visible()) |
162 return; | 165 return; |
163 | 166 |
| 167 this._userInteracted = false; |
164 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound,
true); | 168 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound,
true); |
165 delete this._bodyElement; | 169 delete this._bodyElement; |
166 this._container.remove(); | 170 this._container.remove(); |
167 this._overlay.dispose(); | 171 this._overlay.dispose(); |
168 delete this._overlay; | 172 delete this._overlay; |
169 delete this._selectedElement; | 173 delete this._selectedElement; |
170 this._selectedIndex = -1; | 174 this._selectedIndex = -1; |
171 delete this._lastAnchorBox; | 175 delete this._lastAnchorBox; |
172 }, | 176 }, |
173 | 177 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 /** | 219 /** |
216 * @param {number} shift | 220 * @param {number} shift |
217 * @param {boolean=} isCircular | 221 * @param {boolean=} isCircular |
218 * @return {boolean} is changed | 222 * @return {boolean} is changed |
219 */ | 223 */ |
220 _selectClosest: function(shift, isCircular) | 224 _selectClosest: function(shift, isCircular) |
221 { | 225 { |
222 if (!this._length) | 226 if (!this._length) |
223 return false; | 227 return false; |
224 | 228 |
| 229 this._userInteracted = true; |
| 230 |
225 if (this._selectedIndex === -1 && shift < 0) | 231 if (this._selectedIndex === -1 && shift < 0) |
226 shift += 1; | 232 shift += 1; |
227 | 233 |
228 var index = this._selectedIndex + shift; | 234 var index = this._selectedIndex + shift; |
229 | 235 |
230 if (isCircular) | 236 if (isCircular) |
231 index = (this._length + index) % this._length; | 237 index = (this._length + index) % this._length; |
232 else | 238 else |
233 index = Number.constrain(index, 0, this._length - 1); | 239 index = Number.constrain(index, 0, this._length - 1); |
234 | 240 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 { | 458 { |
453 this._ensureRowCountPerViewport(); | 459 this._ensureRowCountPerViewport(); |
454 return this._selectClosest(this._rowCountPerViewport, false); | 460 return this._selectClosest(this._rowCountPerViewport, false); |
455 }, | 461 }, |
456 | 462 |
457 /** | 463 /** |
458 * @return {boolean} | 464 * @return {boolean} |
459 */ | 465 */ |
460 enterKeyPressed: function() | 466 enterKeyPressed: function() |
461 { | 467 { |
| 468 if (!this._userInteracted && this._captureEnter) |
| 469 return false; |
| 470 |
462 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; | 471 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; |
463 this.acceptSuggestion(); | 472 this.acceptSuggestion(); |
464 | 473 |
465 // Report the event as non-handled if there is no selected item, | 474 // Report the event as non-handled if there is no selected item, |
466 // to commit the input or handle it otherwise. | 475 // to commit the input or handle it otherwise. |
467 return hasSelectedItem; | 476 return hasSelectedItem; |
468 } | 477 } |
469 } | 478 } |
470 | 479 |
471 /** | 480 /** |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 this.element.style.top = containerBox.y + "px"; | 537 this.element.style.top = containerBox.y + "px"; |
529 this.element.style.height = containerBox.height + "px"; | 538 this.element.style.height = containerBox.height + "px"; |
530 this.element.style.width = containerBox.width + "px"; | 539 this.element.style.width = containerBox.width + "px"; |
531 }, | 540 }, |
532 | 541 |
533 dispose: function() | 542 dispose: function() |
534 { | 543 { |
535 this.element.remove(); | 544 this.element.remove(); |
536 } | 545 } |
537 } | 546 } |
OLD | NEW |