Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (188482 => 188483)
--- trunk/Source/WebInspectorUI/ChangeLog 2015-08-14 19:15:27 UTC (rev 188482)
+++ trunk/Source/WebInspectorUI/ChangeLog 2015-08-14 20:05:06 UTC (rev 188483)
@@ -1,5 +1,79 @@
2015-08-14 Devin Rousso <drou...@apple.com>
+ Web Inspector: Add Visual editors for CSS properties with comma separated values
+ https://bugs.webkit.org/show_bug.cgi?id=147578
+
+ Reviewed by Timothy Hatcher.
+
+ Displays comma separated CSS property values as a tree outline list.
+
+ * UserInterface/Images/Minus.svg: Added.
+ * UserInterface/Views/TreeOutline.js:
+ (WebInspector.TreeOutline.prototype.get selectedTreeElementIndex):
+ (WebInspector.TreeOutline):
+
+ * UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.css: Added.
+ (.visual-style-property-container.comma-separated-keyword-editor):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item:nth-child(odd)):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.selected):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > :matches(button, img)):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > .titles):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item.selected:not(.editor-hidden) > .titles > *):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item > .visual-style-comma-separated-keyword-item-editor):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item.editor-hidden > .visual-style-comma-separated-keyword-item-editor):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > .titles > .subtitle):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item:not(.no-value) > .titles > .subtitle):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls > div):
+ (.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls > .visual-style-remove-comma-separated-keyword):
+
+ * UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.js: Added.
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype.set selectedTreeElementValue):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype.get value):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype.set value):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype.get synthesizedValue):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._treeElementSelected):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._treeItemIsEmpty):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._addEmptyCommaSeparatedKeyword):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._removeSelectedCommaSeparatedKeyword):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._removeEmptyCommaSeparatedKeywords):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._addCommaSeparatedKeyword):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._removeCommaSeparatedKeyword):
+ (WebInspector.VisualStyleCommaSeparatedKeywordEditor.prototype._createNewTreeElement):
+
+ * UserInterface/Views/VisualStyleFontFamilyListEditor.js: Added.
+ (WebInspector.VisualStyleFontFamilyListEditor):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype.visualStyleCompletionsControllerCustomizeCompletionElement):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype.get hasCompletions):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype.set completions):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._modifyCommaSeparatedKeyword):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._addCommaSeparatedKeyword):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._addEmptyCommaSeparatedKeyword):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._completionClicked):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._treeElementKeyDown):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._treeElementKeywordChanged):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._hideCompletions):
+ (WebInspector.VisualStyleFontFamilyListEditor.prototype._createNewTreeElement):
+
+ * UserInterface/Views/VisualStyleFontFamilyTreeElement.js: Added.
+ (WebInspector.VisualStyleFontFamilyTreeElement):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.editorBounds):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.updateMainTitle):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.showKeywordEditor):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.hideKeywordEditor):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.get keywordEditorHidden):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.onattach):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype.ondeselect):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype._keywordEditorKeyDown):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype._keywordEditorKeyUp):
+ (WebInspector.VisualStyleFontFamilyTreeElement.prototype._keywordEditorBlurred):
+
+2015-08-14 Devin Rousso <drou...@apple.com>
+
Web Inspector: Add autocomplete controller for Visual property editors
https://bugs.webkit.org/show_bug.cgi?id=147579
Added: trunk/Source/WebInspectorUI/UserInterface/Images/Minus.svg (0 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Images/Minus.svg (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Images/Minus.svg 2015-08-14 20:05:06 UTC (rev 188483)
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright © 2015 Apple Inc. All rights reserved. -->
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13 13">
+ <line class="stroked" fill="none" stroke="black" x1="1.5" y1="6.5" x2="11.5" y2="6.5"/>
+</svg>
Modified: trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js (188482 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js 2015-08-14 19:15:27 UTC (rev 188482)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/TreeOutline.js 2015-08-14 20:05:06 UTC (rev 188483)
@@ -504,6 +504,19 @@
{
// this is the root, do nothing
}
+
+ get selectedTreeElementIndex()
+ {
+ if (!this.hasChildren || !this.selectedTreeElement)
+ return;
+
+ for (var i = 0; i < this.children.length; ++i) {
+ if (this.children[i] === this.selectedTreeElement)
+ return i;
+ }
+
+ return false;
+ }
};
WebInspector.TreeOutline._knownTreeElementNextIdentifier = 1;
Added: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.css (0 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.css (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.css 2015-08-14 20:05:06 UTC (rev 188483)
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+.visual-style-property-container.comma-separated-keyword-editor {
+ margin-bottom: 5px;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container {
+ border: 1px solid hsl(0, 0%, 83%);
+ overflow: auto;
+ font-size: 11px;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list {
+ min-height: 51px;
+ max-height: 94px;
+ margin: 0;
+ padding: 0;
+ background-color: hsl(0, 0%, 95%);
+ overflow: auto;
+ outline: none;
+ list-style-type: none;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item {
+ position: relative;
+ width: 100%;
+ height: 17px;
+ line-height: 17px;
+ overflow: hidden;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item:nth-child(odd) {
+ background-color: white;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.selected {
+ background-color: hsl(213, 92%, 55%) !important;
+ color: white;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > :matches(button, img) {
+ display: none;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > .titles {
+ padding-left: 3px;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item.selected:not(.editor-hidden) > .titles > * {
+ color: transparent;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item > .visual-style-comma-separated-keyword-item-editor {
+ position: absolute;
+ top: 0;
+ right: 3px;
+ bottom: 0;
+ left: 3px;
+ margin: 0;
+ padding: 0;
+ line-height: 13px;
+ border: none;
+ background-color: transparent;
+ font-family: inherit;
+ color: white;
+ z-index: 1;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item.visual-style-font-family-list-item.editor-hidden > .visual-style-comma-separated-keyword-item-editor {
+ display: none;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item > .titles > .subtitle {
+ font-size: 9px;
+ color: hsl(0, 0%, 83%);
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-list > .visual-style-comma-separated-keyword-item:not(.no-value) > .titles > .subtitle {
+ display: none;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls {
+ display: flex;
+ border-top: 1px solid hsl(0, 0%, 83%);
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls > div {
+ width: 20px;
+ height: 19px;
+ padding: 4px;
+ border-right: 1px solid hsl(0, 0%, 83%);
+ opacity: 0.7;
+}
+
+.visual-style-property-container.comma-separated-keyword-editor > .visual-style-property-value-container > .visual-style-comma-separated-keyword-controls > .visual-style-remove-comma-separated-keyword {
+ order: 2;
+}
Added: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.js (0 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleCommaSeparatedKeywordEditor.js 2015-08-14 20:05:06 UTC (rev 188483)
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.VisualStyleCommaSeparatedKeywordEditor = class VisualStyleCommaSeparatedKeywordEditor extends WebInspector.VisualStylePropertyEditor
+{
+ constructor(propertyNames, text, insertNewItemsBeforeSelected, layoutReversed)
+ {
+ super(propertyNames, text, null, null, "comma-separated-keyword-editor", layoutReversed);
+
+ this._insertNewItemsBeforeSelected = insertNewItemsBeforeSelected || false;
+
+ let listElement = document.createElement("ol");
+ listElement.classList.add("visual-style-comma-separated-keyword-list");
+ this.contentElement.appendChild(listElement);
+
+ this._commaSeparatedKeywords = new WebInspector.TreeOutline(listElement);
+ this._commaSeparatedKeywords._onselect_ = this._treeElementSelected.bind(this);
+
+ let controlContainer = document.createElement("div");
+ controlContainer.classList.add("visual-style-comma-separated-keyword-controls");
+ this.contentElement.appendChild(controlContainer);
+
+ wrappedSVGDocument("Images/Plus.svg", "visual-style-add-comma-separated-keyword", WebInspector.UIString("Click to add a new item."), function(wrapper) {
+ wrapper.addEventListener("click", this._addEmptyCommaSeparatedKeyword.bind(this));
+ controlContainer.appendChild(wrapper);
+ }.bind(this));
+
+ wrappedSVGDocument("Images/Minus.svg", "visual-style-remove-comma-separated-keyword", WebInspector.UIString("Click to remove the selected item."), function(wrapper) {
+ wrapper.addEventListener("click", this._removeSelectedCommaSeparatedKeyword.bind(this));
+ controlContainer.appendChild(wrapper);
+ }.bind(this));
+ }
+
+ // Public
+
+ set selectedTreeElementValue(text)
+ {
+ let selectedTreeElement = this._commaSeparatedKeywords.selectedTreeElement;
+ if (!selectedTreeElement)
+ return;
+
+ selectedTreeElement.element.classList.toggle("no-value", !text || !text.length);
+ selectedTreeElement.mainTitle = text;
+ this._valueDidChange();
+ }
+
+ get value()
+ {
+ if (!this._commaSeparatedKeywords.hasChildren)
+ return;
+
+ let value = "";
+ for (let treeItem of this._commaSeparatedKeywords.children) {
+ if (this._treeElementIsEmpty(treeItem))
+ continue;
+
+ if (value.length)
+ value += ", ";
+
+ let text = treeItem.mainTitle;
+ if (typeof this._modifyCommaSeparatedKeyword === "function")
+ text = this._modifyCommaSeparatedKeyword(text);
+
+ value += text;
+ }
+
+ return value;
+ }
+
+ set value(commaSeparatedValue)
+ {
+ if (commaSeparatedValue && commaSeparatedValue === this.value)
+ return;
+
+ this._commaSeparatedKeywords.removeChildren();
+ if (!commaSeparatedValue || !commaSeparatedValue.length) {
+ this.dispatchEventToListeners(WebInspector.VisualStyleCommaSeparatedKeywordEditor.Event.NoRemainingTreeItems);
+ return;
+ }
+
+ let values = commaSeparatedValue.split(/\s*,\s*(?![^\(]*\))/);
+ for (let value of values)
+ this._addCommaSeparatedKeyword(value);
+
+ this._commaSeparatedKeywords.children[0].select(true);
+ }
+
+ get synthesizedValue()
+ {
+ return this.value || null;
+ }
+
+ // Private
+
+ _treeElementSelected(item, selectedByUser)
+ {
+ this._removeEmptyCommaSeparatedKeywords();
+ this.dispatchEventToListeners(WebInspector.VisualStyleCommaSeparatedKeywordEditor.Event.TreeItemSelected, {text: item.mainTitle});
+ }
+
+ _treeElementIsEmpty(item)
+ {
+ return !item._mainTitle || !item._mainTitle.length;
+ }
+
+ _addEmptyCommaSeparatedKeyword()
+ {
+ let newTreeElement = this._addCommaSeparatedKeyword(null, this._commaSeparatedKeywords.selectedTreeElementIndex);
+ newTreeElement.subtitle = WebInspector.UIString("(modify the boxes below to add a value)");
+ newTreeElement.element.classList.add("no-value");
+ newTreeElement.select(true, true);
+ return newTreeElement;
+ }
+
+ _removeSelectedCommaSeparatedKeyword()
+ {
+ let selectedTreeElement = this._commaSeparatedKeywords.selectedTreeElement;
+ this._removeCommaSeparatedKeyword(selectedTreeElement);
+ }
+
+ _removeEmptyCommaSeparatedKeywords()
+ {
+ for (let treeElement of this._commaSeparatedKeywords.children) {
+ if (!this._treeElementIsEmpty(treeElement) || treeElement.selected)
+ continue;
+
+ treeElement.deselect();
+ this._removeCommaSeparatedKeyword(treeElement);
+ }
+ }
+
+ _addCommaSeparatedKeyword(value, index)
+ {
+ let valueElement = this._createNewTreeElement(value);
+ let indexIsSet = !isNaN(index);
+ this._commaSeparatedKeywords.insertChild(valueElement, indexIsSet ? index + !this._insertNewItemsBeforeSelected : 0);
+ return valueElement;
+ }
+
+ _removeCommaSeparatedKeyword(treeElement)
+ {
+ if (!treeElement)
+ return;
+
+ this._commaSeparatedKeywords.removeChild(treeElement);
+ if (!this._commaSeparatedKeywords.children.length)
+ this.dispatchEventToListeners(WebInspector.VisualStyleCommaSeparatedKeywordEditor.Event.NoRemainingTreeItems);
+
+ this._valueDidChange();
+ }
+
+ _createNewTreeElement(value)
+ {
+ return new WebInspector.GeneralTreeElement(WebInspector.VisualStyleCommaSeparatedKeywordEditor.ListItemClassName, value);
+ }
+};
+
+WebInspector.VisualStyleCommaSeparatedKeywordEditor.ListItemClassName = "visual-style-comma-separated-keyword-item";
+
+WebInspector.VisualStyleCommaSeparatedKeywordEditor.Event = {
+ TreeItemSelected: "visual-style-comma-separated-keyword-editor-tree-item-selected",
+ NoRemainingTreeItems: "visual-style-comma-separated-keyword-editor-no-remaining-tree-items"
+}
Added: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyListEditor.js (0 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyListEditor.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyListEditor.js 2015-08-14 20:05:06 UTC (rev 188483)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.VisualStyleFontFamilyListEditor = class VisualStyleFontFamilyListEditor extends WebInspector.VisualStyleCommaSeparatedKeywordEditor
+{
+ constructor(propertyNames, text, layoutReversed)
+ {
+ super(propertyNames, text, true, layoutReversed);
+
+ this._commaSeparatedKeywords.element.addEventListener("scroll", this._hideCompletions.bind(this));
+
+ this._completionController = new WebInspector.VisualStyleCompletionsController(this);
+ this._completionController.addEventListener(WebInspector.VisualStyleCompletionsController.Event.CompletionSelected, this._completionClicked, this);
+
+ this._wrapWithQuotesRegExp = /^[a-zA-Z\-]+$/;
+ this._removeWrappedQuotesRegExp = /[\"\']/g;
+ }
+
+ // Public
+
+ visualStyleCompletionsControllerCustomizeCompletionElement(suggestionsView, element, item)
+ {
+ element.style.fontFamily = item;
+ }
+
+ get hasCompletions()
+ {
+ return this._completionController.hasCompletions;
+ }
+
+ set completions(completions)
+ {
+ this._completionController.completions = completions;
+ }
+
+ // Private
+
+ _modifyCommaSeparatedKeyword(text)
+ {
+ if (!this._wrapWithQuotesRegExp.test(text))
+ text = "\"" + text + "\"";
+
+ return text;
+ }
+
+ _addCommaSeparatedKeyword(value, index)
+ {
+ if (value)
+ value = value.replace(this._removeWrappedQuotesRegExp, "");
+
+ let valueElement = super._addCommaSeparatedKeyword(value, index);
+ valueElement.addEventListener(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown, this._treeElementKeyDown, this);
+ valueElement.addEventListener(WebInspector.VisualStyleFontFamilyTreeElement.Event.KeywordChanged, this._treeElementKeywordChanged, this);
+ valueElement.addEventListener(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorBlurred, this._hideCompletions, this);
+ return valueElement;
+ }
+
+ _addEmptyCommaSeparatedKeyword()
+ {
+ let newItem = super._addEmptyCommaSeparatedKeyword();
+ newItem.showKeywordEditor();
+ }
+
+ _completionClicked(event)
+ {
+ this.value = event.data.text;
+ this._valueDidChange();
+ }
+
+ _treeElementKeyDown(event)
+ {
+ if (!this._completionController.visible)
+ return;
+
+ let key = event && event.data && event.data.key;
+ if (!key)
+ return;
+
+ if (key === "Enter" || key === "Tab") {
+ let selectedTreeElement = this._commaSeparatedKeywords.selectedTreeElement;
+ if (!selectedTreeElement)
+ return;
+
+ selectedTreeElement.updateMainTitle(this._completionController.currentCompletion);
+ this._completionController.hide();
+ return;
+ }
+
+ if (key === "Escape") {
+ this._hideCompletions();
+ return;
+ }
+
+ if (key === "Up") {
+ this._completionController.previous();
+ return;
+ }
+
+ if (key === "Down") {
+ this._completionController.next();
+ return;
+ }
+ }
+
+ _treeElementKeywordChanged()
+ {
+ if (!this.hasCompletions)
+ return;
+
+ let result = this._valueDidChange();
+ if (!result)
+ return;
+
+ let treeElement = this._commaSeparatedKeywords.selectedTreeElement;
+ if (!treeElement)
+ return;
+
+ if (this._completionController.update(treeElement.mainTitle)) {
+ let bounds = treeElement.editorBounds(2);
+ if (!bounds)
+ return;
+
+ this._completionController.show(bounds);
+ }
+ }
+
+ _hideCompletions()
+ {
+ this._completionController.hide();
+ }
+
+ _createNewTreeElement(value)
+ {
+ return new WebInspector.VisualStyleFontFamilyTreeElement(value);
+ }
+};
Added: trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyTreeElement.js (0 => 188483)
--- trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyTreeElement.js (rev 0)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/VisualStyleFontFamilyTreeElement.js 2015-08-14 20:05:06 UTC (rev 188483)
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+WebInspector.VisualStyleFontFamilyTreeElement = class VisualStyleFontFamilyTreeElement extends WebInspector.GeneralTreeElement
+{
+ constructor(text)
+ {
+ super([WebInspector.VisualStyleCommaSeparatedKeywordEditor.ListItemClassName, "visual-style-font-family-list-item"], text);
+
+ this._keywordEditor = document.createElement("input");
+ this._keywordEditor.classList.add("visual-style-comma-separated-keyword-item-editor");
+ this._keywordEditor.placeholder = WebInspector.UIString("(modify the boxes below to add a value)");
+ this._keywordEditor.spellcheck = false;
+ this._keywordEditor.addEventListener("keydown", this._keywordEditorKeyDown.bind(this));
+ this._keywordEditor.addEventListener("keyup", this._keywordEditorKeyUp.bind(this));
+ this._keywordEditor.addEventListener("blur", this._keywordEditorBlurred.bind(this));
+ }
+
+ // Public
+
+ editorBounds(padding)
+ {
+ if (this.keywordEditorHidden)
+ return;
+
+ let bounds = WebInspector.Rect.rectFromClientRect(this._keywordEditor.getBoundingClientRect());
+ return bounds.pad(padding || 0);
+ }
+
+ updateMainTitle(text)
+ {
+ this.mainTitle = this._listItemNode.style.fontFamily = this._keywordEditor.value = text;
+
+ let hasText = text && text.length;
+ this._listItemNode.classList.toggle("no-value", !hasText);
+ if (!hasText)
+ this.subtitle = this._keywordEditor.placeholder;
+
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.KeywordChanged);
+ }
+
+ showKeywordEditor()
+ {
+ if (!this.keywordEditorHidden)
+ return;
+
+ this.subtitle = "";
+ this._listItemNode.classList.remove("editor-hidden");
+ this._listItemNode.scrollIntoViewIfNeeded();
+
+ this._keywordEditor.value = this._mainTitle;
+ this._keywordEditor.select();
+ }
+
+ hideKeywordEditor()
+ {
+ if (this.keywordEditorHidden)
+ return;
+
+ this.updateMainTitle(this._keywordEditor.value);
+ this._listItemNode.classList.add("editor-hidden");
+ }
+
+ get keywordEditorHidden()
+ {
+ return this._listItemNode.classList.contains("editor-hidden");
+ }
+
+ // Protected
+
+ onattach()
+ {
+ super.onattach();
+
+ this._listItemNode.style.fontFamily = this._mainTitle;
+ this._listItemNode.classList.add("editor-hidden");
+ this._listItemNode.appendChild(this._keywordEditor);
+ this._listItemNode.addEventListener("click", this.showKeywordEditor.bind(this));
+ }
+
+ ondeselect()
+ {
+ this.hideKeywordEditor();
+ }
+
+ // Private
+
+ _keywordEditorKeyDown(event)
+ {
+ if (this.keywordEditorHidden)
+ return;
+
+ let keyCode = event.keyCode;
+ let enterKeyCode = WebInspector.KeyboardShortcut.Key.Enter.keyCode;
+ if (keyCode === enterKeyCode) {
+ this._listItemNode.classList.add("editor-hidden");
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown, {key: "Enter"});
+ return;
+ }
+
+ let escapeKeyCode = WebInspector.KeyboardShortcut.Key.Escape.keyCode;
+ if (keyCode === escapeKeyCode) {
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown, {key: "Escape"});
+ return;
+ }
+
+ let tabKeyCode = WebInspector.KeyboardShortcut.Key.Tab.keyCode;
+ if (keyCode === tabKeyCode) {
+ event.preventDefault();
+ this._dontFireKeyUp = true;
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown, {key: "Tab"});
+ return;
+ }
+
+ let key = event.keyIdentifier;
+ if (key === "Up" || key === "Down") {
+ event.preventDefault();
+ this._dontFireKeyUp = true;
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown, {key});
+ return;
+ }
+
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorKeyDown);
+ }
+
+ _keywordEditorKeyUp()
+ {
+ if (this.keywordEditorHidden || this._dontFireKeyUp)
+ return;
+
+ this.updateMainTitle(this._keywordEditor.value);
+ }
+
+ _keywordEditorBlurred()
+ {
+ this.hideKeywordEditor();
+ this.dispatchEventToListeners(WebInspector.VisualStyleFontFamilyTreeElement.Event.EditorBlurred);
+ }
+};
+
+WebInspector.VisualStyleFontFamilyTreeElement.Event = {
+ KeywordChanged: "visual-style-font-family-tree-element-keyword-changed",
+ EditorKeyDown: "visual-style-font-family-tree-element-editor-key-down",
+ EditorBlurred: "visual-style-font-family-tree-element-editor-blurred"
+};