OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
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 1935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1946 * @param {string} text | 1946 * @param {string} text |
1947 * @return {!Node} | 1947 * @return {!Node} |
1948 */ | 1948 */ |
1949 _processColor: function(text) | 1949 _processColor: function(text) |
1950 { | 1950 { |
1951 // We can be called with valid non-color values of |text| (like 'none' f rom border style) | 1951 // We can be called with valid non-color values of |text| (like 'none' f rom border style) |
1952 var color = WebInspector.Color.parse(text); | 1952 var color = WebInspector.Color.parse(text); |
1953 if (!color) | 1953 if (!color) |
1954 return createTextNode(text); | 1954 return createTextNode(text); |
1955 | 1955 |
1956 if (!this._editable()) { | |
1957 var swatch = WebInspector.ColorSwatch.create(); | |
1958 swatch.setColorText(text); | |
1959 return swatch; | |
1960 } | |
1961 | |
1962 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; | 1956 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; |
1963 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, swatchPop overHelper, text); | 1957 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, swatchPop overHelper, text); |
1964 | 1958 |
1965 /** | 1959 /** |
1966 * @param {?Array<string>} backgroundColors | 1960 * @param {?Array<string>} backgroundColors |
1967 */ | 1961 */ |
1968 function computedCallback(backgroundColors) | 1962 function computedCallback(backgroundColors) |
1969 { | 1963 { |
1970 // TODO(aboxhall): distinguish between !backgroundColors (no text) a nd | 1964 // TODO(aboxhall): distinguish between !backgroundColors (no text) a nd |
1971 // !backgroundColors.length (no computed bg color) | 1965 // !backgroundColors.length (no computed bg color) |
(...skipping 19 matching lines...) Expand all Loading... | |
1991 | 1985 |
1992 if (this.property.name === "color" && this._parentPane.cssModel() && thi s.node()) { | 1986 if (this.property.name === "color" && this._parentPane.cssModel() && thi s.node()) { |
1993 var cssModel = this._parentPane.cssModel(); | 1987 var cssModel = this._parentPane.cssModel(); |
1994 cssModel.backgroundColorsPromise(this.node().id).then(computedCallba ck); | 1988 cssModel.backgroundColorsPromise(this.node().id).then(computedCallba ck); |
1995 } | 1989 } |
1996 | 1990 |
1997 return swatchIcon.element(); | 1991 return swatchIcon.element(); |
1998 }, | 1992 }, |
1999 | 1993 |
2000 /** | 1994 /** |
1995 * @param {string} text | |
1996 * @return {!Node} | |
1997 */ | |
1998 _processColorUneditable: function(text) | |
1999 { | |
2000 // We can be called with valid non-color values of |text| (like 'none' f rom border style) | |
2001 if (!WebInspector.Color.parse(text)) | |
2002 return createTextNode(text); | |
2003 var swatch = WebInspector.ColorSwatch.create(); | |
2004 swatch.setColorText(text); | |
2005 return swatch; | |
2006 }, | |
2007 | |
2008 /** | |
2001 * @return {string} | 2009 * @return {string} |
2002 */ | 2010 */ |
2003 renderedPropertyText: function() | 2011 renderedPropertyText: function() |
2004 { | 2012 { |
2005 return this.nameElement.textContent + ": " + this.valueElement.textConte nt; | 2013 return this.nameElement.textContent + ": " + this.valueElement.textConte nt; |
2006 }, | 2014 }, |
2007 | 2015 |
2008 /** | 2016 /** |
2009 * @param {string} text | 2017 * @param {string} text |
2010 * @return {!Node} | 2018 * @return {!Node} |
2011 */ | 2019 */ |
2012 _processBezier: function(text) | 2020 _processBezier: function(text) |
2013 { | 2021 { |
2014 var geometry = WebInspector.Geometry.CubicBezier.parse(text); | 2022 if (!WebInspector.Geometry.CubicBezier.parse(text)) |
2015 if (!geometry || !this._editable()) | |
2016 return createTextNode(text); | 2023 return createTextNode(text); |
2017 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; | 2024 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; |
2018 return new WebInspector.BezierPopoverIcon(this, swatchPopoverHelper, tex t).element(); | 2025 return new WebInspector.BezierPopoverIcon(this, swatchPopoverHelper, tex t).element(); |
2019 }, | 2026 }, |
2020 | 2027 |
2028 /** | |
2029 * @param {string} propertyValue | |
2030 * @param {string} propertyName | |
2031 * @return {!Node} | |
2032 */ | |
2033 _processShadow: function(propertyValue, propertyName) | |
2034 { | |
2035 var shadowValues = []; | |
2036 // Split by commas that aren't inside of color values to get the individ ual shadow values. | |
2037 var results = WebInspector.TextUtils.splitStringByRegexes(propertyValue, [WebInspector.Color.Regex, /,/g]); | |
lushnikov
2016/08/10 19:29:02
we should put this logic somewhere else - we might
flandy
2016/08/11 00:23:19
Done.
| |
2038 var currentIndex = 0; | |
2039 for (var i = 0; i < results.length; i++) { | |
2040 if (results[i].regexIndex === 1) { | |
2041 var comma = results[i]; | |
2042 shadowValues.push(propertyValue.substring(currentIndex, comma.po sition)); | |
2043 currentIndex = comma.position + 1; | |
2044 } | |
2045 } | |
2046 shadowValues.push(propertyValue.substring(currentIndex, propertyValue.le ngth)); | |
2047 | |
2048 var container = createDocumentFragment(); | |
2049 for (var i = 0; i < shadowValues.length; i++) { | |
2050 if (i !== 0) | |
2051 container.appendChild(createTextNode(",")); // Add back the remo ved commas. | |
2052 var shadowPopoverIcon = new WebInspector.ShadowPopoverIcon(this, thi s._parentPane._swatchPopoverHelper, shadowValues[i], propertyName); | |
2053 container.appendChild(shadowPopoverIcon.element()); | |
2054 } | |
2055 return container; | |
2056 }, | |
2057 | |
2021 _updateState: function() | 2058 _updateState: function() |
2022 { | 2059 { |
2023 if (!this.listItemElement) | 2060 if (!this.listItemElement) |
2024 return; | 2061 return; |
2025 | 2062 |
2026 if (this._style.isPropertyImplicit(this.name)) | 2063 if (this._style.isPropertyImplicit(this.name)) |
2027 this.listItemElement.classList.add("implicit"); | 2064 this.listItemElement.classList.add("implicit"); |
2028 else | 2065 else |
2029 this.listItemElement.classList.remove("implicit"); | 2066 this.listItemElement.classList.remove("implicit"); |
2030 | 2067 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2172 }, | 2209 }, |
2173 | 2210 |
2174 updateTitle: function() | 2211 updateTitle: function() |
2175 { | 2212 { |
2176 this._updateState(); | 2213 this._updateState(); |
2177 this._expandElement = createElement("span"); | 2214 this._expandElement = createElement("span"); |
2178 this._expandElement.className = "expand-element"; | 2215 this._expandElement.className = "expand-element"; |
2179 | 2216 |
2180 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._style.parentRule, this.node(), this.name, this.value); | 2217 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._style.parentRule, this.node(), this.name, this.value); |
2181 if (this.property.parsedOk) { | 2218 if (this.property.parsedOk) { |
2182 propertyRenderer.setColorHandler(this._processColor.bind(this)); | 2219 if (this._editable()) { |
2183 propertyRenderer.setBezierHandler(this._processBezier.bind(this)); | 2220 propertyRenderer.setColorHandler(this._processColor.bind(this)); |
2221 propertyRenderer.setBezierHandler(this._processBezier.bind(this) ); | |
2222 propertyRenderer.setShadowHandler(this._processShadow.bind(this) ); | |
2223 } else { | |
2224 propertyRenderer.setColorHandler(this._processColorUneditable.bi nd(this)); | |
lushnikov
2016/08/10 19:29:02
ideally, we should show bezier and shadow swatches
flandy
2016/08/11 00:23:19
Okay let's hold off on this for now.
| |
2225 } | |
2184 } | 2226 } |
2185 | 2227 |
2186 this.listItemElement.removeChildren(); | 2228 this.listItemElement.removeChildren(); |
2187 this.nameElement = propertyRenderer.renderName(); | 2229 this.nameElement = propertyRenderer.renderName(); |
2188 this.valueElement = propertyRenderer.renderValue(); | 2230 this.valueElement = propertyRenderer.renderValue(); |
2189 if (!this.treeOutline) | 2231 if (!this.treeOutline) |
2190 return; | 2232 return; |
2191 | 2233 |
2192 var indent = WebInspector.moduleSetting("textEditorIndent").get(); | 2234 var indent = WebInspector.moduleSetting("textEditorIndent").get(); |
2193 this.listItemElement.createChild("span", "styles-clipboard-only").create TextChild(indent + (this.property.disabled ? "/* " : "")); | 2235 this.listItemElement.createChild("span", "styles-clipboard-only").create TextChild(indent + (this.property.disabled ? "/* " : "")); |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2985 | 3027 |
2986 /** | 3028 /** |
2987 * @param {function(string):!Node} handler | 3029 * @param {function(string):!Node} handler |
2988 */ | 3030 */ |
2989 setBezierHandler: function(handler) | 3031 setBezierHandler: function(handler) |
2990 { | 3032 { |
2991 this._bezierHandler = handler; | 3033 this._bezierHandler = handler; |
2992 }, | 3034 }, |
2993 | 3035 |
2994 /** | 3036 /** |
3037 * @param {function(string, string):!Node} handler | |
3038 */ | |
3039 setShadowHandler: function(handler) | |
3040 { | |
3041 this._shadowHandler = handler; | |
3042 }, | |
3043 | |
3044 /** | |
2995 * @return {!Element} | 3045 * @return {!Element} |
2996 */ | 3046 */ |
2997 renderName: function() | 3047 renderName: function() |
2998 { | 3048 { |
2999 var nameElement = createElement("span"); | 3049 var nameElement = createElement("span"); |
3000 nameElement.className = "webkit-css-property"; | 3050 nameElement.className = "webkit-css-property"; |
3001 nameElement.textContent = this._propertyName; | 3051 nameElement.textContent = this._propertyName; |
3002 nameElement.normalize(); | 3052 nameElement.normalize(); |
3003 return nameElement; | 3053 return nameElement; |
3004 }, | 3054 }, |
3005 | 3055 |
3006 /** | 3056 /** |
3007 * @return {!Element} | 3057 * @return {!Element} |
3008 */ | 3058 */ |
3009 renderValue: function() | 3059 renderValue: function() |
3010 { | 3060 { |
3011 var valueElement = createElement("span"); | 3061 var valueElement = createElement("span"); |
3012 valueElement.className = "value"; | 3062 valueElement.className = "value"; |
3013 if (!this._propertyValue) | 3063 if (!this._propertyValue) |
3014 return valueElement; | 3064 return valueElement; |
3015 | 3065 |
3066 if (this._shadowHandler && (this._propertyName === "box-shadow" || this. _propertyName === "text-shadow") | |
3067 && !WebInspector.CSSMetadata.VariableRegex.test(this._propertyVa lue) && Runtime.experiments.isEnabled("shadowEditor")) { | |
3068 valueElement.appendChild(this._shadowHandler(this._propertyValue, th is._propertyName)); | |
lushnikov
2016/08/10 19:29:02
does this mean there could be only one shadow swat
flandy
2016/08/11 00:23:19
No, value could have multiple shadow swatches if _
| |
3069 valueElement.normalize(); | |
3070 return valueElement; | |
3071 } | |
3072 | |
3016 var regexes = [WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSM etadata.URLRegex]; | 3073 var regexes = [WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSM etadata.URLRegex]; |
3017 var processors = [createTextNode, this._processURL.bind(this)]; | 3074 var processors = [createTextNode, this._processURL.bind(this)]; |
3018 if (this._bezierHandler && WebInspector.cssMetadata().isBezierAwarePrope rty(this._propertyName)) { | 3075 if (this._bezierHandler && WebInspector.cssMetadata().isBezierAwarePrope rty(this._propertyName)) { |
3019 regexes.push(WebInspector.Geometry.CubicBezier.Regex); | 3076 regexes.push(WebInspector.Geometry.CubicBezier.Regex); |
3020 processors.push(this._bezierHandler); | 3077 processors.push(this._bezierHandler); |
3021 } | 3078 } |
3022 if (this._colorHandler && WebInspector.cssMetadata().isColorAwarePropert y(this._propertyName)) { | 3079 if (this._colorHandler && WebInspector.cssMetadata().isColorAwarePropert y(this._propertyName)) { |
3023 regexes.push(WebInspector.Color.Regex); | 3080 regexes.push(WebInspector.Color.Regex); |
3024 processors.push(this._colorHandler); | 3081 processors.push(this._colorHandler); |
3025 } | 3082 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3099 | 3156 |
3100 /** | 3157 /** |
3101 * @override | 3158 * @override |
3102 * @return {!WebInspector.ToolbarItem} | 3159 * @return {!WebInspector.ToolbarItem} |
3103 */ | 3160 */ |
3104 item: function() | 3161 item: function() |
3105 { | 3162 { |
3106 return this._button; | 3163 return this._button; |
3107 } | 3164 } |
3108 } | 3165 } |
OLD | NEW |