Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js

Issue 2230183004: DevTools: Add shadow-editor swatch/icon before box-shadows and text-shadows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update model Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1942 matching lines...) Expand 10 before | Expand all | Expand 10 after
1953 if (!color) 1953 if (!color)
1954 return createTextNode(text); 1954 return createTextNode(text);
1955 1955
1956 if (!this._editable()) { 1956 if (!this._editable()) {
1957 var swatch = WebInspector.ColorSwatch.create(); 1957 var swatch = WebInspector.ColorSwatch.create();
1958 swatch.setColorText(text); 1958 swatch.setColorText(text);
1959 return swatch; 1959 return swatch;
1960 } 1960 }
1961 1961
1962 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; 1962 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper;
1963 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, swatchPop overHelper, text); 1963 var colorSwatch = WebInspector.ColorSwatch.create();
1964 colorSwatch.setColorText(text);
1965 colorSwatch.setFormat(WebInspector.Color.detectColorFormat(colorSwatch.c olor()));
1966 var swatchPopoverIcon = new WebInspector.ColorSwatchPopoverIcon(this, sw atchPopoverHelper, colorSwatch);
1964 1967
1965 /** 1968 /**
1966 * @param {?Array<string>} backgroundColors 1969 * @param {?Array<string>} backgroundColors
1967 */ 1970 */
1968 function computedCallback(backgroundColors) 1971 function computedCallback(backgroundColors)
1969 { 1972 {
1970 // TODO(aboxhall): distinguish between !backgroundColors (no text) a nd 1973 // TODO(aboxhall): distinguish between !backgroundColors (no text) a nd
1971 // !backgroundColors.length (no computed bg color) 1974 // !backgroundColors.length (no computed bg color)
1972 if (!backgroundColors || !backgroundColors.length) 1975 if (!backgroundColors || !backgroundColors.length)
1973 return; 1976 return;
1974 // TODO(samli): figure out what to do in the case of multiple backgr ound colors (i.e. gradients) 1977 // TODO(samli): figure out what to do in the case of multiple backgr ound colors (i.e. gradients)
1975 var bgColorText = backgroundColors[0]; 1978 var bgColorText = backgroundColors[0];
1976 var bgColor = WebInspector.Color.parse(bgColorText); 1979 var bgColor = WebInspector.Color.parse(bgColorText);
1977 if (!bgColor) 1980 if (!bgColor)
1978 return; 1981 return;
1979 1982
1980 // If we have a semi-transparent background color over an unknown 1983 // If we have a semi-transparent background color over an unknown
1981 // background, draw the line for the "worst case" scenario: where 1984 // background, draw the line for the "worst case" scenario: where
1982 // the unknown background is the same color as the text. 1985 // the unknown background is the same color as the text.
1983 if (bgColor.hasAlpha) { 1986 if (bgColor.hasAlpha) {
1984 var blendedRGBA = []; 1987 var blendedRGBA = [];
1985 WebInspector.Color.blendColors(bgColor.rgba(), color.rgba(), ble ndedRGBA); 1988 WebInspector.Color.blendColors(bgColor.rgba(), color.rgba(), ble ndedRGBA);
1986 bgColor = new WebInspector.Color(blendedRGBA, WebInspector.Color .Format.RGBA); 1989 bgColor = new WebInspector.Color(blendedRGBA, WebInspector.Color .Format.RGBA);
1987 } 1990 }
1988 1991
1989 swatchIcon.setContrastColor(bgColor); 1992 swatchPopoverIcon.setContrastColor(bgColor);
1990 } 1993 }
1991 1994
1992 if (this.property.name === "color" && this._parentPane.cssModel() && thi s.node()) { 1995 if (this.property.name === "color" && this._parentPane.cssModel() && thi s.node()) {
1993 var cssModel = this._parentPane.cssModel(); 1996 var cssModel = this._parentPane.cssModel();
1994 cssModel.backgroundColorsPromise(this.node().id).then(computedCallba ck); 1997 cssModel.backgroundColorsPromise(this.node().id).then(computedCallba ck);
1995 } 1998 }
1996 1999
1997 return swatchIcon.element(); 2000 return colorSwatch;
1998 }, 2001 },
1999 2002
2000 /** 2003 /**
2001 * @return {string} 2004 * @return {string}
2002 */ 2005 */
2003 renderedPropertyText: function() 2006 renderedPropertyText: function()
2004 { 2007 {
2005 return this.nameElement.textContent + ": " + this.valueElement.textConte nt; 2008 return this.nameElement.textContent + ": " + this.valueElement.textConte nt;
2006 }, 2009 },
2007 2010
2008 /** 2011 /**
2009 * @param {string} text 2012 * @param {string} text
2010 * @return {!Node} 2013 * @return {!Node}
2011 */ 2014 */
2012 _processBezier: function(text) 2015 _processBezier: function(text)
2013 { 2016 {
2014 var geometry = WebInspector.Geometry.CubicBezier.parse(text); 2017 var geometry = WebInspector.Geometry.CubicBezier.parse(text);
2015 if (!geometry || !this._editable()) 2018 if (!geometry || !this._editable())
2016 return createTextNode(text); 2019 return createTextNode(text);
2017 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper; 2020 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper;
2018 return new WebInspector.BezierPopoverIcon(this, swatchPopoverHelper, tex t).element(); 2021 return new WebInspector.BezierPopoverIcon(this, swatchPopoverHelper, tex t).element();
2019 }, 2022 },
2020 2023
2024 /**
2025 * @param {string} propertyValue
2026 * @param {string} propertyName
2027 * @return {!Node}
2028 */
2029 _processShadow: function(propertyValue, propertyName)
2030 {
2031 var shadows;
2032 if (propertyName === "box-shadow")
2033 shadows = WebInspector.CSSShadowModel.parseBoxShadow(propertyValue);
2034 else
2035 shadows = WebInspector.CSSShadowModel.parseTextShadow(propertyValue) ;
2036 if (!shadows || !this._editable())
2037 return createTextNode(propertyValue);
2038 var container = createDocumentFragment();
2039 var swatchPopoverHelper = this._parentPane._swatchPopoverHelper;
2040 for (var i = 0; i < shadows.length; i++) {
2041 if (i !== 0)
2042 container.appendChild(createTextNode(", ")); // Add back commas and spaces between each shadow.
2043 var cssShadowSwatch = WebInspector.CSSShadowSwatch.create();
2044 cssShadowSwatch.setCSSShadow(shadows[i]);
2045 new WebInspector.ColorSwatchPopoverIcon(this, swatchPopoverHelper, c ssShadowSwatch.colorSwatch());
2046 container.appendChild(cssShadowSwatch);
2047 }
2048 return container;
2049 },
2050
2021 _updateState: function() 2051 _updateState: function()
2022 { 2052 {
2023 if (!this.listItemElement) 2053 if (!this.listItemElement)
2024 return; 2054 return;
2025 2055
2026 if (this._style.isPropertyImplicit(this.name)) 2056 if (this._style.isPropertyImplicit(this.name))
2027 this.listItemElement.classList.add("implicit"); 2057 this.listItemElement.classList.add("implicit");
2028 else 2058 else
2029 this.listItemElement.classList.remove("implicit"); 2059 this.listItemElement.classList.remove("implicit");
2030 2060
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 updateTitle: function() 2204 updateTitle: function()
2175 { 2205 {
2176 this._updateState(); 2206 this._updateState();
2177 this._expandElement = createElement("span"); 2207 this._expandElement = createElement("span");
2178 this._expandElement.className = "expand-element"; 2208 this._expandElement.className = "expand-element";
2179 2209
2180 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._style.parentRule, this.node(), this.name, this.value); 2210 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._style.parentRule, this.node(), this.name, this.value);
2181 if (this.property.parsedOk) { 2211 if (this.property.parsedOk) {
2182 propertyRenderer.setColorHandler(this._processColor.bind(this)); 2212 propertyRenderer.setColorHandler(this._processColor.bind(this));
2183 propertyRenderer.setBezierHandler(this._processBezier.bind(this)); 2213 propertyRenderer.setBezierHandler(this._processBezier.bind(this));
2214 propertyRenderer.setShadowHandler(this._processShadow.bind(this));
2184 } 2215 }
2185 2216
2186 this.listItemElement.removeChildren(); 2217 this.listItemElement.removeChildren();
2187 this.nameElement = propertyRenderer.renderName(); 2218 this.nameElement = propertyRenderer.renderName();
2188 this.valueElement = propertyRenderer.renderValue(); 2219 this.valueElement = propertyRenderer.renderValue();
2189 if (!this.treeOutline) 2220 if (!this.treeOutline)
2190 return; 2221 return;
2191 2222
2192 var indent = WebInspector.moduleSetting("textEditorIndent").get(); 2223 var indent = WebInspector.moduleSetting("textEditorIndent").get();
2193 this.listItemElement.createChild("span", "styles-clipboard-only").create TextChild(indent + (this.property.disabled ? "/* " : "")); 2224 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
2985 3016
2986 /** 3017 /**
2987 * @param {function(string):!Node} handler 3018 * @param {function(string):!Node} handler
2988 */ 3019 */
2989 setBezierHandler: function(handler) 3020 setBezierHandler: function(handler)
2990 { 3021 {
2991 this._bezierHandler = handler; 3022 this._bezierHandler = handler;
2992 }, 3023 },
2993 3024
2994 /** 3025 /**
3026 * @param {function(string, string):!Node} handler
3027 */
3028 setShadowHandler: function(handler)
3029 {
3030 this._shadowHandler = handler;
3031 },
3032
3033 /**
2995 * @return {!Element} 3034 * @return {!Element}
2996 */ 3035 */
2997 renderName: function() 3036 renderName: function()
2998 { 3037 {
2999 var nameElement = createElement("span"); 3038 var nameElement = createElement("span");
3000 nameElement.className = "webkit-css-property"; 3039 nameElement.className = "webkit-css-property";
3001 nameElement.textContent = this._propertyName; 3040 nameElement.textContent = this._propertyName;
3002 nameElement.normalize(); 3041 nameElement.normalize();
3003 return nameElement; 3042 return nameElement;
3004 }, 3043 },
3005 3044
3006 /** 3045 /**
3007 * @return {!Element} 3046 * @return {!Element}
3008 */ 3047 */
3009 renderValue: function() 3048 renderValue: function()
3010 { 3049 {
3011 var valueElement = createElement("span"); 3050 var valueElement = createElement("span");
3012 valueElement.className = "value"; 3051 valueElement.className = "value";
3013 if (!this._propertyValue) 3052 if (!this._propertyValue)
3014 return valueElement; 3053 return valueElement;
3015 3054
3055 if (this._shadowHandler && (this._propertyName === "box-shadow" || this. _propertyName === "text-shadow")
3056 && !WebInspector.CSSMetadata.VariableRegex.test(this._propertyVa lue) && Runtime.experiments.isEnabled("shadowEditor")) {
3057 valueElement.appendChild(this._shadowHandler(this._propertyValue, th is._propertyName));
3058 valueElement.normalize();
3059 return valueElement;
3060 }
3061
3016 var regexes = [WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSM etadata.URLRegex]; 3062 var regexes = [WebInspector.CSSMetadata.VariableRegex, WebInspector.CSSM etadata.URLRegex];
3017 var processors = [createTextNode, this._processURL.bind(this)]; 3063 var processors = [createTextNode, this._processURL.bind(this)];
3018 if (this._bezierHandler && WebInspector.cssMetadata().isBezierAwarePrope rty(this._propertyName)) { 3064 if (this._bezierHandler && WebInspector.cssMetadata().isBezierAwarePrope rty(this._propertyName)) {
3019 regexes.push(WebInspector.Geometry.CubicBezier.Regex); 3065 regexes.push(WebInspector.Geometry.CubicBezier.Regex);
3020 processors.push(this._bezierHandler); 3066 processors.push(this._bezierHandler);
3021 } 3067 }
3022 if (this._colorHandler && WebInspector.cssMetadata().isColorAwarePropert y(this._propertyName)) { 3068 if (this._colorHandler && WebInspector.cssMetadata().isColorAwarePropert y(this._propertyName)) {
3023 regexes.push(WebInspector.Color.Regex); 3069 regexes.push(WebInspector.Color.Regex);
3024 processors.push(this._colorHandler); 3070 processors.push(this._colorHandler);
3025 } 3071 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3099 3145
3100 /** 3146 /**
3101 * @override 3147 * @override
3102 * @return {!WebInspector.ToolbarItem} 3148 * @return {!WebInspector.ToolbarItem}
3103 */ 3149 */
3104 item: function() 3150 item: function()
3105 { 3151 {
3106 return this._button; 3152 return this._button;
3107 } 3153 }
3108 } 3154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698