Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: Source/devtools/front_end/ui/TextPrompt.js

Issue 367093003: DevTools: More code reduce via using document.createElementWithClass and document.createChild. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/ui/TabbedPane.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 /** 151 /**
152 * @param {string} x 152 * @param {string} x
153 */ 153 */
154 set text(x) 154 set text(x)
155 { 155 {
156 this._removeSuggestionAids(); 156 this._removeSuggestionAids();
157 if (!x) { 157 if (!x) {
158 // Append a break element instead of setting textContent to make sur e the selection is inside the prompt. 158 // Append a break element instead of setting textContent to make sur e the selection is inside the prompt.
159 this._element.removeChildren(); 159 this._element.removeChildren();
160 this._element.appendChild(document.createElement("br")); 160 this._element.createChild("br");
161 } else 161 } else {
162 this._element.textContent = x; 162 this._element.textContent = x;
163 }
163 164
164 this.moveCaretToEndOfPrompt(); 165 this.moveCaretToEndOfPrompt();
165 this._element.scrollIntoView(); 166 this._element.scrollIntoView();
166 }, 167 },
167 168
168 _removeFromElement: function() 169 _removeFromElement: function()
169 { 170 {
170 this.clearAutoComplete(true); 171 this.clearAutoComplete(true);
171 this._element.removeEventListener("keydown", this._boundOnKeyDown, false ); 172 this._element.removeEventListener("keydown", this._boundOnKeyDown, false );
172 this._element.removeEventListener("input", this._boundOnInput, false); 173 this._element.removeEventListener("input", this._boundOnInput, false);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 this._userEnteredRange.deleteContents(); 475 this._userEnteredRange.deleteContents();
475 this._element.normalize(); 476 this._element.normalize();
476 var finalSelectionRange = document.createRange(); 477 var finalSelectionRange = document.createRange();
477 var completionText = completions[selectedIndex]; 478 var completionText = completions[selectedIndex];
478 var prefixText = completionText.substring(0, wordPrefixLength); 479 var prefixText = completionText.substring(0, wordPrefixLength);
479 var suffixText = completionText.substring(wordPrefixLength); 480 var suffixText = completionText.substring(wordPrefixLength);
480 481
481 var prefixTextNode = document.createTextNode(prefixText); 482 var prefixTextNode = document.createTextNode(prefixText);
482 fullWordRange.insertNode(prefixTextNode); 483 fullWordRange.insertNode(prefixTextNode);
483 484
484 this.autoCompleteElement = document.createElement("span"); 485 this.autoCompleteElement = document.createElementWithClass("span", " auto-complete-text");
485 this.autoCompleteElement.className = "auto-complete-text";
486 this.autoCompleteElement.textContent = suffixText; 486 this.autoCompleteElement.textContent = suffixText;
487 487
488 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre fixTextNode.nextSibling); 488 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre fixTextNode.nextSibling);
489 489
490 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength); 490 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
491 finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength); 491 finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
492 selection.removeAllRanges(); 492 selection.removeAllRanges();
493 selection.addRange(finalSelectionRange); 493 selection.addRange(finalSelectionRange);
494 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApp lied); 494 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApp lied);
495 } 495 }
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 899
900 return; 900 return;
901 } 901 }
902 902
903 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); 903 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments);
904 }, 904 },
905 905
906 __proto__: WebInspector.TextPrompt.prototype 906 __proto__: WebInspector.TextPrompt.prototype
907 } 907 }
908 908
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/TabbedPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698