Title: [99407] trunk/Source/WebCore
Revision
99407
Author
[email protected]
Date
2011-11-07 04:50:02 -0800 (Mon, 07 Nov 2011)

Log Message

Web Inspector: autocomplete combobox for Styles sidebar and Console.
https://bugs.webkit.org/show_bug.cgi?id=65511

Reviewed by Pavel Feldman.

* inspector/front-end/ConsoleView.js:
(WebInspector.ConsoleView):
* inspector/front-end/StylesSidebarPane.js:
(WebInspector.StylePropertyTreeElement.prototype):
():
* inspector/front-end/TextPrompt.js:
(WebInspector.TextPrompt):
(WebInspector.TextPrompt.prototype.setSuggestBoxEnabled):
(WebInspector.TextPrompt.prototype._attachInternal):
(WebInspector.TextPrompt.prototype.applySuggestion):
(WebInspector.TextPrompt.prototype.acceptSuggestion):
(WebInspector.TextPromptWithHistory):
* inspector/front-end/inspector.css:
(.suggest-box.generic-suggest):
(.suggest-box.generic-suggest.above-anchor):
(.suggest-box.generic-suggest .content):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (99406 => 99407)


--- trunk/Source/WebCore/ChangeLog	2011-11-07 12:44:33 UTC (rev 99406)
+++ trunk/Source/WebCore/ChangeLog	2011-11-07 12:50:02 UTC (rev 99407)
@@ -1,3 +1,27 @@
+2011-11-07  Alexander Pavlov  <[email protected]>
+
+        Web Inspector: autocomplete combobox for Styles sidebar and Console.
+        https://bugs.webkit.org/show_bug.cgi?id=65511
+
+        Reviewed by Pavel Feldman.
+
+        * inspector/front-end/ConsoleView.js:
+        (WebInspector.ConsoleView):
+        * inspector/front-end/StylesSidebarPane.js:
+        (WebInspector.StylePropertyTreeElement.prototype):
+        ():
+        * inspector/front-end/TextPrompt.js:
+        (WebInspector.TextPrompt):
+        (WebInspector.TextPrompt.prototype.setSuggestBoxEnabled):
+        (WebInspector.TextPrompt.prototype._attachInternal):
+        (WebInspector.TextPrompt.prototype.applySuggestion):
+        (WebInspector.TextPrompt.prototype.acceptSuggestion):
+        (WebInspector.TextPromptWithHistory):
+        * inspector/front-end/inspector.css:
+        (.suggest-box.generic-suggest):
+        (.suggest-box.generic-suggest.above-anchor):
+        (.suggest-box.generic-suggest .content):
+
 2011-11-07  Pavel Feldman  <[email protected]>
 
         Web Inspector: split script-formatter test into multiple tests.

Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (99406 => 99407)


--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-11-07 12:44:33 UTC (rev 99406)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js	2011-11-07 12:50:02 UTC (rev 99407)
@@ -112,6 +112,7 @@
     this._linkifier = WebInspector.debuggerPresentationModel.createLinkifier();
 
     this.prompt = new WebInspector.TextPromptWithHistory(this.completions.bind(this), ExpressionStopCharacters + ".");
+    this.prompt.setSuggestBoxEnabled("generic-suggest");
     this.prompt.attach(this.promptElement);
     this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get());
 }
@@ -352,12 +353,7 @@
         if (dotNotation || bracketNotation)
             expressionString = expressionString.substr(0, lastIndex);
 
-        if (!expressionString && !prefix) {
-            completionsReadyCallback([]);
-            return;
-        }
-
-        if (parseInt(expressionString, 10) == expressionString) {
+        if (expressionString && parseInt(expressionString, 10) == expressionString) {
             // User is entering float value, do not suggest anything.
             completionsReadyCallback([]);
             return;

Modified: trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js (99406 => 99407)


--- trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2011-11-07 12:44:33 UTC (rev 99406)
+++ trunk/Source/WebCore/inspector/front-end/StylesSidebarPane.js	2011-11-07 12:50:02 UTC (rev 99407)
@@ -107,7 +107,7 @@
     HSLA: "hsla"
 }
 
-WebInspector.StylesSidebarPane.StyleValueDelimiters = " \t\n\"':;,/()";
+WebInspector.StylesSidebarPane.StyleValueDelimiters = " \xA0\t\n\"':;,/()";
 
 
 // Keep in sync with RenderStyleConstants.h PseudoId enum. Array below contains pseudo id names for corresponding enum indexes.
@@ -1872,7 +1872,12 @@
         if (selectElement.parentElement)
             selectElement.parentElement.scrollIntoViewIfNeeded(false);
 
+        var applyItemCallback = !isEditingName ? this._applyFreeFlowStyleTextEdit.bind(this, true) : undefined;
         this._prompt = new WebInspector.StylesSidebarPane.CSSPropertyPrompt(isEditingName ? WebInspector.CSSCompletions.cssNameCompletions : WebInspector.CSSKeywordCompletions.forProperty(this.nameElement.textContent), this, isEditingName);
+        if (applyItemCallback) {
+            this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemApplied, applyItemCallback, this);
+            this._prompt.addEventListener(WebInspector.TextPrompt.Events.ItemAccepted, applyItemCallback, this);
+        }
         var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurListener.bind(this, context));
 
         proxyElement.addEventListener("keydown", this.editingNameValueKeyDown.bind(this, context), false);
@@ -2199,10 +2204,13 @@
 /**
  * @constructor
  * @extends {WebInspector.TextPrompt}
+ * @param {function(*)=} acceptCallback
  */
-WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, sidebarPane, isEditingName)
+WebInspector.StylesSidebarPane.CSSPropertyPrompt = function(cssCompletions, sidebarPane, isEditingName, acceptCallback)
 {
+    // Use the same callback both for applyItemCallback and acceptItemCallback.
     WebInspector.TextPrompt.call(this, this._buildPropertyCompletions.bind(this), WebInspector.StylesSidebarPane.StyleValueDelimiters);
+    this.setSuggestBoxEnabled("generic-suggest");
     this._cssCompletions = cssCompletions;
     this._sidebarPane = sidebarPane;
     this._isEditingName = isEditingName;
@@ -2222,8 +2230,11 @@
             }
             break;
         case "U+0009":
-            this.acceptAutoComplete();
-            return;
+            if (this.isSuggestBoxVisible()) {
+                this._suggestBox.acceptSuggestion();
+                return !this._isEditingName;
+            }
+            return this.acceptAutoComplete();
         }
 
         WebInspector.TextPrompt.prototype.onKeyDown.call(this, event);
@@ -2231,19 +2242,11 @@
 
     _handleNameOrValueUpDown: function(event)
     {
+        // Handle numeric value increment/decrement only at this point.
         if (!this._isEditingName && this._handleUpOrDownValue(event))
             return true;
 
-        var reverse = event.keyIdentifier === "Up";
-        if (this.autoCompleteElement)
-            this.complete(false, true, reverse); // Accept the current suggestion, if any.
-        else {
-            // Select the word suffix to affect it when computing the subsequent suggestion.
-            this._selectCurrentWordSuffix();
-        }
-
-        this.complete(false, true, reverse); // Actually increment/decrement the suggestion.
-        return true;
+        return false;
     },
 
     _handleUpOrDownValue: function(event)
@@ -2313,22 +2316,6 @@
         return false;
     },
 
-    _selectCurrentWordSuffix: function()
-    {
-        var selection = window.getSelection();
-        if (!selection.rangeCount)
-            return;
-
-        var selectionRange = selection.getRangeAt(0);
-        if (!selectionRange.commonAncestorContainer.isDescendant(this._element))
-            return;
-        var wordSuffixRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, WebInspector.StylesSidebarPane.StyleValueDelimiters, this._element, "forward");
-        if (!wordSuffixRange.toString())
-            return;
-        selection.removeAllRanges();
-        selection.addRange(wordSuffixRange);
-    },
-
     _buildPropertyCompletions: function(wordRange, force, completionsReadyCallback)
     {
         var prefix = wordRange.toString().toLowerCase();

Modified: trunk/Source/WebCore/inspector/front-end/TextPrompt.js (99406 => 99407)


--- trunk/Source/WebCore/inspector/front-end/TextPrompt.js	2011-11-07 12:44:33 UTC (rev 99406)
+++ trunk/Source/WebCore/inspector/front-end/TextPrompt.js	2011-11-07 12:50:02 UTC (rev 99407)
@@ -29,11 +29,11 @@
 
 /**
  * @constructor
+ * @extends WebInspector.Object
  * @param {function(Range, boolean, function(*))} completions
  * @param {string} stopCharacters
- * @param {WebInspector.TextPrompt.SuggestBoxConfig=} suggestBoxConfig
  */
-WebInspector.TextPrompt = function(completions, stopCharacters, suggestBoxConfig)
+WebInspector.TextPrompt = function(completions, stopCharacters)
 {
     /**
      * @type {Element|undefined}
@@ -41,10 +41,14 @@
     this._proxyElement;
     this._loadCompletions = completions;
     this._completionStopCharacters = stopCharacters;
-    this._suggestBoxConfig = suggestBoxConfig;
     this._suggestForceable = true;
 }
 
+WebInspector.TextPrompt.Events = {
+    ItemApplied: "text-prompt-item-applied",
+    ItemAccepted: "text-prompt-item-accepted"
+};
+
 WebInspector.TextPrompt.prototype = {
     get proxyElement()
     {
@@ -56,6 +60,11 @@
         this._suggestForceable = x;
     },
 
+    setSuggestBoxEnabled: function(className)
+    {
+        this._suggestBoxClassName = className;
+    },
+
     /**
      * Clients should never attach any event listeners to the |element|. Instead,
      * they should use the result of this method to attach listeners for bubbling events.
@@ -99,11 +108,9 @@
         this._element.addEventListener("keydown", this._boundOnKeyDown, true);
         this._element.addEventListener("selectstart", this._selectStart.bind(this), false);
 
-        if (this._suggestBoxConfig) {
-            this._suggestBox = new WebInspector.TextPrompt.SuggestBox(this, this._element, this._suggestBoxConfig.styleClass);
-            this._applyCallback = this._suggestBoxConfig.applyItemCallback;
-            this._acceptCallback = this._suggestBoxConfig.acceptItemCallback;
-        }
+        if (typeof this._suggestBoxClassName === "string")
+            this._suggestBox = new WebInspector.TextPrompt.SuggestBox(this, this._element, this._suggestBoxClassName);
+
         return this.proxyElement;
     },
 
@@ -482,8 +489,8 @@
         var selection = window.getSelection();
         selection.removeAllRanges();
         selection.addRange(finalSelectionRange);
-        if (isIntermediateSuggestion && this._applyCallback)
-            this._applyCallback();
+        if (isIntermediateSuggestion)
+            this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApplied, { itemText: completionText });
     },
 
     acceptSuggestion: function()
@@ -491,8 +498,7 @@
         this.acceptAutoComplete();
         if (this._suggestBox)
             this._suggestBox.hide();
-        if (this._acceptCallback)
-            this._acceptCallback();
+        this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
     },
 
     isSuggestBoxVisible: function()
@@ -624,29 +630,17 @@
     }
 }
 
-/**
- * @constructor
- * @param {string=} styleClass
- * @param {function(*)=} applyItemCallback
- * @param {function(*)=} acceptItemCallback
- */
-WebInspector.TextPrompt.SuggestBoxConfig = function(styleClass, applyItemCallback, acceptItemCallback)
-{
-    this.styleClass = styleClass;
-    this.applyItemCallback = applyItemCallback;
-    this.acceptItemCallback = acceptItemCallback;
-}
+WebInspector.TextPrompt.prototype.__proto__ = WebInspector.Object.prototype;
 
 /**
  * @constructor
  * @extends {WebInspector.TextPrompt}
  * @param {function(Range, boolean, function(*))} completions
  * @param {string} stopCharacters
- * @param {WebInspector.TextPrompt.SuggestBoxConfig=} suggestBoxConfig
  */
-WebInspector.TextPromptWithHistory = function(completions, stopCharacters, suggestBoxConfig)
+WebInspector.TextPromptWithHistory = function(completions, stopCharacters)
 {
-    WebInspector.TextPrompt.call(this, completions, stopCharacters, suggestBoxConfig);
+    WebInspector.TextPrompt.call(this, completions, stopCharacters);
 
     /**
      * @type {Array.<string>}

Modified: trunk/Source/WebCore/inspector/front-end/inspector.css (99406 => 99407)


--- trunk/Source/WebCore/inspector/front-end/inspector.css	2011-11-07 12:44:33 UTC (rev 99406)
+++ trunk/Source/WebCore/inspector/front-end/inspector.css	2011-11-07 12:50:02 UTC (rev 99407)
@@ -2517,6 +2517,24 @@
     white-space: pre-wrap;
 }
 
+/* Generic suggest box style */
+
+.suggest-box.generic-suggest {
+    border-radius: 0 5px 5px 5px;
+    margin-left: -1px;
+    border-color: rgb(66%, 66%, 66%);
+    -webkit-box-shadow: 8px 8px 6px rgba(40, 40, 40, 0.40);
+}
+
+.suggest-box.generic-suggest.above-anchor {
+   border-radius: 5px 5px 5px 0;
+    -webkit-box-shadow: 8px -8px 6px rgba(40, 40, 40, 0.40);
+}
+
+.suggest-box.generic-suggest .content {
+    margin: 3px;
+}
+
 /* Custom popup scrollers */
 
 .custom-popup-horizontal-scroll ::-webkit-scrollbar, .custom-popup-vertical-scroll ::-webkit-scrollbar {
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to