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

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

Issue 663083004: [DevTools] Remove remaining usages of global properties. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fixed review comments Created 6 years, 2 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/SuggestBox.js ('k') | Source/devtools/front_end/ui/UIUtils.js » ('j') | 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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 if (commonPrefix[j] !== completion[j]) { 438 if (commonPrefix[j] !== completion[j]) {
439 commonPrefix = commonPrefix.substr(0, j); 439 commonPrefix = commonPrefix.substr(0, j);
440 break; 440 break;
441 } 441 }
442 } 442 }
443 } 443 }
444 return commonPrefix; 444 return commonPrefix;
445 }, 445 },
446 446
447 /** 447 /**
448 * @return {?Range}
449 * @suppressGlobalPropertiesCheck
450 */
451 _createRange: function()
452 {
453 return document.createRange();
454 },
455
456 /**
448 * @param {!Selection} selection 457 * @param {!Selection} selection
449 * @param {!Range} originalWordPrefixRange 458 * @param {!Range} originalWordPrefixRange
450 * @param {boolean} reverse 459 * @param {boolean} reverse
451 * @param {!Array.<string>} completions 460 * @param {!Array.<string>} completions
452 * @param {number=} selectedIndex 461 * @param {number=} selectedIndex
453 */ 462 */
454 _completionsReady: function(selection, originalWordPrefixRange, reverse, com pletions, selectedIndex) 463 _completionsReady: function(selection, originalWordPrefixRange, reverse, com pletions, selectedIndex)
455 { 464 {
456 if (!this._waitingForCompletions || !completions.length) { 465 if (!this._waitingForCompletions || !completions.length) {
457 this.hideSuggestBox(); 466 this.hideSuggestBox();
458 return; 467 return;
459 } 468 }
460 delete this._waitingForCompletions; 469 delete this._waitingForCompletions;
461 470
462 var selectionRange = selection.getRangeAt(0); 471 var selectionRange = selection.getRangeAt(0);
463 472
464 var fullWordRange = document.createRange(); 473 var fullWordRange = this._createRange();
465 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset); 474 fullWordRange.setStart(originalWordPrefixRange.startContainer, originalW ordPrefixRange.startOffset);
466 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et); 475 fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffs et);
467 476
468 if (originalWordPrefixRange.toString() + selectionRange.toString() !== f ullWordRange.toString()) 477 if (originalWordPrefixRange.toString() + selectionRange.toString() !== f ullWordRange.toString())
469 return; 478 return;
470 479
471 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt) ? -1 : (selectedIndex || 0); 480 selectedIndex = (this._disableDefaultSuggestionForEmptyInput && !this.te xt) ? -1 : (selectedIndex || 0);
472 481
473 this._userEnteredRange = fullWordRange; 482 this._userEnteredRange = fullWordRange;
474 this._userEnteredText = fullWordRange.toString(); 483 this._userEnteredText = fullWordRange.toString();
475 484
476 if (this._suggestBox) 485 if (this._suggestBox)
477 this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selecti on, fullWordRange), completions, selectedIndex, !this.isCaretAtEndOfPrompt(), th is._userEnteredText); 486 this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selecti on, fullWordRange), completions, selectedIndex, !this.isCaretAtEndOfPrompt(), th is._userEnteredText);
478 487
479 if (selectedIndex === -1) 488 if (selectedIndex === -1)
480 return; 489 return;
481 490
482 var wordPrefixLength = originalWordPrefixRange.toString().length; 491 var wordPrefixLength = originalWordPrefixRange.toString().length;
483 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng th); 492 this._commonPrefix = this._buildCommonPrefix(completions, wordPrefixLeng th);
484 493
485 if (this.isCaretAtEndOfPrompt()) { 494 if (this.isCaretAtEndOfPrompt()) {
486 var completionText = completions[selectedIndex]; 495 var completionText = completions[selectedIndex];
487 var prefixText = this._userEnteredRange.toString(); 496 var prefixText = this._userEnteredRange.toString();
488 var suffixText = completionText.substring(wordPrefixLength); 497 var suffixText = completionText.substring(wordPrefixLength);
489 this._userEnteredRange.deleteContents(); 498 this._userEnteredRange.deleteContents();
490 this._element.normalize(); 499 this._element.normalize();
491 var finalSelectionRange = document.createRange(); 500 var finalSelectionRange = this._createRange();
492 501
493 var prefixTextNode = createTextNode(prefixText); 502 var prefixTextNode = createTextNode(prefixText);
494 fullWordRange.insertNode(prefixTextNode); 503 fullWordRange.insertNode(prefixTextNode);
495 504
496 this.autoCompleteElement = createElementWithClass("span", "auto-comp lete-text"); 505 this.autoCompleteElement = createElementWithClass("span", "auto-comp lete-text");
497 this.autoCompleteElement.textContent = suffixText; 506 this.autoCompleteElement.textContent = suffixText;
498 507
499 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre fixTextNode.nextSibling); 508 prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, pre fixTextNode.nextSibling);
500 509
501 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength); 510 finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 _applySuggestion: function(completionText, isIntermediateSuggestion, origina lPrefixRange) 546 _applySuggestion: function(completionText, isIntermediateSuggestion, origina lPrefixRange)
538 { 547 {
539 var wordPrefixLength; 548 var wordPrefixLength;
540 if (originalPrefixRange) 549 if (originalPrefixRange)
541 wordPrefixLength = originalPrefixRange.toString().length; 550 wordPrefixLength = originalPrefixRange.toString().length;
542 else 551 else
543 wordPrefixLength = this._userEnteredText ? this._userEnteredText.len gth : 0; 552 wordPrefixLength = this._userEnteredText ? this._userEnteredText.len gth : 0;
544 553
545 this._userEnteredRange.deleteContents(); 554 this._userEnteredRange.deleteContents();
546 this._element.normalize(); 555 this._element.normalize();
547 var finalSelectionRange = document.createRange(); 556 var finalSelectionRange = this._createRange();
548 var completionTextNode = createTextNode(completionText); 557 var completionTextNode = createTextNode(completionText);
549 this._userEnteredRange.insertNode(completionTextNode); 558 this._userEnteredRange.insertNode(completionTextNode);
550 if (this.autoCompleteElement) { 559 if (this.autoCompleteElement) {
551 this.autoCompleteElement.remove(); 560 this.autoCompleteElement.remove();
552 delete this.autoCompleteElement; 561 delete this.autoCompleteElement;
553 } 562 }
554 563
555 if (isIntermediateSuggestion) 564 if (isIntermediateSuggestion)
556 finalSelectionRange.setStart(completionTextNode, wordPrefixLength); 565 finalSelectionRange.setStart(completionTextNode, wordPrefixLength);
557 else 566 else
(...skipping 23 matching lines...) Expand all
581 _acceptSuggestionInternal: function(prefixAccepted) 590 _acceptSuggestionInternal: function(prefixAccepted)
582 { 591 {
583 if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode) 592 if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode)
584 return false; 593 return false;
585 594
586 var text = this.autoCompleteElement.textContent; 595 var text = this.autoCompleteElement.textContent;
587 var textNode = createTextNode(text); 596 var textNode = createTextNode(text);
588 this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoComp leteElement); 597 this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoComp leteElement);
589 delete this.autoCompleteElement; 598 delete this.autoCompleteElement;
590 599
591 var finalSelectionRange = document.createRange(); 600 var finalSelectionRange = this._createRange();
592 finalSelectionRange.setStart(textNode, text.length); 601 finalSelectionRange.setStart(textNode, text.length);
593 finalSelectionRange.setEnd(textNode, text.length); 602 finalSelectionRange.setEnd(textNode, text.length);
594 603
595 var selection = window.getSelection(); 604 var selection = window.getSelection();
596 selection.removeAllRanges(); 605 selection.removeAllRanges();
597 selection.addRange(finalSelectionRange); 606 selection.addRange(finalSelectionRange);
598 607
599 if (!prefixAccepted) { 608 if (!prefixAccepted) {
600 this.hideSuggestBox(); 609 this.hideSuggestBox();
601 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAcc epted); 610 this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAcc epted);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 return false; 713 return false;
705 focusNode = focusNode.nextSibling; 714 focusNode = focusNode.nextSibling;
706 } 715 }
707 716
708 return true; 717 return true;
709 }, 718 },
710 719
711 moveCaretToEndOfPrompt: function() 720 moveCaretToEndOfPrompt: function()
712 { 721 {
713 var selection = window.getSelection(); 722 var selection = window.getSelection();
714 var selectionRange = document.createRange(); 723 var selectionRange = this._createRange();
715 724
716 var offset = this._element.childNodes.length; 725 var offset = this._element.childNodes.length;
717 selectionRange.setStart(this._element, offset); 726 selectionRange.setStart(this._element, offset);
718 selectionRange.setEnd(this._element, offset); 727 selectionRange.setEnd(this._element, offset);
719 728
720 selection.removeAllRanges(); 729 selection.removeAllRanges();
721 selection.addRange(selectionRange); 730 selection.addRange(selectionRange);
722 }, 731 },
723 732
724 /** 733 /**
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 if (newText !== undefined) { 897 if (newText !== undefined) {
889 event.consume(true); 898 event.consume(true);
890 this.text = newText; 899 this.text = newText;
891 900
892 if (isPrevious) { 901 if (isPrevious) {
893 var firstNewlineIndex = this.text.indexOf("\n"); 902 var firstNewlineIndex = this.text.indexOf("\n");
894 if (firstNewlineIndex === -1) 903 if (firstNewlineIndex === -1)
895 this.moveCaretToEndOfPrompt(); 904 this.moveCaretToEndOfPrompt();
896 else { 905 else {
897 var selection = window.getSelection(); 906 var selection = window.getSelection();
898 var selectionRange = document.createRange(); 907 var selectionRange = this._createRange();
899 908
900 selectionRange.setStart(this._element.firstChild, firstNewli neIndex); 909 selectionRange.setStart(this._element.firstChild, firstNewli neIndex);
901 selectionRange.setEnd(this._element.firstChild, firstNewline Index); 910 selectionRange.setEnd(this._element.firstChild, firstNewline Index);
902 911
903 selection.removeAllRanges(); 912 selection.removeAllRanges();
904 selection.addRange(selectionRange); 913 selection.addRange(selectionRange);
905 } 914 }
906 } 915 }
907 916
908 return; 917 return;
909 } 918 }
910 919
911 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments); 920 WebInspector.TextPrompt.prototype.onKeyDown.apply(this, arguments);
912 }, 921 },
913 922
914 __proto__: WebInspector.TextPrompt.prototype 923 __proto__: WebInspector.TextPrompt.prototype
915 } 924 }
916 925
OLDNEW
« no previous file with comments | « Source/devtools/front_end/ui/SuggestBox.js ('k') | Source/devtools/front_end/ui/UIUtils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698