diff options
author | Henri Sara <hesara@vaadin.com> | 2012-08-09 14:45:42 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-08-09 14:45:42 +0300 |
commit | ef64d5becc40d85a5a27735775376062fa4ed8ff (patch) | |
tree | 4b90acdfb9e9ad0819303d01d5163c59a8c4781a /sass | |
parent | 30f0f85cf04edef6f04610ee9f8190ffe49585d8 (diff) | |
download | vaadin-framework-ef64d5becc40d85a5a27735775376062fa4ed8ff.tar.gz vaadin-framework-ef64d5becc40d85a5a27735775376062fa4ed8ff.zip |
Manual merge for SASS: fixed a bug in VariableVisitor
Diffstat (limited to 'sass')
-rw-r--r-- | sass/src/com/vaadin/sass/util/ColorUtil.java | 33 | ||||
-rw-r--r-- | sass/src/com/vaadin/sass/visitor/VariableVisitor.java | 29 |
2 files changed, 42 insertions, 20 deletions
diff --git a/sass/src/com/vaadin/sass/util/ColorUtil.java b/sass/src/com/vaadin/sass/util/ColorUtil.java index e65b3a80fa..9abcf57310 100644 --- a/sass/src/com/vaadin/sass/util/ColorUtil.java +++ b/sass/src/com/vaadin/sass/util/ColorUtil.java @@ -41,12 +41,12 @@ public class ColorUtil { StringBuilder builder = new StringBuilder("#"); for (int i = 0; i < 3; i++) { String color = Integer.toHexString(rgb[i]); - if (lengh == 3) { + if (lengh == 6) { if (color.length() == 1) { color = "0" + color; } } - if (lengh == 6) { + if (lengh == 3) { color = color.substring(0, 1); } builder.append(color); @@ -233,7 +233,7 @@ public class ColorUtil { public static LexicalUnitImpl darken(LexicalUnitImpl darkenFunc) { LexicalUnitImpl color = darkenFunc.getParameters(); - LexicalUnit amount = color.getNextLexicalUnit().getNextLexicalUnit(); + float amount = getAmountValue(color); LexicalUnitImpl pre = (LexicalUnitImpl) darkenFunc .getPreviousLexicalUnit(); @@ -241,7 +241,7 @@ public class ColorUtil { } private static LexicalUnitImpl adjust(LexicalUnitImpl color, - LexicalUnit amount, ColorOperation op, LexicalUnitImpl pre) { + float amountByPercent, ColorOperation op, LexicalUnitImpl pre) { if (color.getLexicalUnitType() == LexicalUnit.SAC_FUNCTION) { LexicalUnit funcParam = color.getParameters(); if ("hsl".equals(color.getFunctionName())) { @@ -251,12 +251,10 @@ public class ColorUtil { } float newValue = 0f; if (op == ColorOperation.Darken) { - newValue = lightness.getFloatValue() - - amount.getFloatValue(); + newValue = lightness.getFloatValue() - amountByPercent; newValue = newValue < 0 ? 0 : newValue; } else if (op == ColorOperation.Lighten) { - newValue = lightness.getFloatValue() - + amount.getFloatValue(); + newValue = lightness.getFloatValue() + amountByPercent; newValue = newValue > 100 ? 100 : newValue; } ((LexicalUnitImpl) lightness).setFloatValue(newValue); @@ -268,12 +266,13 @@ public class ColorUtil { } else if (color.getLexicalUnitType() == LexicalUnit.SAC_IDENT) { if (color.getStringValue().startsWith("#")) { return hslToHexColor( - adjust(hexColorToHsl(color), amount, op, pre), color - .getStringValue().substring(1).length()); + adjust(hexColorToHsl(color), amountByPercent, op, pre), + color.getStringValue().substring(1).length()); } } else if (color.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { LexicalUnitImpl hsl = rgbToHsl(color); - LexicalUnitImpl hslAfterDarken = adjust(hsl, amount, op, pre); + LexicalUnitImpl hslAfterDarken = adjust(hsl, amountByPercent, op, + pre); return hslToRgb(hslAfterDarken); } return color; @@ -281,13 +280,23 @@ public class ColorUtil { public static LexicalUnitImpl lighten(LexicalUnitImpl lightenFunc) { LexicalUnitImpl color = lightenFunc.getParameters(); - LexicalUnit amount = color.getNextLexicalUnit().getNextLexicalUnit(); + float amount = getAmountValue(color); LexicalUnitImpl pre = (LexicalUnitImpl) lightenFunc .getPreviousLexicalUnit(); return adjust(color, amount, ColorOperation.Lighten, pre); } + private static float getAmountValue(LexicalUnitImpl color) { + LexicalUnit next = color.getNextLexicalUnit(); + float amount = 10f; + if (next != null && next.getNextLexicalUnit() != null) { + next = next.getNextLexicalUnit(); + amount = next.getFloatValue(); + } + return amount; + } + enum ColorOperation { Darken, Lighten } diff --git a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java index 104b849780..8a567dacae 100644 --- a/sass/src/com/vaadin/sass/visitor/VariableVisitor.java +++ b/sass/src/com/vaadin/sass/visitor/VariableVisitor.java @@ -28,14 +28,7 @@ public class VariableVisitor implements Visitor { private void traverse(Node node, Map<String, LexicalUnitImpl> variables) { if (node instanceof RuleNode) { LexicalUnit value = ((RuleNode) node).getValue(); - for (String variable : variables.keySet()) { - if (value.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) { - if (value.getStringValue().contains(variable)) { - LexicalUnitImpl lexVal = (LexicalUnitImpl) value; - lexVal.replaceValue(variables.get(variable)); - } - } - } + updateValue(value, variables); } else { Set<Node> toBeDeleted = new HashSet<Node>(); for (Node child : node.getChildren()) { @@ -53,4 +46,24 @@ public class VariableVisitor implements Visitor { } } } + + private void updateValue(LexicalUnit value, + Map<String, LexicalUnitImpl> variables) { + if (value == null) { + return; + } + for (String variable : variables.keySet()) { + if (value.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) { + if (value.getStringValue().contains(variable)) { + LexicalUnitImpl lexVal = (LexicalUnitImpl) value; + lexVal.replaceValue(variables.get(variable)); + } + } else if (value.getLexicalUnitType() == SCSSLexicalUnit.SAC_FUNCTION) { + LexicalUnit params = value.getParameters(); + updateValue(params, variables); + } + } + LexicalUnit next = value.getNextLexicalUnit(); + updateValue(next, variables); + } } |