From 98daa6adf490e5a3e70994e8ccabea0fa1ccefbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Due=C3=B1as?= Date: Wed, 18 May 2011 22:41:58 -0400 Subject: [PATCH 1/5] Border and Outline declarations dont breakdown anymore :) --- stylebot/js/libs/parser.js | 64 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/stylebot/js/libs/parser.js b/stylebot/js/libs/parser.js index 657ebe22..f8b8e739 100644 --- a/stylebot/js/libs/parser.js +++ b/stylebot/js/libs/parser.js @@ -2819,6 +2819,64 @@ CSSParser.prototype = { return bWidth + " " + bStyle + " " + bColor; }, + parseBorderShorthand: function(token, aDecl, aAcceptPriority, aProperty) + { + var bWidth = null; + var bStyle = null; + var bColor = null; + + while (true) { + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!bWidth && !bStyle && !bColor + && token.isIdent(this.kINHERIT)) { + bWidth = this.kINHERIT; + bStyle = this.kINHERIT; + bColor = this.kINHERIT; + } + + else if (!bWidth && + (token.isDimension() + || (token.isIdent() && token.value in this.kBORDER_WIDTH_NAMES) + || token.isNumber("0"))) { + bWidth = token.value; + } + + else if (!bStyle && + (token.isIdent() && token.value in this.kBORDER_STYLE_NAMES)) { + bStyle = token.value; + } + + else { + var color = (aProperty == "outline" && token.isIdent("invert")) + ? "invert" : this.parseColor(token); + if (!bColor && color) + bColor = color; + else + return ""; + } + token = this.getToken(true, true); + } + + // create the declarations + this.forgetState(); + var decl = ""; + decl += bWidth ? bWidth : ""; + decl += bStyle ? (bWidth ? " " : "" ) + bStyle : ""; + decl += bColor ? (bWidth || bStyle ? " " : "" ) + bColor : ""; + aDecl.push(this._createJscsspDeclarationFromValue(aProperty, decl)); + return decl; + }, + parseBackgroundShorthand: function(token, aDecl, aAcceptPriority) { var kHPos = {"left": true, "right": true }; @@ -3424,7 +3482,9 @@ CSSParser.prototype = { case "border-left": case "border": case "outline": - value = this.parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); + /// @rduenasf the next line is commented out so we can avoid the declaration breakdown + //value = this.parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); + value = this.parseBorderShorthand(token, declarations, aAcceptPriority, descriptor); break; case "cue": value = this.parseCueShorthand(token, declarations, aAcceptPriority); @@ -3683,7 +3743,7 @@ CSSParser.prototype = { if (token.isWhiteSpace()) s += " "; else - s += token.value; + s += token.value + " "; if (token.isSymbol(">") || token.isSymbol("+") || token.isSymbol("~")) From 10f3c693ed16d7e867a17b098fc1fa765c48d390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Due=C3=B1as?= Date: Wed, 18 May 2011 22:49:44 -0400 Subject: [PATCH 2/5] Fixed a bug in the options page, causing custom styles to be shown multiple times after editing --- stylebot/js/options.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stylebot/js/options.js b/stylebot/js/options.js index 98c82ebc..1a3a7673 100644 --- a/stylebot/js/options.js +++ b/stylebot/js/options.js @@ -314,14 +314,14 @@ function onAdd() { if (css === "") return false; - if (saveStyle(url, css)) { + if (saveStyle(url, css, true)) { cache.modal.hide(); } } // Saves a style and updates the UI. Called by onSave and onAdd // -function saveStyle(url, css) { +function saveStyle(url, css, add) { // if css is empty. remove the style if (css === "") { @@ -362,7 +362,8 @@ function saveStyle(url, css) { bg_window.saveStyles(styles); bg_window.pushStyles(); - createCustomStyleOption(url, styles[url]).appendTo($("#custom-styles")); + if (add) + createCustomStyleOption(url, styles[url]).appendTo($("#custom-styles")); return true; } From c17d542144193d7867a0d8ef12fa51e7b90b53ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Due=C3=B1as?= Date: Wed, 18 May 2011 23:05:45 -0400 Subject: [PATCH 3/5] Background declaration doesnt breakdown anymore :) --- stylebot/js/libs/parser.js | 128 ++++++++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 3 deletions(-) diff --git a/stylebot/js/libs/parser.js b/stylebot/js/libs/parser.js index f8b8e739..97ca415f 100644 --- a/stylebot/js/libs/parser.js +++ b/stylebot/js/libs/parser.js @@ -2819,7 +2819,7 @@ CSSParser.prototype = { return bWidth + " " + bStyle + " " + bColor; }, - parseBorderShorthand: function(token, aDecl, aAcceptPriority, aProperty) + stylebot_parseBorderEdgeOrOutlineShorthand: function(token, aDecl, aAcceptPriority, aProperty) { var bWidth = null; var bStyle = null; @@ -3003,6 +3003,128 @@ CSSParser.prototype = { return bgColor + " " + bgImage + " " + bgRepeat + " " + bgAttachment + " " + bgPosition; }, + stylebot_parseBackgroundShorthand: function(token, aDecl, aAcceptPriority) + { + var kHPos = {"left": true, "right": true }; + var kVPos = {"top": true, "bottom": true }; + var kPos = {"left": true, "right": true, "top": true, "bottom": true, "center": true}; + + var bgColor = null; + var bgRepeat = null; + var bgAttachment = null; + var bgImage = null; + var bgPosition = null; + + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!bgColor && !bgRepeat && !bgAttachment && !bgImage && !bgPosition + && token.isIdent(this.kINHERIT)) { + bgColor = this.kINHERIT; + bgRepeat = this.kINHERIT; + bgAttachment = this.kINHERIT; + bgImage = this.kINHERIT; + bgPosition = this.kINHERIT; + } + + else { + if (!bgAttachment && + (token.isIdent("scroll") + || token.isIdent("fixed"))) { + bgAttachment = token.value; + } + + else if (!bgPosition && + ((token.isIdent() && token.value in kPos) + || token.isDimension() + || token.isNumber("0") + || token.isPercentage())) { + bgPosition = token.value; + token = this.getToken(true, true); + if (token.isDimension() || token.isNumber("0") || token.isPercentage()) { + bgPosition += " " + token.value; + } + else if (token.isIdent() && token.value in kPos) { + if ((bgPosition in kHPos && token.value in kHPos) || + (bgPosition in kVPos && token.value in kVPos)) + return ""; + bgPosition += " " + token.value; + } + else { + this.ungetToken(); + bgPosition += " center"; + } + } + + else if (!bgRepeat && + (token.isIdent("repeat") + || token.isIdent("repeat-x") + || token.isIdent("repeat-y") + || token.isIdent("no-repeat"))) { + bgRepeat = token.value; + } + + else if (!bgImage && + (token.isFunction("url(") + || token.isIdent("none"))) { + bgImage = token.value; + if (token.isFunction("url(")) { + token = this.getToken(true, true); + var url = this.parseURL(token); // TODO + if (url) + bgImage += url; + else + return ""; + } + } + + else if (!bgImage && + (token.isFunction("-moz-linear-gradient(") + || token.isFunction("-moz-radial-gradient(") + || token.isFunction("-moz-repeating-linear-gradient(") + || token.isFunction("-moz-repeating-radial-gradient("))) { + var gradient = CssInspector.parseGradient(this, token); + if (gradient) + bgImage = CssInspector.serializeGradient(gradient); + else + return ""; + } + + else { + var color = this.parseColor(token); + if (!bgColor && color) + bgColor = color; + else + return ""; + } + + } + + token = this.getToken(true, true); + } + + // create the declarations + this.forgetState(); + var decl = ""; + decl += bgColor ? bgColor : ""; + decl += bgImage ? ( bgColor ? " " : "" ) + bgImage : ""; + decl += bgRepeat ? ( bgColor || bgImage ? " " : "" ) + bgRepeat : ""; + decl += bgAttachment ? ( bgColor || bgImage || bgRepeat ? " " : "" ) + bgAttachment : ""; + decl += bgPosition ? ( bgColor || bgImage || bgRepeat || bgAttachment ? " " : "" ) + bgPosition : ""; + aDecl.push(this._createJscsspDeclarationFromValue("background", decl)); + return decl; + }, + parseListStyleShorthand: function(token, aDecl, aAcceptPriority) { var kPosition = { "inside": true, "outside": true }; @@ -3461,7 +3583,7 @@ CSSParser.prototype = { if (aExpandShorthands) switch (descriptor) { case "background": - value = this.parseBackgroundShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parseBackgroundShorthand(token, declarations, aAcceptPriority); break; case "margin": case "padding": @@ -3484,7 +3606,7 @@ CSSParser.prototype = { case "outline": /// @rduenasf the next line is commented out so we can avoid the declaration breakdown //value = this.parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); - value = this.parseBorderShorthand(token, declarations, aAcceptPriority, descriptor); + value = this.stylebot_parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); break; case "cue": value = this.parseCueShorthand(token, declarations, aAcceptPriority); From 822d1e9f93311b94b60fc59935f7c122459d546b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Due=C3=B1as?= Date: Wed, 18 May 2011 23:19:35 -0400 Subject: [PATCH 4/5] border-color, margin and padding dont breakdown anymore too --- stylebot/js/libs/parser.js | 109 ++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 3 deletions(-) diff --git a/stylebot/js/libs/parser.js b/stylebot/js/libs/parser.js index 97ca415f..9a05d4d5 100644 --- a/stylebot/js/libs/parser.js +++ b/stylebot/js/libs/parser.js @@ -2415,6 +2415,58 @@ CSSParser.prototype = { return top + " " + right + " " + bottom + " " + left; }, + stylebot_parseMarginOrPaddingShorthand: function(token, aDecl, aAcceptPriority, aProperty) + { + var top = null; + var bottom = null; + var left = null; + var right = null; + + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + token = this.getToken(true, true); + break; + } + + else if (token.isDimension() + || token.isNumber("0") + || token.isPercentage() + || token.isIdent("auto")) { + values.push(token.value); + } + else + return ""; + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 4) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue(aProperty, decl)); + return decl; + }, + parseBorderColorShorthand: function(token, aDecl, aAcceptPriority) { var top = null; @@ -2490,6 +2542,57 @@ CSSParser.prototype = { return top + " " + right + " " + bottom + " " + left; }, + stylebot_parseBorderColorShorthand: function(token, aDecl, aAcceptPriority) + { + var top = null; + var bottom = null; + var left = null; + var right = null; + + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + token = this.getToken(true, true); + break; + } + + else { + var color = this.parseColor(token); + if (color) + values.push(color); + else + return ""; + } + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 4) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue("border-color", decl)); + return decl; + }, + parseCueShorthand: function(token, declarations, aAcceptPriority) { var before = ""; @@ -3583,11 +3686,12 @@ CSSParser.prototype = { if (aExpandShorthands) switch (descriptor) { case "background": + // @rduenasf the next line was changed so we can avoid the declaration breakdown value = this.stylebot_parseBackgroundShorthand(token, declarations, aAcceptPriority); break; case "margin": case "padding": - value = this.parseMarginOrPaddingShorthand(token, declarations, aAcceptPriority, descriptor); + value = this.stylebot_parseMarginOrPaddingShorthand(token, declarations, aAcceptPriority, descriptor); break; case "border-color": value = this.parseBorderColorShorthand(token, declarations, aAcceptPriority); @@ -3604,8 +3708,7 @@ CSSParser.prototype = { case "border-left": case "border": case "outline": - /// @rduenasf the next line is commented out so we can avoid the declaration breakdown - //value = this.parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); + // @rduenasf the next line was changed so we can avoid the declaration breakdown value = this.stylebot_parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); break; case "cue": From 666c75fff035b46fa7737d3259db3df43f5a9425 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Due=C3=B1as?= Date: Wed, 18 May 2011 23:58:55 -0400 Subject: [PATCH 5/5] everything else except for font dont breakdown anymore --- stylebot/js/libs/parser.js | 273 ++++++++++++++++++++++++++++++++++++- 1 file changed, 268 insertions(+), 5 deletions(-) diff --git a/stylebot/js/libs/parser.js b/stylebot/js/libs/parser.js index 9a05d4d5..63f3a030 100644 --- a/stylebot/js/libs/parser.js +++ b/stylebot/js/libs/parser.js @@ -2653,6 +2653,60 @@ CSSParser.prototype = { return before + " " + after; }, + stylebot_parseCueShorthand: function(token, declarations, aAcceptPriority) + { + var before = ""; + var after = ""; + + var values = []; + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + } + + else if (token.isIdent("none")) + values.push(token.value); + + else if (token.isFunction("url(")) { + var token = this.getToken(true, true); + var urlContent = this.parseURL(token); + if (urlContent) + values.push("url(" + urlContent); + else + return ""; + } + else + return ""; + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 2) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue("cue", decl)); + return decl; + }, + parsePauseShorthand: function(token, declarations, aAcceptPriority) { var before = ""; @@ -2707,6 +2761,54 @@ CSSParser.prototype = { return before + " " + after; }, + stylebot_parsePauseShorthand: function(token, declarations, aAcceptPriority) + { + var before = ""; + var after = ""; + + var values = []; + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + } + + else if (token.isDimensionOfUnit("ms") + || token.isDimensionOfUnit("s") + || token.isPercentage() + || token.isNumber("0")) + values.push(token.value); + else + return ""; + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 2) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue("pause", decl)); + return decl; + }, + parseBorderWidthShorthand: function(token, aDecl, aAcceptPriority) { var top = null; @@ -2780,6 +2882,55 @@ CSSParser.prototype = { return top + " " + right + " " + bottom + " " + left; }, + stylebot_parseBorderWidthShorthand: function(token, aDecl, aAcceptPriority) + { + var top = null; + var bottom = null; + var left = null; + var right = null; + + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + } + + else if (token.isDimension() + || token.isNumber("0") + || (token.isIdent() && token.value in this.kBORDER_WIDTH_NAMES)) { + values.push(token.value); + } + else + return ""; + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 4) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue("border-width", decl)); + return decl; + }, + parseBorderStyleShorthand: function(token, aDecl, aAcceptPriority) { var top = null; @@ -2851,6 +3002,53 @@ CSSParser.prototype = { return top + " " + right + " " + bottom + " " + left; }, + stylebot_parseBorderStyleShorthand: function(token, aDecl, aAcceptPriority) + { + var top = null; + var bottom = null; + var left = null; + var right = null; + + var values = []; + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!values.length && token.isIdent(this.kINHERIT)) { + values.push(token.value); + } + + else if (token.isIdent() && token.value in this.kBORDER_STYLE_NAMES) { + values.push(token.value); + } + else + return ""; + + token = this.getToken(true, true); + } + + this.forgetState(); + + var count = values.length; + var decl = ""; + if (count < 1 || count > 4) return ""; + for(var i = 0;i < count;i++) { + decl += values[i]; + if(i < count - 1) decl += " "; + } + aDecl.push(this._createJscsspDeclarationFromValue("border-style", decl)); + return decl; + }, + parseBorderEdgeOrOutlineShorthand: function(token, aDecl, aAcceptPriority, aProperty) { var bWidth = null; @@ -3293,6 +3491,71 @@ CSSParser.prototype = { return lType + " " + lPosition + " " + lImage; }, + parseListStyleShorthand: function(token, aDecl, aAcceptPriority) + { + var kPosition = { "inside": true, "outside": true }; + + var lType = null; + var lPosition = null; + var lImage = null; + + while (true) { + + if (!token.isNotNull()) + break; + + if (token.isSymbol(";") + || (aAcceptPriority && token.isSymbol("!")) + || token.isSymbol("}")) { + if (token.isSymbol("}")) + this.ungetToken(); + break; + } + + else if (!lType && !lPosition && ! lImage + && token.isIdent(this.kINHERIT)) { + lType = this.kINHERIT; + lPosition = this.kINHERIT; + lImage = this.kINHERIT; + } + + else if (!lType && + (token.isIdent() && token.value in this.kLIST_STYLE_TYPE_NAMES)) { + lType = token.value; + } + + else if (!lPosition && + (token.isIdent() && token.value in kPosition)) { + lPosition = token.value; + } + + else if (!lImage && token.isFunction("url")) { + token = this.getToken(true, true); + var urlContent = this.parseURL(token); + if (urlContent) { + lImage = "url(" + urlContent; + } + else + return ""; + } + else if (!token.isIdent("none")) + return ""; + + token = this.getToken(true, true); + } + + // create the declarations + this.forgetState(); + lType = lType ? lType : "none"; + lImage = lImage ? lImage : "none"; + lPosition = lPosition ? lPosition : "outside"; + + aDecl.push(this._createJscsspDeclarationFromValue("list-style-type", lType)); + aDecl.push(this._createJscsspDeclarationFromValue("list-style-position", lPosition)); + aDecl.push(this._createJscsspDeclarationFromValue("list-style-image", lImage)); + return lType + " " + lPosition + " " + lImage; + }, + parseFontShorthand: function(token, aDecl, aAcceptPriority) { var kStyle = {"italic": true, "oblique": true }; @@ -3694,13 +3957,13 @@ CSSParser.prototype = { value = this.stylebot_parseMarginOrPaddingShorthand(token, declarations, aAcceptPriority, descriptor); break; case "border-color": - value = this.parseBorderColorShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parseBorderColorShorthand(token, declarations, aAcceptPriority); break; case "border-style": - value = this.parseBorderStyleShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parseBorderStyleShorthand(token, declarations, aAcceptPriority); break; case "border-width": - value = this.parseBorderWidthShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parseBorderWidthShorthand(token, declarations, aAcceptPriority); break; case "border-top": case "border-right": @@ -3712,10 +3975,10 @@ CSSParser.prototype = { value = this.stylebot_parseBorderEdgeOrOutlineShorthand(token, declarations, aAcceptPriority, descriptor); break; case "cue": - value = this.parseCueShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parseCueShorthand(token, declarations, aAcceptPriority); break; case "pause": - value = this.parsePauseShorthand(token, declarations, aAcceptPriority); + value = this.stylebot_parsePauseShorthand(token, declarations, aAcceptPriority); break; case "font": value = this.parseFontShorthand(token, declarations, aAcceptPriority);