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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 return proxyElement; | 94 return proxyElement; |
95 } | 95 } |
96 | 96 |
97 /** | 97 /** |
98 * @param {!Element} element | 98 * @param {!Element} element |
99 * @return {!Element} | 99 * @return {!Element} |
100 */ | 100 */ |
101 _attachInternal(element) { | 101 _attachInternal(element) { |
102 if (this._proxyElement) | 102 if (this._proxyElement) |
103 throw 'Cannot attach an attached TextPrompt'; | 103 throw 'Cannot attach an attached TextPrompt'; |
104 this._element = element; | 104 this._element = element; |
dgozman
2017/05/02 21:09:21
Let's just do it here.
einbinder
2017/05/04 00:56:25
Sounds good.
| |
105 | 105 |
106 this._boundOnKeyDown = this.onKeyDown.bind(this); | 106 this._boundOnKeyDown = this.onKeyDown.bind(this); |
107 this._boundOnInput = this.onInput.bind(this); | 107 this._boundOnInput = this.onInput.bind(this); |
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; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 this._stopEditing(); | 209 this._stopEditing(); |
210 if (this._suggestBox) | 210 if (this._suggestBox) |
211 this._suggestBox.hide(); | 211 this._suggestBox.hide(); |
212 } | 212 } |
213 | 213 |
214 /** | 214 /** |
215 * @param {function(!Event)=} blurListener | 215 * @param {function(!Event)=} blurListener |
216 */ | 216 */ |
217 _startEditing(blurListener) { | 217 _startEditing(blurListener) { |
218 this._isEditing = true; | 218 this._isEditing = true; |
219 this._element.setAttribute('contenteditable', 'plaintext-only'); | |
219 this._contentElement.classList.add('text-prompt-editing'); | 220 this._contentElement.classList.add('text-prompt-editing'); |
220 if (blurListener) { | 221 if (blurListener) { |
221 this._blurListener = blurListener; | 222 this._blurListener = blurListener; |
222 this._element.addEventListener('blur', this._blurListener, false); | 223 this._element.addEventListener('blur', this._blurListener, false); |
223 } | 224 } |
224 this._oldTabIndex = this._element.tabIndex; | 225 this._oldTabIndex = this._element.tabIndex; |
225 if (this._element.tabIndex < 0) | 226 if (this._element.tabIndex < 0) |
226 this._element.tabIndex = 0; | 227 this._element.tabIndex = 0; |
227 this._focusRestorer = new UI.ElementFocusRestorer(this._element); | 228 this._focusRestorer = new UI.ElementFocusRestorer(this._element); |
228 if (!this.text()) | 229 if (!this.text()) |
229 this.autoCompleteSoon(); | 230 this.autoCompleteSoon(); |
230 } | 231 } |
231 | 232 |
232 _stopEditing() { | 233 _stopEditing() { |
233 this._element.tabIndex = this._oldTabIndex; | 234 this._element.tabIndex = this._oldTabIndex; |
234 if (this._blurListener) | 235 if (this._blurListener) |
235 this._element.removeEventListener('blur', this._blurListener, false); | 236 this._element.removeEventListener('blur', this._blurListener, false); |
236 this._contentElement.classList.remove('text-prompt-editing'); | 237 this._contentElement.classList.remove('text-prompt-editing'); |
238 this._element.removeAttribute('contenteditable'); | |
237 delete this._isEditing; | 239 delete this._isEditing; |
238 } | 240 } |
239 | 241 |
240 /** | 242 /** |
241 * @param {!Event} event | 243 * @param {!Event} event |
242 */ | 244 */ |
243 onMouseWheel(event) { | 245 onMouseWheel(event) { |
244 // Subclasses can implement. | 246 // Subclasses can implement. |
245 } | 247 } |
246 | 248 |
(...skipping 380 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 |