OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2011 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 this._boundOnMouseWheel = this.onMouseWheel.bind(this); | 108 this._boundOnMouseWheel = this.onMouseWheel.bind(this); |
109 this._boundClearAutocomplete = this.clearAutocomplete.bind(this); | 109 this._boundClearAutocomplete = this.clearAutocomplete.bind(this); |
110 this._proxyElement = element.ownerDocument.createElement('span'); | 110 this._proxyElement = element.ownerDocument.createElement('span'); |
111 var shadowRoot = UI.createShadowRootWithCoreStyles(this._proxyElement, 'ui/t
extPrompt.css'); | 111 var shadowRoot = UI.createShadowRootWithCoreStyles(this._proxyElement, 'ui/t
extPrompt.css'); |
112 this._contentElement = shadowRoot.createChild('div', 'text-prompt-root'); | 112 this._contentElement = shadowRoot.createChild('div', 'text-prompt-root'); |
113 this._contentElement.createChild('content'); | 113 this._contentElement.createChild('content'); |
114 this._proxyElement.style.display = this._proxyElementDisplay; | 114 this._proxyElement.style.display = this._proxyElementDisplay; |
115 element.parentElement.insertBefore(this._proxyElement, element); | 115 element.parentElement.insertBefore(this._proxyElement, element); |
116 this._proxyElement.appendChild(element); | 116 this._proxyElement.appendChild(element); |
117 this._element.classList.add('text-prompt'); | 117 this._element.classList.add('text-prompt'); |
| 118 this._element.setAttribute('contenteditable', 'plaintext-only'); |
118 this._element.addEventListener('keydown', this._boundOnKeyDown, false); | 119 this._element.addEventListener('keydown', this._boundOnKeyDown, false); |
119 this._element.addEventListener('input', this._boundOnInput, false); | 120 this._element.addEventListener('input', this._boundOnInput, false); |
120 this._element.addEventListener('mousewheel', this._boundOnMouseWheel, false)
; | 121 this._element.addEventListener('mousewheel', this._boundOnMouseWheel, false)
; |
121 this._element.addEventListener('selectstart', this._boundClearAutocomplete,
false); | 122 this._element.addEventListener('selectstart', this._boundClearAutocomplete,
false); |
122 this._element.addEventListener('blur', this._boundClearAutocomplete, false); | 123 this._element.addEventListener('blur', this._boundClearAutocomplete, false); |
123 | 124 |
124 this._suggestBox = new UI.SuggestBox(this, 20, true); | 125 this._suggestBox = new UI.SuggestBox(this, 20, true); |
125 | 126 |
126 if (this._title) | 127 if (this._title) |
127 this._proxyElement.title = this._title; | 128 this._proxyElement.title = this._title; |
128 | 129 |
129 return this._proxyElement; | 130 return this._proxyElement; |
130 } | 131 } |
131 | 132 |
132 detach() { | 133 detach() { |
133 this._removeFromElement(); | 134 this._removeFromElement(); |
134 this._focusRestorer.restore(); | 135 this._focusRestorer.restore(); |
135 this._proxyElement.parentElement.insertBefore(this._element, this._proxyElem
ent); | 136 this._proxyElement.parentElement.insertBefore(this._element, this._proxyElem
ent); |
136 this._proxyElement.remove(); | 137 this._proxyElement.remove(); |
137 delete this._proxyElement; | 138 delete this._proxyElement; |
138 this._element.classList.remove('text-prompt'); | 139 this._element.classList.remove('text-prompt'); |
| 140 this._element.removeAttribute('contenteditable'); |
139 } | 141 } |
140 | 142 |
141 /** | 143 /** |
142 * @return {string} | 144 * @return {string} |
143 */ | 145 */ |
144 textWithCurrentSuggestion() { | 146 textWithCurrentSuggestion() { |
145 var text = this.text(); | 147 var text = this.text(); |
146 if (!this._queryRange) | 148 if (!this._queryRange) |
147 return text; | 149 return text; |
148 return text.substring(0, this._queryRange.startColumn) + this._currentSugges
tion + | 150 return text.substring(0, this._queryRange.startColumn) + this._currentSugges
tion + |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 return this._proxyElement || null; | 629 return this._proxyElement || null; |
628 } | 630 } |
629 }; | 631 }; |
630 | 632 |
631 UI.TextPrompt.DefaultAutocompletionTimeout = 250; | 633 UI.TextPrompt.DefaultAutocompletionTimeout = 250; |
632 | 634 |
633 /** @enum {symbol} */ | 635 /** @enum {symbol} */ |
634 UI.TextPrompt.Events = { | 636 UI.TextPrompt.Events = { |
635 TextChanged: Symbol('TextChanged') | 637 TextChanged: Symbol('TextChanged') |
636 }; | 638 }; |
OLD | NEW |