Changeset 74352 in webkit
- Timestamp:
- Dec 20, 2010 9:25:59 AM (13 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r74350 r74352 1 2010-12-20 Alexander Pavlov <apavlov@chromium.org> 2 3 Reviewed by Yury Semikhatsky. 4 5 Web Inspector: Make CSSCompletions a real class rather than singleton 6 https://bugs.webkit.org/show_bug.cgi?id=51332 7 8 Drive-by: make use of keywords from re2js in the CSS tokenizer 9 (apparently, various authors have presumed that re2js is processed at build time). 10 11 No new tests, as this is a refactoring. 12 13 * inspector/front-end/CSSCompletions.js: 14 (WebInspector.CSSCompletions): 15 (WebInspector.CSSCompletions.prototype.startsWith): 16 (WebInspector.CSSCompletions.prototype.firstStartsWith): 17 (WebInspector.CSSCompletions.prototype._firstIndexOfPrefix): 18 (WebInspector.CSSCompletions.prototype.keySet): 19 (WebInspector.CSSCompletions.prototype.next): 20 (WebInspector.CSSCompletions.prototype.previous): 21 (WebInspector.CSSCompletions.prototype._closest): 22 * inspector/front-end/SourceCSSTokenizer.js: 23 (WebInspector.SourceCSSTokenizer): 24 * inspector/front-end/SourceCSSTokenizer.re2js: 25 * inspector/front-end/StylesSidebarPane.js: 26 (WebInspector.StylePropertyTreeElement.prototype): 27 * inspector/front-end/inspector.js: 28 (WebInspector.doLoadedDone.propertyNamesCallback): 29 (WebInspector.doLoadedDone): 30 1 31 2010-12-10 Pavel Podivilov <podivilov@chromium.org> 2 32 -
trunk/WebCore/inspector/front-end/CSSCompletions.js
r65942 r74352 1 WebInspector.CSSCompletions = []; 1 /* 2 * Copyright (C) 2010 Nikita Vasilyev. All rights reserved. 3 * Copyright (C) 2010 Joseph Pecoraro. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above 13 * copyright notice, this list of conditions and the following disclaimer 14 * in the documentation and/or other materials provided with the 15 * distribution. 16 * * Neither the name of Google Inc. nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 2 32 3 WebInspector.CSSCompletions .startsWith = function(prefix)33 WebInspector.CSSCompletions = function(values) 4 34 { 5 var firstIndex = this._firstIndexOfPrefix(prefix); 6 if (firstIndex === -1) 7 return []; 8 9 var results = []; 10 while (this[firstIndex].indexOf(prefix) === 0) 11 results.push(this[firstIndex++]); 12 return results; 35 this._values = values.slice(); 36 this._values.sort(); 13 37 } 14 38 15 WebInspector.CSSCompletions.firstStartsWith = function(prefix) 16 { 17 var foundIndex = this._firstIndexOfPrefix(prefix); 18 return (foundIndex === -1 ? "" : this[foundIndex]); 39 WebInspector.CSSCompletions.prototype = { 40 startsWith: function(prefix) 41 { 42 var firstIndex = this._firstIndexOfPrefix(prefix); 43 if (firstIndex === -1) 44 return []; 45 46 var results = []; 47 while (this._values[firstIndex].indexOf(prefix) === 0) 48 results.push(this._values[firstIndex++]); 49 return results; 50 }, 51 52 firstStartsWith: function(prefix) 53 { 54 var foundIndex = this._firstIndexOfPrefix(prefix); 55 return (foundIndex === -1 ? "" : this._values[foundIndex]); 56 }, 57 58 _firstIndexOfPrefix: function(prefix) 59 { 60 if (!prefix) 61 return -1; 62 if (!this._values.length) 63 return -1; 64 65 var maxIndex = this._values.length - 1; 66 var minIndex = 0; 67 var foundIndex; 68 69 do { 70 var middleIndex = (maxIndex + minIndex) >> 1; 71 if (this._values[middleIndex].indexOf(prefix) === 0) { 72 foundIndex = middleIndex; 73 break; 74 } 75 if (this._values[middleIndex] < prefix) 76 minIndex = middleIndex + 1; 77 else 78 maxIndex = middleIndex - 1; 79 } while (minIndex <= maxIndex); 80 81 if (foundIndex === undefined) 82 return -1; 83 84 while (foundIndex && this._values[foundIndex - 1].indexOf(prefix) === 0) 85 foundIndex--; 86 87 return foundIndex; 88 }, 89 90 keySet: function() 91 { 92 return this._values.keySet(); 93 }, 94 95 next: function(str, prefix) 96 { 97 return this._closest(str, prefix, 1); 98 }, 99 100 previous: function(str, prefix) 101 { 102 return this._closest(str, prefix, -1); 103 }, 104 105 _closest: function(str, prefix, shift) 106 { 107 if (!str) 108 return ""; 109 110 var index = this._values.indexOf(str); 111 if (index === -1) 112 return ""; 113 114 if (!prefix) { 115 index = (index + this._values.length + shift) % this._values.length; 116 return this._values[index]; 117 } 118 119 var propertiesWithPrefix = this.startsWith(prefix); 120 var j = propertiesWithPrefix.indexOf(str); 121 j = (j + propertiesWithPrefix.length + shift) % propertiesWithPrefix.length; 122 return propertiesWithPrefix[j]; 123 } 19 124 } 20 21 WebInspector.CSSCompletions._firstIndexOfPrefix = function(prefix)22 {23 if (!prefix)24 return -1;25 if (!this.length)26 return -1;27 28 var maxIndex = this.length - 1;29 var minIndex = 0;30 var foundIndex;31 32 do {33 var middleIndex = (maxIndex + minIndex) >> 1;34 if (this[middleIndex].indexOf(prefix) === 0) {35 foundIndex = middleIndex;36 break;37 }38 if (this[middleIndex] < prefix)39 minIndex = middleIndex + 1;40 else41 maxIndex = middleIndex - 1;42 } while (minIndex <= maxIndex);43 44 if (!foundIndex)45 return -1;46 47 while (foundIndex && this[foundIndex - 1].indexOf(prefix) === 0)48 foundIndex--;49 50 return foundIndex;51 }52 53 WebInspector.CSSCompletions.next = function(str, prefix)54 {55 return WebInspector.CSSCompletions._closest(str, prefix, 1);56 }57 58 WebInspector.CSSCompletions.previous = function(str, prefix)59 {60 return WebInspector.CSSCompletions._closest(str, prefix, -1);61 }62 63 WebInspector.CSSCompletions._closest = function(str, prefix, shift)64 {65 if (!str)66 return "";67 68 var index = this.indexOf(str);69 if (index === -1)70 return "";71 72 if (!prefix) {73 index = (index + this.length + shift) % this.length;74 return this[index];75 }76 77 var propertiesWithPrefix = this.startsWith(prefix);78 var j = propertiesWithPrefix.indexOf(str);79 j = (j + propertiesWithPrefix.length + shift) % propertiesWithPrefix.length;80 return propertiesWithPrefix[j];81 }82 83 WebInspector.CSSCompletions._load = function(properties)84 {85 for (var i = 0; i < properties.length; ++i)86 WebInspector.CSSCompletions.push(properties[i]);87 WebInspector.CSSCompletions.sort();88 } -
trunk/WebCore/inspector/front-end/SourceCSSTokenizer.js
r65942 r74352 1 /* Generated by re2c 0.13.5 on Thu Feb 25 21:44:552010 */1 /* Generated by re2c 0.13.5 on Mon Dec 20 18:44:30 2010 */ 2 2 /* 3 3 * Copyright (C) 2009 Google Inc. All rights reserved. … … 46 46 WebInspector.SourceTokenizer.call(this); 47 47 48 this._propertyKeywords = WebInspector. CSSCompletions.keySet();48 this._propertyKeywords = WebInspector.cssNameCompletions.keySet(); 49 49 50 50 this._valueKeywords = [ 51 51 "above", "absolute", "activeborder", "activecaption", "afar", "after-white-space", "ahead", "alias", "all", "all-scroll", 52 "alternate", "always","amharic", "amharic-abegede", "antialiased", "appworkspace", "aqua", "arabic-indic", "armenian", 52 "alternate", "always","amharic", "amharic-abegede", "antialiased", "appworkspace", "aqua", "arabic-indic", "armenian", "asterisks", 53 53 "auto", "avoid", "background", "backwards", "baseline", "below", "bidi-override", "binary", "bengali", "black", "blink", 54 54 "block", "block-axis", "blue", "bold", "bolder", "border", "border-box", "both", "bottom", "break-all", "break-word", "button", … … 63 63 "ethiopic-halehame-am-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-sid-et", 64 64 "ethiopic-halehame-so-et", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ew-resize", "expanded", 65 "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "fo rwards", "from", "fuchsia", "geometricPrecision",65 "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", "forwards", "from", "fuchsia", "geometricPrecision", 66 66 "georgian", "gray", "graytext", "green", "grey", "groove", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", "help", 67 67 "hidden", "hide", "higher", "highlight", "highlighttext", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore", … … 69 69 "inline-axis", "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "justify", "kannada", "katakana", 70 70 "katakana-iroha", "khmer", "landscape", "lao", "large", "larger", "left", "level", "lighter", "lime", "line-through", "linear", "lines", 71 "list-button", "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower- greek", "lower-hexadecimal", "lower-latin",72 "lower- norwegian", "lower-roman", "lowercase", "ltr", "malayalam", "maroon", "match", "media-controls-background", "media-current-time-display",73 "media- fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button", "media-rewind-button",74 "media- seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display",71 "list-button", "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "lower-greek", 72 "lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-roman", "lowercase", "ltr", "malayalam", "maroon", "match", "media-controls-background", 73 "media-current-time-display", "media-fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button", 74 "media-rewind-button", "media-seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display", 75 75 "media-volume-slider", "media-volume-slider-container", "media-volume-sliderthumb", "medium", "menu", "menulist", "menulist-button", 76 76 "menulist-text", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "mix", "mongolian", "monospace", "move", "multiple", … … 89 89 "table-row", "table-row-group", "teal", "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", "thick", "thin", 90 90 "threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", "tigrinya-er-abegede", 91 "tigrinya-et", "tigrinya-et-abegede", "to", "top", "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", "upper-alpha", "upper- greek",92 "upper- hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "vertical", "vertical-text", "visible",91 "tigrinya-et", "tigrinya-et-abegede", "to", "top", "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", "upper-alpha", "upper-armenian", 92 "upper-greek", "upper-hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "vertical", "vertical-text", "visible", 93 93 "visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider", "window", "windowframe", "windowtext", 94 94 "x-large", "x-small", "xor", "xx-large", "xx-small", "yellow", "-wap-marquee", "-webkit-activelink", "-webkit-auto", "-webkit-baseline-middle", -
trunk/WebCore/inspector/front-end/SourceCSSTokenizer.re2js
r73338 r74352 45 45 WebInspector.SourceTokenizer.call(this); 46 46 47 this._propertyKeywords = WebInspector. CSSCompletions.keySet();47 this._propertyKeywords = WebInspector.cssNameCompletions.keySet(); 48 48 49 49 this._valueKeywords = [ -
trunk/WebCore/inspector/front-end/StylesSidebarPane.js
r73913 r74352 1580 1580 var selection = window.getSelection(); 1581 1581 var prefix = selection.anchorNode.textContent.substring(0, selection.anchorOffset); 1582 var property = WebInspector. CSSCompletions.firstStartsWith(prefix + character);1582 var property = WebInspector.cssNameCompletions.firstStartsWith(prefix + character); 1583 1583 1584 1584 if (!selection.isCollapsed) … … 1622 1622 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, styleValueDelimeters, this.nameElement); 1623 1623 var wordString = wordRange.toString(); 1624 var prefix = selectionRange.startContainer.textContent.substring(0, selectionRange.startOffset); 1624 var cursorPosition = selectionRange.startOffset != selectionRange.endOffset ? selectionRange.startOffset : 0; 1625 var prefix = selectionRange.startContainer.textContent.substring(0, cursorPosition); 1625 1626 var property; 1626 1627 1627 1628 if (showNext) 1628 property = WebInspector. CSSCompletions.next(wordString, prefix);1629 property = WebInspector.cssNameCompletions.next(wordString, prefix); 1629 1630 else 1630 property = WebInspector. CSSCompletions.previous(wordString, prefix);1631 property = WebInspector.cssNameCompletions.previous(wordString, prefix); 1631 1632 1632 1633 if (property) { 1633 1634 this.nameElement.textContent = property; 1634 this.nameElement.firstChild.select( selectionRange.startOffset);1635 this.nameElement.firstChild.select(cursorPosition); 1635 1636 } 1636 1637 event.preventDefault(); -
trunk/WebCore/inspector/front-end/inspector.js
r74253 r74352 614 614 InspectorBackend.setConsoleMessagesEnabled(true); 615 615 616 function propertyNamesCallback(names) 617 { 618 WebInspector.cssNameCompletions = new WebInspector.CSSCompletions(names); 619 } 620 616 621 // As a DOMAgent method, this needs to happen after the frontend has loaded and the agent is available. 617 InspectorBackend.getSupportedCSSProperties( WebInspector.CSSCompletions._load);622 InspectorBackend.getSupportedCSSProperties(propertyNamesCallback); 618 623 } 619 624
Note: See TracChangeset
for help on using the changeset viewer.