You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/12/17 01:07:21 UTC
git commit: [flex-falcon] [refs/heads/develop] - get more
CSS-compliant output
Repository: flex-falcon
Updated Branches:
refs/heads/develop 8412f4100 -> 7dc84ed2c
get more CSS-compliant output
Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/7dc84ed2
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/7dc84ed2
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/7dc84ed2
Branch: refs/heads/develop
Commit: 7dc84ed2ca86c6a1f5f4340fdd255955f4d24580
Parents: 8412f41
Author: Alex Harui <ah...@apache.org>
Authored: Tue Dec 16 16:06:53 2014 -0800
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Dec 16 16:06:53 2014 -0800
----------------------------------------------------------------------
.../js/flexjs/JSCSSCompilationSession.java | 79 +++++++++++++++++++-
.../flex/compiler/internal/css/CSSProperty.java | 20 +++++
2 files changed, 96 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7dc84ed2/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
index 453d5d4..d4a67af 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/driver/js/flexjs/JSCSSCompilationSession.java
@@ -19,6 +19,8 @@
package org.apache.flex.compiler.internal.driver.js.flexjs;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import org.apache.flex.compiler.constants.IASLanguageConstants;
import org.apache.flex.compiler.css.ICSSDocument;
@@ -34,10 +36,12 @@ import org.apache.flex.compiler.internal.css.CSSColorPropertyValue;
import org.apache.flex.compiler.internal.css.CSSFunctionCallPropertyValue;
import org.apache.flex.compiler.internal.css.CSSKeywordPropertyValue;
import org.apache.flex.compiler.internal.css.CSSNumberPropertyValue;
+import org.apache.flex.compiler.internal.css.CSSProperty;
import org.apache.flex.compiler.internal.css.CSSRgbColorPropertyValue;
import org.apache.flex.compiler.internal.css.CSSStringPropertyValue;
import org.apache.flex.compiler.internal.css.codegen.CSSCompilationSession;
+import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
public class JSCSSCompilationSession extends CSSCompilationSession
@@ -68,14 +72,77 @@ public class JSCSSCompilationSession extends CSSCompilationSession
return sb.toString();
}
+ private String cssRuleToString(ICSSRule rule)
+ {
+ final StringBuilder result = new StringBuilder();
+
+ ImmutableList<ICSSMediaQueryCondition> mqList = rule.getMediaQueryConditions();
+ boolean hasMediaQuery = !mqList.isEmpty();
+ if (hasMediaQuery)
+ {
+ result.append("@media ");
+ result.append(Joiner.on(" and ").join(rule.getMediaQueryConditions()));
+ result.append(" {\n");
+ result.append(" ");
+ }
+
+ ImmutableList<ICSSSelector> selectors = rule.getSelectorGroup();
+ boolean firstOne = true;
+ for (ICSSSelector selector : selectors)
+ {
+ String s = selector.toString();
+ // add "." to type selectors that don't map cleanly
+ // to CSS type selectors to convert them to class
+ // selectors.
+ if (!s.startsWith(".") && !s.startsWith("*"))
+ {
+ String condition = null;
+ int colon = s.indexOf(":");
+ if (colon != -1)
+ {
+ condition = s.substring(colon);
+ s = s.substring(0, colon);
+ }
+ if (!htmlElementNames.contains(s.toLowerCase()))
+ s = "." + s;
+ if (condition != null)
+ s = s + condition;
+ }
+ if (!firstOne)
+ result.append(",\n");
+ result.append(s);
+ }
+
+ result.append(" {\n");
+ for (final ICSSProperty prop : rule.getProperties())
+ {
+ if (!hasMediaQuery)
+ result.append(" ");
+
+ String propString = ((CSSProperty)prop).toCSSString();
+ // skip class references since the won't work in CSS
+ if (propString.contains("ClassReference"))
+ continue;
+ result.append(" ").append(propString).append("\n");
+ }
+ if (hasMediaQuery)
+ result.append(" }\n");
+
+ result.append("}\n");
+
+ return result.toString();
+ }
+
private void walkCSS(ICSSDocument css, StringBuilder sb)
{
ImmutableList<ICSSRule> rules = css.getRules();
for (ICSSRule rule : rules)
{
- String s = rule.toString();
- if (s.startsWith("global {"))
- s = s.replace("global {", "* {");
+ String s = cssRuleToString(rule);
+ if (s.startsWith("@media -flex-flash"))
+ continue;
+ if (s.startsWith(".global {"))
+ s = s.replace(".global {", "* {");
sb.append(s);
sb.append("\n\n");
}
@@ -99,6 +166,12 @@ public class JSCSSCompilationSession extends CSSCompilationSession
}
}
+ List<String> htmlElementNames = Arrays.asList(
+ "body",
+ "button",
+ "span"
+ );
+
private String encodeRule(ICSSRule rule)
{
final StringBuilder result = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7dc84ed2/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java b/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
index 3c7bc87..76ffced 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/CSSProperty.java
@@ -65,6 +65,26 @@ public class CSSProperty extends CSSNodeBase implements ICSSProperty
return String.format("%s : %s ;", rawName, value.toString());
}
+ public String toCSSString()
+ {
+ String cssName = rawName;
+ if (!rawName.equals(rawName.toLowerCase()))
+ {
+ cssName = cssName.replaceAll("[A-Z]", "-$0").toLowerCase();
+ }
+ if (value instanceof CSSStringPropertyValue)
+ {
+ return String.format("%s : %s ;", cssName, ((CSSStringPropertyValue)value).getValue());
+ }
+ if (cssName.equalsIgnoreCase("border"))
+ {
+ CSSArrayPropertyValue borderValues = (CSSArrayPropertyValue)value;
+ return String.format("%s : %s ;", cssName, Joiner.on(" ").join(borderValues.getElements()));
+ }
+ return String.format("%s : %s ;", cssName, value.toString());
+ }
+
+
/**
* Normalize CSS property names to camel-case style names. Names alread in
* camel-cases will be returned as-is.