зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1154809 - remove dead css-parsing code; r=pbrosset
This commit is contained in:
Родитель
9bf022ea63
Коммит
c82c12171e
|
@ -42,7 +42,6 @@ function testColorUtils(canvas) {
|
|||
testColorMatch(name, hex, hsl, rgb, color.rgba, canvas);
|
||||
}
|
||||
|
||||
testProcessCSSString();
|
||||
testSetAlpha();
|
||||
}
|
||||
|
||||
|
@ -106,20 +105,6 @@ function testColorMatch(name, hex, hsl, rgb, rgba, canvas) {
|
|||
test(rgb, "rgb");
|
||||
}
|
||||
|
||||
function testProcessCSSString() {
|
||||
let before = "border: 1px solid red; border-radius: 5px; " +
|
||||
"color rgb(0, 255, 0); font-weight: bold; " +
|
||||
"background-color: transparent; " +
|
||||
"border-top-color: rgba(0, 0, 255, 0.5);";
|
||||
let expected = "border: 1px solid #F00; border-radius: 5px; " +
|
||||
"color #0F0; font-weight: bold; " +
|
||||
"background-color: transparent; " +
|
||||
"border-top-color: rgba(0, 0, 255, 0.5);";
|
||||
let after = colorUtils.processCSSString(before);
|
||||
|
||||
is(after, expected, "CSS string processed correctly");
|
||||
}
|
||||
|
||||
function testSetAlpha() {
|
||||
let values = [
|
||||
["longhex", "#ff0000", 0.5, "rgba(255, 0, 0, 0.5)"],
|
||||
|
|
|
@ -35,9 +35,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "VariablesViewController",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
const GRADIENT_RE = /\b(repeating-)?(linear|radial)-gradient\(((rgb|hsl)a?\(.+?\)|[^\)])+\)/gi;
|
||||
const BORDERCOLOR_RE = /^border-[-a-z]*color$/ig;
|
||||
const BORDER_RE = /^border(-(top|bottom|left|right))?$/ig;
|
||||
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
const SPECTRUM_FRAME = "chrome://browser/content/devtools/spectrum-frame.xhtml";
|
||||
const CUBIC_BEZIER_FRAME = "chrome://browser/content/devtools/cubic-bezier-frame.xhtml";
|
||||
|
|
|
@ -34,15 +34,9 @@ const FILTER_CHANGED_TIMEOUT = 150;
|
|||
* used to parse CSSStyleDeclaration's cssText attribute.
|
||||
*/
|
||||
|
||||
// Used to split on css line separators
|
||||
const CSS_LINE_RE = /(?:[^;\(]*(?:\([^\)]*?\))?[^;\(]*)*;?/g;
|
||||
|
||||
// Used to parse a single property line.
|
||||
const CSS_PROP_RE = /\s*([^:\s]*)\s*:\s*(.*?)\s*(?:! (important))?;?$/;
|
||||
|
||||
// Used to parse an external resource from a property value
|
||||
const CSS_RESOURCE_RE = /url\([\'\"]?(.*?)[\'\"]?\)/;
|
||||
|
||||
const IOService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
|
||||
|
@ -2855,22 +2849,6 @@ TextPropertyEditor.prototype = {
|
|||
return relativePath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check the property value to find an external resource (if any).
|
||||
* @return {string} the URI in the property value, or null if there is no match.
|
||||
*/
|
||||
getResourceURI: function() {
|
||||
let val = this.prop.value;
|
||||
let uriMatch = CSS_RESOURCE_RE.exec(val);
|
||||
let uri = null;
|
||||
|
||||
if (uriMatch && uriMatch[1]) {
|
||||
uri = uriMatch[1];
|
||||
}
|
||||
|
||||
return uri;
|
||||
},
|
||||
|
||||
/**
|
||||
* Populate the span based on changes to the TextProperty.
|
||||
*/
|
||||
|
|
|
@ -9,25 +9,8 @@ const {Services} = Cu.import("resource://gre/modules/Services.jsm", {});
|
|||
|
||||
const COLOR_UNIT_PREF = "devtools.defaultColorUnit";
|
||||
|
||||
const REGEX_JUST_QUOTES = /^""$/;
|
||||
const REGEX_HSL_3_TUPLE = /^\bhsl\(([\d.]+),\s*([\d.]+%),\s*([\d.]+%)\)$/i;
|
||||
|
||||
/**
|
||||
* This regex matches:
|
||||
* - #F00
|
||||
* - #FF0000
|
||||
* - hsl()
|
||||
* - hsla()
|
||||
* - rgb()
|
||||
* - rgba()
|
||||
* - red
|
||||
*
|
||||
* It also matches css keywords e.g. "background-color" otherwise
|
||||
* "background" would be replaced with #6363CE ("background" is a platform
|
||||
* color).
|
||||
*/
|
||||
const REGEX_ALL_COLORS = /#[0-9a-fA-F]{3}\b|#[0-9a-fA-F]{6}\b|hsl\(.*?\)|hsla\(.*?\)|rgba?\(.*?\)|\b[a-zA-Z-]+\b/g;
|
||||
|
||||
const SPECIALVALUES = new Set([
|
||||
"currentcolor",
|
||||
"initial",
|
||||
|
@ -66,9 +49,6 @@ const SPECIALVALUES = new Set([
|
|||
* // Color objects can be reused
|
||||
* color.newColor("green") === "#0F0"; // true
|
||||
*
|
||||
* let processed = colorUtils.processCSSString("color:red; background-color:green;");
|
||||
* // Returns "color:#F00; background-color:#0F0;"
|
||||
*
|
||||
* Valid values for COLOR_UNIT_PREF are contained in CssColor.COLORUNIT.
|
||||
*/
|
||||
|
||||
|
@ -78,7 +58,6 @@ function CssColor(colorValue) {
|
|||
|
||||
module.exports.colorUtils = {
|
||||
CssColor: CssColor,
|
||||
processCSSString: processCSSString,
|
||||
rgbToHsl: rgbToHsl,
|
||||
setAlpha: setAlpha
|
||||
};
|
||||
|
@ -364,31 +343,6 @@ CssColor.prototype = {
|
|||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Process a CSS string
|
||||
*
|
||||
* @param {String} value
|
||||
* CSS string e.g. "color:red; background-color:green;"
|
||||
* @return {String}
|
||||
* Converted CSS String e.g. "color:#F00; background-color:#0F0;"
|
||||
*/
|
||||
function processCSSString(value) {
|
||||
if (value && REGEX_JUST_QUOTES.test(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
let colorPattern = REGEX_ALL_COLORS;
|
||||
|
||||
value = value.replace(colorPattern, function(match) {
|
||||
let color = new CssColor(match);
|
||||
if (color.valid) {
|
||||
return color;
|
||||
}
|
||||
return match;
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert rgb value to hsl
|
||||
*
|
||||
|
|
|
@ -42,14 +42,6 @@ const { Cc, Ci, Cu } = require("chrome");
|
|||
const Services = require("Services");
|
||||
const DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
|
||||
|
||||
const RX_UNIVERSAL_SELECTOR = /\s*\*\s*/g;
|
||||
const RX_NOT = /:not\((.*?)\)/g;
|
||||
const RX_PSEUDO_CLASS_OR_ELT = /(:[\w-]+\().*?\)/g;
|
||||
const RX_CONNECTORS = /\s*[\s>+~]\s*/g;
|
||||
const RX_ID = /\s*#\w+\s*/g;
|
||||
const RX_CLASS_OR_ATTRIBUTE = /\s*(?:\.\w+|\[.+?\])\s*/g;
|
||||
const RX_PSEUDO = /\s*:?:([\w-]+)(\(?\)?)\s*/g;
|
||||
|
||||
// This should be ok because none of the functions that use this should be used
|
||||
// on the worker thread, where Cu is not available.
|
||||
if (Cu) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче