Title: [105499] branches/chromium/963/Source/WebCore/inspector/front-end
Revision
105499
Author
apav...@chromium.org
Date
2012-01-20 02:17:36 -0800 (Fri, 20 Jan 2012)

Log Message

Revert 105252 - Merge 105140 - Web Inspector: [TextPrompt] Autocomplete adds unwanted text that's hard to remove
https://bugs.webkit.org/show_bug.cgi?id=76058

Reviewed by Pavel Feldman.

As per the results of a war room:
- Auto-suggest only after user typing (avoid showing suggestions when navigating through the user input.)
- Do not select the first item if the suggest box is shown at the end of prompt (to allow Enter to commit the input.)
- Only show grayed autocompletion at the end of prompt (otherwise show a suggest box with the first item selected.)
- Grayed autocompletion can only be accepted with the End or Right keys.
- Enter can accept a selected suggestion item from the list, without committing the input.
- Retain the CSS model editing behavior as close to the existing one as possible.
- Enable PageUp/PageDown to navigate the suggest box items.

* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertyTreeElement.prototype):
():
* inspector/front-end/TextPrompt.js:
(WebInspector.TextPrompt.prototype.set text):
(WebInspector.TextPrompt.prototype._removeSuggestionAids):
(WebInspector.TextPrompt.prototype._selectStart.moveBackIfOutside):
(WebInspector.TextPrompt.prototype._selectStart):
(WebInspector.TextPrompt.prototype.onKeyDown):
(WebInspector.TextPrompt.prototype.acceptAutoComplete):
(WebInspector.TextPrompt.prototype.complete):
(WebInspector.TextPrompt.prototype._completionsReady):
(WebInspector.TextPrompt.prototype.isCaretAtEndOfPrompt):
(WebInspector.TextPrompt.prototype.tabKeyPressed):
(WebInspector.TextPrompt.prototype.downKeyPressed):
(WebInspector.TextPrompt.prototype.pageUpKeyPressed):
(WebInspector.TextPrompt.prototype.pageDownKeyPressed):
(WebInspector.TextPrompt.SuggestBox.prototype._onNextItem):
(WebInspector.TextPrompt.SuggestBox.prototype._onPreviousItem):
(WebInspector.TextPrompt.SuggestBox.prototype.updateSuggestions):
(WebInspector.TextPrompt.SuggestBox.prototype._updateItems):
(WebInspector.TextPrompt.SuggestBox.prototype._canShowBox):
(WebInspector.TextPrompt.SuggestBox.prototype._rememberRowCountPerViewport):
(WebInspector.TextPrompt.SuggestBox.prototype._completionsReady):
(WebInspector.TextPrompt.SuggestBox.prototype.pageUpKeyPressed):
(WebInspector.TextPrompt.SuggestBox.prototype.pageDownKeyPressed):
(WebInspector.TextPrompt.SuggestBox.prototype.enterKeyPressed):

TBR=apav...@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9252006

TBR=apav...@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9131006

Modified Paths

Diff

Modified: branches/chromium/963/Source/WebCore/inspector/front-end/StylesSidebarPane.js (105498 => 105499)


--- branches/chromium/963/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-01-20 10:04:30 UTC (rev 105498)
+++ branches/chromium/963/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2012-01-20 10:17:36 UTC (rev 105499)
@@ -2150,9 +2150,9 @@
 
     _hasBeenModifiedIncrementally: function()
     {
-        // New properties applied via up/down or live editing have an originalPropertyText and will be deleted later
+        // New properties applied via up/down have an originalPropertyText and will be deleted later
         // on, if cancelled, when the empty string gets applied as their style text.
-        return typeof this.originalPropertyText === "string" || (!!this.property.propertyText && this._newProperty);
+        return typeof this.originalPropertyText === "string";
     },
 
     applyStyleText: function(styleText, updateInterface, majorChange, isRevert)
@@ -2178,7 +2178,7 @@
         styleText = styleText.replace(/\s/g, " ").trim(); // Replace   with whitespace.
         var styleTextLength = styleText.length;
         if (!styleTextLength && updateInterface && !isRevert && this._newProperty && !this._hasBeenModifiedIncrementally()) {
-            // The user deleted everything and never applied a new property value via Up/Down scrolling/live editing, so remove the tree element and update.
+            // The user deleted everything and never applied a new property value via Up/Down scrolling, so remove the tree element and update.
             this.parent.removeChild(this);
             section.afterUpdate();
             return;
@@ -2252,19 +2252,17 @@
                 return;
             }
             break;
+        case "U+0009":
+            if (this.isSuggestBoxVisible()) {
+                this._suggestBox.acceptSuggestion();
+                return !this._isEditingName;
+            }
+            return this.acceptAutoComplete();
         }
 
         WebInspector.TextPrompt.prototype.onKeyDown.call(this, event);
     },
 
-    tabKeyPressed: function()
-    {
-        this.acceptAutoComplete();
-
-        // Always tab to the next field.
-        return false;
-    },
-
     _handleNameOrValueUpDown: function(event)
     {
         // Handle numeric value increment/decrement only at this point.

Modified: branches/chromium/963/Source/WebCore/inspector/front-end/TextPrompt.js (105498 => 105499)


--- branches/chromium/963/Source/WebCore/inspector/front-end/TextPrompt.js	2012-01-20 10:04:30 UTC (rev 105498)
+++ branches/chromium/963/Source/WebCore/inspector/front-end/TextPrompt.js	2012-01-20 10:17:36 UTC (rev 105499)
@@ -137,7 +137,7 @@
 
     set text(x)
     {
-        this._removeSuggestionAids();
+        this.clearAutoComplete(true);
         if (!x) {
             // Append a break element instead of setting textContent to make sure the selection is inside the prompt.
             this._element.removeChildren();
@@ -186,26 +186,19 @@
         WebInspector.markBeingEdited(this._element, false);
     },
 
-    _removeSuggestionAids: function()
-    {
-        this.clearAutoComplete();
-        this.hideSuggestBox();
-    },
-
     _selectStart: function(event)
     {
         if (this._selectionTimeout)
             clearTimeout(this._selectionTimeout);
 
-        this._removeSuggestionAids();
+        this.clearAutoComplete();
 
         function moveBackIfOutside()
         {
             delete this._selectionTimeout;
-            if (!this.isCaretInsidePrompt() && window.getSelection().isCollapsed) {
+            if (!this.isCaretInsidePrompt() && window.getSelection().isCollapsed)
                 this.moveCaretToEndOfPrompt();
-                this.autoCompleteSoon();
-            }
+            this.autoCompleteSoon();
         }
 
         this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100);
@@ -233,37 +226,28 @@
         case "Down":
             handled = this.downKeyPressed(event);
             break;
-        case "PageUp":
-            handled = this.pageUpKeyPressed(event);
-            break;
-        case "PageDown":
-            handled = this.pageDownKeyPressed(event);
-            break;
         case "U+0009": // Tab
             handled = this.tabKeyPressed(event);
             break;
         case "Enter":
             handled = this.enterKeyPressed(event);
             break;
-        case "Left":
-        case "Home":
-            this._removeSuggestionAids();
-            invokeDefault = false;
-            break;
         case "Right":
         case "End":
-            if (this.isCaretAtEndOfPrompt())
+            if (this.isSuggestBoxVisible() && this.isCaretAtEndOfPrompt())
+                handled = this._suggestBox.tabKeyPressed(event);
+            else {
                 handled = this.acceptAutoComplete();
-            else
-                this._removeSuggestionAids();
-            invokeDefault = false;
+                if (!handled)
+                    this.autoCompleteSoon();
+            }
             break;
         case "U+001B": // Esc
             if (this.isSuggestBoxVisible()) {
                 this._suggestBox.hide();
                 handled = true;
+                break;
             }
-            break;
         case "U+0020": // Space
             if (this._suggestForceable && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
                 this.defaultKeyHandler(event, true);
@@ -291,13 +275,9 @@
 
     acceptAutoComplete: function()
     {
-        var result = false;
         if (this.isSuggestBoxVisible())
-            result = this._suggestBox.acceptSuggestion();
-        if (!result)
-            result = this.acceptSuggestion();
-
-        return result;
+            return this._suggestBox.acceptSuggestion();
+        return this.acceptSuggestion();
     },
 
     /**
@@ -368,7 +348,7 @@
             shouldExit = true;
         else if (!auto && !isEmptyInput && !selectionRange.commonAncestorContainer.isDescendant(this._element))
             shouldExit = true;
-        else if (auto && !force && !this.isCaretAtEndOfPrompt() && !this.isSuggestBoxVisible())
+        else if (auto && !this._suggestBox && !force && !this.isCaretAtEndOfPrompt())
             shouldExit = true;
         else if (!selection.isCollapsed)
             shouldExit = true;
@@ -425,7 +405,7 @@
         this._userEnteredText = fullWordRange.toString();
 
         if (this._suggestBox)
-            this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions, !this.isCaretAtEndOfPrompt());
+            this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions);
 
         var wordPrefixLength = originalWordPrefixRange.toString().length;
 
@@ -472,27 +452,25 @@
         }
 
         if (auto) {
-            if (this.isCaretAtEndOfPrompt()) {
-                this._userEnteredRange.deleteContents();
-                this._element.pruneEmptyTextNodes();
-                var finalSelectionRange = document.createRange();
-                var prefixText = completionText.substring(0, wordPrefixLength);
-                var suffixText = completionText.substring(wordPrefixLength);
+            this._userEnteredRange.deleteContents();
+            this._element.pruneEmptyTextNodes();
+            var finalSelectionRange = document.createRange();
+            var prefixText = completionText.substring(0, wordPrefixLength);
+            var suffixText = completionText.substring(wordPrefixLength);
 
-                var prefixTextNode = document.createTextNode(prefixText);
-                fullWordRange.insertNode(prefixTextNode);
+            var prefixTextNode = document.createTextNode(prefixText);
+            fullWordRange.insertNode(prefixTextNode);
 
-                this.autoCompleteElement = document.createElement("span");
-                this.autoCompleteElement.className = "auto-complete-text";
-                this.autoCompleteElement.textContent = suffixText;
+            this.autoCompleteElement = document.createElement("span");
+            this.autoCompleteElement.className = "auto-complete-text";
+            this.autoCompleteElement.textContent = suffixText;
 
-                prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling);
+            prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling);
 
-                finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
-                finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
-                selection.removeAllRanges();
-                selection.addRange(finalSelectionRange);
-            }
+            finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
+            finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
+            selection.removeAllRanges();
+            selection.addRange(finalSelectionRange);
         } else
             this.applySuggestion(completionText, completions.length > 1, originalWordPrefixRange);
     },
@@ -587,7 +565,7 @@
         var foundNextText = false;
         while (node) {
             if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) {
-                if (foundNextText && (!this.autoCompleteElement || !this.autoCompleteElement.isAncestor(node)))
+                if (foundNextText)
                     return false;
                 foundNextText = true;
             }
@@ -657,7 +635,10 @@
 
     tabKeyPressed: function(event)
     {
-        // Just consume the key.
+        if (this.isSuggestBoxVisible())
+            return this._suggestBox.tabKeyPressed(event);
+
+        this.complete(false, false, event.shiftKey);
         return true;
     },
 
@@ -683,23 +664,7 @@
             return this._suggestBox.downKeyPressed(event);
 
         return false;
-    },
-
-    pageUpKeyPressed: function(event)
-    {
-        if (this.isSuggestBoxVisible())
-            return this._suggestBox.pageUpKeyPressed(event);
-
-        return false;
-    },
-
-    pageDownKeyPressed: function(event)
-    {
-        if (this.isSuggestBoxVisible())
-            return this._suggestBox.pageDownKeyPressed(event);
-
-        return false;
-    },
+    }
 }
 
 WebInspector.TextPrompt.prototype.__proto__ = WebInspector.Object.prototype;
@@ -1022,59 +987,31 @@
         return true;
     },
 
-    _onNextItem: function(event, isPageScroll)
+    _onNextItem: function(event)
     {
         var children = this.contentElement.childNodes;
         if (!children.length)
             return false;
 
-        if (!this._selectedElement)
+        if (this._selectedElement)
+            this._selectedElement = this._selectedElement.nextSibling || this.contentElement.firstChild;
+        else
             this._selectedElement = this.contentElement.firstChild;
-        else {
-            if (!isPageScroll)
-                this._selectedElement = this._selectedElement.nextSibling || this.contentElement.firstChild;
-            else {
-                var candidate = this._selectedElement;
-
-                for (var itemsLeft = this._rowCountPerViewport; itemsLeft; --itemsLeft) {
-                    if (candidate.nextSibling)
-                        candidate = candidate.nextSibling;
-                    else
-                        break;
-                }
-
-                this._selectedElement = candidate;
-            }
-        }
         this._updateSelection();
         this._applySuggestion(undefined, true);
         return true;
     },
 
-    _onPreviousItem: function(event, isPageScroll)
+    _onPreviousItem: function(event)
     {
         var children = this.contentElement.childNodes;
         if (!children.length)
             return false;
 
-        if (!this._selectedElement)
+        if (this._selectedElement)
+            this._selectedElement = this._selectedElement.previousSibling || this.contentElement.lastChild;
+        else
             this._selectedElement = this.contentElement.lastChild;
-        else {
-            if (!isPageScroll)
-                this._selectedElement = this._selectedElement.previousSibling || this.contentElement.lastChild;
-            else {
-                var candidate = this._selectedElement;
-
-                for (var itemsLeft = this._rowCountPerViewport; itemsLeft; --itemsLeft) {
-                    if (candidate.previousSibling)
-                        candidate = candidate.previousSibling;
-                    else
-                        break;
-                }
-
-                this._selectedElement = candidate;
-            }
-        }
         this._updateSelection();
         this._applySuggestion(undefined, true);
         return true;
@@ -1083,15 +1020,14 @@
     /**
      * @param {AnchorBox} anchorBox
      * @param {Array.<string>=} completions
-     * @param {boolean=} canShowForSingleItem
      */
-    updateSuggestions: function(anchorBox, completions, canShowForSingleItem)
+    updateSuggestions: function(anchorBox, completions)
     {
         if (this._suggestTimeout) {
             clearTimeout(this._suggestTimeout);
             delete this._suggestTimeout;
         }
-        this._completionsReady(anchorBox, completions, canShowForSingleItem);
+        this._completionsReady(anchorBox, completions);
     },
 
     _onItemMouseDown: function(text, event)
@@ -1119,11 +1055,14 @@
         return element;
     },
 
-    /**
-     * @param {boolean=} canShowForSingleItem
-     */
-    _updateItems: function(items, canShowForSingleItem)
+    _updateItems: function(items)
     {
+        var children = this.contentElement.children;
+        this._selectedIndex = Math.min(children.length - 1, this._selectedIndex);
+        var selectedItemText = this._selectedIndex >= 0 ? children[this._selectedIndex].textContent : null;
+        var itemIndex = 0;
+        var child = this.contentElement.firstChild;
+        var childText = child ? child.textContent : null;
         this.contentElement.removeChildren();
 
         var userEnteredText = this._textPrompt._userEnteredText;
@@ -1133,7 +1072,7 @@
             this.contentElement.appendChild(currentItemElement);
         }
 
-        this._selectedElement = canShowForSingleItem ? this.contentElement.firstChild : null;
+        this._selectedElement = this.contentElement.firstChild;
         this._updateSelection();
     },
 
@@ -1151,41 +1090,21 @@
     },
 
     /**
+     * @param {AnchorBox} anchorBox
      * @param {Array.<string>=} completions
-     * @param {boolean=} canShowForSingleItem
      */
-    _canShowBox: function(completions, canShowForSingleItem)
+    _completionsReady: function(anchorBox, completions)
     {
-        if (!completions || !completions.length)
-            return false;
-
-        if (completions.length > 1)
-            return true;
-
-        // Do not show a single suggestion if it is the same as user-entered prefix, even if allowed to show single-item suggest boxes.
-        return canShowForSingleItem && completions[0] !== this._textPrompt._userEnteredText;
-    },
-
-    _rememberRowCountPerViewport: function()
-    {
-        if (!this.contentElement.firstChild)
+        if (!completions || !completions.length) {
+            this.hide()
             return;
+        }
 
-        this._rowCountPerViewport = Math.floor(this.containerElement.offsetHeight / this.contentElement.firstChild.offsetHeight);
-    },
-
-    /**
-     * @param {AnchorBox} anchorBox
-     * @param {Array.<string>=} completions
-     * @param {boolean=} canShowForSingleItem
-     */
-    _completionsReady: function(anchorBox, completions, canShowForSingleItem)
-    {
-        if (this._canShowBox(completions, canShowForSingleItem)) {
-            this._updateItems(completions, canShowForSingleItem);
-            this._updateBoxPosition(anchorBox);
+        this._updateItems(completions);
+        this._updateBoxPosition(anchorBox);
+        if (this.contentElement.children.length && this.contentElement.children.length > 1) {
+            // Will not be shown if a sole suggestion is equal to the user input.
             this._element.addStyleClass("visible");
-            this._rememberRowCountPerViewport();
         } else
             this.hide();
     },
@@ -1200,24 +1119,10 @@
         return this._onNextItem(event);
     },
 
-    pageUpKeyPressed: function(event)
-    {
-        return this._onPreviousItem(event, true);
-    },
-
-    pageDownKeyPressed: function(event)
-    {
-        return this._onNextItem(event, true);
-    },
-
     enterKeyPressed: function(event)
     {
-        var hasSelectedItem = !!this._selectedElement;
         this.acceptSuggestion();
-
-        // Report the event as non-handled if there is no selected item,
-        // to commit the input or handle it otherwise.
-        return hasSelectedItem;
+        return true;
     },
 
     tabKeyPressed: function(event)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to