| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 */ | 55 */ |
| 56 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight) | 56 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight) |
| 57 { | 57 { |
| 58 this._suggestBoxDelegate = suggestBoxDelegate; | 58 this._suggestBoxDelegate = suggestBoxDelegate; |
| 59 this._length = 0; | 59 this._length = 0; |
| 60 this._selectedIndex = -1; | 60 this._selectedIndex = -1; |
| 61 this._selectedElement = null; | 61 this._selectedElement = null; |
| 62 this._maxItemsHeight = maxItemsHeight; | 62 this._maxItemsHeight = maxItemsHeight; |
| 63 this._bodyElement = document.body; | 63 this._bodyElement = document.body; |
| 64 this._maybeHideBound = this._maybeHide.bind(this); | 64 this._maybeHideBound = this._maybeHide.bind(this); |
| 65 this._element = document.createElement("div"); | 65 this._element = document.createElementWithClass("div", "suggest-box"); |
| 66 this._element.className = "suggest-box"; | |
| 67 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); | 66 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); |
| 68 } | 67 } |
| 69 | 68 |
| 70 WebInspector.SuggestBox.prototype = { | 69 WebInspector.SuggestBox.prototype = { |
| 71 /** | 70 /** |
| 72 * @return {boolean} | 71 * @return {boolean} |
| 73 */ | 72 */ |
| 74 visible: function() | 73 visible: function() |
| 75 { | 74 { |
| 76 return !!this._element.parentElement; | 75 return !!this._element.parentElement; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 this.acceptSuggestion(); | 236 this.acceptSuggestion(); |
| 238 event.consume(true); | 237 event.consume(true); |
| 239 }, | 238 }, |
| 240 | 239 |
| 241 /** | 240 /** |
| 242 * @param {string} prefix | 241 * @param {string} prefix |
| 243 * @param {string} text | 242 * @param {string} text |
| 244 */ | 243 */ |
| 245 _createItemElement: function(prefix, text) | 244 _createItemElement: function(prefix, text) |
| 246 { | 245 { |
| 247 var element = document.createElement("div"); | 246 var element = document.createElementWithClass("div", "suggest-box-conten
t-item source-code"); |
| 248 element.className = "suggest-box-content-item source-code"; | |
| 249 element.tabIndex = -1; | 247 element.tabIndex = -1; |
| 250 if (prefix && prefix.length && !text.indexOf(prefix)) { | 248 if (prefix && prefix.length && !text.indexOf(prefix)) { |
| 251 var prefixElement = element.createChild("span", "prefix"); | 249 element.createChild("span", "prefix").textContent = prefix; |
| 252 prefixElement.textContent = prefix; | 250 element.createChild("span", "suffix").textContent = text.substring(p
refix.length); |
| 253 var suffixElement = element.createChild("span", "suffix"); | |
| 254 suffixElement.textContent = text.substring(prefix.length); | |
| 255 } else { | 251 } else { |
| 256 var suffixElement = element.createChild("span", "suffix"); | 252 element.createChild("span", "suffix").textContent = text; |
| 257 suffixElement.textContent = text; | |
| 258 } | 253 } |
| 259 element.createChild("span", "spacer"); | 254 element.createChild("span", "spacer"); |
| 260 element.addEventListener("mousedown", this._onItemMouseDown.bind(this),
false); | 255 element.addEventListener("mousedown", this._onItemMouseDown.bind(this),
false); |
| 261 return element; | 256 return element; |
| 262 }, | 257 }, |
| 263 | 258 |
| 264 /** | 259 /** |
| 265 * @param {!Array.<string>} items | 260 * @param {!Array.<string>} items |
| 266 * @param {string} userEnteredText | 261 * @param {string} userEnteredText |
| 267 */ | 262 */ |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // to commit the input or handle it otherwise. | 406 // to commit the input or handle it otherwise. |
| 412 return hasSelectedItem; | 407 return hasSelectedItem; |
| 413 } | 408 } |
| 414 } | 409 } |
| 415 | 410 |
| 416 /** | 411 /** |
| 417 * @constructor | 412 * @constructor |
| 418 */ | 413 */ |
| 419 WebInspector.SuggestBox.Overlay = function() | 414 WebInspector.SuggestBox.Overlay = function() |
| 420 { | 415 { |
| 421 this.element = document.createElement("div"); | 416 this.element = document.createElementWithClass("div", "suggest-box-overlay")
; |
| 422 this.element.classList.add("suggest-box-overlay"); | |
| 423 this._resize(); | 417 this._resize(); |
| 424 document.body.appendChild(this.element); | 418 document.body.appendChild(this.element); |
| 425 } | 419 } |
| 426 | 420 |
| 427 WebInspector.SuggestBox.Overlay.prototype = { | 421 WebInspector.SuggestBox.Overlay.prototype = { |
| 428 _resize: function() | 422 _resize: function() |
| 429 { | 423 { |
| 430 var container = WebInspector.Dialog.modalHostView().element; | 424 var container = WebInspector.Dialog.modalHostView().element; |
| 431 var containerBox = container.boxInWindow(container.ownerDocument.default
View); | 425 var containerBox = container.boxInWindow(container.ownerDocument.default
View); |
| 432 | 426 |
| 433 this.element.style.left = containerBox.x + "px"; | 427 this.element.style.left = containerBox.x + "px"; |
| 434 this.element.style.top = containerBox.y + "px"; | 428 this.element.style.top = containerBox.y + "px"; |
| 435 this.element.style.height = containerBox.height + "px"; | 429 this.element.style.height = containerBox.height + "px"; |
| 436 this.element.style.width = containerBox.width + "px"; | 430 this.element.style.width = containerBox.width + "px"; |
| 437 }, | 431 }, |
| 438 | 432 |
| 439 dispose: function() | 433 dispose: function() |
| 440 { | 434 { |
| 441 this.element.remove(); | 435 this.element.remove(); |
| 442 } | 436 } |
| 443 } | 437 } |
| OLD | NEW |